Add organic sea grottos

- Plan winding sea-level passages into tall coastal rock, one per site cell, owned by the mouth's window
- Keep walks out of rivers, ponds, own arms, and ground other windows' arms could reach
- Shape them with a warped path and a 3D radial function keyed on plan data and CellHash, with caverns, hanging rock, shelves and skylights
- Rasterize own-chunk into mantle WET_SOURCE, DRY_AIR and SEAL_GUARD; guards only at or below sea level
- Persist grottos in window plans, plugging cut-off wet cells at plan time
- Add IrisGrottos to settings, fingerprint, schema and pack validation; recapture pins
- Add /iris find river grotto, Studio map drawing, recorded mouths and an export limit
- Add grottoProbe and arm lines in the tidal rivers digest
This commit is contained in:
Brian Fopiano committed 2026-11-03 23:52:18 -05:00
1 parent 5df42fc49e
commit 343da05e3d
42 files changed
+3791 -38

No files matched your search

@@ -30,7 +30,8 @@ public class PersistedCodesTest {
Map.entry(HydrologyFeatureType.LAKE, 7),
Map.entry(HydrologyFeatureType.DAM, 8),
Map.entry(HydrologyFeatureType.SEA_INLET, 9),
Map.entry(HydrologyFeatureType.CAVE_POOL, 10));
Map.entry(HydrologyFeatureType.CAVE_POOL, 10),
Map.entry(HydrologyFeatureType.GROTTO, 11));
private static final Map<ReachStyle, Integer> REACH_STYLE_CODES = Map.of(
ReachStyle.RUN, 0,
ReachStyle.RIFFLE, 1,
@@ -78,12 +78,15 @@ public class HydrologyFeatureSearchTest {
config.getPonds().getDams().setEnabled(true);
config.getUnderground().getSeaInlets().setEnabled(false);
config.getUnderground().getCavePools().setEnabled(false);
config.getUnderground().getGrottos().setEnabled(false);
});
String ponds = "hydrology.ponds.natural and hydrology.ponds.seeded are disabled";
assertEquals(Optional.of(ponds), HydrologyFeatureSearch.disabledReason(dry, HydrologyFeatureType.POND));
assertEquals(Optional.of(ponds), HydrologyFeatureSearch.disabledReason(dry, HydrologyFeatureType.DAM));
assertEquals(Optional.of("hydrology.underground.seaInlets is disabled"),
HydrologyFeatureSearch.disabledReason(dry, HydrologyFeatureType.SEA_INLET));
assertEquals(Optional.of("hydrology.underground.grottos is disabled"),
HydrologyFeatureSearch.disabledReason(dry, HydrologyFeatureType.GROTTO));
assertEquals(Optional.of("hydrology.underground.cavePools is disabled"),
HydrologyFeatureSearch.disabledReason(dry, HydrologyFeatureType.CAVE_POOL));
assertEquals(Optional.empty(), HydrologyFeatureSearch.disabledReason(dry, HydrologyFeatureType.LAKE));
@@ -16,6 +16,7 @@ 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.Grotto;
import art.arcane.iris.generation.hydrology.water.Pond;
import art.arcane.iris.generation.hydrology.water.PondKind;
import art.arcane.iris.generation.hydrology.water.PondMask;
@@ -348,6 +349,18 @@ public class HydrologyRuntimeTest {
assertEquals(List.of(INLET), runtime.planPreview(900, 300, 1100, 500).reaches().stream().map(Reach::id).filter(id -> id == INLET).toList());
}
@Test(timeout = 180_000L)
public void grottosAreSearchedAtTheirMouthsAndListedByChunk() throws Exception {
FakePlanners planners = new FakePlanners(settings());
HydrologyRuntime runtime = runtime(planners, () -> false);
Grotto grotto = FakePlanners.grotto();
assertEquals(new HydrologyFeatureRef(grotto.id(), HydrologyFeatureType.GROTTO, grotto.mouthX(), grotto.seaLevel(), grotto.mouthZ()),
runtime.nearestFeature(1050, 405, HydrologyFeatureQuery.of(HydrologyFeatureType.GROTTO), 512, ANY, RUNNING).orElseThrow());
assertEquals(List.of(grotto), runtime.grottos(grotto.mouthX() >> 4, grotto.mouthZ() >> 4));
assertEquals(List.of(), runtime.grottos(0, 0));
assertEquals(List.of(grotto), runtime.planPreview(900, 300, 1100, 500).grottos());
}
@Test(timeout = 180_000L)
public void nearestFeatureSkipsIneligibleCandidatesForTheNextNearest() throws Exception {
FakePlanners planners = new FakePlanners(settings());
@@ -1282,7 +1295,7 @@ public class HydrologyRuntimeTest {
pond(POND + 1, PondKind.SEEDED, 70, 296, 296, 3)));
}
if (key.equals(new WindowKey(1, 0))) {
return new WindowPlan(key, List.of(tidal()), List.of());
return new WindowPlan(key, List.of(tidal()), List.of(), List.of(grotto()));
}
if (key.equals(new WindowKey(3, 0))) {
return new WindowPlan(key, List.of(), List.of(pond(FAR_POND, PondKind.NATURAL, 75, 1700, 100, 3)));
@@ -1308,6 +1321,11 @@ public class HydrologyRuntimeTest {
}
}
static Grotto grotto() {
return new Grotto(0x47524FL, 40, 0.5f, 1, new float[]{1090f, 1080f, 1070f, 1060f}, new float[]{420f, 420f, 424f, 430f}, new float[]{6f, 6f, 5f, 5f},
new float[]{6f, 6f, 6f, 6f}, new float[]{3f, 3f, 3f, 3f}, new float[]{0f, 0f, 0f, 0f}, new float[0], new float[0], new float[0], new int[0], new long[0]);
}
private Reach tidal() {
int points = 13;
float[] xs = new float[points];
@@ -0,0 +1,273 @@
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.underground.Grotto;
import art.arcane.iris.generation.hydrology.underground.GrottoPlanner;
import art.arcane.iris.generation.hydrology.underground.GrottoShape;
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 org.junit.Test;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class GrottoPlannerTest {
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> WINDOWS = List.of(new WindowKey(0, -1), new WindowKey(0, 0), new WindowKey(0, 1), new WindowKey(-1, 0), new WindowKey(1, 0), new WindowKey(0, 2));
private static HydrologySettings settings(IrisHydrology config) {
return HydrologySettings.compile(config, SEED, SEA, SyntheticTerrain.MIN_Y, SyntheticTerrain.MAX_Y);
}
private static SyntheticTerrain tallCoast() {
return SyntheticTerrain.cliffCoast(COAST_X);
}
private record Fixture(GrottoPlanner planner, HeightLattice fine) {
Fixture(HydrologySettings settings, SyntheticTerrain terrain) {
this(settings, new HeightLattice(terrain, WindowPlanner.FINE_CELL, false, 1 << 21));
}
Fixture(HydrologySettings settings, HeightLattice lattice) {
this(new GrottoPlanner(settings, lattice, new TidalPlanner(settings, lattice)), lattice);
}
List<Grotto> plan(WindowKey window, ShapedNetwork network, List<Reach> arms) {
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 planner.plan(window, natural, samples, network, arms);
}
List<Grotto> plan(List<WindowKey> windows) {
List<Grotto> grottos = new ArrayList<>();
for (WindowKey window : windows) {
grottos.addAll(plan(window, NOTHING, List.of()));
}
return grottos;
}
}
private static double length(Grotto grotto) {
double total = 0D;
for (int point = grotto.coast() + 1; point < grotto.xs().length; point++) {
total += Math.hypot(grotto.xs()[point] - grotto.xs()[point - 1], grotto.zs()[point] - grotto.zs()[point - 1]);
}
return total;
}
@Test
public void tallCoastHoldsLongWindingGrottosThatStartInTheSea() {
HydrologySettings settings = settings(new IrisHydrology());
SyntheticTerrain terrain = tallCoast();
List<Grotto> grottos = new Fixture(settings, terrain).plan(WINDOWS);
assertTrue("grottos " + grottos.size(), grottos.size() >= 2);
int winding = 0;
for (Grotto grotto : grottos) {
assertEquals(SEA, grotto.seaLevel());
assertTrue(grotto + " starts at sea " + grotto.xs()[0], grotto.xs()[0] < COAST_X);
int last = grotto.xs().length - 1;
assertTrue("head inland " + grotto.xs()[last], grotto.xs()[last] > COAST_X + 16f);
assertTrue("length " + length(grotto), length(grotto) >= settings.underground().grottos().length().min());
double straight = Math.hypot(grotto.xs()[last] - grotto.xs()[grotto.coast()], grotto.zs()[last] - grotto.zs()[grotto.coast()]);
winding += length(grotto) / straight >= 1.15D ? 1 : 0;
assertTrue(new GrottoShape(grotto).inside((int) Math.floor(grotto.xs()[0]), SEA, (int) Math.floor(grotto.zs()[0])));
}
assertTrue("winding " + winding + " of " + grottos.size(), winding * 2 >= grottos.size());
}
@Test
public void lowCoastHoldsNoGrottos() {
assertTrue(new Fixture(settings(new IrisHydrology()), SyntheticTerrain.lowCoast(COAST_X)).plan(WINDOWS).isEmpty());
}
@Test
public void disabledHoldsNoGrottos() {
IrisHydrology config = new IrisHydrology();
config.getUnderground().getGrottos().setEnabled(false);
assertTrue(new Fixture(settings(config), tallCoast()).plan(WINDOWS).isEmpty());
}
@Test
public void everyWetCellConnectsToTheSea() {
HydrologySettings settings = settings(new IrisHydrology());
for (Grotto grotto : new Fixture(settings, tallCoast()).plan(WINDOWS)) {
GrottoShape shape = new GrottoShape(grotto);
int[] bounds = grotto.bounds();
int layers = SEA - shape.minY() + 1;
int width = bounds[2] - bounds[0] + 1;
int depth = bounds[3] - bounds[1] + 1;
boolean[] wet = new boolean[width * depth * layers];
long total = 0L;
for (int z = 0; z < depth; z++) {
for (int x = 0; x < width; x++) {
if (shape.near(bounds[0] + x, bounds[1] + z)) {
for (int layer = 0; layer < layers; layer++) {
if (shape.inside(bounds[0] + x, shape.minY() + layer, bounds[1] + z)) {
wet[(layer * depth + z) * width + x] = true;
total++;
}
}
}
}
}
int start = ((layers - 1) * depth + ((int) Math.floor(grotto.zs()[0]) - bounds[1])) * width + (int) Math.floor(grotto.xs()[0]) - bounds[0];
assertTrue(wet[start]);
ArrayDeque<Integer> frontier = new ArrayDeque<>();
frontier.add(start);
wet[start] = false;
long reached = 1L;
while (!frontier.isEmpty()) {
int cell = frontier.poll();
for (int offset : new int[]{1, -1, width, -width, width * depth, -width * depth}) {
int next = cell + offset;
if (next >= 0 && next < wet.length && wet[next]) {
wet[next] = false;
reached++;
frontier.add(next);
}
}
}
assertEquals("grotto " + grotto.id(), total, reached);
}
}
@Test
public void grottosNeverJoin() {
HydrologySettings settings = settings(new IrisHydrology());
List<Grotto> grottos = new Fixture(settings, tallCoast()).plan(WINDOWS);
for (int a = 0; a < grottos.size(); a++) {
for (int b = a + 1; b < grottos.size(); b++) {
GrottoShape first = new GrottoShape(grottos.get(a));
GrottoShape second = new GrottoShape(grottos.get(b));
int[] bounds = grottos.get(a).bounds();
for (int z = bounds[1]; z <= bounds[3]; z += 2) {
for (int x = bounds[0]; x <= bounds[2]; x += 2) {
if (first.near(x, z) && second.near(x, z)) {
for (int y = SEA - 8; y <= SEA + 20; y += 2) {
assertFalse(x + "," + y + "," + z, first.inside(x, y, z) && second.inside(x, y, z));
}
}
}
}
}
}
}
@Test
public void planIgnoresWindowOrderAndRepeats() {
HydrologySettings settings = settings(new IrisHydrology());
SyntheticTerrain terrain = tallCoast();
List<WindowKey> reversed = new ArrayList<>(WINDOWS);
Collections.reverse(reversed);
List<Grotto> forward = new Fixture(settings, terrain).plan(WINDOWS);
List<Grotto> backward = new Fixture(settings, terrain).plan(reversed);
forward.sort(Comparator.comparingLong(Grotto::id));
backward.sort(Comparator.comparingLong(Grotto::id));
assertEquals(forward.size(), backward.size());
for (int index = 0; index < forward.size(); index++) {
assertEquals(forward.get(index).id(), backward.get(index).id());
assertArrayEquals(forward.get(index).xs(), backward.get(index).xs(), 0f);
assertArrayEquals(forward.get(index).roof(), backward.get(index).roof(), 0f);
assertArrayEquals(forward.get(index).plugs(), backward.get(index).plugs());
}
}
@Test
public void grottosKeepClearOfRiversAndArms() {
HydrologySettings settings = settings(new IrisHydrology());
SyntheticTerrain terrain = tallCoast();
Fixture fixture = new Fixture(settings, terrain);
WindowKey window = null;
Grotto clear = null;
for (WindowKey key : WINDOWS) {
List<Grotto> grottos = fixture.plan(key, NOTHING, List.of());
if (!grottos.isEmpty()) {
window = key;
clear = grottos.get(0);
break;
}
}
assertTrue(clear != null);
int middle = clear.xs().length / 2;
float[] xs = new float[81];
float[] zs = new float[81];
int[] grade = new int[81];
float[] half = new float[81];
float[] depth = new float[81];
ReachStyle[] style = new ReachStyle[81];
for (int point = 0; point < 81; point++) {
xs[point] = clear.xs()[middle];
zs[point] = clear.zs()[middle] - 200f + point * 5f;
grade[point] = SEA + 10;
half[point] = 4f;
depth[point] = 2f;
style[point] = ReachStyle.RUN;
}
Reach dense = new Reach(1L, settings.tidalTier(), 0L, xs, zs, grade, half, depth, style, 0f);
float apart = dense.tier().bankBand();
for (Grotto grotto : fixture.plan(window, new ShapedNetwork(List.of(dense), List.of()), List.of())) {
for (int point = 0; point < grotto.xs().length; point++) {
for (int river2 = 0; river2 < xs.length; river2++) {
assertTrue("station " + point, Math.hypot(grotto.xs()[point] - xs[river2], grotto.zs()[point] - zs[river2]) > half[river2] + Math.min(apart, 32f) - 12f);
}
}
}
}
@Test
public void walkKeepsOutOfTheTerritoryOfArmsOwnedByOtherWindows() {
IrisHydrology config = new IrisHydrology();
HydrologySettings settings = settings(config);
SyntheticTerrain low = SyntheticTerrain.lowCoast(COAST_X);
TidalPlanner tidal = new TidalPlanner(settings, new HeightLattice(low, WindowPlanner.FINE_CELL, false, 1 << 21));
boolean foreign = false;
boolean own = false;
for (int z = -800; z <= 800; z += 16) {
WindowKey window = WindowKey.containing((int) COAST_X, z);
boolean here = tidal.foreignArmMayReach(window, COAST_X + 30D, z, 16f);
boolean elsewhere = tidal.foreignArmMayReach(new WindowKey(window.wx() + 7, window.wz()), COAST_X + 30D, z, 16f);
own |= !here;
foreign |= elsewhere;
assertTrue("every anchor is foreign to a far window", !here || elsewhere);
}
assertTrue(own);
assertTrue(foreign);
config.getUnderground().getSeaInlets().setEnabled(false);
TidalPlanner off = new TidalPlanner(settings(config), new HeightLattice(low, WindowPlanner.FINE_CELL, false, 1 << 21));
assertFalse(off.foreignArmMayReach(new WindowKey(9, 9), COAST_X + 30D, 0D, 16f));
}
@Test
public void everyGrottoStaysWithinTheNextWindow() {
HydrologySettings settings = settings(new IrisHydrology());
Fixture fixture = new Fixture(settings, tallCoast());
for (WindowKey window : WINDOWS) {
for (Grotto grotto : fixture.plan(window, NOTHING, List.of())) {
int[] bounds = grotto.bounds();
assertTrue(bounds[0] >= (window.wx() - 1) * WindowKey.SIZE && bounds[2] < (window.wx() + 2) * WindowKey.SIZE);
assertTrue(bounds[1] >= (window.wz() - 1) * WindowKey.SIZE && bounds[3] < (window.wz() + 2) * WindowKey.SIZE);
}
}
}
}
@@ -4,6 +4,7 @@ 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.Grotto;
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
import art.arcane.iris.generation.hydrology.water.Pond;
import art.arcane.iris.generation.hydrology.water.PondKind;
@@ -46,7 +47,7 @@ public class HydrologyPlanCodecTest {
0577617465720000001c000000060000000000000007020000004400000040ffffffec0000001042898000fffffffc00
00000800000004000000000000000000000000000000000000002900000002000000046c617661ffffffea0000000e00
0000000000000803000000500000003c00000040ffffffc042a10000fffffffc00000008000000040000000000000000
00000000ffffffffffffffff00000000ffffffff0000003cffffffc4
00000000ffffffffffffffff00000000ffffffff0000003cffffffc400000000
""";
@Test
@@ -99,6 +100,17 @@ public class HydrologyPlanCodecTest {
assertBitExact(planned, HydrologyPlanCodec.decodeWindow(settings, HydrologyPlanCodec.encode(settings, planned)).orElseThrow(), tiers);
}
@Test
public void grottosRoundTripBitExact() {
HydrologySettings settings = settings(new IrisHydrology());
Grotto grotto = new Grotto(99L, 40, 0.6f, 1, new float[]{1.5f, 5.25f, 9f}, new float[]{-2f, -3f, -4f}, new float[]{6f, 7f, 5f}, new float[]{8f, 9f, 6f}, new float[]{3f, 4f, 3f},
new float[]{0f, 0f, 2f}, new float[]{5f}, new float[]{-3f}, new float[]{2f}, new int[]{70}, new long[]{Grotto.plug(3, 39, -2), Grotto.plug(4, 39, -2)});
WindowPlan window = new WindowPlan(new WindowKey(4, -2), List.of(), List.of(), List.of(grotto));
WindowPlan decoded = HydrologyPlanCodec.decodeWindow(settings, HydrologyPlanCodec.encode(settings, window)).orElseThrow();
assertEquals(window, decoded);
assertEquals(grotto.hashCode(), decoded.grottos().get(0).hashCode());
}
@Test
public void tidalReachesRoundTripOnTheTidalTier() {
HydrologySettings settings = settings(new IrisHydrology());
@@ -8,6 +8,7 @@ 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.IrisGrottos;
import art.arcane.iris.generation.hydrology.config.IrisSeaInlets;
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
@@ -38,7 +39,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 = 8483795183515434045L;
private static final long DEFAULT_FINGERPRINT = 2652772297681753957L;
@Test
public void densityIsBoundedAndChangesThePlanIdentity() {
@@ -227,6 +228,12 @@ public class HydrologySettingsTest {
IrisHydrology seaInlets = new IrisHydrology();
seaInlets.getUnderground().getSeaInlets().setSpacing(256);
fingerprints.add(compile(seaInlets).fingerprint());
IrisHydrology grottos = new IrisHydrology();
grottos.getUnderground().getGrottos().setSpacing(320);
fingerprints.add(compile(grottos).fingerprint());
IrisHydrology rougher = new IrisHydrology();
rougher.getUnderground().getGrottos().setRoughness(0.2D);
fingerprints.add(compile(rougher).fingerprint());
IrisHydrology shoreDepth = new IrisHydrology();
shoreDepth.getPonds().getMaterials().setShoreDepth(3);
@@ -764,6 +771,25 @@ public class HydrologySettingsTest {
assertTrue(failure.getMessage(), failure.getMessage().contains("mouthHalfWidth"));
}
@Test
public void grottoKnobsAreBounded() {
List<Consumer<IrisGrottos>> bad = List.of(
grottos -> grottos.setSpacing(16),
grottos -> grottos.setRadius(new KList<>(1D, 7D)),
grottos -> grottos.setRadius(new KList<>(4D, 40D)),
grottos -> grottos.setHeadroom(new KList<>(1, 7)),
grottos -> grottos.setHeadroom(new KList<>(4, 99)),
grottos -> grottos.setMouthWidth(new KList<>(1D, 8D)),
grottos -> grottos.setLength(new KList<>(32, 600)),
grottos -> grottos.setRoughness(1.5D));
for (Consumer<IrisGrottos> tweak : bad) {
IrisHydrology config = new IrisHydrology();
tweak.accept(config.getUnderground().getGrottos());
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class, () -> compile(config));
assertTrue(failure.getMessage(), failure.getMessage().contains("underground.grottos"));
}
}
@Test
public void overLongSeaInletsFailAtCompile() {
compile(inlets(config -> config.setLength(new KList<>(64, 447)).setMouthHalfWidth(new KList<>(11D, 16D)).setBankBand(24)));
@@ -0,0 +1,157 @@
package art.arcane.iris.generation.hydrology.underground;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
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;
public class GrottoRasterizerTest {
private static final int SEA = GrottoShapeTest.SEA;
private static long key(int x, int z) {
return ((long) x << 32) | (z & 0xFFFFFFFFL);
}
@Test
public void cellsMatchTheShapeInEveryChunk() {
Grotto grotto = GrottoShapeTest.winding(11L, 0.6f);
GrottoShape shape = new GrottoShape(grotto);
int[] bounds = grotto.bounds();
long wet = 0L;
long dry = 0L;
for (int chunkZ = bounds[1] >> 4; chunkZ <= bounds[3] >> 4; chunkZ++) {
for (int chunkX = bounds[0] >> 4; chunkX <= bounds[2] >> 4; chunkX++) {
GrottoRasterizer.Cells cells = GrottoRasterizer.cells(grotto, chunkX, chunkZ, GrottoRasterizer.Exclusion.NOWHERE);
if (cells == null) {
continue;
}
for (int lz = 0; lz < 16; lz++) {
for (int lx = 0; lx < 16; lx++) {
for (int y = cells.minY(); y <= cells.maxY(); y++) {
int x = (chunkX << 4) + lx;
int z = (chunkZ << 4) + lz;
byte kind = cells.at(lx, y, lz);
boolean inside = shape.inside(x, y, z);
if (inside) {
assertEquals(x + "," + y + "," + z, y <= SEA ? GrottoRasterizer.WET : GrottoRasterizer.DRY, kind);
} else {
assertTrue(x + "," + y + "," + z + " kind " + kind, kind == GrottoRasterizer.NONE || kind == GrottoRasterizer.GUARD);
}
wet += kind == GrottoRasterizer.WET ? 1L : 0L;
dry += kind == GrottoRasterizer.DRY ? 1L : 0L;
}
}
}
}
}
assertTrue("wet " + wet, wet > 2000L);
assertTrue("dry " + dry, dry > 2000L);
}
@Test
public void everyWetCellIsWalledByGuardAcrossChunkLines() {
Grotto grotto = GrottoShapeTest.winding(12L, 0.6f);
int[] bounds = grotto.bounds();
Map<Long, GrottoRasterizer.Cells> chunks = new HashMap<>();
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++) {
chunks.put(key(chunkX, chunkZ), GrottoRasterizer.cells(grotto, chunkX, chunkZ, GrottoRasterizer.Exclusion.NOWHERE));
}
}
long checked = 0L;
for (Map.Entry<Long, GrottoRasterizer.Cells> entry : chunks.entrySet()) {
if (entry.getValue() == null) {
continue;
}
int chunkX = (int) (entry.getKey() >> 32);
int chunkZ = (int) (long) entry.getKey();
GrottoRasterizer.Cells cells = entry.getValue();
for (int lz = 0; lz < 16; lz++) {
for (int lx = 0; lx < 16; lx++) {
for (int y = cells.minY(); y <= SEA; y++) {
if (cells.at(lx, y, lz) != GrottoRasterizer.WET) {
continue;
}
int x = (chunkX << 4) + lx;
int z = (chunkZ << 4) + lz;
for (int[] side : new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}) {
int nx = x + side[0];
int nz = z + side[1];
GrottoRasterizer.Cells other = chunks.get(key(nx >> 4, nz >> 4));
assertNotNull("chunk beside " + nx + "," + nz, other);
byte beside = other.at(nx & 15, y, nz & 15);
assertTrue(nx + "," + y + "," + nz + " is " + beside, beside == GrottoRasterizer.WET || beside == GrottoRasterizer.GUARD);
checked++;
}
}
}
}
}
assertTrue("checked " + checked, checked > 2000L);
}
@Test
public void guardStaysAtOrBelowTheWaterSoItCannotFillOpenAir() {
Grotto grotto = GrottoShapeTest.winding(13L, 0.6f);
int[] bounds = grotto.bounds();
boolean any = false;
for (int chunkZ = bounds[1] >> 4; chunkZ <= bounds[3] >> 4; chunkZ++) {
for (int chunkX = bounds[0] >> 4; chunkX <= bounds[2] >> 4; chunkX++) {
GrottoRasterizer.Cells cells = GrottoRasterizer.cells(grotto, chunkX, chunkZ, GrottoRasterizer.Exclusion.NOWHERE);
if (cells == null) {
continue;
}
for (int lz = 0; lz < 16; lz++) {
for (int lx = 0; lx < 16; lx++) {
for (int y = cells.minY(); y <= cells.maxY(); y++) {
if (cells.at(lx, y, lz) == GrottoRasterizer.GUARD) {
any = true;
assertTrue("guard at " + y, y <= SEA);
}
}
}
}
}
}
assertTrue(any);
}
@Test
public void excludedCellsStayRockAndNextWaterIsGuarded() {
Grotto grotto = GrottoShapeTest.winding(14L, 0.6f);
int wallX = (int) grotto.xs()[24];
GrottoRasterizer.Exclusion beyond = (x, y, z) -> x >= wallX;
int chunkX = wallX >> 4;
int chunkZ = ((int) grotto.zs()[24]) >> 4;
GrottoRasterizer.Cells cells = GrottoRasterizer.cells(grotto, chunkX, chunkZ, beyond);
assertNotNull(cells);
GrottoShape shape = new GrottoShape(grotto);
boolean guarded = 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;
for (int y = cells.minY(); y <= cells.maxY(); y++) {
byte kind = cells.at(lx, y, lz);
if (x >= wallX) {
assertFalse(kind == GrottoRasterizer.WET || kind == GrottoRasterizer.DRY);
guarded |= kind == GrottoRasterizer.GUARD && shape.inside(x, y, z);
}
}
}
}
assertTrue(guarded);
}
@Test
public void chunksFarFromTheGrottoHoldNothing() {
Grotto grotto = GrottoShapeTest.winding(15L, 0.6f);
assertNull(GrottoRasterizer.cells(grotto, 1000, 1000, GrottoRasterizer.Exclusion.NOWHERE));
}
}
@@ -0,0 +1,208 @@
package art.arcane.iris.generation.hydrology.underground;
import org.junit.Test;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class GrottoShapeTest {
static final int SEA = 100;
static Grotto winding(long id, float roughness) {
int points = 50;
float[] xs = new float[points];
float[] zs = new float[points];
float[] halfWidth = new float[points];
float[] roof = new float[points];
float[] floor = new float[points];
float[] lift = new float[points];
for (int point = 0; point < points; point++) {
xs[point] = point * 4f;
zs[point] = (float) (22D * Math.sin(point / 7D));
halfWidth[point] = point > 30 && point < 38 ? 11f : 6f;
roof[point] = point > 30 && point < 38 ? 13f : 7f;
floor[point] = 4f;
}
return new Grotto(id, SEA, roughness, 4, xs, zs, halfWidth, roof, floor, lift, new float[0], new float[0], new float[0], new int[0], new long[0]);
}
private static int[][] section(GrottoShape shape, Grotto grotto, int point) {
int x = (int) grotto.xs()[point];
int[][] spans = new int[121][];
for (int z = -60; z <= 60; z++) {
int low = Integer.MAX_VALUE;
int high = Integer.MIN_VALUE;
for (int y = shape.minY(); y <= shape.maxY(); y++) {
if (shape.inside(x, y, z + (int) grotto.zs()[point])) {
low = Math.min(low, y);
high = Math.max(high, y);
}
}
spans[z + 60] = low == Integer.MAX_VALUE ? null : new int[]{low, high};
}
return spans;
}
@Test
public void shapeDependsOnlyOnThePlan() {
Grotto a = winding(77L, 0.6f);
Grotto b = winding(77L, 0.6f);
GrottoShape first = new GrottoShape(a);
GrottoShape second = new GrottoShape(b);
GrottoShape scoped = new GrottoShape(a).scoped(0, -40, 80, 40);
for (int x = 8; x < 72; x += 3) {
for (int z = -30; z < 30; z += 3) {
for (int y = first.minY(); y <= first.maxY(); y += 2) {
assertEquals(first.inside(x, y, z), second.inside(x, y, z));
assertEquals(first.inside(x, y, z), scoped.inside(x, y, z));
}
}
}
}
@Test
public void differentGrottosGetDifferentRock() {
GrottoShape first = new GrottoShape(winding(1L, 0.6f));
GrottoShape second = new GrottoShape(winding(2L, 0.6f));
int differ = 0;
for (int x = 8; x < 180; x += 2) {
for (int z = -40; z < 40; z += 2) {
for (int y = SEA - 8; y <= SEA + 16; y += 2) {
differ += first.inside(x, y, z) != second.inside(x, y, z) ? 1 : 0;
}
}
}
assertTrue("differ " + differ, differ > 200);
}
@Test
public void waterSliceRunsFromMouthToHeadInEveryRoughness() {
for (float roughness : new float[]{0f, 0.3f, 0.6f, 1f}) {
for (long id = 1L; id <= 8L; id++) {
Grotto grotto = winding(id, roughness);
GrottoShape shape = new GrottoShape(grotto);
int startX = (int) grotto.xs()[0];
int startZ = (int) grotto.zs()[0];
assertTrue(shape.inside(startX, SEA, startZ));
Set<Long> seen = new HashSet<>();
ArrayDeque<int[]> frontier = new ArrayDeque<>();
frontier.add(new int[]{startX, startZ});
seen.add(key(startX, startZ));
while (!frontier.isEmpty()) {
int[] cell = frontier.poll();
for (int[] side : new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}) {
int nx = cell[0] + side[0];
int nz = cell[1] + side[1];
if (shape.inside(nx, SEA, nz) && seen.add(key(nx, nz))) {
frontier.add(new int[]{nx, nz});
}
}
}
int last = grotto.xs().length - 1;
assertTrue("roughness " + roughness + " id " + id, seen.contains(key((int) grotto.xs()[last], (int) grotto.zs()[last])) || nearReached(seen, grotto, last));
}
}
}
private static boolean nearReached(Set<Long> seen, Grotto grotto, int point) {
for (int dx = -4; dx <= 4; dx++) {
for (int dz = -4; dz <= 4; dz++) {
if (seen.contains(key((int) grotto.xs()[point] + dx, (int) grotto.zs()[point] + dz))) {
return true;
}
}
}
return false;
}
private static long key(int x, int z) {
return ((long) x << 32) | (z & 0xFFFFFFFFL);
}
@Test
public void sectionsAreNotBoxes() {
int flatRuns = 0;
int sections = 0;
int widest = 0;
Grotto grotto = winding(5L, 0.6f);
GrottoShape shape = new GrottoShape(grotto);
for (int point = 8; point < 44; point += 3) {
int[][] spans = section(shape, grotto, point);
int longest = 0;
int run = 0;
int width = 0;
Integer last = null;
for (int[] span : spans) {
if (span == null) {
continue;
}
width++;
run = last != null && last == span[1] ? run + 1 : 1;
longest = Math.max(longest, run);
last = span[1];
}
flatRuns += longest * 2 > width ? 1 : 0;
sections++;
widest = Math.max(widest, width);
}
assertTrue("sections with a flat roof over half their width " + flatRuns + " of " + sections, flatRuns * 5 <= sections);
assertTrue("widest " + widest, widest >= 14);
}
@Test
public void someColumnsHoldOverhangs() {
Grotto grotto = winding(9L, 0.8f);
GrottoShape shape = new GrottoShape(grotto);
int columns = 0;
int overhangs = 0;
for (int x = 8; x < 190; x++) {
for (int z = -50; z < 50; z++) {
boolean carved = false;
boolean over = false;
for (int y = SEA + 1; y <= shape.maxY() - 3; y++) {
if (!shape.inside(x, y, z)) {
continue;
}
carved = true;
for (int up = 1; up <= 3 && !over; up++) {
over = !shape.inside(x, y + up, z) && (shape.inside(x + 1, y + up, z) || shape.inside(x - 1, y + up, z)
|| shape.inside(x, y + up, z + 1) || shape.inside(x, y + up, z - 1));
}
}
columns += carved ? 1 : 0;
overhangs += over ? 1 : 0;
}
}
assertTrue("overhangs " + overhangs + " of " + columns, overhangs * 4 > columns);
}
@Test
public void pluggedCellsAreRock() {
Grotto plain = winding(5L, 0.6f);
int x = (int) plain.xs()[20];
int z = (int) plain.zs()[20];
assertTrue(new GrottoShape(plain).inside(x, SEA, z));
Grotto plugged = new Grotto(plain.id(), plain.seaLevel(), plain.roughness(), plain.coast(), plain.xs(), plain.zs(), plain.halfWidth(), plain.roof(), plain.floor(), plain.lift(),
plain.holeX(), plain.holeZ(), plain.holeRadius(), plain.holeTop(), new long[]{Grotto.plug(x, SEA, z)});
assertFalse(new GrottoShape(plugged).inside(x, SEA, z));
}
@Test
public void skylightOpensAboveTheRoofOnly() {
Grotto plain = winding(5L, 0.3f);
float x = plain.xs()[20];
float z = plain.zs()[20];
Grotto holed = new Grotto(plain.id(), plain.seaLevel(), plain.roughness(), plain.coast(), plain.xs(), plain.zs(), plain.halfWidth(), plain.roof(), plain.floor(), plain.lift(),
new float[]{x}, new float[]{z}, new float[]{2.5f}, new int[]{SEA + 30}, new long[0]);
GrottoShape shape = new GrottoShape(holed);
assertTrue(shape.maxY() >= SEA + 30);
assertTrue(shape.inside((int) x, SEA + 25, (int) z));
assertFalse(shape.inside((int) x, SEA + 40, (int) z));
assertFalse(new GrottoShape(plain).inside((int) x, SEA + 25, (int) z));
}
}
@@ -178,7 +178,7 @@ public class RiverCompilerTest {
compile(new Field.Const(SEA_LEVEL + 2.0), overworldHydrology(), registry(), DataVersion.V26_3, diagnostics);
assertEquals(List.of(ExportLimit.ELEVATED_WATER, ExportLimit.RIVER_DRAINAGE, ExportLimit.SEA_INLET, ExportLimit.CAVE_POOL),
assertEquals(List.of(ExportLimit.ELEVATED_WATER, ExportLimit.RIVER_DRAINAGE, ExportLimit.SEA_INLET, ExportLimit.GROTTO, ExportLimit.CAVE_POOL),
diagnostics.stream().map(ExportDiagnostic::limit).toList());
assertEquals("dimensions/rivers/hydrology", diagnostics.getFirst().resource());
}
@@ -404,6 +404,17 @@ public class RiverCompilerTest {
assertTrue(diagnostics.toString(), limited(diagnostics, ExportLimit.CAVE_POOL).isEmpty());
}
@Test
public void grottosReportADiagnostic() {
List<ExportDiagnostic> diagnostics = new ArrayList<>();
IrisHydrology hydrology = overworldHydrology();
hydrology.getUnderground().getSeaInlets().setEnabled(false);
hydrology.getUnderground().getCavePools().setEnabled(false);
compile(new Field.Const(SEA_LEVEL + 2.0), hydrology, registry(), DataVersion.V26_3, diagnostics);
assertEquals(1, limited(diagnostics, ExportLimit.GROTTO).size());
assertEquals("dimensions/rivers/hydrology", limited(diagnostics, ExportLimit.GROTTO).getFirst().resource());
}
@Test
public void cavePoolsReportADiagnostic() {
List<ExportDiagnostic> diagnostics = new ArrayList<>();
@@ -458,7 +469,7 @@ public class RiverCompilerTest {
ExportLimit.RIVER_CLIMATE,
ExportLimit.RIVER_SHORE_BIOME,
ExportLimit.RIVER_DECORATOR, ExportLimit.RIVER_DECORATOR,
ExportLimit.SEA_INLET, ExportLimit.CAVE_POOL), forward.stream().map(ExportDiagnostic::limit).toList());
ExportLimit.SEA_INLET, ExportLimit.GROTTO, ExportLimit.CAVE_POOL), forward.stream().map(ExportDiagnostic::limit).toList());
assertEquals(List.of("regions/hot", "regions/wet", "biomes/deep"),
limited(forward, ExportLimit.RIVER_POLICY).stream().map(ExportDiagnostic::resource).toList());
assertEquals(List.of("dimensions/rivers/hydrology", "biomes/marsh"),
@@ -556,6 +567,7 @@ public class RiverCompilerTest {
private static IrisHydrologyUnderground underground(boolean enabled) {
IrisHydrologyUnderground underground = new IrisHydrologyUnderground();
underground.getSeaInlets().setEnabled(enabled);
underground.getGrottos().setEnabled(enabled);
underground.getCavePools().setEnabled(enabled);
return underground;
}
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
@ClassRule
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
private static final String EXPECTED_SCHEMA_DIGEST = "07bb61c7034a6aadae8d03c9c0fe8a31326113f7ad515c99512ded2ab9be686c";
private static final String EXPECTED_SCHEMA_DIGEST = "9bb901e1c56c0a3996b956b0aeb0f1aa1060489181164790c554f8a89da16794";
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
IrisDimension.class,
@@ -3,6 +3,7 @@ package art.arcane.iris.studio.render;
import art.arcane.iris.generation.hydrology.engine.HydrologyPlanPreview;
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
import art.arcane.iris.generation.hydrology.underground.Grotto;
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
import art.arcane.iris.generation.hydrology.water.Pond;
import art.arcane.iris.generation.hydrology.water.Reach;
@@ -50,6 +51,18 @@ public class WaterMapTest {
assertEquals("open lake water", HydrologyFeatureType.LAKE, map.at(13, 7));
}
@Test
public void grottosDrawAtMidZoom() {
Grotto grotto = new Grotto(9L, LEVEL, 0.5f, 0, new float[]{4f, 60f}, new float[]{POND_Z, POND_Z}, new float[]{4f, 4f}, new float[]{5f, 5f}, new float[]{3f, 3f}, new float[]{0f, 0f},
new float[0], new float[0], new float[0], new int[0], new long[0]);
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
when(runtime.planPreview(anyInt(), anyInt(), anyInt(), anyInt()))
.thenReturn(new HydrologyPlanPreview(List.of(), List.of(), List.of(), List.of(grotto), true));
WaterMap map = new WaterMap(runtime, PIXELS, 0D, 0D, MID_STEP);
map.advance(() -> false);
assertEquals(HydrologyFeatureType.GROTTO, map.at((int) (30D / MID_STEP), (int) (POND_Z / MID_STEP)));
}
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()))