mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 09:44:24 +00:00
Merge tidal inlets
- Sea inlets become tidal reaches on the river pipeline - Recaptures the schema digest for the merged lane
This commit is contained in:
commit
5df42fc49e
82 files changed
+3370
-4647
No files matched your search
@@ -37,7 +37,8 @@ public class PersistedCodesTest {
|
||||
ReachStyle.CASCADE, 2,
|
||||
ReachStyle.WATERFALL, 3,
|
||||
ReachStyle.POND_OUTLET, 4,
|
||||
ReachStyle.MOUTH, 5);
|
||||
ReachStyle.MOUTH, 5,
|
||||
ReachStyle.TIDAL, 6);
|
||||
private static final Map<PondKind, Integer> POND_KIND_CODES = Map.of(
|
||||
PondKind.NATURAL, 0,
|
||||
PondKind.SEEDED, 1,
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public class IrisHydrologyDefaultsTest {
|
||||
"lakes": { "enabled": true, "minArea": 65536, "maxArea": 4194304 },
|
||||
"deformation": { "maxFill": 6, "bankSlope": 0.2, "bankSteepFactor": 3.5, "bankNoise": 0.2, "caveMask": true },
|
||||
"underground": {
|
||||
"seaInlets": { "enabled": true, "spacing": 192, "minimumCliffHeight": 8, "length": [64, 256], "halfWidth": [2, 5], "depth": [2, 5], "headroom": [4, 10], "roofClearance": 6, "chamberRadius": [6, 12] },
|
||||
"seaInlets": { "enabled": true, "spacing": 160, "length": [64, 256], "maximumBankHeight": 44, "mouthHalfWidth": [13, 15], "headHalfWidth": [2.5, 3], "taper": 1.4, "widthVariation": 0.18, "meanderWidth": 4, "depth": [2, 5], "bankBand": 32, "bankStyle": "SMOOTH" },
|
||||
"cavePools": { "enabled": true, "density": 0.15, "minArea": 6, "maxArea": 400, "maxDepth": 4, "radius": 15, "freeboard": [0, 1], "fluid": "water" }
|
||||
},
|
||||
"fluids": [ { "name": "water", "palette": { "palette": [ { "block": "minecraft:water" } ] } } ],
|
||||
|
||||
+2
-2
@@ -222,12 +222,12 @@ public class HydrologyFeatureSearchTest {
|
||||
WindowPlan window(WindowKey key, List<RegionPlan> plans) {
|
||||
calls.incrementAndGet();
|
||||
if (channelTier != null && key.equals(new WindowKey(0, 0))) {
|
||||
return new WindowPlan(key, List.of(channel(channelTier)), List.of(), List.of());
|
||||
return new WindowPlan(key, List.of(channel(channelTier)), List.of());
|
||||
}
|
||||
if (Math.max(Math.abs(key.wx()), Math.abs(key.wz())) > openRing) {
|
||||
hold();
|
||||
}
|
||||
return new WindowPlan(key, List.of(), List.of(), List.of());
|
||||
return new WindowPlan(key, List.of(), List.of());
|
||||
}
|
||||
|
||||
private void hold() {
|
||||
|
||||
+32
-57
@@ -16,8 +16,6 @@ import art.arcane.iris.generation.hydrology.query.HydrologyFeatureRef;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
import art.arcane.iris.generation.hydrology.water.PondMask;
|
||||
@@ -331,48 +329,23 @@ public class HydrologyRuntimeTest {
|
||||
}
|
||||
|
||||
@Test(timeout = 180_000L)
|
||||
public void seaInletsReachChunksPastTheirOwnerAndFailClosedOnTheMainThread() throws Exception {
|
||||
AtomicBoolean main = new AtomicBoolean(true);
|
||||
public void seaInletsAreSearchedAndPreviewedAsTidalReaches() throws Exception {
|
||||
FakePlanners planners = new FakePlanners(settings());
|
||||
HydrologyRuntime runtime = runtime(planners, main::get);
|
||||
|
||||
CountDownLatch gate = new CountDownLatch(1);
|
||||
planners.gate = gate;
|
||||
assertThrows(IllegalStateException.class, () -> runtime.inlets(68, 25));
|
||||
gate.countDown();
|
||||
main.set(false);
|
||||
List<SeaInlet> tail = runtime.inlets(68, 25);
|
||||
assertEquals(List.of(FakePlanners.inlet()), tail);
|
||||
assertEquals(new WindowKey(2, 0), WindowKey.containing(68 << 4, 25 << 4));
|
||||
assertEquals(tail, runtime.inlets(62, 25));
|
||||
assertEquals(List.of(), runtime.inlets(75, 25));
|
||||
assertEquals(List.of(), runtime.inlets(68, 30));
|
||||
assertEquals(List.of(), runtime.inlets(0, 0));
|
||||
main.set(true);
|
||||
assertEquals(tail, runtime.inlets(68, 25));
|
||||
main.set(false);
|
||||
|
||||
Map<Long, HydrologyCaveCell> written = new ConcurrentHashMap<>();
|
||||
MantleWriter writer = mock(MantleWriter.class);
|
||||
doAnswer(call -> {
|
||||
HydrologyCaveCell cell = call.getArgument(3);
|
||||
int x = call.getArgument(0);
|
||||
assertEquals(68, x >> 4);
|
||||
written.put(((long) x << 40) ^ ((long) (int) call.getArgument(2) << 20) ^ (int) call.getArgument(1), cell);
|
||||
return null;
|
||||
}).when(writer).setData(anyInt(), anyInt(), anyInt(), any(HydrologyCaveCell.class));
|
||||
new SeaInletRasterizer().write(tail.getFirst(), 68, 25, writer, HydrologyCaveCell.SEA_FLUID, SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
assertTrue("the chunk past the owner window writes inlet water",
|
||||
written.values().stream().anyMatch(cell -> cell.action() == HydrologyCaveAction.WET_SOURCE));
|
||||
|
||||
HydrologyRuntime runtime = runtime(planners, () -> false);
|
||||
HydrologyFeatureRef nearest = runtime.nearestFeature(1050, 405, HydrologyFeatureQuery.of(HydrologyFeatureType.SEA_INLET), 512, ANY,
|
||||
RUNNING).orElseThrow();
|
||||
assertEquals(new HydrologyFeatureRef(INLET, HydrologyFeatureType.SEA_INLET, 1048, 40, 400), nearest);
|
||||
HydrologyFeatureRef fromInland = runtime.nearestFeature(960, 400, HydrologyFeatureQuery.of(HydrologyFeatureType.SEA_INLET), 512, ANY,
|
||||
RUNNING).orElseThrow();
|
||||
assertEquals("a search lands in the half of the arm toward the sea", new HydrologyFeatureRef(INLET, HydrologyFeatureType.SEA_INLET, 1040, 40, 400), fromInland);
|
||||
HydrologyFeatureRef fromTheSea = runtime.nearestFeature(1200, 400, HydrologyFeatureQuery.of(HydrologyFeatureType.SEA_INLET), 512, ANY,
|
||||
RUNNING).orElseThrow();
|
||||
assertEquals("a search lands short of the open sea", new HydrologyFeatureRef(INLET, HydrologyFeatureType.SEA_INLET, 1072, 40, 400), fromTheSea);
|
||||
assertEquals("a tidal reach is not a river mouth", Optional.empty(),
|
||||
runtime.nearestFeature(1050, 405, HydrologyFeatureQuery.of(HydrologyFeatureType.MOUTH), 128, ANY, RUNNING));
|
||||
assertEquals(Optional.empty(),
|
||||
runtime.nearestFeature(0, 0, HydrologyFeatureQuery.of(HydrologyFeatureType.SEA_INLET), 64, ANY, RUNNING));
|
||||
assertEquals(List.of(FakePlanners.inlet()), runtime.planPreview(900, 300, 1100, 500).inlets());
|
||||
assertEquals(List.of(), FakeHydrology.disabled().inlets(0, 0));
|
||||
assertEquals(List.of(INLET), runtime.planPreview(900, 300, 1100, 500).reaches().stream().map(Reach::id).filter(id -> id == INLET).toList());
|
||||
}
|
||||
|
||||
@Test(timeout = 180_000L)
|
||||
@@ -548,7 +521,7 @@ public class HydrologyRuntimeTest {
|
||||
}
|
||||
assertTrue("a released cap admits new previews", preview.complete());
|
||||
assertEquals(2, preview.ponds().size());
|
||||
assertEquals(1, preview.reaches().size());
|
||||
assertEquals(2, preview.reaches().size());
|
||||
}
|
||||
|
||||
@Test(timeout = 180_000L)
|
||||
@@ -1306,15 +1279,15 @@ public class HydrologyRuntimeTest {
|
||||
throw new IllegalStateException("window planner exploded");
|
||||
}
|
||||
return new WindowPlan(key, List.of(river()), List.of(pond(POND, PondKind.NATURAL, 70, 2, 2, 8),
|
||||
pond(POND + 1, PondKind.SEEDED, 70, 296, 296, 3)), List.of());
|
||||
pond(POND + 1, PondKind.SEEDED, 70, 296, 296, 3)));
|
||||
}
|
||||
if (key.equals(new WindowKey(1, 0))) {
|
||||
return new WindowPlan(key, List.of(), List.of(), List.of(inlet()));
|
||||
return new WindowPlan(key, List.of(tidal()), List.of());
|
||||
}
|
||||
if (key.equals(new WindowKey(3, 0))) {
|
||||
return new WindowPlan(key, List.of(), List.of(pond(FAR_POND, PondKind.NATURAL, 75, 1700, 100, 3)), List.of());
|
||||
return new WindowPlan(key, List.of(), List.of(pond(FAR_POND, PondKind.NATURAL, 75, 1700, 100, 3)));
|
||||
}
|
||||
return new WindowPlan(key, List.of(), List.of(), List.of());
|
||||
return new WindowPlan(key, List.of(), List.of());
|
||||
}
|
||||
|
||||
private void pass() {
|
||||
@@ -1335,21 +1308,23 @@ public class HydrologyRuntimeTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static SeaInlet inlet() {
|
||||
int stations = 13;
|
||||
float[] xs = new float[stations];
|
||||
float[] zs = new float[stations];
|
||||
float[] halfWidth = new float[stations];
|
||||
int[] floor = new int[stations];
|
||||
int[] ceiling = new int[stations];
|
||||
for (int station = 0; station < stations; station++) {
|
||||
xs[station] = 992f + station * 8f;
|
||||
zs[station] = 400f;
|
||||
halfWidth[station] = 3f;
|
||||
floor[station] = 37;
|
||||
ceiling[station] = 45;
|
||||
private Reach tidal() {
|
||||
int points = 13;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grade = new int[points];
|
||||
float[] halfWidth = new float[points];
|
||||
float[] depth = new float[points];
|
||||
ReachStyle[] style = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = 992f + point * 8f;
|
||||
zs[point] = 400f;
|
||||
grade[point] = 40;
|
||||
halfWidth[point] = 3f;
|
||||
depth[point] = 3f;
|
||||
style[point] = ReachStyle.TIDAL;
|
||||
}
|
||||
return new SeaInlet(INLET, xs, zs, halfWidth, 40, floor, ceiling, 1088, 400, 6);
|
||||
return new Reach(INLET, settings.tidalTier(), 0L, xs, zs, grade, halfWidth, depth, style, 0f);
|
||||
}
|
||||
|
||||
private Reach river() {
|
||||
|
||||
+2
-2
@@ -317,7 +317,7 @@ public class HydrologyPlanCacheTest {
|
||||
WindowKey key = new WindowKey(5, -3);
|
||||
HydrologyPlanCache cache = new HydrologyPlanCache(planners.settings, planners::region, (window, regions) -> {
|
||||
Reach reach = planners.window(window, regions).reaches().get(0);
|
||||
return new WindowPlan(window, List.of(reach, reach), List.of(), List.of());
|
||||
return new WindowPlan(window, List.of(reach, reach), List.of());
|
||||
}, pool(1), () -> false);
|
||||
caches.add(cache);
|
||||
Throwable failure = failureOf(() -> cache.window(key));
|
||||
@@ -1174,7 +1174,7 @@ public class HydrologyPlanCacheTest {
|
||||
throw new AssertionError("Window " + key + " got region plans " + given + ", needs " + needed);
|
||||
}
|
||||
hook.accept(key);
|
||||
return new WindowPlan(key, List.of(reach(key)), List.of(), List.of());
|
||||
return new WindowPlan(key, List.of(reach(key)), List.of());
|
||||
}
|
||||
|
||||
private Reach reach(WindowKey key) {
|
||||
|
||||
+19
-23
@@ -4,7 +4,6 @@ import art.arcane.iris.generation.hydrology.config.IrisBankStyle;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyMaterials;
|
||||
import art.arcane.iris.generation.hydrology.grid.HeightLattice;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
@@ -47,7 +46,7 @@ public class HydrologyPlanCodecTest {
|
||||
0577617465720000001c000000060000000000000007020000004400000040ffffffec0000001042898000fffffffc00
|
||||
00000800000004000000000000000000000000000000000000002900000002000000046c617661ffffffea0000000e00
|
||||
0000000000000803000000500000003c00000040ffffffc042a10000fffffffc00000008000000040000000000000000
|
||||
00000000ffffffffffffffff00000000ffffffff0000003cffffffc400000000
|
||||
00000000ffffffffffffffff00000000ffffffff0000003cffffffc4
|
||||
""";
|
||||
|
||||
@Test
|
||||
@@ -60,7 +59,7 @@ public class HydrologyPlanCodecTest {
|
||||
new int[]{Integer.MIN_VALUE, -64, 0, 63, 319, Integer.MAX_VALUE},
|
||||
new float[]{0.5f, 1f, 2.75f, NAN_PAYLOAD, 12f, 0f},
|
||||
new float[]{1f, Float.POSITIVE_INFINITY, 0.4f, 1e-42f, -0f, 3f},
|
||||
ReachStyle.values(), NEGATIVE_NAN);
|
||||
Arrays.copyOf(ReachStyle.values(), 6), 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).withStraightFalls(new int[]{0});
|
||||
List<Pond> ponds = new ArrayList<>();
|
||||
@@ -70,12 +69,7 @@ public class HydrologyPlanCodecTest {
|
||||
index == 0 ? NAN_PAYLOAD : 61.5f + index, mask(index), index == 1 ? -1L : 77L, index * 2, fluid(index),
|
||||
-650 + index, 880 + index));
|
||||
}
|
||||
SeaInlet oddInlet = new SeaInlet(-5_000_000_000L, new float[]{-0f, NAN_PAYLOAD, 1e-40f}, new float[]{NEGATIVE_NAN, 3.5f, -0f},
|
||||
new float[]{Float.MIN_VALUE, 5f, 2.25f}, 63, new int[]{Integer.MIN_VALUE, 60, 62}, new int[]{63, Integer.MAX_VALUE, 70},
|
||||
-12, 40, 9);
|
||||
SeaInlet plainInlet = new SeaInlet(91L, new float[]{8f, 16f}, new float[]{-24f, -16f}, new float[]{5f, 4f}, 306,
|
||||
new int[]{303, 302}, new int[]{340, 312}, 16, -16, 6);
|
||||
WindowPlan window = new WindowPlan(new WindowKey(-3, 7), List.of(odd, plain), ponds, List.of(oddInlet, plainInlet));
|
||||
WindowPlan window = new WindowPlan(new WindowKey(-3, 7), List.of(odd, plain), ponds);
|
||||
WindowPlan decodedWindow = HydrologyPlanCodec.decodeWindow(settings, HydrologyPlanCodec.encode(settings, window)).orElseThrow();
|
||||
assertBitExact(window, decodedWindow, tiers);
|
||||
|
||||
@@ -85,7 +79,7 @@ public class HydrologyPlanCodecTest {
|
||||
assertReachesBitExact(region.majorReaches(), decodedRegion.majorReaches(), tiers);
|
||||
assertPondsBitExact(region.lakes(), decodedRegion.lakes());
|
||||
|
||||
WindowPlan empty = new WindowPlan(new WindowKey(Integer.MIN_VALUE, Integer.MAX_VALUE), List.of(), List.of(), List.of());
|
||||
WindowPlan empty = new WindowPlan(new WindowKey(Integer.MIN_VALUE, Integer.MAX_VALUE), List.of(), List.of());
|
||||
assertEquals(empty, HydrologyPlanCodec.decodeWindow(settings, HydrologyPlanCodec.encode(settings, empty)).orElseThrow());
|
||||
|
||||
SyntheticTerrain terrain = SyntheticTerrain.openFractal(SEED);
|
||||
@@ -105,6 +99,18 @@ public class HydrologyPlanCodecTest {
|
||||
assertBitExact(planned, HydrologyPlanCodec.decodeWindow(settings, HydrologyPlanCodec.encode(settings, planned)).orElseThrow(), tiers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tidalReachesRoundTripOnTheTidalTier() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
int sea = settings.seaLevel();
|
||||
Reach tidal = new Reach(404L, settings.tidalTier(), 0L, new float[]{0f, 8f, 16f}, new float[]{0f, 4f, 2f}, new int[]{sea, sea, sea},
|
||||
new float[]{2f, 6f, 12f}, new float[]{1f, 4f, 1f}, new ReachStyle[]{ReachStyle.TIDAL, ReachStyle.TIDAL, ReachStyle.TIDAL}, 0f);
|
||||
WindowPlan window = new WindowPlan(new WindowKey(0, 0), List.of(tidal), List.of());
|
||||
WindowPlan decoded = HydrologyPlanCodec.decodeWindow(settings, HydrologyPlanCodec.encode(settings, window)).orElseThrow();
|
||||
assertEquals(window, decoded);
|
||||
assertSame(settings.tidalTier(), decoded.reaches().get(0).tier());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void codecDecodesMismatchedOrCorruptDataAsEmpty() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
@@ -112,9 +118,7 @@ public class HydrologyPlanCodecTest {
|
||||
Reach reach = new Reach(5L, tier, -1L, new float[]{1f, 2f, 3f}, new float[]{4f, 5f, 6f}, new int[]{70, 69, 68},
|
||||
new float[]{1f, 1f, 1.5f}, new float[]{1f, 1f, 1f}, new ReachStyle[]{ReachStyle.RUN, ReachStyle.RIFFLE, ReachStyle.MOUTH}, 2000f);
|
||||
Pond pond = new Pond(9L, PondKind.SEEDED, 66, 62, 10, 12, 66.5f, mask(3), 5L, 0, "water", 11, 13);
|
||||
SeaInlet inlet = new SeaInlet(12L, new float[]{8f, 16f, 24f}, new float[]{0f, 0f, 8f}, new float[]{5f, 4f, 3f}, 63,
|
||||
new int[]{60, 61, 59}, new int[]{90, 68, 70}, 24, 8, 7);
|
||||
WindowPlan window = new WindowPlan(new WindowKey(1, 2), List.of(reach), List.of(pond), List.of(inlet));
|
||||
WindowPlan window = new WindowPlan(new WindowKey(1, 2), List.of(reach), List.of(pond));
|
||||
byte[] encoded = HydrologyPlanCodec.encode(settings, window);
|
||||
|
||||
HydrologySettings reseeded = HydrologySettings.compile(new IrisHydrology(), SEED + 1L, SyntheticTerrain.SEA_LEVEL,
|
||||
@@ -147,7 +151,7 @@ public class HydrologyPlanCodecTest {
|
||||
Reach stray = new Reach(6L, foreign, -1L, new float[]{1f, 2f}, new float[]{1f, 2f}, new int[]{1, 1}, new float[]{1f, 1f},
|
||||
new float[]{1f, 1f}, new ReachStyle[]{ReachStyle.RUN, ReachStyle.RUN}, 1f);
|
||||
try {
|
||||
HydrologyPlanCodec.encode(settings, new WindowPlan(new WindowKey(0, 0), List.of(stray), List.of(), List.of()));
|
||||
HydrologyPlanCodec.encode(settings, new WindowPlan(new WindowKey(0, 0), List.of(stray), List.of()));
|
||||
fail("a tier outside the settings has no index");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(expected.getMessage(), expected.getMessage().contains("foreign"));
|
||||
@@ -174,21 +178,13 @@ public class HydrologyPlanCodecTest {
|
||||
new Pond(6L, PondKind.SEEDED, 74, 71, 30, 8, 74.25f, mask(2), -1L, 1, "water", 28, 6),
|
||||
new Pond(7L, PondKind.CHAINED, 68, 64, -20, 16, 68.75f, mask(0), 41L, 2, "lava", -22, 14),
|
||||
new Pond(8L, PondKind.LAKE, 80, 60, 64, -64, 80.5f, mask(0), -1L, 0, null, 60, -60));
|
||||
return new WindowPlan(new WindowKey(2, -3), List.of(reach), ponds, List.of());
|
||||
return new WindowPlan(new WindowKey(2, -3), List.of(reach), ponds);
|
||||
}
|
||||
|
||||
private static void assertBitExact(WindowPlan expected, WindowPlan actual, List<HydrologyTier> tiers) {
|
||||
assertEquals(expected, actual);
|
||||
assertReachesBitExact(expected.reaches(), actual.reaches(), tiers);
|
||||
assertPondsBitExact(expected.ponds(), actual.ponds());
|
||||
assertEquals(expected.inlets().size(), actual.inlets().size());
|
||||
for (int index = 0; index < expected.inlets().size(); index++) {
|
||||
SeaInlet want = expected.inlets().get(index);
|
||||
SeaInlet got = actual.inlets().get(index);
|
||||
assertArrayEquals(rawBits(want.xs()), rawBits(got.xs()));
|
||||
assertArrayEquals(rawBits(want.zs()), rawBits(got.zs()));
|
||||
assertArrayEquals(rawBits(want.halfWidth()), rawBits(got.halfWidth()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertReachesBitExact(List<Reach> expected, List<Reach> actual, List<HydrologyTier> tiers) {
|
||||
|
||||
+1
-1
@@ -225,7 +225,7 @@ public class HydrologyPlanStoreTest {
|
||||
new ReachStyle[]{ReachStyle.RUN, ReachStyle.CASCADE, ReachStyle.RUN}, 1600f);
|
||||
Pond pond = new Pond(key.wz() * 17L - key.wx(), PondKind.NATURAL, 72, 68, (int) x, (int) z, 72.25f,
|
||||
new PondMask((int) x, (int) z, 4, 3, 2, new long[]{0b101101L}), reach.id(), 0, "water", (int) x + 4, (int) z);
|
||||
return new WindowPlan(key, List.of(reach), List.of(pond), List.of());
|
||||
return new WindowPlan(key, List.of(reach), List.of(pond));
|
||||
}
|
||||
|
||||
private static HydrologySettings settings(long seed) {
|
||||
|
||||
+60
-8
@@ -4,9 +4,11 @@ import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorationPart;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorator;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisFluidProfile;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisBankStyle;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyMaterials;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisSeaInlets;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
@@ -21,6 +23,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -35,7 +38,7 @@ public class HydrologySettingsTest {
|
||||
private static final int SEA_LEVEL = 62;
|
||||
private static final int MIN_Y = -64;
|
||||
private static final int MAX_Y = 320;
|
||||
private static final long DEFAULT_FINGERPRINT = -2359553697125315860L;
|
||||
private static final long DEFAULT_FINGERPRINT = 8483795183515434045L;
|
||||
|
||||
@Test
|
||||
public void densityIsBoundedAndChangesThePlanIdentity() {
|
||||
@@ -708,22 +711,71 @@ public class HydrologySettingsTest {
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains(field));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seaInletDefaultsDescribeAFunnelReachingInland() {
|
||||
HydrologySettings.SeaInlets inlets = compile(new IrisHydrology()).underground().seaInlets();
|
||||
assertTrue(inlets.enabled());
|
||||
assertEquals(160, inlets.spacing());
|
||||
assertEquals(new HydrologySettings.IntRange(64, 256), inlets.length());
|
||||
assertEquals(44, inlets.maximumBankHeight());
|
||||
assertEquals(new HydrologySettings.FloatRange(13f, 15f), inlets.mouthHalfWidth());
|
||||
assertEquals(new HydrologySettings.FloatRange(2.5f, 3f), inlets.headHalfWidth());
|
||||
assertEquals(1.4f, inlets.taper(), 0f);
|
||||
assertEquals(0.18f, inlets.widthVariation(), 1e-6f);
|
||||
assertEquals(4f, inlets.meanderWidth(), 0f);
|
||||
assertEquals(new HydrologySettings.IntRange(2, 5), inlets.depth());
|
||||
assertEquals(32, inlets.bankBand());
|
||||
assertEquals(IrisBankStyle.SMOOTH, inlets.bankStyle());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seaInletRangesAreBounded() {
|
||||
compile(inlets(new KList<>(1D, 16D), new KList<>(2, 16)));
|
||||
for (IrisHydrology rejected : List.of(inlets(new KList<>(0.5D, 5D), new KList<>(2, 5)), inlets(new KList<>(2D, 17D), new KList<>(2, 5)),
|
||||
inlets(new KList<>(2D, 5D), new KList<>(2, 17)), inlets(new KList<>(2D, 5D), new KList<>(1, 5)))) {
|
||||
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class, () -> compile(rejected));
|
||||
compile(inlets(config -> config.setMouthHalfWidth(new KList<>(8D, 32D)).setHeadHalfWidth(new KList<>(1D, 8D)).setDepth(new KList<>(2, 16))));
|
||||
List<IrisHydrology> rejected = List.of(
|
||||
inlets(config -> config.setMouthHalfWidth(new KList<>(1.5D, 14D)).setHeadHalfWidth(new KList<>(1D, 1.5D))),
|
||||
inlets(config -> config.setMouthHalfWidth(new KList<>(10D, 33D))),
|
||||
inlets(config -> config.setHeadHalfWidth(new KList<>(0.5D, 3D))),
|
||||
inlets(config -> config.setHeadHalfWidth(new KList<>(2D, 9D))),
|
||||
inlets(config -> config.setDepth(new KList<>(2, 17))),
|
||||
inlets(config -> config.setDepth(new KList<>(1, 5))),
|
||||
inlets(config -> config.setMaximumBankHeight(1)),
|
||||
inlets(config -> config.setMaximumBankHeight(129)),
|
||||
inlets(config -> config.setTaper(0.4D)),
|
||||
inlets(config -> config.setTaper(4.1D)),
|
||||
inlets(config -> config.setWidthVariation(-0.1D)),
|
||||
inlets(config -> config.setWidthVariation(0.6D)),
|
||||
inlets(config -> config.setMeanderWidth(0.5D)),
|
||||
inlets(config -> config.setMeanderWidth(17D)),
|
||||
inlets(config -> config.setBankBand(3)),
|
||||
inlets(config -> config.setBankBand(65)));
|
||||
for (IrisHydrology config : rejected) {
|
||||
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class, () -> compile(config));
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("underground.seaInlets"));
|
||||
}
|
||||
IllegalArgumentException belowWorld = assertThrows(IllegalArgumentException.class,
|
||||
() -> HydrologySettings.compile(inlets(new KList<>(2D, 5D), new KList<>(2, 16)), SEED, MIN_Y + 18, MIN_Y, MAX_Y));
|
||||
() -> HydrologySettings.compile(inlets(config -> config.setDepth(new KList<>(2, 16))), SEED, MIN_Y + 16, MIN_Y, MAX_Y));
|
||||
assertTrue(belowWorld.getMessage(), belowWorld.getMessage().contains("world bottom"));
|
||||
}
|
||||
|
||||
private static IrisHydrology inlets(KList<Double> halfWidth, KList<Integer> depth) {
|
||||
@Test
|
||||
public void seaInletMouthMustBeWiderThanItsHead() {
|
||||
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class,
|
||||
() -> compile(inlets(config -> config.setMouthHalfWidth(new KList<>(4D, 14D)).setHeadHalfWidth(new KList<>(2D, 5D)))));
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("mouthHalfWidth"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overLongSeaInletsFailAtCompile() {
|
||||
compile(inlets(config -> config.setLength(new KList<>(64, 447)).setMouthHalfWidth(new KList<>(11D, 16D)).setBankBand(24)));
|
||||
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class,
|
||||
() -> compile(inlets(config -> config.setLength(new KList<>(64, 512)))));
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("underground.seaInlets"));
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains(Integer.toString(WindowKey.SIZE)));
|
||||
}
|
||||
|
||||
private static IrisHydrology inlets(Consumer<IrisSeaInlets> tweak) {
|
||||
IrisHydrology config = new IrisHydrology();
|
||||
config.getUnderground().getSeaInlets().setHalfWidth(halfWidth).setDepth(depth);
|
||||
tweak.accept(config.getUnderground().getSeaInlets());
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import art.arcane.iris.generation.hydrology.raster.ChunkRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.ReachIndex;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondPlanner;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
@@ -33,7 +32,6 @@ final class PlannedScene {
|
||||
private final Function<RegionKey, RegionPlan> regions;
|
||||
private final List<Reach> reaches;
|
||||
private final List<Pond> ponds;
|
||||
private final List<SeaInlet> inlets;
|
||||
private final ChunkRasterizer rasterizer;
|
||||
private final Map<WindowKey, IndexedWindow> windows = new HashMap<>();
|
||||
private final Map<Long, ChunkWaterRaster> rasters = new HashMap<>();
|
||||
@@ -49,15 +47,12 @@ final class PlannedScene {
|
||||
this.rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
List<Reach> ownedReaches = new ArrayList<>();
|
||||
List<Pond> ownedPonds = new ArrayList<>();
|
||||
List<SeaInlet> ownedInlets = new ArrayList<>();
|
||||
for (WindowPlan plan : plans.values()) {
|
||||
ownedReaches.addAll(plan.reaches());
|
||||
ownedPonds.addAll(plan.ponds());
|
||||
ownedInlets.addAll(plan.inlets());
|
||||
}
|
||||
this.reaches = List.copyOf(ownedReaches);
|
||||
this.ponds = List.copyOf(ownedPonds);
|
||||
this.inlets = List.copyOf(ownedInlets);
|
||||
}
|
||||
|
||||
static PlannedScene plan(SyntheticTerrain terrain, HydrologySettings settings, int windowsX, int windowsZ) {
|
||||
@@ -87,7 +82,7 @@ final class PlannedScene {
|
||||
requireOrigin(origin, WindowKey.containing(pond.floorX(), pond.floorZ()), pond);
|
||||
}
|
||||
Map<WindowKey, WindowPlan> plans = new LinkedHashMap<>();
|
||||
plans.put(origin, new WindowPlan(origin, reaches, ponds, List.of()));
|
||||
plans.put(origin, new WindowPlan(origin, reaches, ponds));
|
||||
return new PlannedScene(terrain, settings, 1, 1, plans, key -> new RegionPlan(key, List.of(), List.of()));
|
||||
}
|
||||
|
||||
@@ -123,10 +118,6 @@ final class PlannedScene {
|
||||
return ponds;
|
||||
}
|
||||
|
||||
List<SeaInlet> inlets() {
|
||||
return inlets;
|
||||
}
|
||||
|
||||
int minX() {
|
||||
return 0;
|
||||
}
|
||||
@@ -184,7 +175,7 @@ final class PlannedScene {
|
||||
|
||||
private IndexedWindow window(WindowKey key) {
|
||||
return windows.computeIfAbsent(key, ignored -> {
|
||||
WindowPlan plan = plans.getOrDefault(key, new WindowPlan(key, List.of(), List.of(), List.of()));
|
||||
WindowPlan plan = plans.getOrDefault(key, new WindowPlan(key, List.of(), List.of()));
|
||||
return new IndexedWindow(plan, ReachIndex.build(key, plan.reaches(), plan.ponds()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,6 +58,16 @@ final class SyntheticTerrain implements HydrologyTerrainSource {
|
||||
return new SyntheticTerrain(natural, rainfall, streamsBlocked, area, land);
|
||||
}
|
||||
|
||||
SyntheticTerrain rising(double fromX, double slope) {
|
||||
DoubleBinaryOperator inner = natural;
|
||||
return new SyntheticTerrain((x, z) -> inner.applyAsDouble(x, z) + Math.max(0D, x - fromX) * slope, rainfall, streamsBlocked, pondsBlocked, land);
|
||||
}
|
||||
|
||||
SyntheticTerrain steppedAbove(double fromZ, double rise) {
|
||||
DoubleBinaryOperator inner = natural;
|
||||
return new SyntheticTerrain((x, z) -> inner.applyAsDouble(x, z) + (z >= fromZ ? rise : 0D), rainfall, streamsBlocked, pondsBlocked, land);
|
||||
}
|
||||
|
||||
SyntheticTerrain lowered(double depth) {
|
||||
DoubleBinaryOperator inner = natural;
|
||||
return new SyntheticTerrain((x, z) -> inner.applyAsDouble(x, z) - depth, rainfall, streamsBlocked, pondsBlocked, land);
|
||||
@@ -278,6 +288,20 @@ final class SyntheticTerrain implements HydrologyTerrainSource {
|
||||
return new SyntheticTerrain((x, z) -> x < coastX ? OCEAN_FLOOR : SEA_LEVEL + 30D + 0.05D * (x - coastX) + 3D * Math.sin(z / 40D));
|
||||
}
|
||||
|
||||
static SyntheticTerrain lowCoast(double coastX) {
|
||||
return new SyntheticTerrain((x, z) -> {
|
||||
double inland = x - coastX;
|
||||
return inland < 0D ? OCEAN_FLOOR : SEA_LEVEL + 2D + 0.06D * inland + 2.5D * Math.sin(z / 37D) * Math.min(1D, inland / 32D);
|
||||
});
|
||||
}
|
||||
|
||||
static SyntheticTerrain lowIsland(double centreX, double centreZ, double coastRadius, double peakAboveSea) {
|
||||
return new SyntheticTerrain((x, z) -> {
|
||||
double radius = Math.hypot(x - centreX, z - centreZ);
|
||||
return radius > coastRadius ? OCEAN_FLOOR : SEA_LEVEL + 1D + peakAboveSea * (1D - radius / coastRadius);
|
||||
});
|
||||
}
|
||||
|
||||
static SyntheticTerrain seaStrip(double stripMinX, double stripWidth) {
|
||||
return new SyntheticTerrain((x, z) -> x >= stripMinX && x < stripMinX + stripWidth ? SEA_LEVEL - 2D : valleySlope(x, z));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,414 @@
|
||||
package art.arcane.iris.generation.hydrology.plan;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.grid.DemGrid;
|
||||
import art.arcane.iris.generation.hydrology.grid.HeightLattice;
|
||||
import art.arcane.iris.generation.hydrology.grid.HydrologySampleBuffer;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
import art.arcane.iris.generation.hydrology.water.PondMask;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
import art.arcane.iris.generation.hydrology.water.ShapedNetwork;
|
||||
import art.arcane.iris.generation.hydrology.water.TidalPlanner;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TidalPlannerTest {
|
||||
private static final long SEED = 1337L;
|
||||
private static final int SEA = SyntheticTerrain.SEA_LEVEL;
|
||||
private static final double COAST_X = 300D;
|
||||
private static final ShapedNetwork NOTHING = new ShapedNetwork(List.of(), List.of());
|
||||
private static final List<WindowKey> COAST_WINDOWS = List.of(new WindowKey(0, 0), new WindowKey(0, 1), new WindowKey(0, -1), new WindowKey(1, 0));
|
||||
|
||||
private static HydrologySettings settings() {
|
||||
return settings(new IrisHydrology());
|
||||
}
|
||||
|
||||
private static HydrologySettings settings(IrisHydrology config) {
|
||||
return HydrologySettings.compile(config, SEED, SEA, SyntheticTerrain.MIN_Y, SyntheticTerrain.MAX_Y);
|
||||
}
|
||||
|
||||
private static Fixture planner(HydrologySettings settings, SyntheticTerrain terrain) {
|
||||
return new Fixture(settings, new HeightLattice(terrain, WindowPlanner.FINE_CELL, false, 1 << 21));
|
||||
}
|
||||
|
||||
private static List<Reach> arms(Fixture planner) {
|
||||
return arms2(planner, COAST_WINDOWS.toArray(new WindowKey[0]));
|
||||
}
|
||||
|
||||
private record Fixture(TidalPlanner tidal, HeightLattice fine) {
|
||||
Fixture(HydrologySettings settings, HeightLattice fine) {
|
||||
this(new TidalPlanner(settings, fine), fine);
|
||||
}
|
||||
|
||||
List<Reach> plan(WindowKey window, ShapedNetwork network) {
|
||||
int span = 3 * WindowKey.SIZE / WindowPlanner.CELL;
|
||||
int originX = (window.wx() - 1) * WindowKey.SIZE;
|
||||
int originZ = (window.wz() - 1) * WindowKey.SIZE;
|
||||
HydrologySampleBuffer samples = new HydrologySampleBuffer(span * span);
|
||||
fine.fill(originX / WindowPlanner.FINE_CELL, originZ / WindowPlanner.FINE_CELL, span, span, WindowPlanner.CELL / WindowPlanner.FINE_CELL, samples);
|
||||
DemGrid natural = new DemGrid(originX, originZ, WindowPlanner.CELL, span, span);
|
||||
System.arraycopy(samples.height(), 0, natural.values(), 0, span * span);
|
||||
return tidal.plan(window, natural, samples, network);
|
||||
}
|
||||
}
|
||||
|
||||
private static float length(Reach reach) {
|
||||
float length = 0f;
|
||||
for (int point = 1; point < reach.xs().length; point++) {
|
||||
length += (float) Math.hypot(reach.xs()[point] - reach.xs()[point - 1], reach.zs()[point] - reach.zs()[point - 1]);
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
private static int last(Reach reach) {
|
||||
return reach.xs().length - 1;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lowCoastHoldsWholeTidalReachesAtSeaLevelThatDrainToTheSea() {
|
||||
HydrologySettings settings = settings();
|
||||
List<Reach> arms = arms(planner(settings, SyntheticTerrain.lowCoast(COAST_X)));
|
||||
assertTrue("arms on the low coast " + arms.size(), arms.size() >= 3);
|
||||
for (Reach arm : arms) {
|
||||
assertEquals(settings.tidalTier(), arm.tier());
|
||||
assertEquals(0L, arm.downstreamId());
|
||||
for (int point = 0; point < arm.xs().length; point++) {
|
||||
assertEquals(arm + " point " + point, ReachStyle.TIDAL, arm.style()[point]);
|
||||
assertEquals(arm + " point " + point, SEA, arm.grade()[point]);
|
||||
}
|
||||
assertTrue(arm + " starts inland of the coast", arm.xs()[0] > COAST_X + 16f);
|
||||
assertTrue(arm + " ends in the sea", arm.xs()[last(arm)] < COAST_X);
|
||||
assertTrue(arm + " length " + length(arm), length(arm) >= settings.underground().seaInlets().length().min());
|
||||
WindowPlanner.requireSeaConnectedHeads(new WindowPlan(WindowKey.containing((int) Math.floor(arm.xs()[last(arm)]), (int) Math.floor(arm.zs()[last(arm)])),
|
||||
List.of(arm), List.of()), SEA);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void armsBelongToTheWindowOfTheirMouth() {
|
||||
Fixture planner = planner(settings(), SyntheticTerrain.lowCoast(COAST_X));
|
||||
for (WindowKey window : COAST_WINDOWS) {
|
||||
for (Reach arm : planner.plan(window, NOTHING)) {
|
||||
assertEquals(window, WindowKey.containing((int) Math.floor(arm.xs()[last(arm)]), (int) Math.floor(arm.zs()[last(arm)])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tallCoastsHoldNoArms() {
|
||||
assertTrue(arms(planner(settings(), SyntheticTerrain.cliffCoast(COAST_X).lowered(-30D))).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledAndZeroDensityPlanNoArms() {
|
||||
IrisHydrology disabled = new IrisHydrology();
|
||||
disabled.getUnderground().getSeaInlets().setEnabled(false);
|
||||
assertTrue(arms(planner(settings(disabled), SyntheticTerrain.lowCoast(COAST_X))).isEmpty());
|
||||
assertTrue(arms(planner(settings(new IrisHydrology().setDensity(0D)), SyntheticTerrain.lowCoast(COAST_X))).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void densityThinsSites() {
|
||||
List<Reach> full = arms(planner(settings(), SyntheticTerrain.lowCoast(COAST_X)));
|
||||
List<Reach> half = arms(planner(settings(new IrisHydrology().setDensity(0.5D)), SyntheticTerrain.lowCoast(COAST_X)));
|
||||
assertFalse(half.isEmpty());
|
||||
assertTrue(half.size() < full.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streamBlockedGroundHoldsNoArms() {
|
||||
SyntheticTerrain blocked = SyntheticTerrain.lowCoast(COAST_X).withStreamsBlocked((x, z) -> true);
|
||||
assertTrue(arms(planner(settings(), blocked)).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void armsWalkAwayFromTheSeaOnAPeninsulaInsteadOfAlongTheShore() {
|
||||
SyntheticTerrain island = SyntheticTerrain.lowIsland(800D, 800D, 420D, 24D);
|
||||
for (Reach arm : arms2(planner(settings(), island), new WindowKey(0, 0), new WindowKey(1, 0), new WindowKey(0, 1), new WindowKey(1, 1))) {
|
||||
double mouthRadius = Math.hypot(arm.xs()[last(arm)] - 800D, arm.zs()[last(arm)] - 800D);
|
||||
double headRadius = Math.hypot(arm.xs()[0] - 800D, arm.zs()[0] - 800D);
|
||||
assertTrue(arm + " runs inland by at least half its length: " + (mouthRadius - headRadius) + " of " + length(arm),
|
||||
mouthRadius - headRadius >= 0.5D * length(arm));
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Reach> arms2(Fixture planner, WindowKey... windows) {
|
||||
List<Reach> arms = new ArrayList<>();
|
||||
for (WindowKey window : windows) {
|
||||
arms.addAll(planner.plan(window, NOTHING));
|
||||
}
|
||||
return arms;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headsNarrowToAtLeastAThirdOfTheMouth() {
|
||||
for (Reach arm : arms(planner(settings(), SyntheticTerrain.lowCoast(COAST_X)))) {
|
||||
float[] widths = arm.halfWidth();
|
||||
int points = widths.length;
|
||||
float head = widths[points / 8];
|
||||
float mouth = widths[points - 1];
|
||||
assertTrue(arm + " mouth " + mouth + " head " + head, mouth / Math.max(head, 2f) >= 3f);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void armsStopBeforeGroundAboveTheBankLimit() {
|
||||
SyntheticTerrain ramp = SyntheticTerrain.lowCoast(COAST_X);
|
||||
HydrologySettings settings = settings();
|
||||
int limit = settings.underground().seaInlets().maximumBankHeight();
|
||||
for (Reach arm : arms(planner(settings, ramp))) {
|
||||
for (int point = 0; point < arm.xs().length; point++) {
|
||||
assertTrue(arm + " runs through ground " + ramp.natural(arm.xs()[point], arm.zs()[point]),
|
||||
ramp.natural(arm.xs()[point], arm.zs()[point]) <= SEA + limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void armsNeverGradeBanksThroughGroundTooTallForTheBand() {
|
||||
HydrologySettings settings = settings();
|
||||
double wallX = COAST_X + 150D;
|
||||
SyntheticTerrain hill = SyntheticTerrain.lowCoast(COAST_X).rising(wallX, 2D);
|
||||
double graded = 1.5D * settings.underground().seaInlets().maximumBankHeight();
|
||||
List<Reach> arms = arms(planner(settings, hill));
|
||||
assertFalse("a low strip still holds arms", arms.isEmpty());
|
||||
for (Reach arm : arms) {
|
||||
for (int point = 0; point < arm.xs().length; point++) {
|
||||
double side = arm.halfWidth()[point] + settings.underground().seaInlets().bankBand();
|
||||
assertTrue(arm + " grades through " + hill.natural(arm.xs()[point] + side, arm.zs()[point]),
|
||||
hill.natural(arm.xs()[point] + side, arm.zs()[point]) <= SEA + graded + 1D);
|
||||
}
|
||||
double ahead = arm.halfWidth()[0] + settings.underground().seaInlets().bankBand();
|
||||
assertTrue(arm + " ends against a wall", hill.natural(arm.xs()[0] + ahead, arm.zs()[0]) <= SEA + graded + 1D);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void armsTooShortToStopBeforeAWallAreLeftOut() {
|
||||
SyntheticTerrain wall = SyntheticTerrain.lowCoast(COAST_X).rising(COAST_X + 60D, 8D);
|
||||
for (Reach arm : arms(planner(settings(), wall))) {
|
||||
assertTrue(arm + " ends against the wall", arm.xs()[0] + arm.halfWidth()[0] + 16f <= COAST_X + 60D);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void armsLeaveTheBandOfACliffRunningBesideThem() {
|
||||
HydrologySettings settings = settings();
|
||||
SyntheticTerrain coast = SyntheticTerrain.lowCoast(COAST_X);
|
||||
Reach free = arms(planner(settings, coast)).get(0);
|
||||
float middleZ = free.zs()[free.zs().length / 2];
|
||||
float cliffZ = middleZ + 16f;
|
||||
for (Reach arm : arms(planner(settings, coast.steppedAbove(cliffZ, 20D)))) {
|
||||
for (int point = 0; point < arm.xs().length; point++) {
|
||||
float apart = Math.abs(cliffZ - arm.zs()[point]) - arm.halfWidth()[point];
|
||||
assertTrue(arm + " runs " + apart + " from the cliff at point " + point + ", x " + arm.xs()[point],
|
||||
arm.xs()[point] < COAST_X + 8f || apart >= settings.underground().seaInlets().bankBand() / 2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void territoriesKeepCloseMouthsApart() {
|
||||
IrisHydrology dense = new IrisHydrology();
|
||||
dense.getUnderground().getSeaInlets().setSpacing(48).setMouthHalfWidth(new KList<>(3D, 4D)).setHeadHalfWidth(new KList<>(1D, 1.5D)).setMeanderWidth(1D);
|
||||
HydrologySettings settings = settings(dense);
|
||||
List<Reach> arms = arms(planner(settings, SyntheticTerrain.lowCoast(COAST_X)));
|
||||
assertFalse(arms.isEmpty());
|
||||
for (int a = 0; a < arms.size(); a++) {
|
||||
for (int b = a + 1; b < arms.size(); b++) {
|
||||
double apart = Math.hypot(arms.get(a).zs()[last(arms.get(a))] - arms.get(b).zs()[last(arms.get(b))], arms.get(a).xs()[last(arms.get(a))] - arms.get(b).xs()[last(arms.get(b))]);
|
||||
assertTrue("mouths " + apart + " apart", apart >= 13D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groundBelowTheSeaBesideAnArmCutsTheArmOffAtIt() {
|
||||
SyntheticTerrain plain = SyntheticTerrain.lowCoast(COAST_X);
|
||||
List<Reach> clean = arms(planner(settings(), plain));
|
||||
assertFalse(clean.isEmpty());
|
||||
Reach longest = clean.get(0);
|
||||
for (Reach arm : clean) {
|
||||
longest = length(arm) > length(longest) ? arm : longest;
|
||||
}
|
||||
double hollowX = longest.xs()[0] - 12D;
|
||||
double hollowZ = longest.zs()[0];
|
||||
SyntheticTerrain hollow = plain.withPit(hollowX, hollowZ, 10D, 40D).withLand((x, z) -> x > COAST_X);
|
||||
for (Reach arm : arms(planner(settings(), hollow))) {
|
||||
for (int point = 0; point < arm.xs().length; point++) {
|
||||
double beside = Math.hypot(arm.xs()[point] - hollowX, arm.zs()[point] - hollowZ);
|
||||
assertTrue(arm + " passes the hollow at " + beside, beside > arm.halfWidth()[point] + 4D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void armsKeepClearOfRivers() {
|
||||
SyntheticTerrain coast = SyntheticTerrain.lowCoast(COAST_X);
|
||||
HydrologySettings settings = settings();
|
||||
Fixture planner = planner(settings, coast);
|
||||
List<Reach> free = arms(planner);
|
||||
assertFalse(free.isEmpty());
|
||||
Reach blocked = free.get(0);
|
||||
float z = blocked.zs()[blocked.xs().length / 2];
|
||||
int points = 40;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grade = new int[points];
|
||||
float[] halfWidth = new float[points];
|
||||
float[] depth = new float[points];
|
||||
ReachStyle[] style = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = 700f - point * 10f;
|
||||
zs[point] = z;
|
||||
grade[point] = SEA + 2;
|
||||
halfWidth[point] = 3f;
|
||||
depth[point] = 1f;
|
||||
style[point] = ReachStyle.RUN;
|
||||
}
|
||||
Reach river = new Reach(9L, settings.tiers().get(1), 0L, xs, zs, grade, halfWidth, depth, style, 30000f);
|
||||
ShapedNetwork network = new ShapedNetwork(List.of(river), List.of());
|
||||
WindowKey owner = WindowKey.containing((int) Math.floor(blocked.xs()[last(blocked)]), (int) Math.floor(blocked.zs()[last(blocked)]));
|
||||
for (Reach arm : planner.plan(owner, network)) {
|
||||
for (int point = 0; point < arm.xs().length; point++) {
|
||||
for (int other = 0; other < points; other++) {
|
||||
double apart = Math.hypot(arm.xs()[point] - xs[other], arm.zs()[point] - zs[other]);
|
||||
assertTrue(arm + " nears the river: " + apart, apart > arm.halfWidth()[point] + 3f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void armsKeepClearOfPonds() {
|
||||
SyntheticTerrain coast = SyntheticTerrain.lowCoast(COAST_X);
|
||||
Fixture planner = planner(settings(), coast);
|
||||
Reach blocked = arms(planner).get(0);
|
||||
int pondX = (int) blocked.xs()[blocked.xs().length / 2];
|
||||
int pondZ = (int) blocked.zs()[blocked.xs().length / 2];
|
||||
long[] bits = new long[1];
|
||||
Arrays.fill(bits, -1L);
|
||||
PondMask mask = new PondMask(pondX - 16, pondZ - 16, 8, 5, 5, bits);
|
||||
Pond pond = new Pond(3L, PondKind.NATURAL, SEA + 8, SEA + 4, pondX, pondZ, SEA + 8.5f, mask, 0L, 0, null, pondX, pondZ);
|
||||
WindowKey owner = WindowKey.containing((int) Math.floor(blocked.xs()[last(blocked)]), (int) Math.floor(blocked.zs()[last(blocked)]));
|
||||
for (Reach arm : planner.plan(owner, new ShapedNetwork(List.of(), List.of(pond)))) {
|
||||
for (int point = 0; point < arm.xs().length; point++) {
|
||||
assertFalse(arm + " enters the pond", mask.grownContains((int) arm.xs()[point], (int) arm.zs()[point]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void armsNeverCrowdEachOtherAcrossWindowLines() {
|
||||
HydrologySettings settings = settings();
|
||||
List<Reach> arms = arms(planner(settings, SyntheticTerrain.lowCoast(COAST_X)));
|
||||
for (int a = 0; a < arms.size(); a++) {
|
||||
for (int b = a + 1; b < arms.size(); b++) {
|
||||
Reach first = arms.get(a);
|
||||
Reach second = arms.get(b);
|
||||
for (int p = 0; p < first.xs().length; p += 2) {
|
||||
for (int q = 0; q < second.xs().length; q += 2) {
|
||||
double apart = Math.hypot(first.xs()[p] - second.xs()[q], first.zs()[p] - second.zs()[q]);
|
||||
assertTrue(first + " and " + second + " come within " + apart,
|
||||
apart >= first.halfWidth()[p] + second.halfWidth()[q]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void armsAreIdenticalInAnyPlanningOrderAndAcrossThreads() throws Exception {
|
||||
HydrologySettings settings = settings();
|
||||
SyntheticTerrain coast = SyntheticTerrain.lowCoast(COAST_X);
|
||||
Map<WindowKey, List<Reach>> forward = new HashMap<>();
|
||||
Fixture first = planner(settings, coast);
|
||||
for (WindowKey window : COAST_WINDOWS) {
|
||||
forward.put(window, first.plan(window, NOTHING));
|
||||
}
|
||||
Map<WindowKey, List<Reach>> backward = new HashMap<>();
|
||||
Fixture second = planner(settings, coast);
|
||||
for (int index = COAST_WINDOWS.size() - 1; index >= 0; index--) {
|
||||
backward.put(COAST_WINDOWS.get(index), second.plan(COAST_WINDOWS.get(index), NOTHING));
|
||||
}
|
||||
assertEquals(forward, backward);
|
||||
Fixture third = planner(settings, coast);
|
||||
ExecutorService pool = Executors.newFixedThreadPool(4);
|
||||
try {
|
||||
Map<WindowKey, Future<List<Reach>>> futures = new HashMap<>();
|
||||
for (WindowKey window : COAST_WINDOWS) {
|
||||
futures.put(window, pool.submit(() -> third.plan(window, NOTHING)));
|
||||
}
|
||||
for (WindowKey window : COAST_WINDOWS) {
|
||||
assertEquals(forward.get(window), futures.get(window).get());
|
||||
}
|
||||
} finally {
|
||||
pool.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyArmIsPlannedOnlyByTheWindowOfItsMouth() {
|
||||
Fixture planner = planner(settings(), SyntheticTerrain.lowCoast(COAST_X));
|
||||
Map<Long, WindowKey> owners = new HashMap<>();
|
||||
for (int wz = -2; wz <= 2; wz++) {
|
||||
for (int wx = -1; wx <= 2; wx++) {
|
||||
WindowKey window = new WindowKey(wx, wz);
|
||||
for (Reach arm : planner.plan(window, NOTHING)) {
|
||||
assertEquals(arm + " planned twice", null, owners.put(arm.id(), window));
|
||||
}
|
||||
}
|
||||
}
|
||||
assertFalse(owners.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void territoriesKeepArmsApartWithoutKnowingWhatTheirNeighboursPlanned() {
|
||||
HydrologySettings settings = settings();
|
||||
SyntheticTerrain coast = SyntheticTerrain.lowCoast(COAST_X);
|
||||
Fixture planner = planner(settings, coast);
|
||||
WindowKey first = new WindowKey(0, 0);
|
||||
WindowKey second = new WindowKey(0, 1);
|
||||
List<Reach> alone = planner.plan(second, NOTHING);
|
||||
planner.plan(first, NOTHING);
|
||||
assertEquals("planning the neighbour first changes nothing", alone, planner(settings, coast).plan(second, NOTHING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void armsFollowTheFunnelKnobs() {
|
||||
IrisHydrology wide = new IrisHydrology();
|
||||
wide.getUnderground().getSeaInlets().setMouthHalfWidth(new KList<>(20D, 20D))
|
||||
.setWidthVariation(0D);
|
||||
for (Reach arm : arms(planner(settings(wide), SyntheticTerrain.lowCoast(COAST_X)))) {
|
||||
assertEquals(arm.toString(), 20f, arm.halfWidth()[last(arm)], 0.01f);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void depthShoalsToOneBlockAtBothEnds() {
|
||||
for (Reach arm : arms(planner(settings(), SyntheticTerrain.lowCoast(COAST_X)))) {
|
||||
assertEquals(1f, arm.depth()[0], 0.01f);
|
||||
assertEquals(1f, arm.depth()[last(arm)], 0.01f);
|
||||
float deepest = 0f;
|
||||
for (float depth : arm.depth()) {
|
||||
deepest = Math.max(deepest, depth);
|
||||
}
|
||||
assertTrue(arm + " deepest " + deepest, deepest >= 2f && deepest <= 5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-44
@@ -8,7 +8,6 @@ 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;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.CupSet;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
@@ -804,45 +803,22 @@ public class WindowPlannerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seaInletsBelongToTheWindowOfTheirFirstLandStationInAnyPlanningOrder() {
|
||||
public void seaConnectedHeadsAcceptWholeTidalReachesAtSeaLevelOnly() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
SyntheticTerrain terrain = SyntheticTerrain.cliffCoast(1400D);
|
||||
List<WindowKey> keys = List.of(new WindowKey(2, 0), new WindowKey(3, 0), new WindowKey(2, 1), new WindowKey(3, 1));
|
||||
Map<WindowKey, WindowPlan> forward = new HashMap<>();
|
||||
WindowPlanner first = planner(settings, terrain);
|
||||
for (WindowKey key : keys) {
|
||||
forward.put(key, first.plan(key, noRegions(key)));
|
||||
}
|
||||
Map<WindowKey, WindowPlan> backward = new HashMap<>();
|
||||
WindowPlanner second = planner(settings, terrain);
|
||||
for (int index = keys.size() - 1; index >= 0; index--) {
|
||||
backward.put(keys.get(index), second.plan(keys.get(index), noRegions(keys.get(index))));
|
||||
}
|
||||
assertEquals(forward, backward);
|
||||
int spacing = settings.underground().seaInlets().spacing();
|
||||
Set<Long> sites = new HashSet<>();
|
||||
int inlets = 0;
|
||||
int crossing = 0;
|
||||
for (Map.Entry<WindowKey, WindowPlan> entry : forward.entrySet()) {
|
||||
for (SeaInlet inlet : entry.getValue().inlets()) {
|
||||
inlets++;
|
||||
int landX = (int) Math.floor(inlet.xs()[1]);
|
||||
int landZ = (int) Math.floor(inlet.zs()[1]);
|
||||
assertEquals(inlet + " belongs to the window of its first land station", WindowKey.containing(landX, landZ), entry.getKey());
|
||||
assertTrue(inlet + " is the only inlet of its site", sites.add(((long) Math.floorDiv(landX, spacing) << 32)
|
||||
| (Math.floorDiv(landZ, spacing) & 0xFFFFFFFFL)));
|
||||
boolean leaves = false;
|
||||
for (int station = 0; station < inlet.stations(); station++) {
|
||||
leaves |= !WindowKey.containing((int) Math.floor(inlet.xs()[station]), (int) Math.floor(inlet.zs()[station])).equals(entry.getKey());
|
||||
}
|
||||
crossing += leaves ? 1 : 0;
|
||||
}
|
||||
}
|
||||
assertTrue("sea inlets on the cliff coast " + inlets, inlets >= 2);
|
||||
assertTrue("inlets running into the next window " + crossing, crossing > 0);
|
||||
for (WindowKey key : List.of(new WindowKey(3, 0), new WindowKey(3, 1))) {
|
||||
assertTrue("the inland window owns none of the coast's inlets", forward.get(key).inlets().isEmpty());
|
||||
}
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
int sea = settings.seaLevel();
|
||||
WindowPlanner.requireSeaConnectedHeads(new WindowPlan(key, List.of(tidal(settings, sea, 0L, ReachStyle.TIDAL)), List.of()), sea);
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> WindowPlanner.requireSeaConnectedHeads(new WindowPlan(key, List.of(tidal(settings, sea + 2, 0L, ReachStyle.TIDAL)), List.of()), sea));
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> WindowPlanner.requireSeaConnectedHeads(new WindowPlan(key, List.of(tidal(settings, sea, 9L, ReachStyle.TIDAL)), List.of()), sea));
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> WindowPlanner.requireSeaConnectedHeads(new WindowPlan(key, List.of(tidal(settings, sea, 0L, ReachStyle.RUN)), List.of()), sea));
|
||||
}
|
||||
|
||||
private static Reach tidal(HydrologySettings settings, int grade, long downstream, ReachStyle last) {
|
||||
return new Reach(5L, settings.tidalTier(), downstream, new float[]{0f, 8f}, new float[]{0f, 0f}, new int[]{grade, grade},
|
||||
new float[]{2f, 4f}, new float[]{1f, 1f}, new ReachStyle[]{ReachStyle.TIDAL, last}, 0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -855,8 +831,6 @@ public class WindowPlannerTest {
|
||||
assertTrue("mouth vertices on the coastal fractal " + fractalColumns.vertices(), fractalColumns.vertices() >= 100);
|
||||
assertTrue("mouth columns on the coastal fractal " + fractalColumns.mouths(), fractalColumns.mouths() >= 1000);
|
||||
assertTrue("mouth columns on the cliff coast " + cliffColumns.mouths(), cliffColumns.mouths() >= 1000);
|
||||
assertTrue("sea inlets on the cliff coast " + cliff.inlets().size(), cliff.inlets().size() >= 2);
|
||||
assertTrue("inlet columns on the cliff coast " + cliffColumns.inlets(), cliffColumns.inlets() >= 500);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1193,6 +1167,7 @@ public class WindowPlannerTest {
|
||||
config.getLakes().setEnabled(false);
|
||||
config.getPonds().getSeeded().setAlongChannels(false);
|
||||
config.getTiers().get(0).setMinCatchment(LINE_STREAM_CATCHMENT);
|
||||
config.getUnderground().getSeaInlets().setEnabled(false);
|
||||
HydrologySettings settings = settings(config);
|
||||
int line = LAND.wx() * WindowKey.SIZE;
|
||||
double axis = LAND.wz() * WindowKey.SIZE + SEAM_DISTANCE;
|
||||
@@ -1323,9 +1298,6 @@ public class WindowPlannerTest {
|
||||
}
|
||||
|
||||
private static SeaColumns assertSeaConnectedHeads(String name, PlannedScene scene) {
|
||||
for (SeaInlet inlet : scene.inlets()) {
|
||||
assertEquals(name + " " + inlet, SEA_LEVEL, inlet.waterLevel());
|
||||
}
|
||||
int vertices = 0;
|
||||
for (Reach reach : scene.reaches()) {
|
||||
for (int point = 0; point < reach.grade().length; point++) {
|
||||
|
||||
+123
-45
@@ -11,8 +11,6 @@ import art.arcane.iris.generation.hydrology.plan.RegionKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.RegionPlan;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowPlan;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.water.ConfluenceGrader;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
@@ -416,49 +414,129 @@ public class ChunkWaterRasterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openSeaInletSlotColumnsTakeTheInletRoleAtSeaLevel() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
int stations = 10;
|
||||
float[] xs = new float[stations];
|
||||
float[] zs = new float[stations];
|
||||
float[] halfWidth = new float[stations];
|
||||
int[] floor = new int[stations];
|
||||
int[] ceiling = new int[stations];
|
||||
for (int station = 0; station < stations; station++) {
|
||||
xs[station] = -8f + station * 8f;
|
||||
zs[station] = 8f;
|
||||
halfWidth[station] = 4f;
|
||||
floor[station] = SEA_LEVEL - 3;
|
||||
ceiling[station] = station < 2 ? SeaInlet.OPEN : SEA_LEVEL + 5;
|
||||
private static Reach straight(long id, HydrologyTier tier, float z, int head, ReachStyle style) {
|
||||
int points = 9;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grade = new int[points];
|
||||
float[] halfWidth = new float[points];
|
||||
float[] depth = new float[points];
|
||||
ReachStyle[] styles = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = -16f + point * 8f;
|
||||
zs[point] = z;
|
||||
grade[point] = head;
|
||||
halfWidth[point] = 3f;
|
||||
depth[point] = 2f;
|
||||
styles[point] = style;
|
||||
}
|
||||
SeaInlet inlet = new SeaInlet(71L, xs, zs, halfWidth, SEA_LEVEL, floor, ceiling, 64, 8, 6);
|
||||
return new Reach(id, tier, 0L, xs, zs, grade, halfWidth, depth, styles, 30000f);
|
||||
}
|
||||
|
||||
private static ChunkWaterRaster rasterOf(HydrologySettings settings, List<Reach> reaches, int ground) {
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(), List.of(), List.of(inlet)), ReachIndex.build(key, List.of(), List.of()));
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
ChunkWaterRaster mouth = rasterizer.rasterize(0, 0, (x, z) -> 70, List.of(own), regions(0, 0, List.of()));
|
||||
int[] column = new int[2];
|
||||
int open = 0;
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
boolean slot = SeaInletRasterizer.column(inlet, lx, lz, column) && column[1] == SeaInlet.OPEN;
|
||||
if (slot) {
|
||||
open++;
|
||||
assertEquals(WaterRole.INLET, mouth.role(lx, lz));
|
||||
assertEquals(SEA_LEVEL, mouth.waterHead(lx, lz));
|
||||
assertEquals(SEA_LEVEL - 3, mouth.terrainHeight(lx, lz));
|
||||
assertEquals(SEA_LEVEL - 4, mouth.caveCeiling(lx, lz));
|
||||
assertEquals(71L, mouth.featureId(lx, lz));
|
||||
assertEquals(HydrologyCaveCell.SEA_FLUID, mouth.fluid(lx, lz));
|
||||
} else {
|
||||
assertEquals(WaterRole.NONE, mouth.role(lx, lz));
|
||||
assertEquals(70, mouth.terrainHeight(lx, lz));
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, reaches, List.of()), ReachIndex.build(key, reaches, List.of()));
|
||||
return new ChunkRasterizer(settings, ChannelFluids.TIER).rasterize(0, 0, (x, z) -> ground, List.of(own), regions(0, 0, List.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tidalBanksMeetANeighbouringRiverBankWithoutACliff() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
int ground = SEA_LEVEL + 32;
|
||||
Reach arm = straight(71L, settings.tidalTier(), -6f, SEA_LEVEL, ReachStyle.TIDAL);
|
||||
for (int riverHead : new int[]{SEA_LEVEL, SEA_LEVEL + 24}) {
|
||||
for (HydrologyTier tier : settings.tiers()) {
|
||||
Reach river = straight(72L, tier, 22f, riverHead, ReachStyle.RUN);
|
||||
ChunkWaterRaster raster = rasterOf(settings, List.of(arm, river), ground);
|
||||
ChunkWaterRaster alone = rasterOf(settings, List.of(river), ground);
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
for (int lz = 0; lz < 15; lz++) {
|
||||
int step = Math.abs(raster.terrainHeight(lx, lz + 1) - raster.terrainHeight(lx, lz));
|
||||
assertTrue(tier.name() + " head " + riverHead + " steps " + step + " at " + lx + "," + lz, step <= 8);
|
||||
}
|
||||
for (int lz = 9; lz < 16; lz++) {
|
||||
assertEquals("the river side is the river's own bank at " + lx + "," + lz, alone.terrainHeight(lx, lz), raster.terrainHeight(lx, lz));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("open slot columns " + open, open > 20);
|
||||
assertTrue("a covered passage leaves the surface alone",
|
||||
rasterizer.rasterize(2, 0, (x, z) -> 70, List.of(own), regions(2, 0, List.of())).empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tidalBanksFollowTheBandInsteadOfCuttingRaysToSteepGround() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
int points = 9;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grade = new int[points];
|
||||
float[] halfWidth = new float[points];
|
||||
float[] depth = new float[points];
|
||||
ReachStyle[] style = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = -16f + point * 8f;
|
||||
zs[point] = -8f;
|
||||
grade[point] = SEA_LEVEL;
|
||||
halfWidth[point] = 3f;
|
||||
depth[point] = 3f;
|
||||
style[point] = ReachStyle.TIDAL;
|
||||
}
|
||||
Reach reach = new Reach(71L, settings.tidalTier(), 0L, xs, zs, grade, halfWidth, depth, style, 0f);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(reach), List.of()), ReachIndex.build(key, List.of(reach), List.of()));
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
ChunkWaterRaster ridged = rasterizer.rasterize(0, 0, (x, z) -> SEA_LEVEL + 20 + (Math.floorMod(x, 8) < 2 ? 8 : 0), List.of(own), regions(0, 0, List.of()));
|
||||
ChunkWaterRaster plain = rasterizer.rasterize(0, 0, (x, z) -> SEA_LEVEL + 28, List.of(own), regions(0, 0, List.of()));
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
assertTrue("a ridge reaches no higher than the same band over plain ground at " + lx + "," + lz + ": "
|
||||
+ ridged.terrainHeight(lx, lz) + " over " + plain.terrainHeight(lx, lz), ridged.terrainHeight(lx, lz) <= plain.terrainHeight(lx, lz));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tidalReachColumnsTakeTheInletRoleAtSeaLevelBetweenBanks() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
int points = 9;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grade = new int[points];
|
||||
float[] halfWidth = new float[points];
|
||||
float[] depth = new float[points];
|
||||
ReachStyle[] style = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = -16f + point * 8f;
|
||||
zs[point] = 8f;
|
||||
grade[point] = SEA_LEVEL;
|
||||
halfWidth[point] = 3f;
|
||||
depth[point] = 3f;
|
||||
style[point] = ReachStyle.TIDAL;
|
||||
}
|
||||
Reach reach = new Reach(71L, settings.tidalTier(), 0L, xs, zs, grade, halfWidth, depth, style, 0f);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(reach), List.of()), ReachIndex.build(key, List.of(reach), List.of()));
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
ChunkWaterRaster raster = rasterizer.rasterize(0, 0, (x, z) -> SEA_LEVEL + 12, List.of(own), regions(0, 0, List.of()));
|
||||
int wet = 0;
|
||||
int bank = 0;
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
if (Math.abs(lz - 8) <= 2) {
|
||||
wet++;
|
||||
assertEquals(WaterRole.INLET, raster.role(lx, lz));
|
||||
assertEquals(SEA_LEVEL, raster.waterHead(lx, lz));
|
||||
assertTrue(raster.terrainHeight(lx, lz) < SEA_LEVEL);
|
||||
assertEquals(71L, raster.featureId(lx, lz));
|
||||
assertEquals(HydrologyCaveCell.SEA_FLUID, raster.fluid(lx, lz));
|
||||
} else if (raster.waterHead(lx, lz) == Integer.MIN_VALUE) {
|
||||
bank++;
|
||||
assertTrue("shaped ground stays above the water at " + lx + "," + lz, raster.terrainHeight(lx, lz) >= SEA_LEVEL);
|
||||
assertTrue("the band cuts the bank below the natural ground at " + lx + "," + lz, raster.terrainHeight(lx, lz) < SEA_LEVEL + 12);
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("water columns " + wet, wet > 60);
|
||||
assertTrue("bank columns " + bank, bank > 60);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -466,7 +544,7 @@ public class ChunkWaterRasterTest {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
Reach far = line(61L, tier("stream", 1.5f, 0.5f, 0, IrisBankStyle.SMOOTH), 0L, 400f, 400f, 480f, 400f, (x, z) -> 69);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(far), List.of(), List.of()), ReachIndex.build(key, List.of(far), List.of()));
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(far), List.of()), ReachIndex.build(key, List.of(far), List.of()));
|
||||
AtomicInteger samples = new AtomicInteger();
|
||||
IntBinaryOperator natural = (x, z) -> {
|
||||
samples.incrementAndGet();
|
||||
@@ -503,7 +581,7 @@ public class ChunkWaterRasterTest {
|
||||
Reach outflow = line(61L, stream, 0L, 400f, 403f, 480f, 403f, (x, z) -> 69);
|
||||
Reach inflow = line(62L, stream, 0L, 480f, 412f, 400f, 412f, (x, z) -> 69);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(outflow, inflow), List.of(), List.of()),
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(outflow, inflow), List.of()),
|
||||
ReachIndex.build(key, List.of(outflow, inflow), List.of()));
|
||||
ChannelFluids volcanic = (x, z) -> x < 440 ? "lava" : null;
|
||||
ChunkWaterRaster raster = new ChunkRasterizer(settings, volcanic).rasterize(27, 25, (x, z) -> 70, List.of(own), regions(27, 25, List.of()));
|
||||
@@ -531,7 +609,7 @@ public class ChunkWaterRasterTest {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
Reach river = line(81L, tier("river", 3f, 0.5f, 32, IrisBankStyle.SMOOTH), 0L, 96f, 256f, 416f, 256f, (x, z) -> 69);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(river), List.of(), List.of()), ReachIndex.build(key, List.of(river), List.of()));
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(river), List.of()), ReachIndex.build(key, List.of(river), List.of()));
|
||||
NaturalHeights natural = (x, z) -> {
|
||||
double away = Math.abs(z - 256);
|
||||
if (x < 256) {
|
||||
@@ -1016,7 +1094,7 @@ public class ChunkWaterRasterTest {
|
||||
WindowKey key = new WindowKey(dx, dz);
|
||||
List<Reach> owned = key.equals(new WindowKey(0, 0)) ? List.of(feeder)
|
||||
: key.equals(new WindowKey(1, 0)) || key.equals(new WindowKey(1, -1)) ? List.of(downstream) : List.of();
|
||||
windows.add(new IndexedWindow(new WindowPlan(key, owned, List.of(), List.of()), ReachIndex.build(key, owned, List.of())));
|
||||
windows.add(new IndexedWindow(new WindowPlan(key, owned, List.of()), ReachIndex.build(key, owned, List.of())));
|
||||
}
|
||||
}
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings(new IrisHydrology()), ChannelFluids.TIER);
|
||||
@@ -2644,7 +2722,7 @@ public class ChunkWaterRasterTest {
|
||||
ownedPonds.add(pond);
|
||||
}
|
||||
}
|
||||
return new IndexedWindow(new WindowPlan(key, owned, ownedPonds, List.of()), ReachIndex.build(key, owned, ownedPonds));
|
||||
return new IndexedWindow(new WindowPlan(key, owned, ownedPonds), ReachIndex.build(key, owned, ownedPonds));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -114,7 +114,7 @@ public class PondChannelSettlementTest {
|
||||
for (long seed = 1L; seed <= 24L; seed++) {
|
||||
HydrologySettings settings = HydrologySettings.compile(new IrisHydrology(), seed, SEA_LEVEL, -64, 320);
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
IndexedWindow window = new IndexedWindow(new WindowPlan(WINDOW, List.of(river), List.of(), List.of()), ReachIndex.build(WINDOW, List.of(river), List.of()));
|
||||
IndexedWindow window = new IndexedWindow(new WindowPlan(WINDOW, List.of(river), List.of()), ReachIndex.build(WINDOW, List.of(river), List.of()));
|
||||
for (int z = 124; z <= 132; z++) {
|
||||
Pond pond = pond(1L, PondKind.NATURAL, 94, circle(504, z, 0));
|
||||
int lowest = Math.min(94, Math.min(rasterHead(rasterizer, window, 504, z), Math.min(rasterHead(rasterizer, window, 505, z),
|
||||
@@ -163,7 +163,7 @@ public class PondChannelSettlementTest {
|
||||
private static int assertSettlementMatchesTheRaster(long seed, Reach river, int minX, int maxX, int minZ, int maxZ, int stride) {
|
||||
HydrologySettings settings = HydrologySettings.compile(new IrisHydrology(), seed, SEA_LEVEL, -64, 320);
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
IndexedWindow window = new IndexedWindow(new WindowPlan(WINDOW, List.of(river), List.of(), List.of()), ReachIndex.build(WINDOW, List.of(river), List.of()));
|
||||
IndexedWindow window = new IndexedWindow(new WindowPlan(WINDOW, List.of(river), List.of()), ReachIndex.build(WINDOW, List.of(river), List.of()));
|
||||
Map<Long, ChunkWaterRaster> rasters = new HashMap<>();
|
||||
int lowered = 0;
|
||||
for (int x = minX; x <= maxX; x += stride) {
|
||||
|
||||
-224
@@ -1,224 +0,0 @@
|
||||
package art.arcane.iris.generation.hydrology.underground;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.grid.D8Router;
|
||||
import art.arcane.iris.generation.hydrology.grid.DemGrid;
|
||||
import art.arcane.iris.generation.hydrology.grid.FlowAccumulator;
|
||||
import art.arcane.iris.generation.hydrology.grid.HydrologySampleBuffer;
|
||||
import art.arcane.iris.generation.hydrology.grid.PriorityFlood;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
import art.arcane.iris.generation.hydrology.water.ShapedNetwork;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
import java.util.function.DoubleBinaryOperator;
|
||||
|
||||
final class InletTerrain {
|
||||
static final long SEED = 1337L;
|
||||
static final int SEA = 40;
|
||||
static final int MIN_Y = -64;
|
||||
static final int MAX_Y = 320;
|
||||
static final int COAST_X = 160;
|
||||
static final int CELL = 8;
|
||||
static final int WIDTH = 96;
|
||||
static final int DEPTH = 64;
|
||||
static final int SPAN = 3 * WindowKey.SIZE / CELL;
|
||||
|
||||
final DoubleBinaryOperator natural;
|
||||
final WindowKey window;
|
||||
final DemGrid grid;
|
||||
final HydrologySampleBuffer samples;
|
||||
final int[] receivers;
|
||||
final float[] accumulation;
|
||||
|
||||
private InletTerrain(DoubleBinaryOperator natural) {
|
||||
this(natural, new WindowKey(0, 0));
|
||||
}
|
||||
|
||||
private InletTerrain(DoubleBinaryOperator natural, WindowKey window) {
|
||||
this(natural, window, (window.wx() - 1) * WindowKey.SIZE, (window.wz() - 1) * WindowKey.SIZE, SPAN, SPAN);
|
||||
}
|
||||
|
||||
private InletTerrain(DoubleBinaryOperator natural, WindowKey window, int originX, int originZ, int width, int depth) {
|
||||
this.natural = natural;
|
||||
this.window = window;
|
||||
this.grid = new DemGrid(originX, originZ, CELL, width, depth);
|
||||
int count = width * depth;
|
||||
this.samples = new HydrologySampleBuffer(count);
|
||||
BitSet seeds = new BitSet(count);
|
||||
for (int cell = 0; cell < count; cell++) {
|
||||
int x = grid.blockX(cell);
|
||||
int z = grid.blockZ(cell);
|
||||
float height = (float) natural.applyAsDouble(x, z);
|
||||
grid.values()[cell] = height;
|
||||
samples.height()[cell] = height;
|
||||
samples.ocean()[cell] = Math.round(height) < SEA;
|
||||
int i = cell % width;
|
||||
int j = cell / width;
|
||||
if (samples.ocean()[cell] || i == 0 || j == 0 || i == width - 1 || j == depth - 1) {
|
||||
seeds.set(cell);
|
||||
}
|
||||
}
|
||||
float[] filled = PriorityFlood.fill(grid, seeds, 0.001f);
|
||||
DemGrid surface = new DemGrid(originX, originZ, CELL, width, depth);
|
||||
System.arraycopy(filled, 0, surface.values(), 0, count);
|
||||
this.receivers = D8Router.receivers(surface, filled, SEED);
|
||||
float[] weights = new float[count];
|
||||
for (int cell = 0; cell < count; cell++) {
|
||||
if (samples.ocean()[cell]) {
|
||||
receivers[cell] = -1;
|
||||
}
|
||||
weights[cell] = CELL * CELL;
|
||||
}
|
||||
this.accumulation = FlowAccumulator.accumulate(receivers, filled, weights, 4194304f);
|
||||
}
|
||||
|
||||
static InletTerrain cliff(double cliffHeight) {
|
||||
return new InletTerrain((x, z) -> x < COAST_X ? SEA - 20D : SEA + cliffHeight + 0.08D * (x - COAST_X));
|
||||
}
|
||||
|
||||
InletTerrain wide(WindowKey window, int windows) {
|
||||
int cells = (2 * windows + 1) * WindowKey.SIZE / CELL;
|
||||
int originX = (window.wx() - windows) * WindowKey.SIZE;
|
||||
int originZ = (window.wz() - windows) * WindowKey.SIZE;
|
||||
return new InletTerrain(natural, window, originX, originZ, cells, cells);
|
||||
}
|
||||
|
||||
static InletTerrain bay(int westX, int eastX, int bayZ) {
|
||||
return new InletTerrain((x, z) -> {
|
||||
if (z > bayZ - CELL / 2D) {
|
||||
return Math.abs(z - bayZ) < CELL / 2D && x > westX - CELL / 2D && x < eastX + CELL / 2D ? SEA - 20D : SEA + 5D;
|
||||
}
|
||||
return SEA + 30D + 0.08D * (bayZ - z);
|
||||
});
|
||||
}
|
||||
|
||||
static InletTerrain eastEdgeCoast() {
|
||||
double coast = WindowKey.SIZE - CELL;
|
||||
return new InletTerrain((x, z) -> x < coast - CELL / 2D ? SEA - 20D : SEA + 30D + 0.08D * (x - coast));
|
||||
}
|
||||
|
||||
static InletTerrain openCoast() {
|
||||
return new InletTerrain((x, z) -> {
|
||||
double coast = 768D + 120D * Math.sin(z / 180D) + 40D * Math.sin(z / 53D);
|
||||
return x < coast ? SEA - 20D : SEA + 30D + 0.08D * (x - coast);
|
||||
});
|
||||
}
|
||||
|
||||
static InletTerrain cliffWithTrough(double cliffHeight, double troughFrom, double troughTo, double troughHeight) {
|
||||
return new InletTerrain((x, z) -> {
|
||||
if (x < COAST_X) {
|
||||
return SEA - 20D;
|
||||
}
|
||||
if (x >= troughFrom && x <= troughTo) {
|
||||
return troughHeight;
|
||||
}
|
||||
return SEA + cliffHeight + 0.08D * (x - COAST_X);
|
||||
});
|
||||
}
|
||||
|
||||
static InletTerrain coastalRidge(double crestDistance) {
|
||||
return new InletTerrain((x, z) -> {
|
||||
if (x < COAST_X) {
|
||||
return SEA - 20D;
|
||||
}
|
||||
double crest = SEA + 30D + 0.3D * crestDistance;
|
||||
return x < COAST_X + crestDistance ? SEA + 30D + 0.3D * (x - COAST_X) : crest - 0.02D * (x - COAST_X - crestDistance);
|
||||
});
|
||||
}
|
||||
|
||||
static InletTerrain southCoast(double coastZ) {
|
||||
return new InletTerrain((x, z) -> z < coastZ ? SEA - 20D : SEA + 30D + 0.08D * (z - coastZ));
|
||||
}
|
||||
|
||||
static InletTerrain steppedCoast(double stepX) {
|
||||
return new InletTerrain((x, z) -> x < COAST_X ? SEA - 20D : x < stepX ? SEA + 9D : SEA + 40D + 0.05D * (x - stepX));
|
||||
}
|
||||
|
||||
static InletTerrain pocket(int pocketX, int pocketZ) {
|
||||
return new InletTerrain((x, z) -> Math.abs(x - pocketX) < CELL / 2D && Math.abs(z - pocketZ) < CELL / 2D ? SEA - 20D
|
||||
: SEA + 30D + 0.08D * Math.hypot(x - pocketX, z - pocketZ));
|
||||
}
|
||||
|
||||
static float length(SeaInlet inlet) {
|
||||
float length = 0f;
|
||||
for (int station = 1; station < inlet.stations(); station++) {
|
||||
length += (float) Math.hypot(inlet.xs()[station] - inlet.xs()[station - 1], inlet.zs()[station] - inlet.zs()[station - 1]);
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
static HydrologySettings settings() {
|
||||
return settings(new IrisHydrology());
|
||||
}
|
||||
|
||||
static HydrologySettings settings(IrisHydrology config) {
|
||||
return HydrologySettings.compile(config, SEED, SEA, MIN_Y, MAX_Y);
|
||||
}
|
||||
|
||||
InletTerrain span(WindowKey window) {
|
||||
return new InletTerrain(natural, window);
|
||||
}
|
||||
|
||||
InletTerrain narrow(int originX, int originZ) {
|
||||
return new InletTerrain(natural, WindowKey.containing(originX, originZ), originX, originZ, WIDTH, DEPTH);
|
||||
}
|
||||
|
||||
List<SeaInlet> plan(HydrologySettings settings, ShapedNetwork network) {
|
||||
return new SeaInletPlanner(settings).plan(window, grid, samples, receivers, accumulation, network, SEED);
|
||||
}
|
||||
|
||||
List<SeaInlet> plan(HydrologySettings settings) {
|
||||
return plan(settings, new ShapedNetwork(List.of(), List.of()));
|
||||
}
|
||||
|
||||
boolean ocean(float x, float z) {
|
||||
int cell = grid.index(Math.round((x - grid.originX()) / CELL), Math.round((z - grid.originZ()) / CELL));
|
||||
return samples.ocean()[cell];
|
||||
}
|
||||
|
||||
int naturalAt(int x, int z) {
|
||||
return (int) Math.round(natural.applyAsDouble(x, z));
|
||||
}
|
||||
|
||||
static Reach eastWestReach(HydrologySettings settings, float fromX, float toX, float z, int grade) {
|
||||
int points = Math.max(2, (int) Math.ceil((toX - fromX) / 8f) + 1);
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grades = new int[points];
|
||||
float[] widths = new float[points];
|
||||
float[] depths = new float[points];
|
||||
ReachStyle[] styles = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = fromX + (toX - fromX) * point / (points - 1);
|
||||
zs[point] = z;
|
||||
grades[point] = grade;
|
||||
widths[point] = 2f;
|
||||
depths[point] = 1.5f;
|
||||
styles[point] = ReachStyle.RUN;
|
||||
}
|
||||
return new Reach(78L, settings.tiers().get(0), 0L, xs, zs, grades, widths, depths, styles, 2000f);
|
||||
}
|
||||
|
||||
static Reach northSouthReach(HydrologySettings settings, float x, int grade, float halfWidth, float depth) {
|
||||
int points = 25;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grades = new int[points];
|
||||
float[] widths = new float[points];
|
||||
float[] depths = new float[points];
|
||||
ReachStyle[] styles = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = x;
|
||||
zs[point] = point * 64f - WindowKey.SIZE;
|
||||
grades[point] = grade;
|
||||
widths[point] = halfWidth;
|
||||
depths[point] = depth;
|
||||
styles[point] = ReachStyle.RUN;
|
||||
}
|
||||
return new Reach(77L, settings.tiers().get(0), 0L, xs, zs, grades, widths, depths, styles, 2000f);
|
||||
}
|
||||
}
|
||||
-562
@@ -1,562 +0,0 @@
|
||||
package art.arcane.iris.generation.hydrology.underground;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
import art.arcane.iris.generation.hydrology.water.ShapedNetwork;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SeaInletPlannerTest {
|
||||
private static final int SEA = InletTerrain.SEA;
|
||||
|
||||
@Test
|
||||
public void globalDensityThinsInletSitesWithoutChangingTheirGeometry() {
|
||||
InletTerrain terrain = InletTerrain.cliff(30D);
|
||||
IrisHydrology full = new IrisHydrology();
|
||||
IrisHydrology half = new IrisHydrology().setDensity(0.5D);
|
||||
full.getUnderground().getSeaInlets().setSpacing(256);
|
||||
half.getUnderground().getSeaInlets().setSpacing(256);
|
||||
int baseline = 0;
|
||||
int retained = 0;
|
||||
for (int offset = 0; offset < 32; offset++) {
|
||||
InletTerrain view = terrain.span(new WindowKey(0, offset));
|
||||
List<SeaInlet> all = view.plan(InletTerrain.settings(full));
|
||||
List<SeaInlet> reduced = view.plan(InletTerrain.settings(half));
|
||||
baseline += all.size();
|
||||
retained += reduced.size();
|
||||
for (SeaInlet inlet : reduced) {
|
||||
assertTrue("retained inlets keep the same full passage", all.contains(inlet));
|
||||
}
|
||||
assertEquals(reduced, view.plan(InletTerrain.settings(half)));
|
||||
}
|
||||
assertTrue("cliff provides enough candidates", baseline >= 32);
|
||||
assertTrue("half density retains approximately half the sites", retained > baseline * 0.3 && retained < baseline * 0.7);
|
||||
assertTrue(terrain.plan(InletTerrain.settings(new IrisHydrology().setDensity(0D))).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inletStartsAtOceanCell() {
|
||||
InletTerrain terrain = InletTerrain.cliff(30D);
|
||||
List<SeaInlet> inlets = terrain.plan(InletTerrain.settings());
|
||||
assertFalse("a straight cliff coast holds inlets", inlets.isEmpty());
|
||||
for (SeaInlet inlet : inlets) {
|
||||
assertTrue(inlet + " opens from an ocean cell", terrain.ocean(inlet.xs()[0], inlet.zs()[0]));
|
||||
assertFalse(inlet + " runs inland", terrain.ocean(inlet.xs()[1], inlet.zs()[1]));
|
||||
for (int station = 1; station < inlet.stations(); station++) {
|
||||
assertTrue(inlet + " climbs away from the sea", inlet.xs()[station] > inlet.xs()[station - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void waterLevelIsSeaLevelEverywhere() {
|
||||
InletTerrain terrain = InletTerrain.cliff(30D);
|
||||
HydrologySettings settings = InletTerrain.settings();
|
||||
HydrologySettings.SeaInlets config = settings.underground().seaInlets();
|
||||
List<SeaInlet> inlets = terrain.plan(settings);
|
||||
assertFalse(inlets.isEmpty());
|
||||
for (SeaInlet inlet : inlets) {
|
||||
assertEquals(SEA, inlet.waterLevel());
|
||||
for (int station = 0; station < inlet.stations(); station++) {
|
||||
int depth = SEA - inlet.floor()[station];
|
||||
assertTrue(inlet + " depth " + depth, depth >= config.depth().min() && depth <= config.depth().max());
|
||||
assertTrue(inlet + " keeps air or an open mouth above the water", inlet.ceiling()[station] >= SEA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roofClearanceHeld() {
|
||||
HydrologySettings settings = InletTerrain.settings();
|
||||
int clearance = settings.underground().seaInlets().roofClearance();
|
||||
double troughFrom = 300D;
|
||||
InletTerrain terrain = InletTerrain.cliffWithTrough(30D, troughFrom, 340D, SEA + 9D);
|
||||
List<SeaInlet> inlets = terrain.plan(settings);
|
||||
assertFalse(inlets.isEmpty());
|
||||
int covered = 0;
|
||||
int[] column = new int[2];
|
||||
for (SeaInlet inlet : inlets) {
|
||||
int[] bounds = SeaInletRasterizer.bounds(inlet);
|
||||
for (int z = bounds[1]; z <= bounds[3]; z++) {
|
||||
for (int x = bounds[0]; x <= bounds[2]; x++) {
|
||||
if (!SeaInletRasterizer.column(inlet, x, z, column)) {
|
||||
continue;
|
||||
}
|
||||
int ground = terrain.naturalAt(x, z);
|
||||
assertTrue(inlet + " at " + x + "," + z + " stays clear of the trough", x < troughFrom - clearance);
|
||||
if (column[1] == SeaInlet.OPEN) {
|
||||
assertTrue(inlet + " open slot at " + x + "," + z + " stays at the coast", x < InletTerrain.COAST_X + 3 * InletTerrain.CELL);
|
||||
} else {
|
||||
covered++;
|
||||
assertTrue(inlet + " roof at " + x + "," + z + " is " + (ground - column[1]), ground - column[1] >= clearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("covered columns " + covered, covered > 200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openSlotHoldsAtMostTwoLandStationsFromTheSea() {
|
||||
for (InletTerrain terrain : List.of(InletTerrain.cliff(30D), InletTerrain.cliff(9D), InletTerrain.pocket(152, 256))) {
|
||||
for (SeaInlet inlet : terrain.plan(InletTerrain.settings())) {
|
||||
assertTrue(inlet + " opens at the sea", inlet.open(0));
|
||||
int open = 1;
|
||||
while (open < inlet.stations() && inlet.open(open)) {
|
||||
open++;
|
||||
}
|
||||
assertTrue(inlet + " open land stations " + (open - 1), open - 1 <= 2);
|
||||
for (int station = open; station < inlet.stations(); station++) {
|
||||
assertFalse(inlet + " stays covered after the slot at station " + station, inlet.open(station));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void slotsNeedingAThirdOpenLandStationAreRejected() {
|
||||
List<SeaInlet> twoOpen = InletTerrain.steppedCoast(164D).plan(InletTerrain.settings());
|
||||
assertFalse("a cliff that holds a roof two stations in keeps its inlets", twoOpen.isEmpty());
|
||||
for (SeaInlet inlet : twoOpen) {
|
||||
assertTrue(inlet.open(1) && inlet.open(2) && !inlet.open(3));
|
||||
}
|
||||
assertTrue("a slot three land stations long is refused", InletTerrain.steppedCoast(172D).plan(InletTerrain.settings()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ceilingFollowsSmoothNoiseAlongThePath() {
|
||||
HydrologySettings settings = InletTerrain.settings();
|
||||
int distinct = 0;
|
||||
for (SeaInlet inlet : InletTerrain.cliff(30D).plan(settings)) {
|
||||
Set<Integer> heights = new HashSet<>();
|
||||
for (int station = 1; station < inlet.stations(); station++) {
|
||||
if (inlet.open(station) || inlet.open(station - 1)) {
|
||||
continue;
|
||||
}
|
||||
heights.add(inlet.ceiling()[station]);
|
||||
int step = Math.abs(inlet.ceiling()[station] - inlet.ceiling()[station - 1]);
|
||||
assertTrue(inlet + " ceiling steps " + step + " at station " + station, step <= 3);
|
||||
}
|
||||
distinct += heights.size() > 1 ? 1 : 0;
|
||||
}
|
||||
assertTrue("ceilings vary along the passage", distinct > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inletsSharingAnOceanMouthKeepDistinctIds() {
|
||||
IrisHydrology config = new IrisHydrology();
|
||||
config.getUnderground().getSeaInlets().setSpacing(32);
|
||||
List<SeaInlet> inlets = InletTerrain.pocket(152, 256).plan(InletTerrain.settings(config));
|
||||
long shared = inlets.stream().filter(inlet -> inlet.xs()[0] == 152f && inlet.zs()[0] == 256f).count();
|
||||
assertTrue("inlets opening from the one-cell pocket " + shared, shared >= 2);
|
||||
assertEquals(inlets.size(), inlets.stream().mapToLong(SeaInlet::id).distinct().count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noInletRunsCoveredUnderOrBesideAnotherInletsOpenSlot() {
|
||||
IrisHydrology dense = new IrisHydrology();
|
||||
dense.getUnderground().getSeaInlets().setSpacing(32);
|
||||
int pairs = 0;
|
||||
for (InletTerrain terrain : List.of(InletTerrain.pocket(152, 256), InletTerrain.cliff(30D), InletTerrain.steppedCoast(164))) {
|
||||
List<SeaInlet> inlets = terrain.plan(InletTerrain.settings(dense));
|
||||
for (int first = 0; first < inlets.size(); first++) {
|
||||
for (int second = first + 1; second < inlets.size(); second++) {
|
||||
pairs++;
|
||||
assertFalse(inlets.get(first) + " and " + inlets.get(second) + " cross a covered passage with an open slot",
|
||||
coveredMeetsOpen(inlets.get(first), inlets.get(second)) || coveredMeetsOpen(inlets.get(second), inlets.get(first)));
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("inlet pairs " + pairs, pairs > 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void competingInletsResolveTheSameWayInEveryGridThatSeesBoth() {
|
||||
IrisHydrology dense = new IrisHydrology();
|
||||
dense.getUnderground().getSeaInlets().setSpacing(32);
|
||||
HydrologySettings settings = InletTerrain.settings(dense);
|
||||
InletTerrain pocket = InletTerrain.pocket(512, 256);
|
||||
List<SeaInlet> here = fromPocket(pocket.span(new WindowKey(0, 0)).plan(settings), 512, 256);
|
||||
assertTrue("inlets opening from the pocket " + here, here.size() >= 2);
|
||||
assertEquals("another grid holding every competitor well inside decides the same", here,
|
||||
fromPocket(pocket.span(new WindowKey(1, 0)).plan(settings), 512, 256));
|
||||
for (int first = 0; first < here.size(); first++) {
|
||||
for (int second = first + 1; second < here.size(); second++) {
|
||||
assertFalse(here.get(first) + " and " + here.get(second) + " cross a covered passage with an open slot",
|
||||
coveredMeetsOpen(here.get(first), here.get(second)) || coveredMeetsOpen(here.get(second), here.get(first)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<SeaInlet> fromPocket(List<SeaInlet> inlets, float pocketX, float pocketZ) {
|
||||
return inlets.stream().filter(inlet -> inlet.xs()[0] == pocketX && inlet.zs()[0] == pocketZ).toList();
|
||||
}
|
||||
|
||||
private static boolean coveredMeetsOpen(SeaInlet covered, SeaInlet open) {
|
||||
int[] bounds = SeaInletRasterizer.bounds(open);
|
||||
int[] column = new int[2];
|
||||
int[] near = new int[2];
|
||||
for (int z = bounds[1]; z <= bounds[3]; z++) {
|
||||
for (int x = bounds[0]; x <= bounds[2]; x++) {
|
||||
if (!SeaInletRasterizer.column(open, x, z, column) || column[1] != SeaInlet.OPEN) {
|
||||
continue;
|
||||
}
|
||||
for (int dz = -SeaInletRasterizer.SHELL; dz <= SeaInletRasterizer.SHELL; dz++) {
|
||||
for (int dx = -SeaInletRasterizer.SHELL; dx <= SeaInletRasterizer.SHELL; dx++) {
|
||||
if (SeaInletRasterizer.column(covered, x + dx, z + dz, near) && near[1] != SeaInlet.OPEN) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void siteOnAWindowEdgeIsPlannedOnlyFromItsTargetWindow() {
|
||||
HydrologySettings settings = InletTerrain.settings();
|
||||
int spacing = settings.underground().seaInlets().spacing();
|
||||
int site = Math.floorDiv(WindowKey.SIZE, spacing);
|
||||
assertTrue("the site straddles the window edge", site * spacing < WindowKey.SIZE && (site + 1) * spacing > WindowKey.SIZE);
|
||||
double coastZ = 160D;
|
||||
InletTerrain terrain = InletTerrain.southCoast(coastZ);
|
||||
List<SeaInlet> open = inSite(terrain.plan(settings), spacing, site);
|
||||
assertEquals("the straddling site holds one inlet", 1, open.size());
|
||||
WindowKey owner = WindowKey.containing((int) open.getFirst().xs()[1], (int) open.getFirst().zs()[1]);
|
||||
float fromX = owner.wx() == 0 ? site * spacing - 16f : WindowKey.SIZE - 16f;
|
||||
float toX = owner.wx() == 0 ? WindowKey.SIZE + 16f : (site + 1) * spacing + 16f;
|
||||
Reach blocking = InletTerrain.eastWestReach(settings, fromX, toX, (float) coastZ + 4f, InletTerrain.SEA + 28);
|
||||
List<SeaInlet> blocked = inSite(terrain.plan(settings, new ShapedNetwork(List.of(blocking), List.of())), spacing, site);
|
||||
int doubled = 0;
|
||||
for (SeaInlet inlet : blocked) {
|
||||
doubled += WindowKey.containing((int) inlet.xs()[1], (int) inlet.zs()[1]).equals(owner) ? 0 : 1;
|
||||
}
|
||||
assertEquals("a window that cannot use the target window's coast plans nothing for the site", 0, doubled);
|
||||
}
|
||||
|
||||
private static List<SeaInlet> inSite(List<SeaInlet> inlets, int spacing, int site) {
|
||||
return inlets.stream().filter(inlet -> Math.floorDiv((int) inlet.xs()[1], spacing) == site).toList();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staysUnderSurfaceWaterBeds() {
|
||||
HydrologySettings settings = InletTerrain.settings();
|
||||
int clearance = settings.underground().seaInlets().roofClearance();
|
||||
InletTerrain terrain = InletTerrain.cliff(30D);
|
||||
Reach deep = InletTerrain.northSouthReach(settings, 232f, SEA + 26, 2f, 1.5f);
|
||||
List<SeaInlet> under = terrain.plan(settings, new ShapedNetwork(List.of(deep), List.of()));
|
||||
assertFalse(under.isEmpty());
|
||||
int[] column = new int[2];
|
||||
int crossings = 0;
|
||||
for (SeaInlet inlet : under) {
|
||||
for (int z = SeaInletRasterizer.bounds(inlet)[1]; z <= SeaInletRasterizer.bounds(inlet)[3]; z++) {
|
||||
if (SeaInletRasterizer.column(inlet, 232, z, column)) {
|
||||
crossings++;
|
||||
assertTrue(inlet + " roof under the river bed", (SEA + 26 - 1.5f) - column[1] >= clearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("inlets pass under the deep river", crossings > 0);
|
||||
Reach shallow = InletTerrain.northSouthReach(settings, 232f, SEA + 12, 2f, 1.5f);
|
||||
for (SeaInlet inlet : terrain.plan(settings, new ShapedNetwork(List.of(shallow), List.of()))) {
|
||||
int[] bounds = SeaInletRasterizer.bounds(inlet);
|
||||
assertTrue(inlet + " stops before the low river at x=232", bounds[2] < 232 - settings.tiers().get(0).bankBand());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inletsKeepClearOfSeaLevelDeltaChannels() {
|
||||
HydrologySettings settings = InletTerrain.settings();
|
||||
InletTerrain terrain = InletTerrain.cliff(30D);
|
||||
List<SeaInlet> open = terrain.plan(settings);
|
||||
assertFalse(open.isEmpty());
|
||||
SeaInlet first = open.get(0);
|
||||
Reach channel = deltaChannel(settings, first.xs()[1] + 16f, first.zs()[1], InletTerrain.COAST_X - 12f, first.zs()[0]);
|
||||
assertTrue("the channel runs through the inlet's opening", crosses(first, channel));
|
||||
List<SeaInlet> planned = terrain.plan(settings, new ShapedNetwork(List.of(channel), List.of()));
|
||||
for (SeaInlet inlet : planned) {
|
||||
assertFalse(inlet + " crosses the delta channel", crosses(inlet, channel));
|
||||
}
|
||||
}
|
||||
|
||||
private static Reach deltaChannel(HydrologySettings settings, float fromX, float fromZ, float toX, float toZ) {
|
||||
int points = Math.max(2, (int) Math.ceil(Math.hypot(toX - fromX, toZ - fromZ) / 2D) + 1);
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grades = new int[points];
|
||||
float[] widths = new float[points];
|
||||
float[] depths = new float[points];
|
||||
ReachStyle[] styles = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = fromX + (toX - fromX) * point / (points - 1);
|
||||
zs[point] = fromZ + (toZ - fromZ) * point / (points - 1);
|
||||
grades[point] = SEA;
|
||||
widths[point] = 3.5f;
|
||||
depths[point] = 1.5f;
|
||||
styles[point] = ReachStyle.MOUTH;
|
||||
}
|
||||
return new Reach(79L, settings.tiers().get(2), 0L, xs, zs, grades, widths, depths, styles, 150000f);
|
||||
}
|
||||
|
||||
private static boolean crosses(SeaInlet inlet, Reach channel) {
|
||||
int[] bounds = SeaInletRasterizer.bounds(inlet);
|
||||
int[] column = new int[2];
|
||||
for (int z = bounds[1]; z <= bounds[3]; z++) {
|
||||
for (int x = bounds[0]; x <= bounds[2]; x++) {
|
||||
if (SeaInletRasterizer.column(inlet, x, z, column) && inWater(channel, x, z)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean inWater(Reach reach, int x, int z) {
|
||||
for (int segment = 0; segment + 1 < reach.xs().length; segment++) {
|
||||
double ax = reach.xs()[segment];
|
||||
double az = reach.zs()[segment];
|
||||
double dx = reach.xs()[segment + 1] - ax;
|
||||
double dz = reach.zs()[segment + 1] - az;
|
||||
double length = dx * dx + dz * dz;
|
||||
double t = length == 0D ? 0D : Math.clamp(((x - ax) * dx + (z - az) * dz) / length, 0D, 1D);
|
||||
if (Math.hypot(x - (ax + t * dx), z - (az + t * dz)) <= reach.halfWidth()[segment]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endsInChamber() {
|
||||
HydrologySettings settings = InletTerrain.settings();
|
||||
HydrologySettings.SeaInlets config = settings.underground().seaInlets();
|
||||
InletTerrain terrain = InletTerrain.cliff(30D);
|
||||
int[] column = new int[2];
|
||||
List<SeaInlet> inlets = terrain.plan(settings);
|
||||
assertFalse(inlets.isEmpty());
|
||||
for (SeaInlet inlet : inlets) {
|
||||
int last = inlet.stations() - 1;
|
||||
assertEquals(inlet.xs()[last], inlet.chamberX(), 0f);
|
||||
assertEquals(inlet.zs()[last], inlet.chamberZ(), 0f);
|
||||
assertTrue(inlet + " chamber radius", inlet.chamberRadius() >= config.chamberRadius().min()
|
||||
&& inlet.chamberRadius() <= config.chamberRadius().max());
|
||||
int reach = inlet.chamberRadius() - 1;
|
||||
for (int dz = -reach; dz <= reach; dz++) {
|
||||
for (int dx = -reach; dx <= reach; dx++) {
|
||||
if (dx * dx + dz * dz > reach * reach) {
|
||||
continue;
|
||||
}
|
||||
assertTrue(inlet + " chamber column " + dx + "," + dz,
|
||||
SeaInletRasterizer.column(inlet, inlet.chamberX() + dx, inlet.chamberZ() + dz, column));
|
||||
assertTrue(column[0] < SEA);
|
||||
}
|
||||
}
|
||||
float length = InletTerrain.length(inlet);
|
||||
assertTrue(inlet + " length " + length, length >= config.length().min() && length <= config.length().max() + InletTerrain.CELL * 1.5f);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void continuesInlandPastTheHeadOfTheCoastalCatchment() {
|
||||
double crest = 40D;
|
||||
InletTerrain terrain = InletTerrain.coastalRidge(crest);
|
||||
List<SeaInlet> inlets = terrain.plan(InletTerrain.settings());
|
||||
assertFalse("a short coastal catchment still holds inlets", inlets.isEmpty());
|
||||
for (SeaInlet inlet : inlets) {
|
||||
assertTrue(inlet + " passes under the ridge crest", inlet.xs()[inlet.stations() - 1] > InletTerrain.COAST_X + crest + InletTerrain.CELL);
|
||||
assertTrue(inlet + " length", InletTerrain.length(inlet) >= InletTerrain.settings().underground().seaInlets().length().min());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noInletWithoutCliff() {
|
||||
assertTrue(InletTerrain.cliff(4D).plan(InletTerrain.settings()).isEmpty());
|
||||
IrisHydrology disabled = new IrisHydrology();
|
||||
disabled.getUnderground().getSeaInlets().setEnabled(false);
|
||||
assertTrue(InletTerrain.cliff(30D).plan(InletTerrain.settings(disabled)).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deterministic() {
|
||||
HydrologySettings settings = InletTerrain.settings();
|
||||
List<SeaInlet> first = InletTerrain.cliff(30D).plan(settings);
|
||||
List<SeaInlet> second = InletTerrain.cliff(30D).plan(InletTerrain.settings());
|
||||
assertEquals(first, second);
|
||||
assertEquals(first.size(), first.stream().mapToLong(SeaInlet::id).distinct().count());
|
||||
InletTerrain terrain = InletTerrain.cliff(30D);
|
||||
List<SeaInlet> otherSeed = new SeaInletPlanner(HydrologySettings.compile(new IrisHydrology(), 99L, SEA, InletTerrain.MIN_Y,
|
||||
InletTerrain.MAX_Y)).plan(terrain.window, terrain.grid, terrain.samples, terrain.receivers, terrain.accumulation,
|
||||
new ShapedNetwork(List.of(), List.of()), 99L);
|
||||
assertNotEquals(first, otherSeed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inletsAgreeAcrossWindowsOnOpenCoast() {
|
||||
IrisHydrology dense = new IrisHydrology();
|
||||
dense.getUnderground().getSeaInlets().setSpacing(64);
|
||||
HydrologySettings settings = InletTerrain.settings(dense);
|
||||
InletTerrain coast = InletTerrain.openCoast();
|
||||
List<WindowKey> windows = new ArrayList<>(9);
|
||||
for (int wz = 0; wz <= 2; wz++) {
|
||||
for (int wx = 0; wx <= 2; wx++) {
|
||||
windows.add(new WindowKey(wx, wz));
|
||||
}
|
||||
}
|
||||
Map<WindowKey, List<SeaInlet>> views = views(coast, settings, windows);
|
||||
assertEquals("planning the windows in reverse order changes nothing", views, views(coast, settings, windows.reversed()));
|
||||
List<String> disagreements = new ArrayList<>();
|
||||
int owned = 0;
|
||||
int crossing = 0;
|
||||
int seen = 0;
|
||||
for (WindowKey owner : windows) {
|
||||
for (SeaInlet inlet : views.get(owner)) {
|
||||
if (!owner.equals(owner(inlet))) {
|
||||
continue;
|
||||
}
|
||||
owned++;
|
||||
crossing += leavesWindow(inlet, owner) ? 1 : 0;
|
||||
for (WindowKey view : windows) {
|
||||
if (view.equals(owner)) {
|
||||
continue;
|
||||
}
|
||||
for (SeaInlet other : views.get(view)) {
|
||||
if (other.id() != inlet.id()) {
|
||||
continue;
|
||||
}
|
||||
seen++;
|
||||
if (!other.equals(inlet)) {
|
||||
disagreements.add(inlet + " of " + owner + " is " + other + " in " + view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(disagreements.size() + " views disagree with the owner: " + disagreements, disagreements.isEmpty());
|
||||
assertTrue("owned inlets " + owned, owned >= 20);
|
||||
assertTrue("owned inlets that neighbouring windows also plan " + seen, seen >= 60);
|
||||
assertTrue("owned inlets crossing a window line " + crossing, crossing > 0);
|
||||
}
|
||||
|
||||
private static Map<WindowKey, List<SeaInlet>> views(InletTerrain coast, HydrologySettings settings, List<WindowKey> order) {
|
||||
Map<WindowKey, List<SeaInlet>> views = new LinkedHashMap<>();
|
||||
for (WindowKey window : order) {
|
||||
views.put(window, coast.span(window).plan(settings));
|
||||
}
|
||||
return views;
|
||||
}
|
||||
|
||||
private static WindowKey owner(SeaInlet inlet) {
|
||||
return WindowKey.containing((int) Math.floor(inlet.xs()[1]), (int) Math.floor(inlet.zs()[1]));
|
||||
}
|
||||
|
||||
private static boolean leavesWindow(SeaInlet inlet, WindowKey owner) {
|
||||
int[] bounds = SeaInletRasterizer.bounds(inlet);
|
||||
return !WindowKey.containing(bounds[0], bounds[1]).equals(owner) || !WindowKey.containing(bounds[2], bounds[3]).equals(owner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ownedInletsNeverConflictAcrossAWindowLine() {
|
||||
IrisHydrology config = new IrisHydrology();
|
||||
config.getUnderground().getSeaInlets().setSpacing(WindowKey.SIZE);
|
||||
config.getUnderground().getSeaInlets().setLength(new KList<>(256, 400));
|
||||
config.getUnderground().getSeaInlets().setHalfWidth(new KList<>(12D, 12D));
|
||||
HydrologySettings settings = InletTerrain.settings(config);
|
||||
int bayZ = 904;
|
||||
WindowKey west = new WindowKey(1, 1);
|
||||
WindowKey east = new WindowKey(2, 1);
|
||||
single(InletTerrain.bay(1008, 1008, bayZ).wide(west, 3).plan(settings), west);
|
||||
single(InletTerrain.bay(1032, 1032, bayZ).wide(east, 3).plan(settings), east);
|
||||
InletTerrain bay = InletTerrain.bay(1016, 1024, bayZ);
|
||||
List<SeaInlet> reference = bay.wide(west, 3).plan(settings);
|
||||
List<SeaInlet> union = new ArrayList<>();
|
||||
for (int wz = 0; wz <= 2; wz++) {
|
||||
for (int wx = 0; wx <= 2; wx++) {
|
||||
WindowKey window = new WindowKey(wx, wz);
|
||||
List<SeaInlet> own = bay.span(window).plan(settings).stream().filter(inlet -> owner(inlet).equals(window)).toList();
|
||||
assertEquals(window + " owns what the full-context plan gives it", reference.stream()
|
||||
.filter(inlet -> owner(inlet).equals(window)).toList(), own);
|
||||
union.addAll(own);
|
||||
}
|
||||
}
|
||||
assertEquals("the two windows beside the bay keep one inlet between them: " + union, 1, union.size());
|
||||
for (int first = 0; first < union.size(); first++) {
|
||||
for (int second = first + 1; second < union.size(); second++) {
|
||||
assertFalse(union.get(first) + " and " + union.get(second) + " cross a covered passage with an open slot",
|
||||
coveredMeetsOpen(union.get(first), union.get(second)) || coveredMeetsOpen(union.get(second), union.get(first)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static SeaInlet single(List<SeaInlet> inlets, WindowKey window) {
|
||||
List<SeaInlet> own = inlets.stream().filter(inlet -> owner(inlet).equals(window)).toList();
|
||||
assertEquals(window + " owns one bay inlet: " + own, 1, own.size());
|
||||
return own.getFirst();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extentGuardKeepsEveryPlannerLookupInsideTheOwnersSpan() {
|
||||
for (double halfWidth : new double[]{1D, 16D}) {
|
||||
for (int chamber = 1; chamber <= 32; chamber++) {
|
||||
int length = WindowKey.SIZE - 12 - Math.max((int) Math.ceil(halfWidth), chamber) - 3;
|
||||
IrisHydrology config = new IrisHydrology();
|
||||
config.getUnderground().getSeaInlets().setLength(new KList<>(64, length));
|
||||
config.getUnderground().getSeaInlets().setHalfWidth(new KList<>(1D, halfWidth));
|
||||
config.getUnderground().getSeaInlets().setChamberRadius(new KList<>(1, chamber));
|
||||
InletTerrain.settings(config);
|
||||
long reach = SeaInletPlanner.lookupReach(length, chamber);
|
||||
assertTrue("length " + length + " chamber " + chamber + " looks " + reach + " blocks out", reach <= WindowKey.SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longestInletAtTheFarEdgeOfItsWindowStaysInsideItsSpan() {
|
||||
IrisHydrology config = new IrisHydrology();
|
||||
config.getUnderground().getSeaInlets().setLength(new KList<>(465, 465));
|
||||
config.getUnderground().getSeaInlets().setChamberRadius(new KList<>(32, 32));
|
||||
HydrologySettings settings = InletTerrain.settings(config);
|
||||
WindowKey window = new WindowKey(0, 0);
|
||||
List<SeaInlet> owned = InletTerrain.eastEdgeCoast().plan(settings).stream().filter(inlet -> owner(inlet).equals(window)).toList();
|
||||
assertFalse("inlets start on the window's last column", owned.isEmpty());
|
||||
for (SeaInlet inlet : owned) {
|
||||
assertEquals(inlet + " starts on the window's last column", WindowKey.SIZE - InletTerrain.CELL, inlet.xs()[1], 0f);
|
||||
assertTrue(inlet + " runs the full length toward the span edge", inlet.chamberX() >= WindowKey.SIZE + 448);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ownInletCutOffByTheGridEdgeFailsClosed() {
|
||||
InletTerrain narrow = InletTerrain.cliff(30D).narrow(0, 0);
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class, () -> narrow.plan(InletTerrain.settings()));
|
||||
assertTrue(failure.getMessage(),
|
||||
failure.getMessage().matches("Sea inlet -?\\d+ of window WindowKey\\[wx=0, wz=0\\] reaches the edge of .*"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inletsReachingPastTheNextWindowAreRejected() {
|
||||
IrisHydrology fits = new IrisHydrology();
|
||||
fits.getUnderground().getSeaInlets().setLength(new KList<>(64, 485));
|
||||
InletTerrain.settings(fits);
|
||||
IrisHydrology last = new IrisHydrology();
|
||||
last.getUnderground().getSeaInlets().setLength(new KList<>(64, 486));
|
||||
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class, () -> InletTerrain.settings(last));
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("last step"));
|
||||
}
|
||||
}
|
||||
-451
@@ -1,451 +0,0 @@
|
||||
package art.arcane.iris.generation.hydrology.underground;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveAction;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.mantle.MantleWriter;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class SeaInletRasterizerTest {
|
||||
private static final int SEA = 40;
|
||||
private static final String FLUID = HydrologyCaveCell.SEA_FLUID;
|
||||
private static final int CAVE_CLEARANCE = 2;
|
||||
|
||||
@Test
|
||||
public void waterLevelIsSeaLevelEverywhere() {
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(inlet(1L, 15f)), order(false));
|
||||
int wetColumns = 0;
|
||||
Map<Long, Integer> tops = new TreeMap<>();
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
int y = y(entry.getKey());
|
||||
HydrologyCaveAction action = entry.getValue().action();
|
||||
if (action == HydrologyCaveAction.WET_SOURCE) {
|
||||
assertTrue("water at " + y, y <= SEA);
|
||||
tops.merge(column(entry.getKey()), y, Math::max);
|
||||
} else if (action == HydrologyCaveAction.DRY_AIR) {
|
||||
assertTrue("air at " + y, y > SEA);
|
||||
}
|
||||
assertEquals(FLUID, entry.getValue().fluidProfileKey());
|
||||
}
|
||||
for (int top : tops.values()) {
|
||||
assertEquals(SEA, top);
|
||||
wetColumns++;
|
||||
}
|
||||
assertTrue("wet columns " + wetColumns, wetColumns > 300);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyWaterCellIsHeldBySealedOrWetNeighbours() {
|
||||
List<SeaInlet> inlets = List.of(inlet(1L, 15f), inlet(2L, 30f));
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(inlets, order(false));
|
||||
int checked = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
if (entry.getValue().action() != HydrologyCaveAction.WET_SOURCE) {
|
||||
continue;
|
||||
}
|
||||
int x = x(entry.getKey());
|
||||
int y = y(entry.getKey());
|
||||
int z = z(entry.getKey());
|
||||
for (int[] side : new int[][]{{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}, {0, -1, 0}}) {
|
||||
if (paintedSlot(inlets, x + side[0], y + side[1], z + side[2])) {
|
||||
continue;
|
||||
}
|
||||
HydrologyCaveCell neighbour = cells.get(key(x + side[0], y + side[1], z + side[2]));
|
||||
assertNotNull("water at " + x + "," + y + "," + z + " has an open side " + side[0] + "," + side[1] + "," + side[2], neighbour);
|
||||
assertTrue(neighbour.action() == HydrologyCaveAction.WET_SOURCE || neighbour.action() == HydrologyCaveAction.SEAL_GUARD);
|
||||
}
|
||||
checked++;
|
||||
}
|
||||
assertTrue(checked > 1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sealKeepsCavesTwoBlocksFromTheWater() {
|
||||
List<SeaInlet> inlets = List.of(inlet(1L, 15f));
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(inlets, order(false));
|
||||
int checked = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
if (entry.getValue().action() != HydrologyCaveAction.WET_SOURCE) {
|
||||
continue;
|
||||
}
|
||||
int x = x(entry.getKey());
|
||||
int y = y(entry.getKey());
|
||||
int z = z(entry.getKey());
|
||||
for (int below = 0; below <= CAVE_CLEARANCE; below++) {
|
||||
for (int dz = -CAVE_CLEARANCE; dz <= CAVE_CLEARANCE; dz++) {
|
||||
for (int dx = -CAVE_CLEARANCE; dx <= CAVE_CLEARANCE; dx++) {
|
||||
if (paintedSlot(inlets, x + dx, y - below, z + dz)) {
|
||||
continue;
|
||||
}
|
||||
HydrologyCaveCell held = cells.get(key(x + dx, y - below, z + dz));
|
||||
assertNotNull("no seal at " + (x + dx) + "," + (y - below) + "," + (z + dz) + " near water at " + x + "," + y + "," + z,
|
||||
held);
|
||||
assertTrue(held.action() == HydrologyCaveAction.WET_SOURCE || held.action() == HydrologyCaveAction.SEAL_GUARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cells.get(key(x, y - 1, z)).action() == HydrologyCaveAction.SEAL_GUARD) {
|
||||
for (int under = 1; under <= CAVE_CLEARANCE + 1; under++) {
|
||||
assertEquals("bed and two blocks under the water at " + x + "," + y + "," + z, HydrologyCaveAction.SEAL_GUARD,
|
||||
cells.get(key(x, y - under, z)).action());
|
||||
}
|
||||
}
|
||||
checked++;
|
||||
}
|
||||
assertTrue(checked > 1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openSlotColumnsLeaveTheirWaterToThePainter() {
|
||||
SeaInlet inlet = inlet(1L, 15f);
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(inlet), order(false));
|
||||
int[] column = new int[2];
|
||||
int sealed = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
int x = x(entry.getKey());
|
||||
int z = z(entry.getKey());
|
||||
if (!SeaInletRasterizer.column(inlet, x, z, column) || column[1] != SeaInlet.OPEN) {
|
||||
continue;
|
||||
}
|
||||
assertEquals("open slot column " + x + "," + z + " holds only its seal", HydrologyCaveAction.SEAL_GUARD, entry.getValue().action());
|
||||
assertTrue(y(entry.getKey()) <= column[0]);
|
||||
sealed++;
|
||||
}
|
||||
assertTrue("open slot seal cells " + sealed, sealed > 100);
|
||||
assertTrue(cells.values().stream().anyMatch(cell -> cell.action() == HydrologyCaveAction.DRY_AIR));
|
||||
assertTrue(cells.values().stream().anyMatch(cell -> cell.action() == HydrologyCaveAction.WET_SOURCE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openSlotBedsKeepTheirSeaFloorOnTwoSealedBlocks() {
|
||||
SeaInlet inlet = inlet(1L, 15f);
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(inlet), order(false));
|
||||
int[] column = new int[2];
|
||||
int beds = 0;
|
||||
int covered = 0;
|
||||
for (int z = -16; z <= 63; z++) {
|
||||
for (int x = -32; x <= 79; x++) {
|
||||
if (!SeaInletRasterizer.column(inlet, x, z, column)) {
|
||||
continue;
|
||||
}
|
||||
int floor = column[0];
|
||||
if (column[1] == SeaInlet.OPEN) {
|
||||
assertNull("the open slot bed at " + x + "," + floor + "," + z + " keeps the painted sea floor", cells.get(key(x, floor, z)));
|
||||
for (int under = 1; under <= SeaInletRasterizer.SHELL; under++) {
|
||||
HydrologyCaveCell sealed = cells.get(key(x, floor - under, z));
|
||||
assertNotNull("rock under the open slot bed at " + x + "," + (floor - under) + "," + z, sealed);
|
||||
assertEquals(HydrologyCaveAction.SEAL_GUARD, sealed.action());
|
||||
}
|
||||
beds++;
|
||||
} else {
|
||||
assertEquals("covered bed at " + x + "," + floor + "," + z, HydrologyCaveAction.SEAL_GUARD, cells.get(key(x, floor, z)).action());
|
||||
covered++;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("open slot beds " + beds, beds > 20);
|
||||
assertTrue("covered beds " + covered, covered > 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subterrainFluidWithinTwoBlocksOfInletAirAboveSeaLevelIsSealed() {
|
||||
SeaInlet inlet = inlet(1L, 15f);
|
||||
SeaInletRasterizer.SubterrainFluid flooded = (x, y, z) -> Math.floorMod(x + 2 * z + y, 5) != 0;
|
||||
Map<Long, HydrologyCaveCell> plain = rasterize(List.of(inlet), order(false));
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : plain.entrySet()) {
|
||||
assertTrue("without subterrain fluid nothing above sea level is sealed",
|
||||
y(entry.getKey()) <= SEA || entry.getValue().action() == HydrologyCaveAction.DRY_AIR);
|
||||
}
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(inlet), order(false), flooded);
|
||||
int checked = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
if (entry.getValue().action() != HydrologyCaveAction.DRY_AIR) {
|
||||
continue;
|
||||
}
|
||||
int x = x(entry.getKey());
|
||||
int y = y(entry.getKey());
|
||||
int z = z(entry.getKey());
|
||||
for (int dy = -2; dy <= 2; dy++) {
|
||||
for (int dz = -2; dz <= 2; dz++) {
|
||||
for (int dx = -2; dx <= 2; dx++) {
|
||||
if (y + dy <= SEA || !flooded.at(x + dx, y + dy, z + dz)) {
|
||||
continue;
|
||||
}
|
||||
HydrologyCaveCell held = cells.get(key(x + dx, y + dy, z + dz));
|
||||
assertNotNull("subterrain fluid at " + (x + dx) + "," + (y + dy) + "," + (z + dz) + " beside inlet air at " + x + "," + y
|
||||
+ "," + z, held);
|
||||
assertTrue(held.action() == HydrologyCaveAction.DRY_AIR || held.action() == HydrologyCaveAction.SEAL_GUARD);
|
||||
checked++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int sealed = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
int x = x(entry.getKey());
|
||||
int y = y(entry.getKey());
|
||||
int z = z(entry.getKey());
|
||||
if (y <= SEA || entry.getValue().action() != HydrologyCaveAction.SEAL_GUARD) {
|
||||
continue;
|
||||
}
|
||||
assertTrue("only subterrain fluid is sealed above sea level, not " + x + "," + y + "," + z, flooded.at(x, y, z));
|
||||
assertTrue("the seal at " + x + "," + y + "," + z + " lies within two blocks of inlet air", nearAir(cells, x, y, z));
|
||||
sealed++;
|
||||
}
|
||||
assertTrue("checked " + checked, checked > 1000);
|
||||
assertTrue("sealed " + sealed, sealed > 200);
|
||||
assertEquals(cells, rasterize(List.of(inlet), order(true), flooded));
|
||||
}
|
||||
|
||||
private static boolean nearAir(Map<Long, HydrologyCaveCell> cells, int x, int y, int z) {
|
||||
for (int dy = -2; dy <= 2; dy++) {
|
||||
for (int dz = -2; dz <= 2; dz++) {
|
||||
for (int dx = -2; dx <= 2; dx++) {
|
||||
HydrologyCaveCell cell = cells.get(key(x + dx, y + dy, z + dz));
|
||||
if (cell != null && cell.action() == HydrologyCaveAction.DRY_AIR) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean paintedSlot(List<SeaInlet> inlets, int x, int y, int z) {
|
||||
int[] column = new int[2];
|
||||
for (SeaInlet inlet : inlets) {
|
||||
if (SeaInletRasterizer.column(inlet, x, z, column) && column[1] == SeaInlet.OPEN && y >= column[0] && y <= inlet.waterLevel()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Test(timeout = 20_000L)
|
||||
public void thinDiagonalPassagesSealTheirBedWithoutRunningAway() {
|
||||
float[] xs = {0f, 8f, 16f, 24f, 32f};
|
||||
float[] zs = {0f, 8f, 16f, 24f, 32f};
|
||||
float[] halfWidth = {0.6f, 0.6f, 0.6f, 0.6f, 0.6f};
|
||||
int[] floor = {SEA - 3, SEA - 3, SEA - 3, SEA - 3, SEA - 3};
|
||||
int[] ceiling = {SEA + 4, SEA + 4, SEA + 4, SEA + 4, SEA + 4};
|
||||
SeaInlet thin = new SeaInlet(9L, xs, zs, halfWidth, SEA, floor, ceiling, 32, 32, 2);
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(thin), order(false));
|
||||
int wet = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
assertTrue("no cell runs away below the shell", y(entry.getKey()) >= SEA - 3 - CAVE_CLEARANCE - 1);
|
||||
if (entry.getValue().action() == HydrologyCaveAction.WET_SOURCE) {
|
||||
wet++;
|
||||
assertEquals(HydrologyCaveAction.SEAL_GUARD, cells.get(key(x(entry.getKey()), SEA - 3, z(entry.getKey()))).action());
|
||||
}
|
||||
}
|
||||
assertTrue(wet > 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void passageEndingAtAnOldChunkIsSealed() {
|
||||
SeaInlet inlet = inlet(1L, 15f);
|
||||
SeaInletRasterizer.HistoricalChunks old = (chunkX, chunkZ) -> chunkX == 2;
|
||||
Map<Long, HydrologyCaveCell> open = rasterize(List.of(inlet), order(false), SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(inlet), newChunks(order(false), old), SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
old);
|
||||
int[] column = new int[2];
|
||||
int seamColumns = 0;
|
||||
for (int z = -16; z <= 63; z++) {
|
||||
for (int x = -32; x <= 79; x++) {
|
||||
if (old.at(x >> 4, z >> 4) || !nearOldChunk(old, x, z)) {
|
||||
continue;
|
||||
}
|
||||
if (!SeaInletRasterizer.column(inlet, x, z, column) || column[1] == SeaInlet.OPEN) {
|
||||
continue;
|
||||
}
|
||||
assertEquals("without old chunks the seam column " + x + "," + z + " holds water", HydrologyCaveAction.WET_SOURCE,
|
||||
open.get(key(x, inlet.waterLevel(), z)).action());
|
||||
for (int y = column[0] - SeaInletRasterizer.SHELL; y <= column[1]; y++) {
|
||||
HydrologyCaveCell sealed = cells.get(key(x, y, z));
|
||||
assertNotNull("no seal at " + x + "," + y + "," + z + " beside the old chunk", sealed);
|
||||
assertEquals("seal at " + x + "," + y + "," + z + " beside the old chunk", HydrologyCaveAction.SEAL_GUARD, sealed.action());
|
||||
}
|
||||
seamColumns++;
|
||||
}
|
||||
}
|
||||
int wet = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
int x = x(entry.getKey());
|
||||
int y = y(entry.getKey());
|
||||
int z = z(entry.getKey());
|
||||
assertFalse("old chunk " + (x >> 4) + "," + (z >> 4) + " was written", old.at(x >> 4, z >> 4));
|
||||
HydrologyCaveAction action = entry.getValue().action();
|
||||
if (action == HydrologyCaveAction.SEAL_GUARD) {
|
||||
continue;
|
||||
}
|
||||
assertFalse(action + " at " + x + "," + y + "," + z + " lies within two blocks of an old chunk", nearOldChunk(old, x, z));
|
||||
if (action != HydrologyCaveAction.WET_SOURCE) {
|
||||
continue;
|
||||
}
|
||||
for (int[] side : new int[][]{{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}, {0, -1, 0}}) {
|
||||
if (paintedSlot(List.of(inlet), x + side[0], y + side[1], z + side[2])) {
|
||||
continue;
|
||||
}
|
||||
HydrologyCaveCell neighbour = cells.get(key(x + side[0], y + side[1], z + side[2]));
|
||||
assertNotNull("water at " + x + "," + y + "," + z + " has an open side " + side[0] + "," + side[1] + "," + side[2], neighbour);
|
||||
assertTrue(neighbour.action() == HydrologyCaveAction.WET_SOURCE || neighbour.action() == HydrologyCaveAction.SEAL_GUARD);
|
||||
}
|
||||
wet++;
|
||||
}
|
||||
assertTrue("covered seam columns " + seamColumns, seamColumns > 10);
|
||||
assertTrue("water cells away from the old chunks " + wet, wet > 300);
|
||||
assertEquals(cells, rasterize(List.of(inlet), newChunks(order(true), old), SeaInletRasterizer.SubterrainFluid.NOWHERE, old));
|
||||
}
|
||||
|
||||
private static boolean nearOldChunk(SeaInletRasterizer.HistoricalChunks old, int x, int z) {
|
||||
for (int dz = -SeaInletRasterizer.SHELL; dz <= SeaInletRasterizer.SHELL; dz++) {
|
||||
for (int dx = -SeaInletRasterizer.SHELL; dx <= SeaInletRasterizer.SHELL; dx++) {
|
||||
if (old.at((x + dx) >> 4, (z + dz) >> 4)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<int[]> newChunks(List<int[]> chunks, SeaInletRasterizer.HistoricalChunks old) {
|
||||
List<int[]> fresh = new ArrayList<>();
|
||||
for (int[] chunk : chunks) {
|
||||
if (!old.at(chunk[0], chunk[1])) {
|
||||
fresh.add(chunk);
|
||||
}
|
||||
}
|
||||
return fresh;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chunkOrderAndInletOrderDoNotChangeTheCells() {
|
||||
List<SeaInlet> inlets = List.of(inlet(1L, 15f), inlet(2L, 22f));
|
||||
Map<Long, HydrologyCaveCell> forward = rasterize(inlets, order(false));
|
||||
Map<Long, HydrologyCaveCell> reverse = rasterize(List.of(inlets.get(1), inlets.get(0)), order(true));
|
||||
assertEquals(forward, reverse);
|
||||
assertFalse(forward.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chunksWriteOnlyTheirOwnColumns() {
|
||||
SeaInlet inlet = inlet(1L, 15f);
|
||||
Map<Long, HydrologyCaveCell> cells = new TreeMap<>();
|
||||
MantleWriter writer = writer(cells, 1, 0);
|
||||
new SeaInletRasterizer().write(inlet, 1, 0, writer, FLUID, SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
assertFalse(cells.isEmpty());
|
||||
for (long key : cells.keySet()) {
|
||||
assertEquals(1, x(key) >> 4);
|
||||
assertEquals(0, z(key) >> 4);
|
||||
}
|
||||
Map<Long, HydrologyCaveCell> far = new TreeMap<>();
|
||||
new SeaInletRasterizer().write(inlet, 20, 20, writer(far, 20, 20), FLUID, SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
assertTrue(far.isEmpty());
|
||||
assertFalse(SeaInletRasterizer.touches(inlet, 20, 20));
|
||||
}
|
||||
|
||||
private static SeaInlet inlet(long id, float z) {
|
||||
float[] xs = {-8f, 0f, 8f, 16f, 24f, 32f, 40f, 48f};
|
||||
float[] zs = new float[xs.length];
|
||||
float[] halfWidth = new float[xs.length];
|
||||
int[] floor = new int[xs.length];
|
||||
int[] ceiling = new int[xs.length];
|
||||
for (int station = 0; station < xs.length; station++) {
|
||||
zs[station] = z + (station % 2 == 0 ? 0f : 3f);
|
||||
halfWidth[station] = 5f - station * 0.4f;
|
||||
floor[station] = SEA - 2 - station % 3;
|
||||
ceiling[station] = station < 2 ? SeaInlet.OPEN : SEA + 4 + station % 4;
|
||||
}
|
||||
return new SeaInlet(id, xs, zs, halfWidth, SEA, floor, ceiling, 48, (int) z, 7);
|
||||
}
|
||||
|
||||
private static List<int[]> order(boolean reverse) {
|
||||
List<int[]> chunks = new ArrayList<>();
|
||||
for (int chunkZ = -1; chunkZ <= 3; chunkZ++) {
|
||||
for (int chunkX = -2; chunkX <= 4; chunkX++) {
|
||||
chunks.add(new int[]{chunkX, chunkZ});
|
||||
}
|
||||
}
|
||||
if (reverse) {
|
||||
Collections.reverse(chunks);
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
private static Map<Long, HydrologyCaveCell> rasterize(List<SeaInlet> inlets, List<int[]> chunks) {
|
||||
return rasterize(inlets, chunks, SeaInletRasterizer.SubterrainFluid.NOWHERE);
|
||||
}
|
||||
|
||||
private static Map<Long, HydrologyCaveCell> rasterize(List<SeaInlet> inlets, List<int[]> chunks, SeaInletRasterizer.SubterrainFluid subterrain) {
|
||||
return rasterize(inlets, chunks, subterrain, SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
}
|
||||
|
||||
private static Map<Long, HydrologyCaveCell> rasterize(List<SeaInlet> inlets, List<int[]> chunks, SeaInletRasterizer.SubterrainFluid subterrain,
|
||||
SeaInletRasterizer.HistoricalChunks old) {
|
||||
Map<Long, HydrologyCaveCell> cells = new TreeMap<>();
|
||||
SeaInletRasterizer rasterizer = new SeaInletRasterizer();
|
||||
for (int[] chunk : chunks) {
|
||||
MantleWriter writer = writer(cells, chunk[0], chunk[1]);
|
||||
for (SeaInlet inlet : inlets) {
|
||||
rasterizer.write(inlet, chunk[0], chunk[1], writer, FLUID, subterrain, old);
|
||||
}
|
||||
}
|
||||
return cells;
|
||||
}
|
||||
|
||||
private static MantleWriter writer(Map<Long, HydrologyCaveCell> cells, int chunkX, int chunkZ) {
|
||||
MantleWriter writer = mock(MantleWriter.class);
|
||||
doAnswer(call -> {
|
||||
int x = call.getArgument(0);
|
||||
int z = call.getArgument(2);
|
||||
if (x >> 4 != chunkX || z >> 4 != chunkZ) {
|
||||
throw new AssertionError("chunk " + chunkX + "," + chunkZ + " wrote " + x + "," + z);
|
||||
}
|
||||
cells.put(key(x, call.getArgument(1), z), call.getArgument(3));
|
||||
return null;
|
||||
}).when(writer).setData(anyInt(), anyInt(), anyInt(), any(HydrologyCaveCell.class));
|
||||
when(writer.getDataIfPresent(anyInt(), anyInt(), anyInt(), eq(HydrologyCaveCell.class)))
|
||||
.thenAnswer(call -> cells.get(key(call.getArgument(0), call.getArgument(1), call.getArgument(2))));
|
||||
return writer;
|
||||
}
|
||||
|
||||
private static long key(int x, int y, int z) {
|
||||
return ((long) (x + 4096) << 40) | ((long) (z + 4096) << 20) | (y + 4096);
|
||||
}
|
||||
|
||||
private static long column(long key) {
|
||||
return key >>> 20;
|
||||
}
|
||||
|
||||
private static int x(long key) {
|
||||
return (int) (key >>> 40) - 4096;
|
||||
}
|
||||
|
||||
private static int z(long key) {
|
||||
return (int) ((key >>> 20) & 0xFFFFF) - 4096;
|
||||
}
|
||||
|
||||
private static int y(long key) {
|
||||
return (int) (key & 0xFFFFF) - 4096;
|
||||
}
|
||||
}
|
||||
@@ -837,7 +837,7 @@ public class PondPlannerTest {
|
||||
long key = ((long) (x >> 4) << 32) | ((z >> 4) & 0xFFFFFFFFL);
|
||||
ChunkWaterRaster raster = rasters.get(key);
|
||||
if (raster == null) {
|
||||
WindowPlan window = new WindowPlan(WindowKey.containing(x, z), List.of(), List.of(pond), List.of());
|
||||
WindowPlan window = new WindowPlan(WindowKey.containing(x, z), List.of(), List.of(pond));
|
||||
IndexedWindow indexed = new IndexedWindow(window, ReachIndex.build(window.key(), List.of(), List.of(pond)));
|
||||
List<RegionPlan> regions = new ArrayList<>();
|
||||
for (RegionKey region : ChunkRasterizer.lakeRegions(x >> 4, z >> 4)) {
|
||||
|
||||
@@ -2,8 +2,6 @@ package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.testsupport.WaterScene;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import org.junit.Test;
|
||||
@@ -101,99 +99,6 @@ public class CaveCeilingMaskTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cavesStayOutOfInletHeadroom() {
|
||||
SeaInlet inlet = inlet();
|
||||
int[] bounds = SeaInletRasterizer.bounds(inlet);
|
||||
long[] bands = new long[256];
|
||||
int[] column = new int[2];
|
||||
int covered = 0;
|
||||
int around = 0;
|
||||
for (int chunkZ = (bounds[1] >> 4) - 1; chunkZ <= (bounds[3] >> 4) + 1; chunkZ++) {
|
||||
for (int chunkX = (bounds[0] >> 4) - 1; chunkX <= (bounds[2] >> 4) + 1; chunkX++) {
|
||||
boolean masked = CaveCeilingMask.fillHeadroom(chunkX, chunkZ, List.of(inlet), ROOF_CLEARANCE, bands);
|
||||
long[] headroom = masked ? bands : null;
|
||||
boolean expectedMasked = false;
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
int x = (chunkX << 4) + lx;
|
||||
int z = (chunkZ << 4) + lz;
|
||||
int index = PowerOfTwoCoordinates.packLocal16(lx, lz);
|
||||
int top = highestRoofWithinTwo(inlet, x, z);
|
||||
if (top == NO_ROOF) {
|
||||
for (int y = 0; y <= SEA + 64; y++) {
|
||||
assertFalse("caves stay possible at " + x + "," + y + "," + z + " away from the inlet",
|
||||
CaveCeilingMask.masked(null, headroom, index, y));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
expectedMasked = true;
|
||||
for (int y = inlet.waterLevel() + 1; y <= top; y++) {
|
||||
assertTrue("caves stay out of the inlet headroom and roof at " + x + "," + y + "," + z,
|
||||
CaveCeilingMask.masked(null, headroom, index, y));
|
||||
}
|
||||
assertFalse("the seal holds caves at the water level " + x + "," + z,
|
||||
CaveCeilingMask.masked(null, headroom, index, inlet.waterLevel()));
|
||||
assertFalse("caves stay possible above the inlet roof at " + x + "," + z,
|
||||
CaveCeilingMask.masked(null, headroom, index, top + 1));
|
||||
if (SeaInletRasterizer.column(inlet, x, z, column) && column[1] != SeaInlet.OPEN) {
|
||||
covered++;
|
||||
} else {
|
||||
around++;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertEquals("headroom flag for chunk " + chunkX + "," + chunkZ, expectedMasked, masked);
|
||||
}
|
||||
}
|
||||
assertTrue("covered columns " + covered, covered > 300);
|
||||
assertTrue("columns around the passage " + around, around > 100);
|
||||
assertFalse(CaveCeilingMask.fillHeadroom(0, 0, List.of(), ROOF_CLEARANCE, bands));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headroomJoinsTheWaterCeilings() {
|
||||
int[] ceilings = new int[256];
|
||||
Arrays.fill(ceilings, UNMASKED);
|
||||
ceilings[3] = 40;
|
||||
long[] bands = new long[256];
|
||||
assertTrue(CaveCeilingMask.fillHeadroom(0, 0, List.of(inlet()), ROOF_CLEARANCE, bands));
|
||||
int index = PowerOfTwoCoordinates.packLocal16(12, 6);
|
||||
assertTrue(CaveCeilingMask.masked(ceilings, null, 3, 41));
|
||||
assertFalse(CaveCeilingMask.masked(ceilings, null, 3, 40));
|
||||
assertFalse(CaveCeilingMask.masked(ceilings, bands, index, SEA));
|
||||
assertTrue(CaveCeilingMask.masked(ceilings, bands, index, SEA + 1));
|
||||
assertFalse(CaveCeilingMask.masked(null, null, index, SEA + 1));
|
||||
}
|
||||
|
||||
private static SeaInlet inlet() {
|
||||
float[] xs = {-8f, 0f, 8f, 16f, 24f, 32f, 40f, 48f};
|
||||
float[] zs = new float[xs.length];
|
||||
float[] halfWidth = new float[xs.length];
|
||||
int[] floor = new int[xs.length];
|
||||
int[] ceiling = new int[xs.length];
|
||||
for (int station = 0; station < xs.length; station++) {
|
||||
zs[station] = 6f + (station % 2 == 0 ? 0f : 3f);
|
||||
halfWidth[station] = 5f - station * 0.4f;
|
||||
floor[station] = SEA - 2 - station % 3;
|
||||
ceiling[station] = station < 2 ? SeaInlet.OPEN : SEA + 4 + station % 4;
|
||||
}
|
||||
return new SeaInlet(1L, xs, zs, halfWidth, SEA, floor, ceiling, 48, 6, 7);
|
||||
}
|
||||
|
||||
private static int highestRoofWithinTwo(SeaInlet inlet, int x, int z) {
|
||||
int top = NO_ROOF;
|
||||
int[] column = new int[2];
|
||||
for (int dz = -CaveCeilingMask.CONTAINMENT; dz <= CaveCeilingMask.CONTAINMENT; dz++) {
|
||||
for (int dx = -CaveCeilingMask.CONTAINMENT; dx <= CaveCeilingMask.CONTAINMENT; dx++) {
|
||||
if (SeaInletRasterizer.column(inlet, x + dx, z + dz, column) && column[1] != SeaInlet.OPEN) {
|
||||
top = Math.max(top, column[1] + ROOF_CLEARANCE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
static WaterScene scene(IrisHydrology config) {
|
||||
IntBinaryOperator natural = (x, z) -> 80;
|
||||
return new WaterScene(config, natural)
|
||||
|
||||
@@ -11,8 +11,6 @@ import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.underground.CavePoolFiller;
|
||||
import art.arcane.iris.generation.hydrology.underground.CaveVoxel;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.EnginePlatformHooks;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
@@ -188,48 +186,6 @@ public class MantleCarvedTerrainTest {
|
||||
assertThrows(IllegalStateException.class, () -> carved.voxel(1, 20, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inletSpaceFromEveryNeighbourChunkReadsAsForeignAndPoolsBesideItStayOutInEitherChunkOrder() {
|
||||
Scene probe = inletScene();
|
||||
MantleCarvedTerrain carved = probe.carved();
|
||||
assertEquals("passage water", CaveVoxel.FOREIGN, carved.voxel(7, 28, 21));
|
||||
assertEquals("passage air", CaveVoxel.FOREIGN, carved.voxel(10, 33, 21));
|
||||
assertEquals("seal under the passage", CaveVoxel.FOREIGN, carved.voxel(10, 24, 21));
|
||||
assertEquals("seal beside the passage", CaveVoxel.FOREIGN, carved.voxel(7, 25, 18));
|
||||
assertEquals(CaveVoxel.SOLID, carved.voxel(7, 23, 18));
|
||||
assertEquals(CaveVoxel.AIR, carved.voxel(7, 25, 17));
|
||||
assertEquals(CaveVoxel.SOLID, carved.voxel(10, 34, 21));
|
||||
assertEquals(CaveVoxel.SOLID, carved.voxel(10, 25, 26));
|
||||
|
||||
Map<Long, HydrologyCaveCell> forward = inletScene().generate(0, 1);
|
||||
Map<Long, HydrologyCaveCell> reverse = inletScene().generate(1, 0);
|
||||
|
||||
assertEquals(forward, reverse);
|
||||
int top = Integer.MIN_VALUE;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : forward.entrySet()) {
|
||||
if (entry.getValue().action() != HydrologyCaveAction.POOL_SOURCE) {
|
||||
continue;
|
||||
}
|
||||
long cell = entry.getKey();
|
||||
top = Math.max(top, cellY(cell));
|
||||
for (int[] face : FACES) {
|
||||
HydrologyCaveCell neighbour = forward.get(cell(cellX(cell) + face[0], cellY(cell) + face[1], cellZ(cell) + face[2]));
|
||||
assertFalse("pool water at " + cellX(cell) + "," + cellY(cell) + "," + cellZ(cell) + " touches the inlet",
|
||||
neighbour != null && HydrologyCaveCell.SEA_FLUID.equals(neighbour.fluidProfileKey()));
|
||||
}
|
||||
}
|
||||
assertEquals("the pool stops one level below the inlet seal its next level would reach", 24, top);
|
||||
for (int y = 24; y <= 30; y++) {
|
||||
assertInlet(forward, 7, y, 19, HydrologyCaveAction.SEAL_GUARD);
|
||||
}
|
||||
for (int y = 27; y <= 30; y++) {
|
||||
assertInlet(forward, 7, y, 21, HydrologyCaveAction.WET_SOURCE);
|
||||
}
|
||||
for (int y = 31; y <= 33; y++) {
|
||||
assertInlet(forward, 7, y, 21, HydrologyCaveAction.DRY_AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shallowPoolsUnderVolcanicSurfacesStayWater() {
|
||||
IrisBiome volcanoes = biome("tropical/volcanoes", 0, "lava");
|
||||
@@ -378,35 +334,6 @@ public class MantleCarvedTerrainTest {
|
||||
return region;
|
||||
}
|
||||
|
||||
private static Scene inletScene() {
|
||||
Scene scene = new Scene();
|
||||
Matter[] room = scene.chunk(0, 0);
|
||||
for (int x = 2; x <= 13; x++) {
|
||||
for (int z = 4; z <= 15; z++) {
|
||||
for (int y = 22; y <= 36; y++) {
|
||||
cavern(room, x, y, z, (byte) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Matter[] channel = scene.chunk(0, 1);
|
||||
for (int x = 6; x <= 8; x++) {
|
||||
for (int z = 16; z <= 19; z++) {
|
||||
for (int y = 25; y <= 30; y++) {
|
||||
cavern(channel, x, y, z, (byte) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
scene.inlets.add(new SeaInlet(77L, new float[]{40f, -8f}, new float[]{22f, 22f}, new float[]{2f, 2f}, 30, new int[]{26, 26},
|
||||
new int[]{33, 33}, -8, 22, 2));
|
||||
return scene;
|
||||
}
|
||||
|
||||
private static void assertInlet(Map<Long, HydrologyCaveCell> written, int x, int y, int z, HydrologyCaveAction action) {
|
||||
HydrologyCaveCell cell = written.get(cell(x, y, z));
|
||||
assertTrue("inlet " + action + " at " + x + "," + y + "," + z + " but found " + cell,
|
||||
cell != null && cell.action() == action && HydrologyCaveCell.SEA_FLUID.equals(cell.fluidProfileKey()));
|
||||
}
|
||||
|
||||
private static long cell(int x, int y, int z) {
|
||||
return ((long) (x + 4096) << 40) | ((long) y << 20) | (z + 4096);
|
||||
}
|
||||
@@ -450,7 +377,6 @@ public class MantleCarvedTerrainTest {
|
||||
private final MantleWriter writer = mock(MantleWriter.class);
|
||||
private final IrisComplex complex = mock(IrisComplex.class);
|
||||
private final Engine engine;
|
||||
private final List<SeaInlet> inlets = new ArrayList<>();
|
||||
private final Map<Long, HydrologyCaveCell> cells = new HashMap<>();
|
||||
|
||||
private Scene() {
|
||||
@@ -486,7 +412,6 @@ public class MantleCarvedTerrainTest {
|
||||
when(complex.allowsMantleChunkWrite(anyInt(), anyInt())).thenReturn(true);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
when(runtime.caveFluidPolicies()).thenReturn(true);
|
||||
when(runtime.inlets(anyInt(), anyInt())).thenAnswer(invocation -> touching(invocation.getArgument(0), invocation.getArgument(1)));
|
||||
doAnswer(invocation -> {
|
||||
cells.put(cell(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2)), invocation.getArgument(3));
|
||||
return null;
|
||||
@@ -504,27 +429,12 @@ public class MantleCarvedTerrainTest {
|
||||
return new MantleCarvedTerrain(writer, complex, engine, 0, 0);
|
||||
}
|
||||
|
||||
private List<SeaInlet> touching(int chunkX, int chunkZ) {
|
||||
List<SeaInlet> touching = new ArrayList<>();
|
||||
for (SeaInlet inlet : inlets) {
|
||||
if (SeaInletRasterizer.touches(inlet, chunkX, chunkZ)) {
|
||||
touching.add(inlet);
|
||||
}
|
||||
}
|
||||
return touching;
|
||||
}
|
||||
|
||||
private Map<Long, HydrologyCaveCell> generate(int... chunkZs) {
|
||||
IrisHydrology config = new IrisHydrology().setEnabled(true);
|
||||
config.getFluids().add(new IrisFluidProfile().setName("lava").setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava")));
|
||||
config.getUnderground().getCavePools().setDensity(8D).setFreeboard(new KList<>(0, 0));
|
||||
HydrologySettings settings = HydrologySettings.compile(config, SEED, 63, 0, 384);
|
||||
SeaInletRasterizer rasterizer = new SeaInletRasterizer();
|
||||
for (int chunkZ : chunkZs) {
|
||||
for (SeaInlet inlet : complex.getHydrologyRuntime().inlets(0, chunkZ)) {
|
||||
rasterizer.write(inlet, 0, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
}
|
||||
new CavePoolFiller(settings, 0).fill(0, chunkZ, () -> new MantleCarvedTerrain(writer, complex, engine, 0, chunkZ), writer, SEED);
|
||||
}
|
||||
return cells;
|
||||
|
||||
-86
@@ -8,8 +8,6 @@ import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.EngineMetrics;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
@@ -148,90 +146,6 @@ public class MantleCarvingComponentWaterMaskTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inletHeadroomJoinsTheProfilePassProtection() throws Exception {
|
||||
SeaInlet inlet = coveredInlet(32, 40, 40);
|
||||
installInlet(inlet);
|
||||
IrisCaveCarver3D carver = installProfile();
|
||||
List<long[]> boundaries = new ArrayList<>();
|
||||
doAnswer(call -> {
|
||||
boundaries.add(((long[]) call.getArgument(8)).clone());
|
||||
return 0;
|
||||
}).when(carver).carve(any(), anyInt(), anyInt(), any(), anyDouble(), anyDouble(), any(), any(), any(), any(), any(), any());
|
||||
|
||||
component.generateLayer(writer, 2, 2, context);
|
||||
|
||||
assertEquals(1, boundaries.size());
|
||||
int[] column = new int[2];
|
||||
int covered = 0;
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
int index = PowerOfTwoCoordinates.packLocal16(lx, lz);
|
||||
if (!SeaInletRasterizer.column(inlet, 32 + lx, 32 + lz, column)) {
|
||||
continue;
|
||||
}
|
||||
for (int y = inlet.waterLevel() + 1; y <= column[1] + ROOF_CLEARANCE; y++) {
|
||||
assertTrue("the carver keeps out of the inlet headroom at " + (32 + lx) + "," + y + "," + (32 + lz),
|
||||
SurfaceFluidBoundaryPlan.protects(boundaries.getFirst(), index, y));
|
||||
}
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries.getFirst(), index, inlet.waterLevel()));
|
||||
covered++;
|
||||
}
|
||||
}
|
||||
assertTrue("covered columns " + covered, covered > 80);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subterrainFeaturesStayOutOfInletHeadroom() {
|
||||
IrisSubterrainFeature feature = new IrisSubterrainFeature().setId("room").setFamily(IrisSubterrainFamily.CENOTE)
|
||||
.setProbability(1).setLength(64).setRadius(12).setHeight(24).setPillarSpacing(0).setFormationFraction(0)
|
||||
.setWorldYRange(new IrisRange(-48, 60));
|
||||
SubterrainPlanner planner = new SubterrainPlanner(new SubterrainPlanner.Options(List.of(feature), 83L, -64, 128, (x, z) -> "region"));
|
||||
SubterrainPlan plan = planner.plansForBounds(-512, -512, 512, 512).getFirst();
|
||||
int chunkX = plan.centerX() >> 4;
|
||||
int chunkZ = plan.centerZ() >> 4;
|
||||
when(complex.getSubterrainPlanner()).thenReturn(planner);
|
||||
try (MockedStatic<B> blocks = mockStatic(B.class)) {
|
||||
blocks.when(() -> B.getState(anyString())).thenReturn(mock(NativeBlockState.class));
|
||||
List<int[]> open = openedCells(chunkX, chunkZ);
|
||||
int[] heights = open.stream().mapToInt(cell -> cell[1]).sorted().toArray();
|
||||
int water = heights[heights.length / 4];
|
||||
SeaInlet inlet = coveredInlet(chunkX << 4, (chunkZ << 4) + 8, water);
|
||||
int[] column = new int[2];
|
||||
int inside = 0;
|
||||
for (int[] cell : open) {
|
||||
if (SeaInletRasterizer.column(inlet, cell[0], cell[2], column) && cell[1] > water && cell[1] <= column[1] + ROOF_CLEARANCE) {
|
||||
inside++;
|
||||
}
|
||||
}
|
||||
assertTrue("subterrain cells in the headroom before the inlet " + inside, inside > 20);
|
||||
|
||||
installInlet(inlet);
|
||||
List<int[]> sealed = openedCells(chunkX, chunkZ);
|
||||
assertTrue(sealed.size() > 0);
|
||||
for (int[] cell : sealed) {
|
||||
boolean headroom = SeaInletRasterizer.column(inlet, cell[0], cell[2], column) && cell[1] > water
|
||||
&& cell[1] <= column[1] + ROOF_CLEARANCE;
|
||||
assertFalse("subterrain opened " + cell[0] + "," + cell[1] + "," + cell[2] + " in the inlet headroom", headroom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void installInlet(SeaInlet inlet) {
|
||||
when(hydrology.inlets(anyInt(), anyInt())).thenAnswer(call -> SeaInletRasterizer.touches(inlet, call.getArgument(0), call.getArgument(1))
|
||||
? List.of(inlet) : List.of());
|
||||
when(hydrology.settings()).thenReturn(HydrologySettings.compile(new IrisHydrology().setEnabled(true), 1L, 63, 0, 128));
|
||||
}
|
||||
|
||||
private static SeaInlet coveredInlet(int startX, int z, int water) {
|
||||
float[] xs = {startX - 4f, startX + 4f, startX + 12f, startX + 20f};
|
||||
float[] zs = {z, z, z, z};
|
||||
float[] halfWidth = {4f, 4f, 3.5f, 3f};
|
||||
int[] floor = {water - 3, water - 3, water - 3, water - 3};
|
||||
int[] ceiling = {water + 5, water + 5, water + 4, water + 4};
|
||||
return new SeaInlet(5L, xs, zs, halfWidth, water, floor, ceiling, startX + 20, z, 3);
|
||||
}
|
||||
|
||||
private List<int[]> openedCells(int chunkX, int chunkZ) {
|
||||
List<int[]> opened = new ArrayList<>();
|
||||
Mantle<Matter> storage = writer.getMantle();
|
||||
|
||||
-70
@@ -9,7 +9,6 @@ import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.underground.CavePoolFiller;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainCell;
|
||||
@@ -262,75 +261,6 @@ public class MantleHydrologyComponentTest {
|
||||
verifyNoInteractions(closed.writer, closed.runtime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seaInletsAreWrittenEvenWhereNoSurfaceWaterFlows() {
|
||||
Fixture dry = new Fixture(ChunkWaterRaster.EMPTY, (x, z) -> 99);
|
||||
SeaInlet inlet = new SeaInlet(5L, new float[]{-8f, 8f, 24f}, new float[]{8f, 8f, 8f}, new float[]{4f, 4f, 3f}, 63,
|
||||
new int[]{60, 60, 59}, new int[]{90, 68, 67}, 24, 8, 6);
|
||||
when(dry.runtime.inlets(0, 0)).thenReturn(List.of(inlet));
|
||||
List<HydrologyCaveCell> written = new ArrayList<>();
|
||||
List<Integer> heights = new ArrayList<>();
|
||||
doAnswer(call -> {
|
||||
written.add(call.getArgument(3));
|
||||
heights.add(call.getArgument(1));
|
||||
return null;
|
||||
}).when(dry.writer).setData(anyInt(), anyInt(), anyInt(), any(HydrologyCaveCell.class));
|
||||
dry.generate();
|
||||
verify(dry.complex, never()).effectiveWaterHeads(anyInt(), anyInt(), any(), any());
|
||||
int wet = 0;
|
||||
for (int index = 0; index < written.size(); index++) {
|
||||
HydrologyCaveCell cell = written.get(index);
|
||||
assertEquals(HydrologyCaveCell.SEA_FLUID, cell.fluidProfileKey());
|
||||
if (cell.action() == HydrologyCaveAction.WET_SOURCE) {
|
||||
wet++;
|
||||
assertTrue(heights.get(index) <= 63);
|
||||
}
|
||||
}
|
||||
assertTrue("wet inlet cells " + wet, wet > 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subterrainFluidBesideSeaInletAirIsSealedAboveSeaLevel() {
|
||||
Fixture dry = new Fixture(ChunkWaterRaster.EMPTY, (x, z) -> 99);
|
||||
SeaInlet inlet = new SeaInlet(5L, new float[]{-8f, 8f, 24f}, new float[]{8f, 8f, 8f}, new float[]{4f, 4f, 3f}, 63,
|
||||
new int[]{60, 60, 59}, new int[]{90, 68, 67}, 24, 8, 6);
|
||||
when(dry.runtime.inlets(0, 0)).thenReturn(List.of(inlet));
|
||||
SubterrainPlanner planner = mock(SubterrainPlanner.class);
|
||||
List<SubterrainPlan> plans = List.of(mock(SubterrainPlan.class));
|
||||
SubterrainCell water = new SubterrainCell(SubterrainCell.Kind.WATER, "", null);
|
||||
when(planner.isEmpty()).thenReturn(false);
|
||||
when(planner.plansForBounds(0, 0, 15, 15)).thenReturn(plans);
|
||||
when(planner.sample(eq(plans), anyInt(), anyInt(), anyInt())).thenAnswer(call ->
|
||||
(int) call.getArgument(2) == 69 + MINIMUM_Y ? water : SubterrainCell.OUTSIDE);
|
||||
when(dry.complex.getSubterrainPlanner()).thenReturn(planner);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisWorld world = mock(IrisWorld.class);
|
||||
when(dry.writer.getEngine()).thenReturn(engine);
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
when(world.minHeight()).thenReturn(MINIMUM_Y);
|
||||
Map<Long, HydrologyCaveCell> cells = new HashMap<>();
|
||||
doAnswer(call -> {
|
||||
cells.put(cell(call.getArgument(0), call.getArgument(1), call.getArgument(2)), call.getArgument(3));
|
||||
return null;
|
||||
}).when(dry.writer).setData(anyInt(), anyInt(), anyInt(), any(HydrologyCaveCell.class));
|
||||
when(dry.writer.getDataIfPresent(anyInt(), anyInt(), anyInt(), eq(HydrologyCaveCell.class))).thenAnswer(call ->
|
||||
cells.get(cell(call.getArgument(0), call.getArgument(1), call.getArgument(2))));
|
||||
|
||||
dry.generate();
|
||||
|
||||
assertEquals("inlet air keeps its cell", HydrologyCaveAction.DRY_AIR, cells.get(cell(4, 69, 8)).action());
|
||||
assertEquals("subterrain water beside the passage", HydrologyCaveAction.SEAL_GUARD, cells.get(cell(8, 69, 13)).action());
|
||||
assertEquals("subterrain water over the passage roof", HydrologyCaveAction.SEAL_GUARD, cells.get(cell(12, 69, 8)).action());
|
||||
assertNull("subterrain water three blocks from the passage", cells.get(cell(8, 69, 15)));
|
||||
assertNull("rock beside the passage above sea level", cells.get(cell(8, 70, 13)));
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
int y = (int) ((entry.getKey() >>> 20) & 0xFFFFF);
|
||||
if (y > 63 && entry.getValue().action() == HydrologyCaveAction.SEAL_GUARD) {
|
||||
assertEquals(69, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void provisionalRastersFailTheChunk() {
|
||||
Fixture own = new Fixture(ChunkWaterRaster.PROVISIONAL, (x, z) -> 99);
|
||||
|
||||
-26
@@ -16,32 +16,6 @@ public class SurfaceFluidBoundaryPlanTest {
|
||||
private static final int PADDING = 3;
|
||||
private static final int FLUID_HEIGHT = 64;
|
||||
|
||||
@Test
|
||||
public void joinedBandsWidenTheProtectionToCoverBoth() {
|
||||
long none = SurfaceFluidBoundaryPlan.boundary(SurfaceFluidBoundaryPlan.NO_BOUNDARY, Integer.MIN_VALUE);
|
||||
long[] boundaries = new long[CHUNK_SIZE * CHUNK_SIZE];
|
||||
long[] bands = new long[CHUNK_SIZE * CHUNK_SIZE];
|
||||
Arrays.fill(boundaries, none);
|
||||
Arrays.fill(bands, none);
|
||||
boundaries[0] = SurfaceFluidBoundaryPlan.boundary(60, 64);
|
||||
bands[0] = SurfaceFluidBoundaryPlan.boundary(65, 80);
|
||||
bands[1] = SurfaceFluidBoundaryPlan.boundary(70, 75);
|
||||
boundaries[2] = SurfaceFluidBoundaryPlan.boundary(60, 64);
|
||||
|
||||
SurfaceFluidBoundaryPlan.join(boundaries, bands);
|
||||
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries, 0, 59));
|
||||
assertTrue(SurfaceFluidBoundaryPlan.protects(boundaries, 0, 60));
|
||||
assertTrue(SurfaceFluidBoundaryPlan.protects(boundaries, 0, 80));
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries, 0, 81));
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries, 1, 69));
|
||||
assertTrue(SurfaceFluidBoundaryPlan.protects(boundaries, 1, 70));
|
||||
assertTrue(SurfaceFluidBoundaryPlan.protects(boundaries, 1, 75));
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries, 1, 76));
|
||||
assertEquals(SurfaceFluidBoundaryPlan.boundary(60, 64), boundaries[2]);
|
||||
assertEquals(none, boundaries[3]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void submergedColumnProtectsItsSeabedWithoutBlockingTheCaveBelow() {
|
||||
Fixture fixture = new Fixture();
|
||||
|
||||
+12
-64
@@ -7,8 +7,6 @@ import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.mantle.EngineMantle;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
@@ -86,56 +84,6 @@ public class IrisCarveModifierSubterrainMaskTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preservedSubterrainStaysOutOfInletHeadroom() {
|
||||
IrisSubterrainFeature feature = new IrisSubterrainFeature().setId("room").setFamily(IrisSubterrainFamily.CENOTE)
|
||||
.setProbability(1).setLength(64).setRadius(12).setHeight(24).setPillarSpacing(0).setFormationFraction(0)
|
||||
.setWorldYRange(new IrisRange(-48, 60));
|
||||
SubterrainPlanner planner = new SubterrainPlanner(new SubterrainPlanner.Options(List.of(feature), 83L, MINIMUM_Y, 128, (x, z) -> "region"));
|
||||
SubterrainPlan plan = planner.plansForBounds(-512, -512, 512, 512).getFirst();
|
||||
int blockX = plan.centerX() >> 4 << 4;
|
||||
int blockZ = plan.centerZ() >> 4 << 4;
|
||||
HydrologyRuntime hydrology = mock(HydrologyRuntime.class);
|
||||
when(hydrology.raster(anyInt(), anyInt())).thenReturn(ChunkWaterRaster.EMPTY);
|
||||
IrisCarveModifier modifier = modifier(planner, hydrology);
|
||||
try (MockedStatic<B> blocks = mockStatic(B.class)) {
|
||||
blocks.when(() -> B.getState(anyString())).thenReturn(mock(NativeBlockState.class));
|
||||
List<int[]> open = reopenedCells(modifier, planner, blockX, blockZ);
|
||||
int[] heights = open.stream().mapToInt(cell -> cell[1]).sorted().toArray();
|
||||
int water = heights[heights.length / 4];
|
||||
SeaInlet inlet = coveredInlet(blockX, blockZ + 8, water);
|
||||
assertTrue("subterrain cells in the headroom before the inlet " + inHeadroom(inlet, open).size(), inHeadroom(inlet, open).size() > 20);
|
||||
|
||||
when(hydrology.inlets(anyInt(), anyInt())).thenAnswer(call -> SeaInletRasterizer.touches(inlet, call.getArgument(0),
|
||||
call.getArgument(1)) ? List.of(inlet) : List.of());
|
||||
when(hydrology.settings()).thenReturn(HydrologySettings.compile(new IrisHydrology().setEnabled(true), 1L, 63, 0, 128));
|
||||
List<int[]> sealed = reopenedCells(modifier, planner, blockX, blockZ);
|
||||
assertTrue(sealed.size() > 0);
|
||||
assertEquals("subterrain reopened cells in the inlet headroom", List.of(), inHeadroom(inlet, sealed));
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> inHeadroom(SeaInlet inlet, List<int[]> cells) {
|
||||
List<String> inside = new ArrayList<>();
|
||||
int[] column = new int[2];
|
||||
for (int[] cell : cells) {
|
||||
if (SeaInletRasterizer.column(inlet, cell[0], cell[2], column) && cell[1] > inlet.waterLevel()
|
||||
&& cell[1] <= column[1] + ROOF_CLEARANCE) {
|
||||
inside.add(cell[0] + "," + cell[1] + "," + cell[2]);
|
||||
}
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
|
||||
private static SeaInlet coveredInlet(int startX, int z, int water) {
|
||||
float[] xs = {startX - 4f, startX + 4f, startX + 12f, startX + 20f};
|
||||
float[] zs = {z, z, z, z};
|
||||
float[] halfWidth = {4f, 4f, 3.5f, 3f};
|
||||
int[] floor = {water - 3, water - 3, water - 3, water - 3};
|
||||
int[] ceiling = {water + 5, water + 5, water + 4, water + 4};
|
||||
return new SeaInlet(5L, xs, zs, halfWidth, water, floor, ceiling, startX + 20, z, 3);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<int[]> reopenedCells(IrisCarveModifier modifier, SubterrainPlanner planner, int blockX, int blockZ) {
|
||||
List<int[]> open = new ArrayList<>();
|
||||
@@ -155,7 +103,7 @@ public class IrisCarveModifierSubterrainMaskTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preservedSubterrainLeavesEveryInletCellAlone() {
|
||||
public void preservedSubterrainLeavesEveryPassageCellAlone() {
|
||||
IrisSubterrainFeature feature = new IrisSubterrainFeature().setId("room").setFamily(IrisSubterrainFamily.CENOTE)
|
||||
.setProbability(1).setLength(64).setRadius(12).setHeight(24).setPillarSpacing(0).setFormationFraction(0)
|
||||
.setWorldYRange(new IrisRange(-48, 60));
|
||||
@@ -165,8 +113,8 @@ public class IrisCarveModifierSubterrainMaskTest {
|
||||
int blockZ = plan.centerZ() >> 4 << 4;
|
||||
HydrologyRuntime hydrology = mock(HydrologyRuntime.class);
|
||||
when(hydrology.raster(anyInt(), anyInt())).thenReturn(ChunkWaterRaster.EMPTY);
|
||||
Map<Long, HydrologyCaveCell> inlet = new HashMap<>();
|
||||
IrisCarveModifier modifier = modifier(planner, hydrology, inlet);
|
||||
Map<Long, HydrologyCaveCell> passage = new HashMap<>();
|
||||
IrisCarveModifier modifier = modifier(planner, hydrology, passage);
|
||||
try (MockedStatic<B> blocks = mockStatic(B.class)) {
|
||||
blocks.when(() -> B.getState(anyString())).thenReturn(mock(NativeBlockState.class));
|
||||
Set<Long> room = written(modifier, blockX, blockZ);
|
||||
@@ -178,14 +126,14 @@ public class IrisCarveModifierSubterrainMaskTest {
|
||||
if (y <= water + 2 && y >= water - 3) {
|
||||
HydrologyCaveAction action = y > water ? HydrologyCaveAction.DRY_AIR
|
||||
: y == water - 3 ? HydrologyCaveAction.SEAL_GUARD : HydrologyCaveAction.WET_SOURCE;
|
||||
inlet.put(cell, new HydrologyCaveCell(action, HydrologyCaveCell.SEA_FLUID));
|
||||
passage.put(cell, new HydrologyCaveCell(action, HydrologyCaveCell.SEA_FLUID));
|
||||
}
|
||||
}
|
||||
assertTrue("inlet cells crossing the room " + inlet.size(), inlet.size() > 20);
|
||||
assertTrue("passage cells crossing the room " + passage.size(), passage.size() > 20);
|
||||
Set<Long> crossed = written(modifier, blockX, blockZ);
|
||||
assertTrue("the room still opens away from the inlet", crossed.size() > 0);
|
||||
for (long cell : inlet.keySet()) {
|
||||
assertFalse("the room reopened inlet cell at y " + SubterrainMaskKeys.y(cell), crossed.contains(cell));
|
||||
assertTrue("the room still opens away from the passage", crossed.size() > 0);
|
||||
for (long cell : passage.keySet()) {
|
||||
assertFalse("the room reopened passage cell at y " + SubterrainMaskKeys.y(cell), crossed.contains(cell));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,7 +143,7 @@ public class IrisCarveModifierSubterrainMaskTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static IrisCarveModifier modifier(SubterrainPlanner planner, HydrologyRuntime hydrology, Map<Long, HydrologyCaveCell> inlet) {
|
||||
private static IrisCarveModifier modifier(SubterrainPlanner planner, HydrologyRuntime hydrology, Map<Long, HydrologyCaveCell> passage) {
|
||||
Engine engine = mock(Engine.class);
|
||||
EngineMantle engineMantle = mock(EngineMantle.class);
|
||||
Mantle<Matter> mantle = mock(Mantle.class);
|
||||
@@ -204,7 +152,7 @@ public class IrisCarveModifierSubterrainMaskTest {
|
||||
when(engineMantle.getMantle()).thenReturn(mantle);
|
||||
when(mantle.useChunk(anyInt(), anyInt())).thenReturn(chunk);
|
||||
when(chunk.exists(anyInt())).thenReturn(true);
|
||||
when(chunk.get(anyInt())).thenAnswer(call -> section(call.getArgument(0), inlet));
|
||||
when(chunk.get(anyInt())).thenAnswer(call -> section(call.getArgument(0), passage));
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
when(engine.getWorld()).thenReturn(IrisWorld.builder().minHeight(MINIMUM_Y).maxHeight(64).build());
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
@@ -218,12 +166,12 @@ public class IrisCarveModifierSubterrainMaskTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Matter section(int section, Map<Long, HydrologyCaveCell> inlet) {
|
||||
private static Matter section(int section, Map<Long, HydrologyCaveCell> passage) {
|
||||
Matter matter = mock(Matter.class);
|
||||
MatterSlice<HydrologyCaveCell> slice = mock(MatterSlice.class);
|
||||
when(matter.hasSlice(HydrologyCaveCell.class)).thenReturn(true);
|
||||
when(matter.getSlice(HydrologyCaveCell.class)).thenReturn(slice);
|
||||
when(slice.get(anyInt(), anyInt(), anyInt())).thenAnswer(call -> inlet.get(SubterrainMaskKeys.key(call.getArgument(0),
|
||||
when(slice.get(anyInt(), anyInt(), anyInt())).thenAnswer(call -> passage.get(SubterrainMaskKeys.key(call.getArgument(0),
|
||||
section * 16 + (int) call.getArgument(1), call.getArgument(2))));
|
||||
return matter;
|
||||
}
|
||||
|
||||
+16
@@ -140,6 +140,22 @@ public class IrisTerrainNormalActuatorHydrologyTest {
|
||||
assertSame("a slot cut through the cliff shows the strata below the old surface", cliff.dirt, cliff.paint().get(0, GROUND, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shallowTidalBankCutsKeepTheBiomeSurfaceLayer() {
|
||||
Painter cut = new Painter(WaterRole.BANK, 0);
|
||||
when(cut.complex.naturalTrueHeight(11, -4)).thenReturn(GROUND + 3);
|
||||
NativeBlockState stripped = cut.paint().get(0, GROUND, 0);
|
||||
Painter tidal = new Painter(WaterRole.BANK, 0);
|
||||
when(tidal.complex.naturalTrueHeight(11, -4)).thenReturn(GROUND + 3);
|
||||
when(tidal.complex.isTidalBank(11, -4)).thenReturn(true);
|
||||
assertSame("the shallow tidal cut is resurfaced", tidal.grass, tidal.paint().get(0, GROUND, 0));
|
||||
assertSame("a river bank keeps its strata", cut.dirt, stripped);
|
||||
Painter deep = new Painter(WaterRole.BANK, 0);
|
||||
when(deep.complex.naturalTrueHeight(11, -4)).thenReturn(GROUND + 20);
|
||||
when(deep.complex.isTidalBank(11, -4)).thenReturn(true);
|
||||
assertSame("a deep tidal cut shows the strata", deep.dirt, deep.paint().get(0, GROUND, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openInletSlotsKeepLiquidWaterUnderOnlyTheTopSeaLayer() {
|
||||
Painter slot = new Painter(WaterRole.INLET, HEAD);
|
||||
|
||||
@@ -40,8 +40,7 @@ public class PackHydrologyValidatorTest {
|
||||
"ponds": {"freeboard": [0, 2], "fluid": "lava",
|
||||
"seeded": {"radius": [4, 12], "depth": [2, 8], "channelSpacing": [48, 160]}},
|
||||
"underground": {
|
||||
"seaInlets": {"length": [24, 96], "halfWidth": [2, 5.5], "depth": [3, 6], "headroom": [0, 3],
|
||||
"chamberRadius": [4, 9]},
|
||||
"seaInlets": {"length": [24, 96], "mouthHalfWidth": [8, 12.5], "headHalfWidth": [2, 3.5], "depth": [3, 6]},
|
||||
"cavePools": {"freeboard": [0, 1], "fluid": "water"}
|
||||
},
|
||||
"fluids": [
|
||||
@@ -82,7 +81,7 @@ public class PackHydrologyValidatorTest {
|
||||
"enabled": true,
|
||||
"tiers": [{"name": "stream", "halfWidth": [0, 2]}, {"name": "river", "minCatchment": 9, "halfWidth": [2, 65]}],
|
||||
"ponds": {"freeboard": [-1, 2], "seeded": {"channelSpacing": [0, 160]}},
|
||||
"underground": {"seaInlets": {"headroom": [0, 3], "chamberRadius": [-2, 9]}, "cavePools": {"freeboard": [-1, 0]}}
|
||||
"underground": {"seaInlets": {"mouthHalfWidth": [-2, 9]}, "cavePools": {"freeboard": [-1, 0]}}
|
||||
}
|
||||
""", "")));
|
||||
|
||||
@@ -90,7 +89,7 @@ public class PackHydrologyValidatorTest {
|
||||
assertContains(validation.errors(), "tiers[1].halfWidth must not go above 64.");
|
||||
assertContains(validation.errors(), "ponds.freeboard must not go below 0.");
|
||||
assertContains(validation.errors(), "ponds.seeded.channelSpacing must stay above 0.");
|
||||
assertContains(validation.errors(), "underground.seaInlets.chamberRadius must stay above 0.");
|
||||
assertContains(validation.errors(), "underground.seaInlets.mouthHalfWidth must stay above 0.");
|
||||
assertContains(validation.errors(), "underground.cavePools.freeboard must not go below 0.");
|
||||
assertEquals(validation.errors().toString(), 6, validation.errors().size());
|
||||
}
|
||||
@@ -655,10 +654,10 @@ public class PackHydrologyValidatorTest {
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertEquals(List.of(
|
||||
"Dimension 'main' sets useMantle to false while hydrology is enabled, so the falling water at waterfalls and cascades,"
|
||||
+ " sea inlets and cave pools are not generated.",
|
||||
"Dimension 'main' sets useMantle to false while hydrology is enabled, so the falling water at waterfalls and cascades"
|
||||
+ " and cave pools are not generated.",
|
||||
"Dimension 'other' disables the RIVER_HYDROLOGY component while hydrology is enabled, so the falling water at waterfalls"
|
||||
+ " and cascades, sea inlets and cave pools are not generated."), validation.warnings());
|
||||
+ " and cascades and cave pools are not generated."), validation.warnings());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "050cf892aa20a9b8796dd8bb0299cb39a92cdabc46569fdf165db6dc960ecf4b";
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "07bb61c7034a6aadae8d03c9c0fe8a31326113f7ad515c99512ded2ab9be686c";
|
||||
|
||||
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
|
||||
IrisDimension.class,
|
||||
|
||||
+10
-2
@@ -178,15 +178,23 @@ public class NativeStructurePlacementPlannerTest {
|
||||
StructureWaterRules.admitsStart(plan, stageWater, VILLAGE));
|
||||
|
||||
roles.clear();
|
||||
WaterRole[] dry = {WaterRole.MOUTH, WaterRole.INLET, WaterRole.SHORE, WaterRole.POND_SHORE, WaterRole.BANK, WaterRole.DAM};
|
||||
WaterRole[] dry = {WaterRole.MOUTH, WaterRole.SHORE, WaterRole.POND_SHORE, WaterRole.BANK, WaterRole.DAM};
|
||||
int column = 0;
|
||||
for (int x = 0; x <= 39; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
roles.put(columnKey(x, z), dry[column++ % dry.length]);
|
||||
}
|
||||
}
|
||||
assertTrue("mouths, inlets, shores, banks and dams do not count as river water",
|
||||
assertTrue("mouths, shores, banks and dams do not count as river water",
|
||||
StructureWaterRules.admitsStart(plan, stageWater, VILLAGE));
|
||||
|
||||
roles.clear();
|
||||
for (int x = 0; x <= 39; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
roles.put(columnKey(x, z), x % 2 == 0 ? WaterRole.INLET : WaterRole.BANK);
|
||||
}
|
||||
}
|
||||
assertFalse("a sea inlet under the pieces counts as river water", StructureWaterRules.admitsStart(plan, stageWater, VILLAGE));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -7,6 +7,7 @@ import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
@@ -14,7 +15,6 @@ import art.arcane.iris.world.history.ChunkGenerationSemantics;
|
||||
import art.arcane.iris.world.history.GenerationHistory;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.testsupport.FakeHydrology;
|
||||
import art.arcane.iris.testsupport.WaterScene;
|
||||
import org.junit.Test;
|
||||
@@ -100,7 +100,7 @@ public class IrisRendererRiverTest {
|
||||
Pond pond = WaterScene.pond(32L, 62, 16, 16, 10);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.planPreview(anyInt(), anyInt(), anyInt(), anyInt()))
|
||||
.thenReturn(new HydrologyPlanPreview(List.of(), List.of(pond), List.of(), List.of(), true));
|
||||
.thenReturn(new HydrologyPlanPreview(List.of(), List.of(pond), List.of(), true));
|
||||
when(runtime.rasterPreview(anyInt(), anyInt())).thenReturn(ChunkWaterRaster.PROVISIONAL);
|
||||
IrisRenderer renderer = new IrisRenderer(engine(runtime));
|
||||
|
||||
@@ -166,23 +166,24 @@ public class IrisRendererRiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void planModeDrawsSeaInletPathsUnderground() throws Exception {
|
||||
int stations = 26;
|
||||
float[] xs = new float[stations];
|
||||
float[] zs = new float[stations];
|
||||
float[] halfWidth = new float[stations];
|
||||
int[] floor = new int[stations];
|
||||
int[] ceiling = new int[stations];
|
||||
for (int station = 0; station < stations; station++) {
|
||||
xs[station] = 100f + station * 8f;
|
||||
zs[station] = 200f;
|
||||
halfWidth[station] = 4f;
|
||||
floor[station] = SEA_LEVEL - 3;
|
||||
ceiling[station] = SEA_LEVEL + 5;
|
||||
public void planModeDrawsTidalReachesAsSeaInlets() throws Exception {
|
||||
int points = 26;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grade = new int[points];
|
||||
float[] halfWidth = new float[points];
|
||||
float[] depth = new float[points];
|
||||
ReachStyle[] style = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = 100f + point * 8f;
|
||||
zs[point] = 200f;
|
||||
grade[point] = SEA_LEVEL;
|
||||
halfWidth[point] = 4f;
|
||||
depth[point] = 3f;
|
||||
style[point] = ReachStyle.TIDAL;
|
||||
}
|
||||
SeaInlet inlet = new SeaInlet(51L, xs, zs, halfWidth, SEA_LEVEL, floor, ceiling, 300, 200, 8);
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 90, SEA_LEVEL, List.of(), List.of(), List.of(),
|
||||
List.of(inlet))) {
|
||||
Reach tidal = new Reach(51L, FakeHydrology.settings(SEA_LEVEL).tidalTier(), 0L, xs, zs, grade, halfWidth, depth, style, 0f);
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 90, SEA_LEVEL, List.of(tidal), List.of())) {
|
||||
HydrologyRuntime runtime = spy(hydrology.runtime);
|
||||
int[] plan = settled(engine(runtime), 16D * PIXELS, PIXELS);
|
||||
assertEquals(water(HydrologyFeatureType.SEA_INLET), at(plan, PIXELS, 200 / 16, 200 / 16));
|
||||
|
||||
@@ -31,7 +31,7 @@ public class WaterMapProgressTest {
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
Reach reach = mock(Reach.class);
|
||||
when(runtime.planPreview(anyInt(), anyInt(), anyInt(), anyInt()))
|
||||
.thenReturn(new HydrologyPlanPreview(List.of(reach), List.of(), List.of(), List.of(), true));
|
||||
.thenReturn(new HydrologyPlanPreview(List.of(reach), List.of(), List.of(), true));
|
||||
when(runtime.rasterPreview(anyInt(), anyInt())).thenReturn(ChunkWaterRaster.EMPTY);
|
||||
|
||||
WaterMap map = new WaterMap(runtime, 32, 0D, 0D, 1D);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class WaterMapTest {
|
||||
private static WaterMap draw(List<Reach> reaches, List<Pond> ponds, List<Pond> lakes) {
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
when(runtime.planPreview(anyInt(), anyInt(), anyInt(), anyInt()))
|
||||
.thenReturn(new HydrologyPlanPreview(reaches, ponds, lakes, List.of(), true));
|
||||
.thenReturn(new HydrologyPlanPreview(reaches, ponds, lakes, true));
|
||||
when(runtime.channelType(any(HydrologyTier.class))).thenReturn(HydrologyFeatureType.STREAM);
|
||||
WaterMap map = new WaterMap(runtime, PIXELS, 0D, 0D, MID_STEP);
|
||||
map.advance(() -> false);
|
||||
|
||||
@@ -9,7 +9,6 @@ import art.arcane.iris.generation.hydrology.plan.RegionPlan;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowPlan;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
import art.arcane.iris.generation.hydrology.water.PondMask;
|
||||
@@ -46,35 +45,28 @@ public final class FakeHydrology implements AutoCloseable {
|
||||
private final List<Reach> reaches;
|
||||
private final List<Pond> ponds;
|
||||
private final List<Pond> lakes;
|
||||
private final List<SeaInlet> inlets;
|
||||
private final ExecutorService pool;
|
||||
private volatile CountDownLatch gate;
|
||||
|
||||
public FakeHydrology(BooleanSupplier mainThread, IntBinaryOperator naturalHeight, int seaLevel, int pondLevel) {
|
||||
this(mainThread, naturalHeight, seaLevel, pondLevel, List.of(), null, List.of(), List.of());
|
||||
this(mainThread, naturalHeight, seaLevel, pondLevel, List.of(), null, List.of());
|
||||
}
|
||||
|
||||
public FakeHydrology(BooleanSupplier mainThread, IntBinaryOperator naturalHeight, int seaLevel, List<Reach> reaches, List<Pond> ponds) {
|
||||
this(mainThread, naturalHeight, seaLevel, 0, reaches, ponds, List.of(), List.of());
|
||||
this(mainThread, naturalHeight, seaLevel, 0, reaches, ponds, List.of());
|
||||
}
|
||||
|
||||
public FakeHydrology(BooleanSupplier mainThread, IntBinaryOperator naturalHeight, int seaLevel, List<Reach> reaches, List<Pond> ponds,
|
||||
List<Pond> lakes) {
|
||||
this(mainThread, naturalHeight, seaLevel, 0, reaches, ponds, lakes, List.of());
|
||||
}
|
||||
|
||||
public FakeHydrology(BooleanSupplier mainThread, IntBinaryOperator naturalHeight, int seaLevel, List<Reach> reaches, List<Pond> ponds,
|
||||
List<Pond> lakes, List<SeaInlet> inlets) {
|
||||
this(mainThread, naturalHeight, seaLevel, 0, reaches, ponds, lakes, inlets);
|
||||
this(mainThread, naturalHeight, seaLevel, 0, reaches, ponds, lakes);
|
||||
}
|
||||
|
||||
private FakeHydrology(BooleanSupplier mainThread, IntBinaryOperator naturalHeight, int seaLevel, int pondLevel, List<Reach> reaches,
|
||||
List<Pond> ponds, List<Pond> lakes, List<SeaInlet> inlets) {
|
||||
List<Pond> ponds, List<Pond> lakes) {
|
||||
this.pondLevel = pondLevel;
|
||||
this.reaches = List.copyOf(reaches);
|
||||
this.ponds = ponds == null ? List.of(pond()) : List.copyOf(ponds);
|
||||
this.lakes = List.copyOf(lakes);
|
||||
this.inlets = List.copyOf(inlets);
|
||||
AtomicInteger threads = new AtomicInteger();
|
||||
this.pool = Executors.newFixedThreadPool(4, runnable -> {
|
||||
Thread thread = new Thread(runnable, "fake-hydrology-" + threads.incrementAndGet());
|
||||
@@ -135,12 +127,12 @@ public final class FakeHydrology implements AutoCloseable {
|
||||
windowCalls.incrementAndGet();
|
||||
await(gate);
|
||||
if (!key.equals(new WindowKey(0, 0))) {
|
||||
return new WindowPlan(key, List.of(), List.of(), List.of());
|
||||
return new WindowPlan(key, List.of(), List.of());
|
||||
}
|
||||
if (failing.get()) {
|
||||
throw new IllegalStateException(FAILURE);
|
||||
}
|
||||
return new WindowPlan(key, reaches, ponds, inlets);
|
||||
return new WindowPlan(key, reaches, ponds);
|
||||
}
|
||||
|
||||
private Pond pond() {
|
||||
|
||||
@@ -156,7 +156,7 @@ public final class WaterScene {
|
||||
ownedPonds.add(pond);
|
||||
}
|
||||
}
|
||||
return new IndexedWindow(new WindowPlan(key, owned, ownedPonds, List.of()), ReachIndex.build(key, owned, ownedPonds));
|
||||
return new IndexedWindow(new WindowPlan(key, owned, ownedPonds), ReachIndex.build(key, owned, ownedPonds));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+17
-17
@@ -24,7 +24,6 @@ import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
@@ -514,23 +513,24 @@ public final class GenerationSemanticCaptureTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordsSeaInletsInEveryChunkTheyPassUnderWithTheirOwnProfile() {
|
||||
int stations = 8;
|
||||
float[] xs = new float[stations];
|
||||
float[] zs = new float[stations];
|
||||
float[] halfWidth = new float[stations];
|
||||
int[] floor = new int[stations];
|
||||
int[] ceiling = new int[stations];
|
||||
for (int station = 0; station < stations; station++) {
|
||||
xs[station] = 4f + station * 8f;
|
||||
zs[station] = 24f;
|
||||
halfWidth[station] = 3f;
|
||||
floor[station] = WATER_SEA_LEVEL - 3;
|
||||
ceiling[station] = WATER_SEA_LEVEL + 5;
|
||||
public void recordsTidalReachesInEveryChunkTheyCrossWithTheirOwnProfile() {
|
||||
int points = 8;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grade = new int[points];
|
||||
float[] halfWidth = new float[points];
|
||||
float[] depth = new float[points];
|
||||
ReachStyle[] style = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = 4f + point * 8f;
|
||||
zs[point] = 24f;
|
||||
grade[point] = WATER_SEA_LEVEL;
|
||||
halfWidth[point] = 3f;
|
||||
depth[point] = 3f;
|
||||
style[point] = ReachStyle.TIDAL;
|
||||
}
|
||||
SeaInlet inlet = new SeaInlet(41L, xs, zs, halfWidth, WATER_SEA_LEVEL, floor, ceiling, 60, 24, 4);
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 90, WATER_SEA_LEVEL, List.of(), List.of(), List.of(),
|
||||
List.of(inlet))) {
|
||||
Reach tidal = new Reach(41L, FakeHydrology.settings(WATER_SEA_LEVEL).tidalTier(), 0L, xs, zs, grade, halfWidth, depth, style, 0f);
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 90, WATER_SEA_LEVEL, List.of(tidal), List.of())) {
|
||||
Fixture fixture = new Fixture();
|
||||
fixture.water(hydrology.runtime);
|
||||
|
||||
|
||||
Reference in new issue
Block a user