mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +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
|
||||
|
||||
+3
-2
@@ -40,7 +40,7 @@ public class HydrologyPlanCodecTest {
|
||||
4948595057000000000000000000000002fffffffd000000010000000000000029000000000000006100000000444b20
|
||||
0000000006000000004080000041000000414000004180000041a00000c1000000c0c00000c0800000c0000000000000
|
||||
0040000000000000480000004700000046000000420000003f0000003e3f8000003fa000003fc000003fe00000400000
|
||||
00402000003f8000003f8000003fc0000040000000400000003f80000000010203040500000004000000000000000500
|
||||
00402000003f8000003f8000003fc0000040000000400000003f8000000001020304050000000000000004000000000000000500
|
||||
00000046000000420000000cfffffffc428d0000fffffffc000000080000000400000000000000000000000000000000
|
||||
0000002900000000ffffffff0000000afffffffa0000000000000006010000004a000000470000001e00000008429480
|
||||
0000000003fffffffd000000010000004000000001000000018000000000000001ffffffffffffffff00000001000000
|
||||
@@ -62,7 +62,7 @@ public class HydrologyPlanCodecTest {
|
||||
new float[]{1f, Float.POSITIVE_INFINITY, 0.4f, 1e-42f, -0f, 3f},
|
||||
ReachStyle.values(), NEGATIVE_NAN);
|
||||
Reach plain = new Reach(77L, tiers.get(0), -9_000_000_000L, new float[]{10f, 11.5f}, new float[]{-3f, -2.5f}, new int[]{70, 69},
|
||||
new float[]{0.5f, 0.75f}, new float[]{1f, 1f}, new ReachStyle[]{ReachStyle.RUN, ReachStyle.MOUTH}, 1501.25f);
|
||||
new float[]{0.5f, 0.75f}, new float[]{1f, 1f}, new ReachStyle[]{ReachStyle.RUN, ReachStyle.MOUTH}, 1501.25f).withStraightFalls(new int[]{0});
|
||||
List<Pond> ponds = new ArrayList<>();
|
||||
PondKind[] kinds = PondKind.values();
|
||||
for (int index = 0; index < kinds.length; index++) {
|
||||
@@ -204,6 +204,7 @@ public class HydrologyPlanCodecTest {
|
||||
assertArrayEquals(rawBits(want.halfWidth()), rawBits(got.halfWidth()));
|
||||
assertArrayEquals(rawBits(want.depth()), rawBits(got.depth()));
|
||||
assertArrayEquals(want.style(), got.style());
|
||||
assertArrayEquals(want.straightFalls(), got.straightFalls());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package art.arcane.iris.generation.hydrology.plan;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.grid.HeightLattice;
|
||||
import art.arcane.iris.generation.hydrology.raster.TongueGuard;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterHeads;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
@@ -128,6 +129,26 @@ public class WindowPlannerTest {
|
||||
assertEquals(94, settled.allReaches().get(0).grade()[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void planningStopsTonguesThatWouldRaiseTheBedOverMaxFill() {
|
||||
int stopped = 0;
|
||||
SyntheticTerrain terrain = SyntheticTerrain.southSlope(300D, 5D);
|
||||
for (long seed = 1L; seed <= 6L; seed++) {
|
||||
HydrologySettings settings = HydrologySettings.compile(new IrisHydrology(), seed, SyntheticTerrain.SEA_LEVEL, SyntheticTerrain.MIN_Y, SyntheticTerrain.MAX_Y);
|
||||
Reach river = new Reach(30L, settings.tiers().get(0), 0L, new float[]{64f, 64f}, new float[]{20f, 40f}, new int[]{200, 160},
|
||||
new float[]{8f, 8f}, new float[]{2f, 2f}, new ReachStyle[]{ReachStyle.RUN, ReachStyle.WATERFALL}, 1000f);
|
||||
ReachShaper shaper = mock(ReachShaper.class);
|
||||
doAnswer(call -> new ShapedNetwork(List.of(river), List.of())).when(shaper).shape(any(), any(), any(), any(), any(), any(), any(), any(), anyLong());
|
||||
WindowPlanner planner = new WindowPlanner(settings, new HeightLattice(terrain, WindowPlanner.FINE_CELL, false, 1 << 18), new PondPlanner(settings), shaper);
|
||||
Reach planned = planner.compute(ORIGIN, noRegions(ORIGIN)).allReaches().get(0);
|
||||
ShapedNetwork expected = TongueGuard.guard(new ShapedNetwork(List.of(river), List.of()), (x, z) -> 300D - 5D * z, seed, SyntheticTerrain.SEA_LEVEL,
|
||||
settings.deformation().maxFill());
|
||||
assertEquals("seed " + seed, expected.reaches().get(0), planned);
|
||||
stopped += planned.straightFalls().length;
|
||||
}
|
||||
assertTrue("stopped tongues " + stopped, stopped > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void burnedTrunkCapturesLocalDrainage() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
|
||||
+147
@@ -43,6 +43,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -1787,6 +1788,152 @@ public class ChunkWaterRasterTest {
|
||||
return cells;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTonguePastACliffNeverRaisesTheBedOverMaxFill() {
|
||||
int maxFill = settings(new IrisHydrology()).deformation().maxFill();
|
||||
int[][] drops = {{78, 80}, {74, 76}, {58, 60}};
|
||||
for (int[] drop : drops) {
|
||||
for (float width : new float[]{3f, 4f, 6f, 9f, 12f, 18f}) {
|
||||
HydrologyTier tier = tier("river", width, 0.5f, 8, IrisBankStyle.SMOOTH);
|
||||
Reach reach = line(721L, tier, 0L, -60f, 8f, 100f, 8f, (x, z) -> x < 20f ? 90 : drop[0]);
|
||||
IntBinaryOperator cliff = (x, z) -> x < 20 ? 92 : drop[1];
|
||||
int guarded = 0;
|
||||
int horseshoes = 0;
|
||||
for (long seed = 1L; seed <= 24L; seed++) {
|
||||
String label = "drop to " + drop[0] + " width " + width + " seed " + seed + ": ";
|
||||
BrinkRule before = new BrinkRule(seed, reach);
|
||||
Reach kept = TongueGuard.guard(reach, cliff::applyAsInt, seed, SEA_LEVEL, maxFill);
|
||||
BrinkRule after = new BrinkRule(seed, kept);
|
||||
Scene scene = new Scene(seededSettings(seed), cliff).reach(kept);
|
||||
boolean tongue = false;
|
||||
boolean horseshoe = false;
|
||||
for (int x = -10; x <= 50; x++) {
|
||||
for (int z = 8 - (int) width; z <= 8 + (int) width; z++) {
|
||||
int raise = before.head(x, z) - before.straightHead(x, z);
|
||||
tongue |= raise > 0 && cliff.applyAsInt(x, z) < 89 - maxFill;
|
||||
horseshoe |= raise < 0;
|
||||
if (scene.water(x, z)) {
|
||||
assertTrue(label + "bed " + scene.terrain(x, z) + " over natural " + cliff.applyAsInt(x, z) + " at " + x + "," + z,
|
||||
scene.terrain(x, z) - cliff.applyAsInt(x, z) <= maxFill);
|
||||
assertEquals(label + "head at " + x + "," + z, after.head(x, z), scene.head(x, z));
|
||||
assertTrue(label + "a tongue past the cliff stays straight at " + x + "," + z,
|
||||
after.head(x, z) <= after.straightHead(x, z) || cliff.applyAsInt(x, z) >= 89 - maxFill);
|
||||
}
|
||||
}
|
||||
}
|
||||
guarded += tongue ? 1 : 0;
|
||||
horseshoes += horseshoe ? 1 : 0;
|
||||
assertEquals(label + "only tongues past the cliff are stopped", tongue ? 1 : 0, kept.straightFalls().length);
|
||||
}
|
||||
assertTrue("drop to " + drop[0] + " width " + width + " stops tongues on some seeds: " + guarded, guarded > 0);
|
||||
assertTrue("drop to " + drop[0] + " width " + width + " keeps horseshoes: " + horseshoes, horseshoes > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tonguesKeepTheirCurveWhereTheBedStaysWithinMaxFill() {
|
||||
int maxFill = settings(new IrisHydrology()).deformation().maxFill();
|
||||
for (float width : new float[]{3f, 4f, 8f, 16f}) {
|
||||
HydrologyTier tier = tier("river", width, 0.5f, 8, IrisBankStyle.SMOOTH);
|
||||
Reach tall = line(722L, tier, 0L, -60f, 8f, 100f, 8f, (x, z) -> x < 20f ? 90 : 58);
|
||||
Reach low = line(723L, tier, 0L, -60f, 8f, 100f, 8f, (x, z) -> x < 20f ? 90 : 84);
|
||||
int tongues = 0;
|
||||
for (long seed = 1L; seed <= 24L; seed++) {
|
||||
assertSame("high ground keeps a tall fall's curve", tall, TongueGuard.guard(tall, (x, z) -> 92, seed, SEA_LEVEL, maxFill));
|
||||
assertSame("a large maxFill keeps the curve past a cliff", tall, TongueGuard.guard(tall, (x, z) -> x < 20 ? 92 : 60, seed, SEA_LEVEL, 32));
|
||||
assertSame("a small fall stays within maxFill", low, TongueGuard.guard(low, (x, z) -> x < 20 ? 92 : 86, seed, SEA_LEVEL, maxFill));
|
||||
BrinkRule rule = new BrinkRule(seed, low);
|
||||
for (int x = 18; x <= 40; x++) {
|
||||
tongues += rule.head(x, 8) > rule.straightHead(x, 8) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
assertTrue("width " + width + " tongues " + tongues, tongues > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTongueStopsOneBlockPastMaxFillAndCountsOnlyItsOwnFall() {
|
||||
int maxFill = settings(new IrisHydrology()).deformation().maxFill();
|
||||
HydrologyTier tier = tier("river", 8f, 0.5f, 8, IrisBankStyle.SMOOTH);
|
||||
Reach reach = line(725L, tier, 0L, -60f, 8f, 100f, 8f, (x, z) -> x < 20f ? 90 : 78);
|
||||
int stopped = 0;
|
||||
for (long seed = 1L; seed <= 24L; seed++) {
|
||||
int crest = 89 - maxFill;
|
||||
BrinkRule rule = new BrinkRule(seed, reach);
|
||||
boolean tongue = false;
|
||||
for (int x = 20; x <= 40; x++) {
|
||||
tongue |= rule.head(x, 8) > rule.straightHead(x, 8);
|
||||
}
|
||||
assertSame("seed " + seed + " a raise of exactly maxFill keeps the curve", reach, TongueGuard.guard(reach, (x, z) -> x < 20 ? 92 : crest, seed, SEA_LEVEL, maxFill));
|
||||
Reach below = TongueGuard.guard(reach, (x, z) -> x < 20 ? 92 : crest - 1, seed, SEA_LEVEL, maxFill);
|
||||
assertEquals("seed " + seed + " one block lower stops only a tongue", tongue ? 1 : 0, below.straightFalls().length);
|
||||
stopped += below.straightFalls().length;
|
||||
assertEquals("seed " + seed + " a stopped tongue is part of the reach's identity", tongue, !reach.equals(below));
|
||||
Reach horseshoeGround = TongueGuard.guard(reach, (x, z) -> x < 19 ? crest - 1 : 92, seed, SEA_LEVEL, maxFill);
|
||||
assertSame("seed " + seed + " low ground above the fall stops nothing", reach, horseshoeGround);
|
||||
}
|
||||
assertTrue("stopped tongues " + stopped, stopped > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aStoppedTongueLeavesTheOtherFallsCurved() {
|
||||
int maxFill = settings(new IrisHydrology()).deformation().maxFill();
|
||||
HydrologyTier tier = tier("river", 8f, 0.5f, 8, IrisBankStyle.SMOOTH);
|
||||
Reach reach = line(726L, tier, 0L, -60f, 8f, 100f, 8f, (x, z) -> x < -20f ? 110 : x < 20f ? 90 : 78);
|
||||
int both = 0;
|
||||
for (long seed = 1L; seed <= 24L; seed++) {
|
||||
Reach kept = TongueGuard.guard(reach, (x, z) -> x < 20 ? 120 : 80, seed, SEA_LEVEL, maxFill);
|
||||
BrinkRule rule = new BrinkRule(seed, kept);
|
||||
BrinkRule before = new BrinkRule(seed, reach);
|
||||
boolean upperCurved = false;
|
||||
for (int x = -30; x <= -10; x++) {
|
||||
assertEquals("seed " + seed + " upper fall at " + x, before.head(x, 8), rule.head(x, 8));
|
||||
upperCurved |= before.head(x, 8) != before.straightHead(x, 8);
|
||||
}
|
||||
both += upperCurved && kept.straightFalls().length == 1 ? 1 : 0;
|
||||
}
|
||||
assertTrue("seeds with a stopped lower tongue under a curved upper fall: " + both, both > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTongueIsNotStoppedByTheNextFallsTongueCloseBelowIt() {
|
||||
int maxFill = settings(new IrisHydrology()).deformation().maxFill();
|
||||
HydrologyTier tier = tier("river", 8f, 0.5f, 8, IrisBankStyle.SMOOTH);
|
||||
Reach reach = line(727L, tier, 0L, -60f, 8f, 100f, 8f, (x, z) -> x < 20f ? 110 : x < 28f ? 90 : 78);
|
||||
int upperFall = 39;
|
||||
int lowerFall = 43;
|
||||
assertEquals(110, reach.grade()[upperFall]);
|
||||
assertEquals(90, reach.grade()[upperFall + 1]);
|
||||
assertEquals(90, reach.grade()[lowerFall]);
|
||||
assertEquals(78, reach.grade()[lowerFall + 1]);
|
||||
int lowerStopped = 0;
|
||||
int bothTongues = 0;
|
||||
for (long seed = 1L; seed <= 24L; seed++) {
|
||||
Reach kept = TongueGuard.guard(reach, (x, z) -> x < 28 ? 120 : 80, seed, SEA_LEVEL, maxFill);
|
||||
assertTrue("seed " + seed + " upper fall stays curved", Arrays.binarySearch(kept.straightFalls(), upperFall) < 0);
|
||||
boolean lower = Arrays.binarySearch(kept.straightFalls(), lowerFall) >= 0;
|
||||
lowerStopped += lower ? 1 : 0;
|
||||
bothTongues += lower && new BrinkRule(seed, kept).head(20, 8) > new BrinkRule(seed, kept).straightHead(20, 8) ? 1 : 0;
|
||||
}
|
||||
assertTrue("stopped lower tongues " + lowerStopped + ", with an upper tongue " + bothTongues, lowerStopped > 0 && bothTongues > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aStoppedTongueStaysStraightInEveryChunkAcrossAWindowLine() {
|
||||
HydrologyTier tier = tier("river", 12f, 0.5f, 8, IrisBankStyle.SMOOTH);
|
||||
Reach downstream = line(732L, tier, 0L, 700f, 200f, 1100f, 200f, (x, z) -> 94);
|
||||
Reach feeder = line(731L, tier, downstream.id(), 440f, 200f, 700f, 200f, (x, z) -> x < 512f ? 122 : x < 600f ? 110 : 98);
|
||||
NaturalHeights cliff = (x, z) -> x < 512 ? 124 : 112;
|
||||
int stopped = 0;
|
||||
for (long seed = 1L; seed <= 24L; seed++) {
|
||||
Reach kept = TongueGuard.guard(feeder, cliff, seed, SEA_LEVEL, 6);
|
||||
stopped += kept.straightFalls().length;
|
||||
assertHeadsFollowThePlan("seed " + seed + ": ", kept, downstream, seed, 480, 540);
|
||||
}
|
||||
assertTrue("stopped tongues " + stopped, stopped > 0);
|
||||
}
|
||||
|
||||
private static Reach withStartStyle(Reach reach, ReachStyle style, int points) {
|
||||
ReachStyle[] styles = reach.style().clone();
|
||||
for (int point = 0; point < points; point++) {
|
||||
|
||||
+12
@@ -128,6 +128,18 @@ public class PondChannelSettlementTest {
|
||||
assertTrue("ponds the curve moved on or off the lower water: " + curved, curved >= 12);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void settlementTreatsAStoppedTongueAsAStraightFall() {
|
||||
Reach river = line(2L, 504, 108, 504, 148, 6f, 100, 88);
|
||||
int stopped = 0;
|
||||
for (long seed = 1L; seed <= 24L; seed++) {
|
||||
Reach kept = TongueGuard.guard(river, (x, z) -> z < 128 ? 102 : 90, seed, SEA_LEVEL, 6);
|
||||
stopped += kept.straightFalls().length;
|
||||
assertSettlementMatchesTheRaster(seed, kept, 500, 508, 120, 136, 1);
|
||||
}
|
||||
assertTrue("stopped tongues " + stopped, stopped > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void settlementFollowsAWideAngledBrink() {
|
||||
Reach river = line(2L, 400, 100, 460, 160, 16f, 100, 88);
|
||||
|
||||
Reference in new issue
Block a user