mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 01:04:29 +00:00
Guard tongues at cliffs
- Stop a tongue at plan time where its bed would pass maxFill over natural ground - Store stopped falls on the reach and in the plan codec - Keep settlement and raster on the same geometry rule - Test the cliff fixture on seeds 1..24 from half-width 3 to 18
This commit is contained in:
9 files changed
+330
-11
No files matched your search
+10
-2
@@ -24,7 +24,7 @@ public final class HydrologyPlanCodec {
|
||||
private static final byte WINDOW = 'W';
|
||||
private static final byte REGION = 'R';
|
||||
private static final int POINT_BYTES = 5 * Integer.BYTES + 1;
|
||||
private static final int REACH_BYTES = 2 * Long.BYTES + 3 * Integer.BYTES + 2 * POINT_BYTES;
|
||||
private static final int REACH_BYTES = 2 * Long.BYTES + 4 * Integer.BYTES + 2 * POINT_BYTES;
|
||||
private static final int POND_BYTES = 2 * Long.BYTES + 1 + 15 * Integer.BYTES;
|
||||
private static final int STATION_BYTES = 5 * Integer.BYTES;
|
||||
private static final int INLET_BYTES = Long.BYTES + 5 * Integer.BYTES + 2 * STATION_BYTES;
|
||||
@@ -102,6 +102,10 @@ public final class HydrologyPlanCodec {
|
||||
for (ReachStyle style : reach.style()) {
|
||||
out.writeByte(style.code());
|
||||
}
|
||||
out.writeInt(reach.straightFalls().length);
|
||||
for (int fall : reach.straightFalls()) {
|
||||
out.writeInt(fall);
|
||||
}
|
||||
}
|
||||
|
||||
private static void writePond(DataOutputStream out, Pond pond) throws IOException {
|
||||
@@ -211,7 +215,11 @@ public final class HydrologyPlanCodec {
|
||||
for (int point = 0; point < points; point++) {
|
||||
style[point] = ReachStyle.fromCode(Byte.toUnsignedInt(in.get()));
|
||||
}
|
||||
return new Reach(id, tier, downstreamId, xs, zs, grade, halfWidth, depth, style, catchment);
|
||||
int[] straightFalls = new int[count(in, Integer.BYTES)];
|
||||
for (int fall = 0; fall < straightFalls.length; fall++) {
|
||||
straightFalls[fall] = in.getInt();
|
||||
}
|
||||
return new Reach(id, tier, downstreamId, xs, zs, grade, halfWidth, depth, style, catchment, straightFalls);
|
||||
}
|
||||
|
||||
private static Pond readPond(ByteBuffer in) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import art.arcane.iris.generation.hydrology.grid.HeightLattice;
|
||||
import art.arcane.iris.generation.hydrology.grid.HydrologySampleBuffer;
|
||||
import art.arcane.iris.generation.hydrology.grid.PriorityFlood;
|
||||
import art.arcane.iris.generation.hydrology.raster.PondChannelSettlement;
|
||||
import art.arcane.iris.generation.hydrology.raster.TongueGuard;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletPlanner;
|
||||
import art.arcane.iris.generation.hydrology.water.CupSet;
|
||||
@@ -117,16 +118,16 @@ public final class WindowPlanner {
|
||||
basins.addAll(BasinExtractor.hollows(natural, inland, drainage.filled(), settings.seaLevel(), basins.size()));
|
||||
List<Pond> water = new ArrayList<>(ponds.ponds(raw, drainage.filled(), basins, lakes, fine, cups));
|
||||
water.addAll(lakes);
|
||||
ShapedNetwork network = PondChannelSettlement.settle(key, shaper.shape(key, drainage.surface(), drainage.receivers(),
|
||||
drainage.accumulation(), drainage.channels(), samples.ocean(), water, fine, settings.seed()), settings.seed(), settings.seaLevel());
|
||||
ShapedNetwork network = PondChannelSettlement.settle(key, guarded(shaper.shape(key, drainage.surface(), drainage.receivers(),
|
||||
drainage.accumulation(), drainage.channels(), samples.ocean(), water, fine, settings.seed())), settings.seed(), settings.seaLevel());
|
||||
long passes = settlementPasses(water);
|
||||
for (long pass = 1; lowered(water, network.ponds()); pass++) {
|
||||
if (pass >= passes) {
|
||||
throw new IllegalStateException("Window " + key + " ponds did not settle within " + passes + " shaping passes");
|
||||
}
|
||||
water = replanned(settled(raw, cups, water, network.ponds()));
|
||||
network = PondChannelSettlement.settle(key, shaper.shape(key, drainage.surface(), drainage.receivers(),
|
||||
drainage.accumulation(), drainage.channels(), samples.ocean(), water, fine, settings.seed()), settings.seed(), settings.seaLevel());
|
||||
network = PondChannelSettlement.settle(key, guarded(shaper.shape(key, drainage.surface(), drainage.receivers(),
|
||||
drainage.accumulation(), drainage.channels(), samples.ocean(), water, fine, settings.seed())), settings.seed(), settings.seaLevel());
|
||||
}
|
||||
List<Reach> reaches = network.reaches();
|
||||
List<Pond> windowPonds = windowPonds(network.ponds());
|
||||
@@ -136,6 +137,18 @@ public final class WindowPlanner {
|
||||
return new WindowComputation(owned, reaches, windowPonds);
|
||||
}
|
||||
|
||||
private ShapedNetwork guarded(ShapedNetwork shaped) {
|
||||
HydrologySampleBuffer column = new HydrologySampleBuffer(1);
|
||||
int[] columnX = new int[1];
|
||||
int[] columnZ = new int[1];
|
||||
return TongueGuard.guard(shaped, (x, z) -> {
|
||||
columnX[0] = x;
|
||||
columnZ[0] = z;
|
||||
fine.sampleColumns(columnX, columnZ, column);
|
||||
return column.height()[0];
|
||||
}, settings.seed(), settings.seaLevel(), settings.deformation().maxFill());
|
||||
}
|
||||
|
||||
public WindowPlan plan(WindowKey key, List<RegionPlan> regions) {
|
||||
return compute(key, regions).owned();
|
||||
}
|
||||
|
||||
@@ -77,6 +77,9 @@ final class ReachGeometry {
|
||||
Math.round((reach.zs()[segment] + reach.zs()[segment + 1]) / 2f));
|
||||
double curve = BRINK_CURVE_MIN + (BRINK_CURVE_MAX - BRINK_CURVE_MIN) * CellHash.unit(hash);
|
||||
double wanted = Math.min(BRINK_MAX_SHIFT, Math.max(BRINK_MIN_SHIFT, curve * (width - EDGE_MARGIN)));
|
||||
if (Arrays.binarySearch(reach.straightFalls(), segment) >= 0) {
|
||||
continue;
|
||||
}
|
||||
boolean tongue = (hash & 1L) == 0L;
|
||||
double room = tongue
|
||||
? Math.min(step + 1 < count ? (middle(along, steps[step + 1]) - middle) / 2D : end - middle, mouth - middle)
|
||||
@@ -120,6 +123,36 @@ final class ReachGeometry {
|
||||
return at - moved > middles[curve] ? segments[curve] + 1 : straight;
|
||||
}
|
||||
|
||||
int curvedFall(ReachCursor.Choice choice) {
|
||||
if (segments.length == 0 || point(choice) == choice.point()) {
|
||||
return -1;
|
||||
}
|
||||
double at = along[choice.segment] + choice.t * (along[choice.segment + 1] - along[choice.segment]);
|
||||
int found = Arrays.binarySearch(starts, at);
|
||||
int curve = found >= 0 ? found : -found - 2;
|
||||
return segments[curve];
|
||||
}
|
||||
|
||||
int[] tongueFalls() {
|
||||
int[] falls = new int[segments.length];
|
||||
int count = 0;
|
||||
for (int curve = 0; curve < segments.length; curve++) {
|
||||
if (shifts[curve] > 0D) {
|
||||
falls[count++] = segments[curve];
|
||||
}
|
||||
}
|
||||
return Arrays.copyOf(falls, count);
|
||||
}
|
||||
|
||||
double tongueEnd(int fall) {
|
||||
int curve = Arrays.binarySearch(segments, fall);
|
||||
return middles[curve] + shifts[curve];
|
||||
}
|
||||
|
||||
double along(int point) {
|
||||
return along[point];
|
||||
}
|
||||
|
||||
int lowestGrade(Reach reach, int segment) {
|
||||
int[] grade = reach.grade();
|
||||
int lowest = Math.min(grade[segment], grade[segment + 1]);
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package art.arcane.iris.generation.hydrology.raster;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ShapedNetwork;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public final class TongueGuard {
|
||||
private TongueGuard() {
|
||||
}
|
||||
|
||||
public static ShapedNetwork guard(ShapedNetwork network, NaturalHeights natural, long seed, int seaLevel, int maxFill) {
|
||||
List<Reach> reaches = new ArrayList<>(network.reaches().size());
|
||||
for (Reach reach : network.reaches()) {
|
||||
reaches.add(guard(reach, natural, seed, seaLevel, maxFill));
|
||||
}
|
||||
return new ShapedNetwork(reaches, network.ponds());
|
||||
}
|
||||
|
||||
static Reach guard(Reach reach, NaturalHeights natural, long seed, int seaLevel, int maxFill) {
|
||||
ReachGeometry geometry = ReachGeometry.of(reach, reach, seed, seaLevel);
|
||||
int[] tongues = geometry.tongueFalls();
|
||||
if (tongues.length == 0) {
|
||||
return reach;
|
||||
}
|
||||
ReachSegments segments = new ReachSegments(reach.xs().length);
|
||||
segments.addAll(reach);
|
||||
ReachCursor cursor = new ReachCursor();
|
||||
int[] stopped = new int[tongues.length];
|
||||
int count = 0;
|
||||
for (int fall : tongues) {
|
||||
int lowestGround = WaterHeads.snap(reach.grade()[fall], seaLevel) - 1 - maxFill;
|
||||
if (passesTheGround(reach, geometry, segments, cursor, fall, natural, lowestGround)) {
|
||||
stopped[count++] = fall;
|
||||
}
|
||||
}
|
||||
return count == 0 ? reach : reach.withStraightFalls(Arrays.copyOf(stopped, count));
|
||||
}
|
||||
|
||||
private static boolean passesTheGround(Reach reach, ReachGeometry geometry, ReachSegments segments, ReachCursor cursor, int fall,
|
||||
NaturalHeights natural, int lowestGround) {
|
||||
float[] xs = reach.xs();
|
||||
float[] zs = reach.zs();
|
||||
float[] halfWidth = reach.halfWidth();
|
||||
double end = geometry.tongueEnd(fall);
|
||||
for (int segment = fall; segment + 1 < xs.length && geometry.along(segment) <= end; segment++) {
|
||||
float radius = Math.max(halfWidth[segment], halfWidth[segment + 1]);
|
||||
int minX = (int) Math.floor(Math.min(xs[segment], xs[segment + 1]) - radius);
|
||||
int maxX = (int) Math.ceil(Math.max(xs[segment], xs[segment + 1]) + radius);
|
||||
int minZ = (int) Math.floor(Math.min(zs[segment], zs[segment + 1]) - radius);
|
||||
int maxZ = (int) Math.ceil(Math.max(zs[segment], zs[segment + 1]) + radius);
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
segments.nearest(x, z, ReachSegments.Scope.CHANNEL, cursor);
|
||||
if (cursor.channel.reach != null && geometry.curvedFall(cursor.channel) == fall && Math.round(natural.height(x, z)) < lowestGround) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,16 @@ public record Reach(
|
||||
float[] halfWidth,
|
||||
float[] depth,
|
||||
ReachStyle[] style,
|
||||
float catchment
|
||||
float catchment,
|
||||
int[] straightFalls
|
||||
) {
|
||||
private static final int[] NO_FALLS = new int[0];
|
||||
|
||||
public Reach(long id, HydrologyTier tier, long downstreamId, float[] xs, float[] zs, int[] grade, float[] halfWidth, float[] depth,
|
||||
ReachStyle[] style, float catchment) {
|
||||
this(id, tier, downstreamId, xs, zs, grade, halfWidth, depth, style, catchment, NO_FALLS);
|
||||
}
|
||||
|
||||
public Reach {
|
||||
Objects.requireNonNull(tier, "tier");
|
||||
int points = xs.length;
|
||||
@@ -24,6 +32,15 @@ public record Reach(
|
||||
+ " zs=" + zs.length + " grade=" + grade.length + " halfWidth=" + halfWidth.length + " depth=" + depth.length
|
||||
+ " style=" + style.length);
|
||||
}
|
||||
for (int index = 0; index < straightFalls.length; index++) {
|
||||
if (straightFalls[index] < 0 || straightFalls[index] + 1 >= points || index > 0 && straightFalls[index] <= straightFalls[index - 1]) {
|
||||
throw new IllegalArgumentException("Reach " + id + " has invalid straight falls " + Arrays.toString(straightFalls));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Reach withStraightFalls(int[] falls) {
|
||||
return new Reach(id, tier, downstreamId, xs, zs, grade, halfWidth, depth, style, catchment, falls);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -31,7 +48,8 @@ public record Reach(
|
||||
return other instanceof Reach reach && id == reach.id && downstreamId == reach.downstreamId
|
||||
&& Float.floatToIntBits(catchment) == Float.floatToIntBits(reach.catchment) && tier.equals(reach.tier)
|
||||
&& Arrays.equals(xs, reach.xs) && Arrays.equals(zs, reach.zs) && Arrays.equals(grade, reach.grade)
|
||||
&& Arrays.equals(halfWidth, reach.halfWidth) && Arrays.equals(depth, reach.depth) && Arrays.equals(style, reach.style);
|
||||
&& Arrays.equals(halfWidth, reach.halfWidth) && Arrays.equals(depth, reach.depth) && Arrays.equals(style, reach.style)
|
||||
&& Arrays.equals(straightFalls, reach.straightFalls);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,7 +62,8 @@ public record Reach(
|
||||
hash = 31 * hash + Arrays.hashCode(grade);
|
||||
hash = 31 * hash + Arrays.hashCode(halfWidth);
|
||||
hash = 31 * hash + Arrays.hashCode(depth);
|
||||
return 31 * hash + Arrays.hashCode(style);
|
||||
hash = 31 * hash + Arrays.hashCode(style);
|
||||
return 31 * hash + Arrays.hashCode(straightFalls);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user