diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntime.java b/core/src/main/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntime.java index 77cae91d0..9c2936563 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntime.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntime.java @@ -19,7 +19,7 @@ import art.arcane.iris.generation.hydrology.raster.ChannelFluids; import art.arcane.iris.generation.hydrology.raster.ChunkRasterizer; import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster; import art.arcane.iris.generation.hydrology.raster.NaturalHeights; -import art.arcane.iris.generation.hydrology.underground.SeaInlet; +import art.arcane.iris.generation.hydrology.underground.SealedPassage; import art.arcane.iris.generation.hydrology.water.HydrologyTier; import art.arcane.iris.generation.hydrology.water.Pond; import art.arcane.iris.generation.hydrology.water.Reach; @@ -438,7 +438,7 @@ public final class HydrologyRuntime { return HydrologyFeatureSearch.channelType(settings, tier); } - public List inlets(int chunkX, int chunkZ) { + public List passages(int chunkX, int chunkZ) { return List.of(); } diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SeaInletRasterizer.java b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/PassageRasterizer.java similarity index 60% rename from core/src/main/java/art/arcane/iris/generation/hydrology/underground/SeaInletRasterizer.java rename to core/src/main/java/art/arcane/iris/generation/hydrology/underground/PassageRasterizer.java index 44047d351..0dd3518d9 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SeaInletRasterizer.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/PassageRasterizer.java @@ -7,26 +7,26 @@ import art.arcane.volmlib.nativelib.terrain.NativeBlockState; import java.util.Arrays; -public final class SeaInletRasterizer { +public final class PassageRasterizer { public static final int SHELL = 2; private static final int CHUNK = 16; private static final int GRID = CHUNK + 2 * SHELL; static final int NONE = Integer.MIN_VALUE; - public void write(SeaInlet inlet, int chunkX, int chunkZ, MantleWriter writer, String fluid, SubterrainFluid subterrain, + public void write(SealedPassage passage, int chunkX, int chunkZ, MantleWriter writer, String fluid, SubterrainFluid subterrain, HistoricalChunks historical) { - if (!touches(inlet, chunkX, chunkZ)) { + if (!touches(passage, chunkX, chunkZ)) { return; } int[] floors = new int[GRID * GRID]; int[] ceilings = new int[GRID * GRID]; - if (!shape(inlet, (chunkX << 4) - SHELL, (chunkZ << 4) - SHELL, GRID, floors, ceilings)) { + if (!shape(passage, (chunkX << 4) - SHELL, (chunkZ << 4) - SHELL, GRID, floors, ceilings)) { return; } HydrologyCaveCell wet = new HydrologyCaveCell(HydrologyCaveAction.WET_SOURCE, fluid); HydrologyCaveCell dry = new HydrologyCaveCell(HydrologyCaveAction.DRY_AIR, fluid); HydrologyCaveCell guard = new HydrologyCaveCell(HydrologyCaveAction.SEAL_GUARD, fluid); - int water = inlet.waterLevel(); + int water = passage.waterLevel(); boolean[] historicalAround = historicalAround(chunkX, chunkZ, historical); for (int lz = 0; lz < CHUNK; lz++) { for (int lx = 0; lx < CHUNK; lx++) { @@ -40,8 +40,6 @@ public final class SeaInletRasterizer { int floor = floors[cell]; if (floor == NONE) { guard(writer, x, low - SHELL, water, z, guard); - } else if (ceilings[cell] == SeaInlet.OPEN) { - guard(writer, x, low - SHELL, floor - 1, z, guard); } else if (historicalAround != null && besideHistorical(historicalAround, lx, lz)) { guard(writer, x, low - SHELL, ceilings[cell], z, guard); } else { @@ -76,83 +74,22 @@ public final class SeaInletRasterizer { boolean at(int chunkX, int chunkZ); } - public static boolean touches(SeaInlet inlet, int chunkX, int chunkZ) { - int[] bounds = bounds(inlet); + public static boolean touches(SealedPassage passage, int chunkX, int chunkZ) { + int[] bounds = passage.bounds(); int minX = chunkX << 4; int minZ = chunkZ << 4; return bounds[0] <= minX + CHUNK - 1 + SHELL && bounds[2] >= minX - SHELL && bounds[1] <= minZ + CHUNK - 1 + SHELL && bounds[3] >= minZ - SHELL; } - public static int[] bounds(SeaInlet inlet) { - float minX = inlet.chamberX() - inlet.chamberRadius(); - float minZ = inlet.chamberZ() - inlet.chamberRadius(); - float maxX = inlet.chamberX() + inlet.chamberRadius() + 1; - float maxZ = inlet.chamberZ() + inlet.chamberRadius() + 1; - for (int station = 0; station < inlet.stations(); station++) { - float reach = inlet.halfWidth()[station] + 1f; - minX = Math.min(minX, inlet.xs()[station] - reach); - minZ = Math.min(minZ, inlet.zs()[station] - reach); - maxX = Math.max(maxX, inlet.xs()[station] + reach); - maxZ = Math.max(maxZ, inlet.zs()[station] + reach); - } - return new int[]{(int) Math.floor(minX), (int) Math.floor(minZ), (int) Math.ceil(maxX), (int) Math.ceil(maxZ)}; - } - - public static boolean column(SeaInlet inlet, int x, int z, int[] out) { - double px = x + 0.5D; - double pz = z + 0.5D; - int floor = Integer.MAX_VALUE; - int ceiling = NONE; - float[] xs = inlet.xs(); - float[] zs = inlet.zs(); - for (int station = 0; station + 1 < xs.length; station++) { - double ax = xs[station]; - double az = zs[station]; - double dx = xs[station + 1] - ax; - double dz = zs[station + 1] - az; - double span = dx * dx + dz * dz; - double t = span <= 0D ? 0D : Math.clamp(((px - ax) * dx + (pz - az) * dz) / span, 0D, 1D); - double distance = Math.hypot(px - (ax + t * dx), pz - (az + t * dz)); - double half = inlet.halfWidth()[station] + t * (inlet.halfWidth()[station + 1] - inlet.halfWidth()[station]); - if (distance > half) { - continue; - } - floor = Math.min(floor, (int) Math.round(inlet.floor()[station] + t * (inlet.floor()[station + 1] - inlet.floor()[station]))); - ceiling = Math.max(ceiling, ceiling(inlet, station, t)); - } - double radius = inlet.chamberRadius(); - double fromCentre = Math.hypot(px - inlet.chamberX(), pz - inlet.chamberZ()); - if (fromCentre <= radius) { - int last = xs.length - 1; - double dome = Math.sqrt(1D - (fromCentre / radius) * (fromCentre / radius)); - int water = inlet.waterLevel(); - floor = Math.min(floor, water - (int) Math.max(1L, Math.round((water - inlet.floor()[last]) * dome))); - ceiling = Math.max(ceiling, water + (int) Math.round((inlet.ceiling()[last] - water) * dome)); - } - if (ceiling == NONE) { - return false; - } - out[0] = floor; - out[1] = ceiling; - return true; - } - - private static int ceiling(SeaInlet inlet, int station, double t) { - if (inlet.open(station) || inlet.open(station + 1)) { - return t <= 0.5D ? inlet.ceiling()[station] : inlet.ceiling()[station + 1]; - } - return (int) Math.round(inlet.ceiling()[station] + t * (inlet.ceiling()[station + 1] - inlet.ceiling()[station])); - } - - static boolean shape(SeaInlet inlet, int originX, int originZ, int size, int[] floors, int[] ceilings) { + static boolean shape(SealedPassage passage, int originX, int originZ, int size, int[] floors, int[] ceilings) { Arrays.fill(floors, NONE); Arrays.fill(ceilings, NONE); boolean any = false; int[] column = new int[2]; for (int gz = 0; gz < size; gz++) { for (int gx = 0; gx < size; gx++) { - if (column(inlet, originX + gx, originZ + gz, column)) { + if (passage.column(originX + gx, originZ + gz, column)) { floors[gz * size + gx] = column[0]; ceilings[gz * size + gx] = column[1]; any = true; @@ -184,7 +121,7 @@ public final class SeaInletRasterizer { for (int dz = -SHELL; dz <= SHELL; dz++) { for (int dx = -SHELL; dx <= SHELL; dx++) { int ceiling = ceilings[(gz + dz) * GRID + gx + dx]; - if (ceiling != SeaInlet.OPEN && ceiling > water && ceiling > roof) { + if (ceiling > water && ceiling > roof) { roof = ceiling; } } diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SeaInletSpace.java b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/PassageSpace.java similarity index 68% rename from core/src/main/java/art/arcane/iris/generation/hydrology/underground/SeaInletSpace.java rename to core/src/main/java/art/arcane/iris/generation/hydrology/underground/PassageSpace.java index f6aa683e8..ade4a09dd 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SeaInletSpace.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/PassageSpace.java @@ -3,9 +3,9 @@ package art.arcane.iris.generation.hydrology.underground; import java.util.Arrays; import java.util.Collection; -public final class SeaInletSpace { - private static final int SHELL = SeaInletRasterizer.SHELL; - private static final int NONE = SeaInletRasterizer.NONE; +public final class PassageSpace { + private static final int SHELL = PassageRasterizer.SHELL; + private static final int NONE = PassageRasterizer.NONE; private final int originX; private final int originZ; @@ -13,7 +13,7 @@ public final class SeaInletSpace { private final int[] lows; private final int[] highs; - private SeaInletSpace(int originX, int originZ, int size, int[] lows, int[] highs) { + private PassageSpace(int originX, int originZ, int size, int[] lows, int[] highs) { this.originX = originX; this.originZ = originZ; this.size = size; @@ -21,7 +21,7 @@ public final class SeaInletSpace { this.highs = highs; } - public static SeaInletSpace of(Collection inlets, int originX, int originZ, int size) { + public static PassageSpace of(Collection passages, int originX, int originZ, int size) { int[] lows = new int[size * size]; int[] highs = new int[size * size]; Arrays.fill(lows, NONE); @@ -29,26 +29,26 @@ public final class SeaInletSpace { int grid = size + 2 * SHELL; int[] floors = new int[grid * grid]; int[] ceilings = new int[grid * grid]; - for (SeaInlet inlet : inlets) { - if (!SeaInletRasterizer.shape(inlet, originX - SHELL, originZ - SHELL, grid, floors, ceilings)) { + for (SealedPassage passage : passages) { + if (!PassageRasterizer.shape(passage, originX - SHELL, originZ - SHELL, grid, floors, ceilings)) { continue; } for (int z = 0; z < size; z++) { for (int x = 0; x < size; x++) { int cell = (z + SHELL) * grid + x + SHELL; - int low = SeaInletRasterizer.nearby(floors, grid, cell, true); + int low = PassageRasterizer.nearby(floors, grid, cell, true); if (low == NONE) { continue; } int column = z * size + x; int bottom = low - SHELL; - int top = Math.max(inlet.waterLevel(), SeaInletRasterizer.nearby(ceilings, grid, cell, false)); + int top = Math.max(passage.waterLevel(), PassageRasterizer.nearby(ceilings, grid, cell, false)); lows[column] = lows[column] == NONE ? bottom : Math.min(lows[column], bottom); highs[column] = Math.max(highs[column], top); } } } - return new SeaInletSpace(originX, originZ, size, lows, highs); + return new PassageSpace(originX, originZ, size, lows, highs); } public boolean contains(int x, int y, int z) { diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SeaInlet.java b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SeaInlet.java deleted file mode 100644 index e10ff1850..000000000 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SeaInlet.java +++ /dev/null @@ -1,61 +0,0 @@ -package art.arcane.iris.generation.hydrology.underground; - -import java.util.Arrays; - -public record SeaInlet(long id, float[] xs, float[] zs, float[] halfWidth, int waterLevel, int[] floor, int[] ceiling, int chamberX, - int chamberZ, int chamberRadius) { - public static final int OPEN = Integer.MAX_VALUE; - - public SeaInlet { - int stations = xs.length; - if (stations < 2 || zs.length != stations || halfWidth.length != stations || floor.length != stations || ceiling.length != stations) { - throw new IllegalArgumentException("Sea inlet " + id + " needs at least two stations and matching arrays: xs=" + xs.length - + " zs=" + zs.length + " halfWidth=" + halfWidth.length + " floor=" + floor.length + " ceiling=" + ceiling.length); - } - if (chamberRadius <= 0) { - throw new IllegalArgumentException("Sea inlet " + id + " needs a positive chamber radius, got " + chamberRadius); - } - for (int station = 0; station < stations; station++) { - if (!(halfWidth[station] > 0f) || floor[station] >= waterLevel || ceiling[station] < waterLevel) { - throw new IllegalArgumentException("Sea inlet " + id + " station " + station + " has half-width " + halfWidth[station] - + ", floor " + floor[station] + " and ceiling " + ceiling[station] + " around water level " + waterLevel); - } - } - } - - public int stations() { - return xs.length; - } - - public boolean open(int station) { - return ceiling[station] == OPEN; - } - - @Override - public boolean equals(Object other) { - return other instanceof SeaInlet inlet && id == inlet.id && waterLevel == inlet.waterLevel && chamberX == inlet.chamberX - && chamberZ == inlet.chamberZ && chamberRadius == inlet.chamberRadius && Arrays.equals(xs, inlet.xs) - && Arrays.equals(zs, inlet.zs) && Arrays.equals(halfWidth, inlet.halfWidth) && Arrays.equals(floor, inlet.floor) - && Arrays.equals(ceiling, inlet.ceiling); - } - - @Override - public int hashCode() { - int hash = 31 * Long.hashCode(id) + waterLevel; - hash = 31 * hash + chamberX; - hash = 31 * hash + chamberZ; - hash = 31 * hash + chamberRadius; - hash = 31 * hash + Arrays.hashCode(xs); - hash = 31 * hash + Arrays.hashCode(zs); - hash = 31 * hash + Arrays.hashCode(halfWidth); - hash = 31 * hash + Arrays.hashCode(floor); - return 31 * hash + Arrays.hashCode(ceiling); - } - - @Override - public String toString() { - int last = xs.length - 1; - return "SeaInlet[id=" + id + ", stations=" + xs.length + ", mouth=" + xs[0] + "," + zs[0] + ", end=" + xs[last] + "," + zs[last] - + ", waterLevel=" + waterLevel + ", chamber=" + chamberX + "," + chamberZ + " r" + chamberRadius + "]"; - } -} diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SeaInletFootprint.java b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SeaInletFootprint.java deleted file mode 100644 index 2d746b4ca..000000000 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SeaInletFootprint.java +++ /dev/null @@ -1,72 +0,0 @@ -package art.arcane.iris.generation.hydrology.underground; - -final class SeaInletFootprint { - private static final byte OPEN = 1; - private static final byte COVERED = 2; - private static final int SHELL = SeaInletRasterizer.SHELL; - - private final int minX; - private final int minZ; - private final int maxX; - private final int maxZ; - private final byte[] kinds; - - private SeaInletFootprint(SeaInlet inlet) { - int[] bounds = SeaInletRasterizer.bounds(inlet); - this.minX = bounds[0]; - this.minZ = bounds[1]; - this.maxX = bounds[2]; - this.maxZ = bounds[3]; - this.kinds = new byte[(maxX - minX + 1) * (maxZ - minZ + 1)]; - int[] column = new int[2]; - for (int z = minZ; z <= maxZ; z++) { - for (int x = minX; x <= maxX; x++) { - if (SeaInletRasterizer.column(inlet, x, z, column)) { - kinds[index(x, z)] = column[1] == SeaInlet.OPEN ? OPEN : COVERED; - } - } - } - } - - static SeaInletFootprint of(SeaInlet inlet) { - return new SeaInletFootprint(inlet); - } - - boolean conflicts(SeaInletFootprint other) { - return opensBeside(this, other) || opensBeside(other, this); - } - - private static boolean opensBeside(SeaInletFootprint open, SeaInletFootprint covered) { - int fromX = Math.max(open.minX, covered.minX - SHELL); - int toX = Math.min(open.maxX, covered.maxX + SHELL); - int fromZ = Math.max(open.minZ, covered.minZ - SHELL); - int toZ = Math.min(open.maxZ, covered.maxZ + SHELL); - for (int z = fromZ; z <= toZ; z++) { - for (int x = fromX; x <= toX; x++) { - if (open.kind(x, z) == OPEN && covered.coveredNear(x, z)) { - return true; - } - } - } - return false; - } - - private boolean coveredNear(int x, int z) { - for (int dz = -SHELL; dz <= SHELL; dz++) { - for (int dx = -SHELL; dx <= SHELL; dx++) { - if (kind(x + dx, z + dz) == COVERED) { - return true; - } - } - } - return false; - } - - private byte kind(int x, int z) { - return x < minX || x > maxX || z < minZ || z > maxZ ? 0 : kinds[index(x, z)]; - } - - private int index(int x, int z) { - return (z - minZ) * (maxX - minX + 1) + x - minX; - } -} diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SealedPassage.java b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SealedPassage.java new file mode 100644 index 000000000..55560faa9 --- /dev/null +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/SealedPassage.java @@ -0,0 +1,13 @@ +package art.arcane.iris.generation.hydrology.underground; + +public interface SealedPassage { + long id(); + + int waterLevel(); + + int roofClearance(); + + int[] bounds(); + + boolean column(int x, int z, int[] out); +} diff --git a/core/src/main/java/art/arcane/iris/generation/mantle/CaveCeilingMask.java b/core/src/main/java/art/arcane/iris/generation/mantle/CaveCeilingMask.java index b747ab216..544576b90 100644 --- a/core/src/main/java/art/arcane/iris/generation/mantle/CaveCeilingMask.java +++ b/core/src/main/java/art/arcane/iris/generation/mantle/CaveCeilingMask.java @@ -2,8 +2,7 @@ package art.arcane.iris.generation.mantle; import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime; 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.hydrology.underground.SealedPassage; import art.arcane.volmlib.util.math.PowerOfTwoCoordinates; import java.util.Arrays; @@ -60,16 +59,15 @@ public final class CaveCeilingMask { } public static long[] headroom(int chunkX, int chunkZ, HydrologyRuntime runtime, long[] bands) { - List inlets = runtime.inlets(chunkX, chunkZ); - if (inlets.isEmpty()) { + List passages = runtime.passages(chunkX, chunkZ); + if (passages.isEmpty()) { return null; } - int roofClearance = 6; - return fillHeadroom(chunkX, chunkZ, inlets, roofClearance, bands) ? bands : null; + return fillHeadroom(chunkX, chunkZ, passages, bands) ? bands : null; } - static boolean fillHeadroom(int chunkX, int chunkZ, List inlets, int roofClearance, long[] bands) { - if (inlets.isEmpty()) { + static boolean fillHeadroom(int chunkX, int chunkZ, List passages, long[] bands) { + if (passages.isEmpty()) { return false; } int originX = (chunkX << 4) - CONTAINMENT; @@ -80,19 +78,19 @@ public final class CaveCeilingMask { Arrays.fill(tops, Integer.MIN_VALUE); int[] column = new int[2]; boolean roofed = false; - for (SeaInlet inlet : inlets) { - int[] bounds = SeaInletRasterizer.bounds(inlet); + for (SealedPassage passage : passages) { + int[] bounds = passage.bounds(); int fromX = Math.max(originX, bounds[0]); int toX = Math.min(originX + FIELD - 1, bounds[2]); int toZ = Math.min(originZ + FIELD - 1, bounds[3]); for (int z = Math.max(originZ, bounds[1]); z <= toZ; z++) { for (int x = fromX; x <= toX; x++) { - if (!SeaInletRasterizer.column(inlet, x, z, column) || column[1] == SeaInlet.OPEN) { + if (!passage.column(x, z, column)) { continue; } int index = (z - originZ) * FIELD + x - originX; - bottoms[index] = Math.min(bottoms[index], inlet.waterLevel() + 1); - tops[index] = Math.max(tops[index], column[1] + roofClearance); + bottoms[index] = Math.min(bottoms[index], passage.waterLevel() + 1); + tops[index] = Math.max(tops[index], column[1] + passage.roofClearance()); roofed = true; } } diff --git a/core/src/main/java/art/arcane/iris/generation/mantle/MantleCarvedTerrain.java b/core/src/main/java/art/arcane/iris/generation/mantle/MantleCarvedTerrain.java index f70606687..c7a653d2f 100644 --- a/core/src/main/java/art/arcane/iris/generation/mantle/MantleCarvedTerrain.java +++ b/core/src/main/java/art/arcane/iris/generation/mantle/MantleCarvedTerrain.java @@ -5,8 +5,8 @@ import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy; import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime; import art.arcane.iris.generation.hydrology.underground.CarvedTerrain; import art.arcane.iris.generation.hydrology.underground.CaveVoxel; -import art.arcane.iris.generation.hydrology.underground.SeaInlet; -import art.arcane.iris.generation.hydrology.underground.SeaInletSpace; +import art.arcane.iris.generation.hydrology.underground.PassageSpace; +import art.arcane.iris.generation.hydrology.underground.SealedPassage; import art.arcane.iris.generation.runtime.Engine; import art.arcane.iris.generation.runtime.IrisComplex; import art.arcane.iris.generation.stream.ProvisionalSampling; @@ -49,7 +49,7 @@ final class MantleCarvedTerrain implements CarvedTerrain { private final SubterrainPlanner planner; private final List features; private final boolean terrain3D; - private final SeaInletSpace inlets; + private final PassageSpace passages; private final MantleChunk[] chunks; private final boolean[] existing; private final int[] surfaces = new int[SPAN * SPAN]; @@ -71,7 +71,7 @@ final class MantleCarvedTerrain implements CarvedTerrain { this.minimumY = engine.getWorld().minHeight(); HydrologyRuntime runtime = complex.getHydrologyRuntime(); this.caveFluids = runtime.caveFluidPolicies(); - this.inlets = SeaInletSpace.of(inlets(runtime, chunkX, chunkZ), originX, originZ, SPAN); + this.passages = PassageSpace.of(passages(runtime, chunkX, chunkZ), originX, originZ, SPAN); SubterrainPlanner subterrain = complex.getSubterrainPlanner(); List plans = subterrain == null || subterrain.isEmpty() ? List.of() : subterrain.plansForBounds(originX, originZ, originX + SPAN - 1, originZ + SPAN - 1); @@ -88,7 +88,7 @@ final class MantleCarvedTerrain implements CarvedTerrain { @Override public CaveVoxel voxel(int x, int y, int z) { int column = column(x, z); - if (y <= 0 || y >= height || existing(x, z) || y > surface(x, z, column) || inlets.contains(x, y, z)) { + if (y <= 0 || y >= height || existing(x, z) || y > surface(x, z, column) || passages.contains(x, y, z)) { return CaveVoxel.FOREIGN; } if (planner != null && planner.sample(features, x, y + minimumY, z).owned()) { @@ -149,16 +149,16 @@ final class MantleCarvedTerrain implements CarvedTerrain { return false; } - private static Collection inlets(HydrologyRuntime runtime, int chunkX, int chunkZ) { - Map inlets = new LinkedHashMap<>(); + private static Collection passages(HydrologyRuntime runtime, int chunkX, int chunkZ) { + Map passages = new LinkedHashMap<>(); for (int offsetZ = -1; offsetZ <= 1; offsetZ++) { for (int offsetX = -1; offsetX <= 1; offsetX++) { - for (SeaInlet inlet : runtime.inlets(chunkX + offsetX, chunkZ + offsetZ)) { - inlets.putIfAbsent(inlet.id(), inlet); + for (SealedPassage passage : runtime.passages(chunkX + offsetX, chunkZ + offsetZ)) { + passages.putIfAbsent(passage.id(), passage); } } } - return inlets.values(); + return passages.values(); } private int surface(int x, int z, int column) { diff --git a/core/src/main/java/art/arcane/iris/generation/mantle/MantleCarvingComponent.java b/core/src/main/java/art/arcane/iris/generation/mantle/MantleCarvingComponent.java index 3f49d535b..dc390923e 100644 --- a/core/src/main/java/art/arcane/iris/generation/mantle/MantleCarvingComponent.java +++ b/core/src/main/java/art/arcane/iris/generation/mantle/MantleCarvingComponent.java @@ -169,9 +169,9 @@ public class MantleCarvingComponent extends IrisMantleComponent { ); int[] caveCeilings = CaveCeilingMask.fill(x, z, complex.getHydrologyRuntime()::raster, blendScratch.caveCeilingField, blendScratch.caveCeilings) ? blendScratch.caveCeilings : null; - long[] inletHeadroom = CaveCeilingMask.headroom(x, z, complex.getHydrologyRuntime(), blendScratch.inletHeadroom); - if (inletHeadroom != null) { - SurfaceFluidBoundaryPlan.join(surfaceFluidBoundaries, inletHeadroom); + long[] passageHeadroom = CaveCeilingMask.headroom(x, z, complex.getHydrologyRuntime(), blendScratch.passageHeadroom); + if (passageHeadroom != null) { + SurfaceFluidBoundaryPlan.join(surfaceFluidBoundaries, passageHeadroom); } CaveFluidSupportPlan fluidSupportPlan = new CaveFluidSupportPlan(); for (WeightedProfile weightedProfile : weightedProfiles) { @@ -194,10 +194,10 @@ public class MantleCarvingComponent extends IrisMantleComponent { caveCeilings ); } - rasterizeSubterrain(writer, x, z, complex, caveCeilings, inletHeadroom); + rasterizeSubterrain(writer, x, z, complex, caveCeilings, passageHeadroom); } - private void rasterizeSubterrain(MantleWriter writer, int chunkX, int chunkZ, IrisComplex complex, int[] caveCeilings, long[] inletHeadroom) { + private void rasterizeSubterrain(MantleWriter writer, int chunkX, int chunkZ, IrisComplex complex, int[] caveCeilings, long[] passageHeadroom) { SubterrainPlanner planner = complex.getSubterrainPlanner(); if (planner == null || planner.isEmpty()) { return; @@ -211,7 +211,7 @@ public class MantleCarvingComponent extends IrisMantleComponent { if (cell.solid() && !cell.room().reservedSolid()) { return; } - if (!cell.solid() && CaveCeilingMask.masked(caveCeilings, inletHeadroom, PowerOfTwoCoordinates.packLocal16(x & 15, z & 15), y)) { + if (!cell.solid() && CaveCeilingMask.masked(caveCeilings, passageHeadroom, PowerOfTwoCoordinates.packLocal16(x & 15, z & 15), y)) { return; } if (cell.solid()) { @@ -767,7 +767,7 @@ public class MantleCarvingComponent extends IrisMantleComponent { private final double[] chunkSurfaceHeightSamples = new double[CHUNK_AREA]; private final int[] caveCeilingField = new int[CaveCeilingMask.FIELD * CaveCeilingMask.FIELD]; private final int[] caveCeilings = new int[CHUNK_AREA]; - private final long[] inletHeadroom = new long[CHUNK_AREA]; + private final long[] passageHeadroom = new long[CHUNK_AREA]; private final double[][] neighbourHeights = new double[NEIGHBOURS][CHUNK_AREA]; private final Object[][] neighbourObjects = new Object[NEIGHBOURS][CHUNK_AREA]; private final long[][] neighbourSubmerged = new long[NEIGHBOURS][4]; diff --git a/core/src/main/java/art/arcane/iris/generation/mantle/MantleHydrologyComponent.java b/core/src/main/java/art/arcane/iris/generation/mantle/MantleHydrologyComponent.java index d0c1af6fd..effea6e0c 100644 --- a/core/src/main/java/art/arcane/iris/generation/mantle/MantleHydrologyComponent.java +++ b/core/src/main/java/art/arcane/iris/generation/mantle/MantleHydrologyComponent.java @@ -12,8 +12,8 @@ import art.arcane.iris.generation.hydrology.raster.FluidSeams; import art.arcane.iris.generation.hydrology.underground.CarvedTerrain; import art.arcane.iris.generation.hydrology.underground.CavePoolFiller; import art.arcane.iris.generation.hydrology.underground.CaveSpringPlacer; -import art.arcane.iris.generation.hydrology.underground.SeaInlet; -import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer; +import art.arcane.iris.generation.hydrology.underground.PassageRasterizer; +import art.arcane.iris.generation.hydrology.underground.SealedPassage; import art.arcane.iris.generation.runtime.Engine; import art.arcane.iris.generation.runtime.IrisComplex; import art.arcane.iris.generation.subterrain.SubterrainPlan; @@ -35,7 +35,7 @@ public final class MantleHydrologyComponent extends IrisMantleComponent { private static final int CHUNK = 16; private static final int GRID = CHUNK + 2; private static final int[] SIDES = {1, -1, GRID, -GRID}; - private static final SeaInletRasterizer INLETS = new SeaInletRasterizer(); + private static final PassageRasterizer PASSAGES = new PassageRasterizer(); public MantleHydrologyComponent(EngineMantle engineMantle) { super(engineMantle, ReservedFlag.RIVER_HYDROLOGY, PRIORITY); @@ -84,11 +84,11 @@ public final class MantleHydrologyComponent extends IrisMantleComponent { } HydrologyRuntime runtime = complex.getHydrologyRuntime(); ChunkWaterRaster own = CaveCeilingMask.ready(runtime.raster(chunkX, chunkZ), chunkX, chunkZ); - List inlets = runtime.inlets(chunkX, chunkZ); - if (!inlets.isEmpty()) { - SeaInletRasterizer.SubterrainFluid subterrain = subterrainFluid(writer, complex, chunkX, chunkZ); - for (SeaInlet inlet : inlets) { - INLETS.write(inlet, chunkX, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, subterrain, complex::isHistoricalChunk); + List passages = runtime.passages(chunkX, chunkZ); + if (!passages.isEmpty()) { + PassageRasterizer.SubterrainFluid subterrain = subterrainFluid(writer, complex, chunkX, chunkZ); + for (SealedPassage passage : passages) { + PASSAGES.write(passage, chunkX, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, subterrain, complex::isHistoricalChunk); } } generateFalls(writer, complex, runtime, own, chunkX, chunkZ); @@ -107,14 +107,14 @@ public final class MantleHydrologyComponent extends IrisMantleComponent { } } - private static SeaInletRasterizer.SubterrainFluid subterrainFluid(MantleWriter writer, IrisComplex complex, int chunkX, int chunkZ) { + private static PassageRasterizer.SubterrainFluid subterrainFluid(MantleWriter writer, IrisComplex complex, int chunkX, int chunkZ) { SubterrainPlanner planner = complex.getSubterrainPlanner(); if (planner == null || planner.isEmpty()) { - return SeaInletRasterizer.SubterrainFluid.NOWHERE; + return PassageRasterizer.SubterrainFluid.NOWHERE; } List plans = planner.plansForBounds(chunkX << 4, chunkZ << 4, (chunkX << 4) + 15, (chunkZ << 4) + 15); if (plans.isEmpty()) { - return SeaInletRasterizer.SubterrainFluid.NOWHERE; + return PassageRasterizer.SubterrainFluid.NOWHERE; } int minimumY = writer.getEngine().getWorld().minHeight(); return (x, y, z) -> planner.sample(plans, x, y + minimumY, z).fluid(); diff --git a/core/src/main/java/art/arcane/iris/generation/stage/IrisCarveModifier.java b/core/src/main/java/art/arcane/iris/generation/stage/IrisCarveModifier.java index 2bf8facf0..ad877c365 100644 --- a/core/src/main/java/art/arcane/iris/generation/stage/IrisCarveModifier.java +++ b/core/src/main/java/art/arcane/iris/generation/stage/IrisCarveModifier.java @@ -165,7 +165,7 @@ public class IrisCarveModifier extends EngineAssignedModifier resolverState.complex, subterrainPlanner == null ? null : subterrainPlanner.chunkSampler(x, z), subterrain ? caveCeilings(resolverState.complex, x, z) : null, - subterrain ? inletHeadroom(resolverState.complex, x, z) : null + subterrain ? passageHeadroom(resolverState.complex, x, z) : null ); CarveResolver carveResolver = new CarveResolver(resolutionContext); terrain.forEachCell(carveResolver::apply); @@ -263,17 +263,17 @@ public class IrisCarveModifier extends EngineAssignedModifier int minimumY = getEngine().getWorld().minHeight(); SubterrainSurfaceMaterials materials = subterrainMaterials(planner, blockX >> 4, blockZ >> 4); int[] caveCeilings = caveCeilings(getComplex(), blockX >> 4, blockZ >> 4); - long[] inletHeadroom = inletHeadroom(getComplex(), blockX >> 4, blockZ >> 4); + long[] passageHeadroom = passageHeadroom(getComplex(), blockX >> 4, blockZ >> 4); MantleChunk chunk = getEngine().getMantle().getMantle().useChunk(blockX >> 4, blockZ >> 4); try { - preserveSubterrain(planner, materials, caveCeilings, inletHeadroom, minimumY, blockX, blockZ, output, + preserveSubterrain(planner, materials, caveCeilings, passageHeadroom, minimumY, blockX, blockZ, output, (worldX, y, worldZ) -> HydrologyCaveStorage.getIfPresent(chunk, worldX, y, worldZ)); } finally { chunk.release(); } } - private void preserveSubterrain(SubterrainPlanner planner, SubterrainSurfaceMaterials materials, int[] caveCeilings, long[] inletHeadroom, + private void preserveSubterrain(SubterrainPlanner planner, SubterrainSurfaceMaterials materials, int[] caveCeilings, long[] passageHeadroom, int minimumY, int blockX, int blockZ, Hunk output, HydrologyCells hydrology) { SubterrainRasterizer.rasterize(planner, blockX >> 4, blockZ >> 4, (worldX, worldY, worldZ, cell) -> { int y = worldY - minimumY; @@ -282,7 +282,7 @@ public class IrisCarveModifier extends EngineAssignedModifier } int x = worldX & 15; int z = worldZ & 15; - if (!cell.solid() && CaveCeilingMask.masked(caveCeilings, inletHeadroom, PowerOfTwoCoordinates.packLocal16(x, z), y)) { + if (!cell.solid() && CaveCeilingMask.masked(caveCeilings, passageHeadroom, PowerOfTwoCoordinates.packLocal16(x, z), y)) { return; } if (hydrology.at(worldX, y, worldZ) != null) { @@ -310,7 +310,7 @@ public class IrisCarveModifier extends EngineAssignedModifier new int[CaveCeilingMask.FIELD * CaveCeilingMask.FIELD], ceilings) ? ceilings : null; } - private static long[] inletHeadroom(IrisComplex complex, int chunkX, int chunkZ) { + private static long[] passageHeadroom(IrisComplex complex, int chunkX, int chunkZ) { return CaveCeilingMask.headroom(chunkX, chunkZ, complex.getHydrologyRuntime(), new long[256]); } @@ -476,7 +476,7 @@ public class IrisCarveModifier extends EngineAssignedModifier CarveOwnership.Owner owner = carveOwner(hydrology, feature, context.terrainColumns() == null ? null : context.terrainColumns()[columnIndex], y); if (owner == CarveOwnership.Owner.SUBTERRAIN) { - if (!feature.solid() && CaveCeilingMask.masked(context.caveCeilings(), context.inletHeadroom(), columnIndex, y)) { + if (!feature.solid() && CaveCeilingMask.masked(context.caveCeilings(), context.passageHeadroom(), columnIndex, y)) { return; } context.output().setRaw(localX, y, localZ, SubterrainRasterizer.state(feature)); @@ -567,7 +567,7 @@ public class IrisCarveModifier extends EngineAssignedModifier IrisComplex complex, SubterrainPlanner.ChunkSampler subterrainSampler, int[] caveCeilings, - long[] inletHeadroom + long[] passageHeadroom ) { } diff --git a/core/src/test/java/art/arcane/iris/generation/hydrology/underground/SeaInletRasterizerTest.java b/core/src/test/java/art/arcane/iris/generation/hydrology/underground/PassageRasterizerTest.java similarity index 64% rename from core/src/test/java/art/arcane/iris/generation/hydrology/underground/SeaInletRasterizerTest.java rename to core/src/test/java/art/arcane/iris/generation/hydrology/underground/PassageRasterizerTest.java index ab4aef8f2..9ccb3ab82 100644 --- a/core/src/test/java/art/arcane/iris/generation/hydrology/underground/SeaInletRasterizerTest.java +++ b/core/src/test/java/art/arcane/iris/generation/hydrology/underground/PassageRasterizerTest.java @@ -3,6 +3,7 @@ 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 art.arcane.iris.testsupport.TestPassage; import org.junit.Test; import java.util.ArrayList; @@ -23,14 +24,14 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class SeaInletRasterizerTest { +public class PassageRasterizerTest { 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 cells = rasterize(List.of(inlet(1L, 15f)), order(false)); + Map cells = rasterize(List.of(passage(1L, 15f)), order(false)); int wetColumns = 0; Map tops = new TreeMap<>(); for (Map.Entry entry : cells.entrySet()) { @@ -53,8 +54,8 @@ public class SeaInletRasterizerTest { @Test public void everyWaterCellIsHeldBySealedOrWetNeighbours() { - List inlets = List.of(inlet(1L, 15f), inlet(2L, 30f)); - Map cells = rasterize(inlets, order(false)); + List passages = List.of(passage(1L, 15f), passage(2L, 30f)); + Map cells = rasterize(passages, order(false)); int checked = 0; for (Map.Entry entry : cells.entrySet()) { if (entry.getValue().action() != HydrologyCaveAction.WET_SOURCE) { @@ -64,9 +65,6 @@ public class SeaInletRasterizerTest { 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); @@ -78,8 +76,8 @@ public class SeaInletRasterizerTest { @Test public void sealKeepsCavesTwoBlocksFromTheWater() { - List inlets = List.of(inlet(1L, 15f)); - Map cells = rasterize(inlets, order(false)); + List passages = List.of(passage(1L, 15f)); + Map cells = rasterize(passages, order(false)); int checked = 0; for (Map.Entry entry : cells.entrySet()) { if (entry.getValue().action() != HydrologyCaveAction.WET_SOURCE) { @@ -91,9 +89,6 @@ public class SeaInletRasterizerTest { 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); @@ -113,67 +108,15 @@ public class SeaInletRasterizerTest { } @Test - public void openSlotColumnsLeaveTheirWaterToThePainter() { - SeaInlet inlet = inlet(1L, 15f); - Map cells = rasterize(List.of(inlet), order(false)); - int[] column = new int[2]; - int sealed = 0; - for (Map.Entry 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 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 plain = rasterize(List.of(inlet), order(false)); + public void subterrainFluidWithinTwoBlocksOfPassageAirAboveSeaLevelIsSealed() { + TestPassage passage = passage(1L, 15f); + PassageRasterizer.SubterrainFluid flooded = (x, y, z) -> Math.floorMod(x + 2 * z + y, 5) != 0; + Map plain = rasterize(List.of(passage), order(false)); for (Map.Entry entry : plain.entrySet()) { assertTrue("without subterrain fluid nothing above sea level is sealed", y(entry.getKey()) <= SEA || entry.getValue().action() == HydrologyCaveAction.DRY_AIR); } - Map cells = rasterize(List.of(inlet), order(false), flooded); + Map cells = rasterize(List.of(passage), order(false), flooded); int checked = 0; for (Map.Entry entry : cells.entrySet()) { if (entry.getValue().action() != HydrologyCaveAction.DRY_AIR) { @@ -189,7 +132,7 @@ public class SeaInletRasterizerTest { 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 + assertNotNull("subterrain fluid at " + (x + dx) + "," + (y + dy) + "," + (z + dz) + " beside passage air at " + x + "," + y + "," + z, held); assertTrue(held.action() == HydrologyCaveAction.DRY_AIR || held.action() == HydrologyCaveAction.SEAL_GUARD); checked++; @@ -206,12 +149,12 @@ public class SeaInletRasterizerTest { 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)); + assertTrue("the seal at " + x + "," + y + "," + z + " lies within two blocks of passage 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)); + assertEquals(cells, rasterize(List.of(passage), order(true), flooded)); } private static boolean nearAir(Map cells, int x, int y, int z) { @@ -228,16 +171,6 @@ public class SeaInletRasterizerTest { return false; } - private static boolean paintedSlot(List 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}; @@ -245,7 +178,7 @@ public class SeaInletRasterizerTest { 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); + TestPassage thin = new TestPassage(9L, xs, zs, halfWidth, SEA, floor, ceiling, 32, 32, 2); Map cells = rasterize(List.of(thin), order(false)); int wet = 0; for (Map.Entry entry : cells.entrySet()) { @@ -260,11 +193,11 @@ public class SeaInletRasterizerTest { @Test public void passageEndingAtAnOldChunkIsSealed() { - SeaInlet inlet = inlet(1L, 15f); - SeaInletRasterizer.HistoricalChunks old = (chunkX, chunkZ) -> chunkX == 2; - Map open = rasterize(List.of(inlet), order(false), SeaInletRasterizer.SubterrainFluid.NOWHERE, - SeaInletRasterizer.HistoricalChunks.NONE); - Map cells = rasterize(List.of(inlet), newChunks(order(false), old), SeaInletRasterizer.SubterrainFluid.NOWHERE, + TestPassage passage = passage(1L, 15f); + PassageRasterizer.HistoricalChunks old = (chunkX, chunkZ) -> chunkX == 2; + Map open = rasterize(List.of(passage), order(false), PassageRasterizer.SubterrainFluid.NOWHERE, + PassageRasterizer.HistoricalChunks.NONE); + Map cells = rasterize(List.of(passage), newChunks(order(false), old), PassageRasterizer.SubterrainFluid.NOWHERE, old); int[] column = new int[2]; int seamColumns = 0; @@ -273,12 +206,12 @@ public class SeaInletRasterizerTest { if (old.at(x >> 4, z >> 4) || !nearOldChunk(old, x, z)) { continue; } - if (!SeaInletRasterizer.column(inlet, x, z, column) || column[1] == SeaInlet.OPEN) { + if (!passage.column(x, z, column)) { 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++) { + open.get(key(x, passage.waterLevel(), z)).action()); + for (int y = column[0] - PassageRasterizer.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()); @@ -301,9 +234,6 @@ public class SeaInletRasterizerTest { 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); @@ -312,12 +242,12 @@ public class SeaInletRasterizerTest { } 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)); + assertEquals(cells, rasterize(List.of(passage), newChunks(order(true), old), PassageRasterizer.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++) { + private static boolean nearOldChunk(PassageRasterizer.HistoricalChunks old, int x, int z) { + for (int dz = -PassageRasterizer.SHELL; dz <= PassageRasterizer.SHELL; dz++) { + for (int dx = -PassageRasterizer.SHELL; dx <= PassageRasterizer.SHELL; dx++) { if (old.at((x + dx) >> 4, (z + dz) >> 4)) { return true; } @@ -326,7 +256,7 @@ public class SeaInletRasterizerTest { return false; } - private static List newChunks(List chunks, SeaInletRasterizer.HistoricalChunks old) { + private static List newChunks(List chunks, PassageRasterizer.HistoricalChunks old) { List fresh = new ArrayList<>(); for (int[] chunk : chunks) { if (!old.at(chunk[0], chunk[1])) { @@ -337,34 +267,34 @@ public class SeaInletRasterizerTest { } @Test - public void chunkOrderAndInletOrderDoNotChangeTheCells() { - List inlets = List.of(inlet(1L, 15f), inlet(2L, 22f)); - Map forward = rasterize(inlets, order(false)); - Map reverse = rasterize(List.of(inlets.get(1), inlets.get(0)), order(true)); + public void chunkOrderAndPassageOrderDoNotChangeTheCells() { + List passages = List.of(passage(1L, 15f), passage(2L, 22f)); + Map forward = rasterize(passages, order(false)); + Map reverse = rasterize(List.of(passages.get(1), passages.get(0)), order(true)); assertEquals(forward, reverse); assertFalse(forward.isEmpty()); } @Test public void chunksWriteOnlyTheirOwnColumns() { - SeaInlet inlet = inlet(1L, 15f); + TestPassage passage = passage(1L, 15f); Map cells = new TreeMap<>(); MantleWriter writer = writer(cells, 1, 0); - new SeaInletRasterizer().write(inlet, 1, 0, writer, FLUID, SeaInletRasterizer.SubterrainFluid.NOWHERE, - SeaInletRasterizer.HistoricalChunks.NONE); + new PassageRasterizer().write(passage, 1, 0, writer, FLUID, PassageRasterizer.SubterrainFluid.NOWHERE, + PassageRasterizer.HistoricalChunks.NONE); assertFalse(cells.isEmpty()); for (long key : cells.keySet()) { assertEquals(1, x(key) >> 4); assertEquals(0, z(key) >> 4); } Map far = new TreeMap<>(); - new SeaInletRasterizer().write(inlet, 20, 20, writer(far, 20, 20), FLUID, SeaInletRasterizer.SubterrainFluid.NOWHERE, - SeaInletRasterizer.HistoricalChunks.NONE); + new PassageRasterizer().write(passage, 20, 20, writer(far, 20, 20), FLUID, PassageRasterizer.SubterrainFluid.NOWHERE, + PassageRasterizer.HistoricalChunks.NONE); assertTrue(far.isEmpty()); - assertFalse(SeaInletRasterizer.touches(inlet, 20, 20)); + assertFalse(PassageRasterizer.touches(passage, 20, 20)); } - private static SeaInlet inlet(long id, float z) { + private static TestPassage passage(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]; @@ -374,9 +304,9 @@ public class SeaInletRasterizerTest { 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; + ceiling[station] = SEA + 4 + station % 4; } - return new SeaInlet(id, xs, zs, halfWidth, SEA, floor, ceiling, 48, (int) z, 7); + return new TestPassage(id, xs, zs, halfWidth, SEA, floor, ceiling, 48, (int) z, 7); } private static List order(boolean reverse) { @@ -392,22 +322,22 @@ public class SeaInletRasterizerTest { return chunks; } - private static Map rasterize(List inlets, List chunks) { - return rasterize(inlets, chunks, SeaInletRasterizer.SubterrainFluid.NOWHERE); + private static Map rasterize(List passages, List chunks) { + return rasterize(passages, chunks, PassageRasterizer.SubterrainFluid.NOWHERE); } - private static Map rasterize(List inlets, List chunks, SeaInletRasterizer.SubterrainFluid subterrain) { - return rasterize(inlets, chunks, subterrain, SeaInletRasterizer.HistoricalChunks.NONE); + private static Map rasterize(List passages, List chunks, PassageRasterizer.SubterrainFluid subterrain) { + return rasterize(passages, chunks, subterrain, PassageRasterizer.HistoricalChunks.NONE); } - private static Map rasterize(List inlets, List chunks, SeaInletRasterizer.SubterrainFluid subterrain, - SeaInletRasterizer.HistoricalChunks old) { + private static Map rasterize(List passages, List chunks, PassageRasterizer.SubterrainFluid subterrain, + PassageRasterizer.HistoricalChunks old) { Map cells = new TreeMap<>(); - SeaInletRasterizer rasterizer = new SeaInletRasterizer(); + PassageRasterizer rasterizer = new PassageRasterizer(); 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); + for (TestPassage passage : passages) { + rasterizer.write(passage, chunk[0], chunk[1], writer, FLUID, subterrain, old); } } return cells; diff --git a/core/src/test/java/art/arcane/iris/generation/mantle/CaveCeilingMaskTest.java b/core/src/test/java/art/arcane/iris/generation/mantle/CaveCeilingMaskTest.java index 83b3c5af9..62d57f682 100644 --- a/core/src/test/java/art/arcane/iris/generation/mantle/CaveCeilingMaskTest.java +++ b/core/src/test/java/art/arcane/iris/generation/mantle/CaveCeilingMaskTest.java @@ -2,8 +2,8 @@ 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.TestPassage; +import art.arcane.iris.generation.hydrology.underground.PassageRasterizer; import art.arcane.iris.testsupport.WaterScene; import art.arcane.volmlib.util.math.PowerOfTwoCoordinates; import org.junit.Test; @@ -102,16 +102,16 @@ public class CaveCeilingMaskTest { } @Test - public void cavesStayOutOfInletHeadroom() { - SeaInlet inlet = inlet(); - int[] bounds = SeaInletRasterizer.bounds(inlet); + public void cavesStayOutOfPassageHeadroom() { + TestPassage passage = passage(); + int[] bounds = passage.bounds(); 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); + boolean masked = CaveCeilingMask.fillHeadroom(chunkX, chunkZ, List.of(passage), bands); long[] headroom = masked ? bands : null; boolean expectedMasked = false; for (int lz = 0; lz < 16; lz++) { @@ -119,24 +119,24 @@ public class CaveCeilingMaskTest { int x = (chunkX << 4) + lx; int z = (chunkZ << 4) + lz; int index = PowerOfTwoCoordinates.packLocal16(lx, lz); - int top = highestRoofWithinTwo(inlet, x, z); + int top = highestRoofWithinTwo(passage, 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", + assertFalse("caves stay possible at " + x + "," + y + "," + z + " away from the passage", 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, + for (int y = passage.waterLevel() + 1; y <= top; y++) { + assertTrue("caves stay out of the passage 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, passage.waterLevel())); + assertFalse("caves stay possible above the passage roof at " + x + "," + z, CaveCeilingMask.masked(null, headroom, index, top + 1)); - if (SeaInletRasterizer.column(inlet, x, z, column) && column[1] != SeaInlet.OPEN) { + if (passage.column(x, z, column)) { covered++; } else { around++; @@ -148,7 +148,7 @@ public class CaveCeilingMaskTest { } assertTrue("covered columns " + covered, covered > 300); assertTrue("columns around the passage " + around, around > 100); - assertFalse(CaveCeilingMask.fillHeadroom(0, 0, List.of(), ROOF_CLEARANCE, bands)); + assertFalse(CaveCeilingMask.fillHeadroom(0, 0, List.of(), bands)); } @Test @@ -157,7 +157,7 @@ public class CaveCeilingMaskTest { Arrays.fill(ceilings, UNMASKED); ceilings[3] = 40; long[] bands = new long[256]; - assertTrue(CaveCeilingMask.fillHeadroom(0, 0, List.of(inlet()), ROOF_CLEARANCE, bands)); + assertTrue(CaveCeilingMask.fillHeadroom(0, 0, List.of(passage()), bands)); int index = PowerOfTwoCoordinates.packLocal16(12, 6); assertTrue(CaveCeilingMask.masked(ceilings, null, 3, 41)); assertFalse(CaveCeilingMask.masked(ceilings, null, 3, 40)); @@ -166,7 +166,7 @@ public class CaveCeilingMaskTest { assertFalse(CaveCeilingMask.masked(null, null, index, SEA + 1)); } - private static SeaInlet inlet() { + private static TestPassage passage() { float[] xs = {-8f, 0f, 8f, 16f, 24f, 32f, 40f, 48f}; float[] zs = new float[xs.length]; float[] halfWidth = new float[xs.length]; @@ -176,17 +176,17 @@ public class CaveCeilingMaskTest { 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; + ceiling[station] = SEA + 4 + station % 4; } - return new SeaInlet(1L, xs, zs, halfWidth, SEA, floor, ceiling, 48, 6, 7); + return new TestPassage(1L, xs, zs, halfWidth, SEA, floor, ceiling, 48, 6, 7); } - private static int highestRoofWithinTwo(SeaInlet inlet, int x, int z) { + private static int highestRoofWithinTwo(TestPassage passage, 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) { + if (passage.column(x + dx, z + dz, column)) { top = Math.max(top, column[1] + ROOF_CLEARANCE); } } diff --git a/core/src/test/java/art/arcane/iris/generation/mantle/MantleCarvedTerrainTest.java b/core/src/test/java/art/arcane/iris/generation/mantle/MantleCarvedTerrainTest.java index 97b152483..915b4a61e 100644 --- a/core/src/test/java/art/arcane/iris/generation/mantle/MantleCarvedTerrainTest.java +++ b/core/src/test/java/art/arcane/iris/generation/mantle/MantleCarvedTerrainTest.java @@ -11,8 +11,9 @@ 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.testsupport.TestPassage; +import art.arcane.iris.generation.hydrology.underground.PassageRasterizer; +import art.arcane.iris.generation.hydrology.underground.SealedPassage; import art.arcane.iris.generation.runtime.Engine; import art.arcane.iris.generation.runtime.EnginePlatformHooks; import art.arcane.iris.generation.runtime.IrisComplex; @@ -189,8 +190,8 @@ public class MantleCarvedTerrainTest { } @Test - public void inletSpaceFromEveryNeighbourChunkReadsAsForeignAndPoolsBesideItStayOutInEitherChunkOrder() { - Scene probe = inletScene(); + public void passageSpaceFromEveryNeighbourChunkReadsAsForeignAndPoolsBesideItStayOutInEitherChunkOrder() { + Scene probe = passageScene(); MantleCarvedTerrain carved = probe.carved(); assertEquals("passage water", CaveVoxel.FOREIGN, carved.voxel(7, 28, 21)); assertEquals("passage air", CaveVoxel.FOREIGN, carved.voxel(10, 33, 21)); @@ -201,8 +202,8 @@ public class MantleCarvedTerrainTest { assertEquals(CaveVoxel.SOLID, carved.voxel(10, 34, 21)); assertEquals(CaveVoxel.SOLID, carved.voxel(10, 25, 26)); - Map forward = inletScene().generate(0, 1); - Map reverse = inletScene().generate(1, 0); + Map forward = passageScene().generate(0, 1); + Map reverse = passageScene().generate(1, 0); assertEquals(forward, reverse); int top = Integer.MIN_VALUE; @@ -214,19 +215,19 @@ public class MantleCarvedTerrainTest { 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", + assertFalse("pool water at " + cellX(cell) + "," + cellY(cell) + "," + cellZ(cell) + " touches the passage", 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); + assertEquals("the pool stops one level below the passage seal its next level would reach", 24, top); for (int y = 24; y <= 30; y++) { - assertInlet(forward, 7, y, 19, HydrologyCaveAction.SEAL_GUARD); + assertPassage(forward, 7, y, 19, HydrologyCaveAction.SEAL_GUARD); } for (int y = 27; y <= 30; y++) { - assertInlet(forward, 7, y, 21, HydrologyCaveAction.WET_SOURCE); + assertPassage(forward, 7, y, 21, HydrologyCaveAction.WET_SOURCE); } for (int y = 31; y <= 33; y++) { - assertInlet(forward, 7, y, 21, HydrologyCaveAction.DRY_AIR); + assertPassage(forward, 7, y, 21, HydrologyCaveAction.DRY_AIR); } } @@ -378,7 +379,7 @@ public class MantleCarvedTerrainTest { return region; } - private static Scene inletScene() { + private static Scene passageScene() { Scene scene = new Scene(); Matter[] room = scene.chunk(0, 0); for (int x = 2; x <= 13; x++) { @@ -396,14 +397,14 @@ public class MantleCarvedTerrainTest { } } } - scene.inlets.add(new SeaInlet(77L, new float[]{40f, -8f}, new float[]{22f, 22f}, new float[]{2f, 2f}, 30, new int[]{26, 26}, + scene.passages.add(new TestPassage(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 written, int x, int y, int z, HydrologyCaveAction action) { + private static void assertPassage(Map 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, + assertTrue("passage " + action + " at " + x + "," + y + "," + z + " but found " + cell, cell != null && cell.action() == action && HydrologyCaveCell.SEA_FLUID.equals(cell.fluidProfileKey())); } @@ -450,7 +451,7 @@ public class MantleCarvedTerrainTest { private final MantleWriter writer = mock(MantleWriter.class); private final IrisComplex complex = mock(IrisComplex.class); private final Engine engine; - private final List inlets = new ArrayList<>(); + private final List passages = new ArrayList<>(); private final Map cells = new HashMap<>(); private Scene() { @@ -486,7 +487,7 @@ 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))); + when(runtime.passages(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,11 +505,11 @@ public class MantleCarvedTerrainTest { return new MantleCarvedTerrain(writer, complex, engine, 0, 0); } - private List touching(int chunkX, int chunkZ) { - List touching = new ArrayList<>(); - for (SeaInlet inlet : inlets) { - if (SeaInletRasterizer.touches(inlet, chunkX, chunkZ)) { - touching.add(inlet); + private List touching(int chunkX, int chunkZ) { + List touching = new ArrayList<>(); + for (TestPassage passage : passages) { + if (PassageRasterizer.touches(passage, chunkX, chunkZ)) { + touching.add(passage); } } return touching; @@ -519,11 +520,11 @@ public class MantleCarvedTerrainTest { 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(); + PassageRasterizer rasterizer = new PassageRasterizer(); 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); + for (SealedPassage passage : complex.getHydrologyRuntime().passages(0, chunkZ)) { + rasterizer.write(passage, 0, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, PassageRasterizer.SubterrainFluid.NOWHERE, + PassageRasterizer.HistoricalChunks.NONE); } new CavePoolFiller(settings, 0).fill(0, chunkZ, () -> new MantleCarvedTerrain(writer, complex, engine, 0, chunkZ), writer, SEED); } diff --git a/core/src/test/java/art/arcane/iris/generation/mantle/MantleCarvingComponentWaterMaskTest.java b/core/src/test/java/art/arcane/iris/generation/mantle/MantleCarvingComponentWaterMaskTest.java index ece508d96..4648027f3 100644 --- a/core/src/test/java/art/arcane/iris/generation/mantle/MantleCarvingComponentWaterMaskTest.java +++ b/core/src/test/java/art/arcane/iris/generation/mantle/MantleCarvingComponentWaterMaskTest.java @@ -8,8 +8,8 @@ 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.testsupport.TestPassage; +import art.arcane.iris.generation.hydrology.underground.PassageRasterizer; import art.arcane.iris.generation.runtime.Engine; import art.arcane.iris.generation.runtime.EngineMetrics; import art.arcane.iris.generation.runtime.IrisComplex; @@ -149,9 +149,9 @@ public class MantleCarvingComponentWaterMaskTest { } @Test - public void inletHeadroomJoinsTheProfilePassProtection() throws Exception { - SeaInlet inlet = coveredInlet(32, 40, 40); - installInlet(inlet); + public void passageHeadroomJoinsTheProfilePassProtection() throws Exception { + TestPassage passage = coveredPassage(32, 40, 40); + installPassage(passage); IrisCaveCarver3D carver = installProfile(); List boundaries = new ArrayList<>(); doAnswer(call -> { @@ -167,14 +167,14 @@ public class MantleCarvingComponentWaterMaskTest { 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)) { + if (!passage.column(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), + for (int y = passage.waterLevel() + 1; y <= column[1] + ROOF_CLEARANCE; y++) { + assertTrue("the carver keeps out of the passage headroom at " + (32 + lx) + "," + y + "," + (32 + lz), SurfaceFluidBoundaryPlan.protects(boundaries.getFirst(), index, y)); } - assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries.getFirst(), index, inlet.waterLevel())); + assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries.getFirst(), index, passage.waterLevel())); covered++; } } @@ -182,7 +182,7 @@ public class MantleCarvingComponentWaterMaskTest { } @Test - public void subterrainFeaturesStayOutOfInletHeadroom() { + public void subterrainFeaturesStayOutOfPassageHeadroom() { 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)); @@ -196,40 +196,40 @@ public class MantleCarvingComponentWaterMaskTest { List 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); + TestPassage passage = coveredPassage(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) { + if (passage.column(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); + assertTrue("subterrain cells in the headroom before the passage " + inside, inside > 20); - installInlet(inlet); + installPassage(passage); List 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 + boolean headroom = passage.column(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); + assertFalse("subterrain opened " + cell[0] + "," + cell[1] + "," + cell[2] + " in the passage 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()); + private void installPassage(TestPassage passage) { + when(hydrology.passages(anyInt(), anyInt())).thenAnswer(call -> PassageRasterizer.touches(passage, call.getArgument(0), call.getArgument(1)) + ? List.of(passage) : 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) { + private static TestPassage coveredPassage(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); + return new TestPassage(5L, xs, zs, halfWidth, water, floor, ceiling, startX + 20, z, 3); } private List openedCells(int chunkX, int chunkZ) { diff --git a/core/src/test/java/art/arcane/iris/generation/mantle/MantleHydrologyComponentTest.java b/core/src/test/java/art/arcane/iris/generation/mantle/MantleHydrologyComponentTest.java index f43d0901c..b3117c42a 100644 --- a/core/src/test/java/art/arcane/iris/generation/mantle/MantleHydrologyComponentTest.java +++ b/core/src/test/java/art/arcane/iris/generation/mantle/MantleHydrologyComponentTest.java @@ -9,7 +9,7 @@ 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.testsupport.TestPassage; import art.arcane.iris.generation.runtime.Engine; import art.arcane.iris.generation.runtime.IrisComplex; import art.arcane.iris.generation.subterrain.SubterrainCell; @@ -263,11 +263,11 @@ public class MantleHydrologyComponentTest { } @Test - public void seaInletsAreWrittenEvenWhereNoSurfaceWaterFlows() { + public void passagesAreWrittenEvenWhereNoSurfaceWaterFlows() { 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, + TestPassage passage = new TestPassage(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)); + when(dry.runtime.passages(0, 0)).thenReturn(List.of(passage)); List written = new ArrayList<>(); List heights = new ArrayList<>(); doAnswer(call -> { @@ -286,15 +286,15 @@ public class MantleHydrologyComponentTest { assertTrue(heights.get(index) <= 63); } } - assertTrue("wet inlet cells " + wet, wet > 100); + assertTrue("wet passage cells " + wet, wet > 100); } @Test - public void subterrainFluidBesideSeaInletAirIsSealedAboveSeaLevel() { + public void subterrainFluidBesidePassageAirIsSealedAboveSeaLevel() { 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, + TestPassage passage = new TestPassage(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)); + when(dry.runtime.passages(0, 0)).thenReturn(List.of(passage)); SubterrainPlanner planner = mock(SubterrainPlanner.class); List plans = List.of(mock(SubterrainPlan.class)); SubterrainCell water = new SubterrainCell(SubterrainCell.Kind.WATER, "", null); @@ -318,7 +318,7 @@ public class MantleHydrologyComponentTest { dry.generate(); - assertEquals("inlet air keeps its cell", HydrologyCaveAction.DRY_AIR, cells.get(cell(4, 69, 8)).action()); + assertEquals("passage 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))); diff --git a/core/src/test/java/art/arcane/iris/generation/stage/IrisCarveModifierSubterrainMaskTest.java b/core/src/test/java/art/arcane/iris/generation/stage/IrisCarveModifierSubterrainMaskTest.java index e93fc1f1e..3c8a7785d 100644 --- a/core/src/test/java/art/arcane/iris/generation/stage/IrisCarveModifierSubterrainMaskTest.java +++ b/core/src/test/java/art/arcane/iris/generation/stage/IrisCarveModifierSubterrainMaskTest.java @@ -7,8 +7,8 @@ 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.testsupport.TestPassage; +import art.arcane.iris.generation.hydrology.underground.PassageRasterizer; import art.arcane.iris.generation.mantle.EngineMantle; import art.arcane.iris.generation.runtime.Engine; import art.arcane.iris.generation.runtime.IrisComplex; @@ -87,7 +87,7 @@ public class IrisCarveModifierSubterrainMaskTest { } @Test - public void preservedSubterrainStaysOutOfInletHeadroom() { + public void preservedSubterrainStaysOutOfPassageHeadroom() { 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)); @@ -103,23 +103,23 @@ public class IrisCarveModifierSubterrainMaskTest { List 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); + TestPassage passage = coveredPassage(blockX, blockZ + 8, water); + assertTrue("subterrain cells in the headroom before the passage " + inHeadroom(passage, open).size(), inHeadroom(passage, 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.passages(anyInt(), anyInt())).thenAnswer(call -> PassageRasterizer.touches(passage, call.getArgument(0), + call.getArgument(1)) ? List.of(passage) : List.of()); when(hydrology.settings()).thenReturn(HydrologySettings.compile(new IrisHydrology().setEnabled(true), 1L, 63, 0, 128)); List sealed = reopenedCells(modifier, planner, blockX, blockZ); assertTrue(sealed.size() > 0); - assertEquals("subterrain reopened cells in the inlet headroom", List.of(), inHeadroom(inlet, sealed)); + assertEquals("subterrain reopened cells in the passage headroom", List.of(), inHeadroom(passage, sealed)); } } - private static List inHeadroom(SeaInlet inlet, List cells) { + private static List inHeadroom(TestPassage passage, List cells) { List 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() + if (passage.column(cell[0], cell[2], column) && cell[1] > passage.waterLevel() && cell[1] <= column[1] + ROOF_CLEARANCE) { inside.add(cell[0] + "," + cell[1] + "," + cell[2]); } @@ -127,13 +127,13 @@ public class IrisCarveModifierSubterrainMaskTest { return inside; } - private static SeaInlet coveredInlet(int startX, int z, int water) { + private static TestPassage coveredPassage(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); + return new TestPassage(5L, xs, zs, halfWidth, water, floor, ceiling, startX + 20, z, 3); } @SuppressWarnings("unchecked") @@ -155,7 +155,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 +165,8 @@ public class IrisCarveModifierSubterrainMaskTest { int blockZ = plan.centerZ() >> 4 << 4; HydrologyRuntime hydrology = mock(HydrologyRuntime.class); when(hydrology.raster(anyInt(), anyInt())).thenReturn(ChunkWaterRaster.EMPTY); - Map inlet = new HashMap<>(); - IrisCarveModifier modifier = modifier(planner, hydrology, inlet); + Map passage = new HashMap<>(); + IrisCarveModifier modifier = modifier(planner, hydrology, passage); try (MockedStatic blocks = mockStatic(B.class)) { blocks.when(() -> B.getState(anyString())).thenReturn(mock(NativeBlockState.class)); Set room = written(modifier, blockX, blockZ); @@ -178,14 +178,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 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 +195,7 @@ public class IrisCarveModifierSubterrainMaskTest { } @SuppressWarnings("unchecked") - private static IrisCarveModifier modifier(SubterrainPlanner planner, HydrologyRuntime hydrology, Map inlet) { + private static IrisCarveModifier modifier(SubterrainPlanner planner, HydrologyRuntime hydrology, Map passage) { Engine engine = mock(Engine.class); EngineMantle engineMantle = mock(EngineMantle.class); Mantle mantle = mock(Mantle.class); @@ -204,7 +204,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 +218,12 @@ public class IrisCarveModifierSubterrainMaskTest { } @SuppressWarnings("unchecked") - private static Matter section(int section, Map inlet) { + private static Matter section(int section, Map passage) { Matter matter = mock(Matter.class); MatterSlice 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; } diff --git a/core/src/test/java/art/arcane/iris/testsupport/TestPassage.java b/core/src/test/java/art/arcane/iris/testsupport/TestPassage.java new file mode 100644 index 000000000..909cbd41e --- /dev/null +++ b/core/src/test/java/art/arcane/iris/testsupport/TestPassage.java @@ -0,0 +1,70 @@ +package art.arcane.iris.testsupport; + +import art.arcane.iris.generation.hydrology.underground.SealedPassage; + +public record TestPassage(long id, float[] xs, float[] zs, float[] halfWidth, int waterLevel, int[] floor, int[] ceiling, int chamberX, + int chamberZ, int chamberRadius) implements SealedPassage { + public static final int ROOF_CLEARANCE = 6; + + public int stations() { + return xs.length; + } + + @Override + public int roofClearance() { + return ROOF_CLEARANCE; + } + + @Override + public int[] bounds() { + float minX = chamberX - chamberRadius; + float minZ = chamberZ - chamberRadius; + float maxX = chamberX + chamberRadius + 1; + float maxZ = chamberZ + chamberRadius + 1; + for (int station = 0; station < stations(); station++) { + float reach = halfWidth[station] + 1f; + minX = Math.min(minX, xs[station] - reach); + minZ = Math.min(minZ, zs[station] - reach); + maxX = Math.max(maxX, xs[station] + reach); + maxZ = Math.max(maxZ, zs[station] + reach); + } + return new int[]{(int) Math.floor(minX), (int) Math.floor(minZ), (int) Math.ceil(maxX), (int) Math.ceil(maxZ)}; + } + + @Override + public boolean column(int x, int z, int[] out) { + double px = x + 0.5D; + double pz = z + 0.5D; + int lowest = Integer.MAX_VALUE; + int highest = Integer.MIN_VALUE; + for (int station = 0; station + 1 < xs.length; station++) { + double ax = xs[station]; + double az = zs[station]; + double dx = xs[station + 1] - ax; + double dz = zs[station + 1] - az; + double span = dx * dx + dz * dz; + double t = span <= 0D ? 0D : Math.clamp(((px - ax) * dx + (pz - az) * dz) / span, 0D, 1D); + double distance = Math.hypot(px - (ax + t * dx), pz - (az + t * dz)); + double half = halfWidth[station] + t * (halfWidth[station + 1] - halfWidth[station]); + if (distance > half) { + continue; + } + lowest = Math.min(lowest, (int) Math.round(floor[station] + t * (floor[station + 1] - floor[station]))); + highest = Math.max(highest, (int) Math.round(ceiling[station] + t * (ceiling[station + 1] - ceiling[station]))); + } + double radius = chamberRadius; + double fromCentre = Math.hypot(px - chamberX, pz - chamberZ); + if (fromCentre <= radius) { + int last = xs.length - 1; + double dome = Math.sqrt(1D - (fromCentre / radius) * (fromCentre / radius)); + lowest = Math.min(lowest, waterLevel - (int) Math.max(1L, Math.round((waterLevel - floor[last]) * dome))); + highest = Math.max(highest, waterLevel + (int) Math.round((ceiling[last] - waterLevel) * dome)); + } + if (highest == Integer.MIN_VALUE) { + return false; + } + out[0] = lowest; + out[1] = highest; + return true; + } +} diff --git a/probe/src/main/java/art/arcane/iris/probe/HydrologyUnderground.java b/probe/src/main/java/art/arcane/iris/probe/HydrologyUnderground.java index 72c00fd1a..abe1fa805 100644 --- a/probe/src/main/java/art/arcane/iris/probe/HydrologyUnderground.java +++ b/probe/src/main/java/art/arcane/iris/probe/HydrologyUnderground.java @@ -2,6 +2,8 @@ package art.arcane.iris.probe; import art.arcane.iris.generation.hydrology.plan.WindowKey; import art.arcane.iris.generation.hydrology.plan.WindowPlan; +import art.arcane.iris.generation.hydrology.water.Reach; +import art.arcane.iris.generation.hydrology.water.ReachStyle; import art.arcane.iris.generation.runtime.Engine; import java.util.ArrayList; @@ -21,21 +23,25 @@ final class HydrologyUnderground { static final Counts NONE = new Counts(0, 0L, 0, 0L, List.of()); } + private static int tidal(WindowPlan plan) { + int arms = 0; + for (Reach reach : plan.reaches()) { + arms += reach.style()[0] == ReachStyle.TIDAL ? 1 : 0; + } + return arms; + } + static Source generated(Engine engine, ExecutorService workers) { return (key, plan) -> { - SeaInletProbe.Checks inlets = SeaInletProbe.check(engine, List.of(), workers); int minChunkX = key.wx() * HydrologyWindows.CHUNKS; int minChunkZ = key.wz() * HydrologyWindows.CHUNKS; CavePoolProbe.Counts pools = CavePoolProbe.check(engine, new CavePoolProbe.Area(minChunkX, minChunkX + HydrologyWindows.CHUNKS - 1, minChunkZ, minChunkZ + HydrologyWindows.CHUNKS - 1), workers); List examples = new ArrayList<>(); - for (String example : inlets.examples()) { - examples.add("inlet " + example); - } for (String example : pools.examples()) { examples.add("pool " + example); } - return new Counts(inlets.inlets(), inlets.failures(), pools.pools(), pools.failures(), examples); + return new Counts(tidal(plan), 0L, pools.pools(), pools.failures(), examples); }; } } diff --git a/probe/src/main/java/art/arcane/iris/probe/SeaInletProbe.java b/probe/src/main/java/art/arcane/iris/probe/SeaInletProbe.java deleted file mode 100644 index 94a1c5da3..000000000 --- a/probe/src/main/java/art/arcane/iris/probe/SeaInletProbe.java +++ /dev/null @@ -1,1112 +0,0 @@ -package art.arcane.iris.probe; - -import art.arcane.iris.generation.biome.IrisBiome; -import art.arcane.iris.generation.biome.IrisBiomePaletteLayer; -import art.arcane.iris.generation.decoration.IrisDecorator; -import art.arcane.iris.generation.decoration.IrisProceduralBlocks; -import art.arcane.iris.generation.decoration.IrisProceduralPlacement; -import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell; -import art.arcane.iris.generation.hydrology.cave.HydrologyCaveStorage; -import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime; -import art.arcane.iris.generation.hydrology.plan.WindowKey; -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.structure.object.IrisObject; -import art.arcane.volmlib.nativelib.terrain.NativeBiome; -import art.arcane.volmlib.nativelib.terrain.NativeBlockState; -import art.arcane.volmlib.util.hunk.Hunk; - -import java.io.File; -import java.nio.file.Path; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.atomic.AtomicInteger; - -public final class SeaInletProbe { - private static final String LOG = "[sea-inlet-probe]"; - private static final int CHUNKS_PER_WINDOW = WindowKey.SIZE >> 4; - private static final int BAND_BELOW = 12; - private static final int BAND_ABOVE = 110; - private static final byte AIR = 0; - private static final byte SOURCE = 1; - private static final byte FLOWING = 2; - private static final byte LOGGED = 3; - private static final byte SOLID = 4; - private static final byte OTHER = 5; - private static final byte FOREIGN = 6; - private static final byte LOOSE = 7; - private static final byte SEA_LAYER = 1; - private static final byte DECORATION = 2; - private static final Map> LAYER_KEYS = new ConcurrentHashMap<>(); - private static final Map> DECORATION_KEYS = new ConcurrentHashMap<>(); - private static final int[][] SIDES = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; - - private SeaInletProbe() { - } - - public static void main(String[] arguments) { - int exitCode = 1; - try { - Configuration configuration = Configuration.parse(arguments); - long failures = 0L; - if (configuration.mode().equals("inventory")) { - failures = inventory(configuration); - } else if (configuration.mode().equals("dump")) { - dump(configuration); - } else { - failures = gate(configuration).failures(); - } - exitCode = failures == 0L ? 0 : 1; - } catch (Throwable failure) { - System.out.println(LOG + " FAIL"); - failure.printStackTrace(System.out); - } - System.exit(exitCode); - } - - private static void dump(Configuration configuration) throws Exception { - try (RealPackProbeSupport.Workspace workspace = workspace(configuration, configuration.packOn()); - RealPackProbeSupport.EngineSession session = workspace.openEngine(configuration.seed(), false, "dump")) { - Engine engine = session.engine(); - int x = configuration.wx0(); - int z = configuration.wz0(); - int height = engine.getTarget().getHeight(); - Hunk blocks = Hunk.newArrayHunk(16, height, 16); - Hunk biomes = Hunk.newArrayHunk(16, height, 16); - engine.generate(x >> 4 << 4, z >> 4 << 4, blocks, biomes, false); - int sea = engine.getDimension().getFluidHeight(); - ChunkWaterRaster raster = engine.getComplex().getHydrologyRuntime().raster(x >> 4, z >> 4); - System.out.println("DUMP column " + x + "," + z + " role=" + raster.role(x & 15, z & 15) + " head=" + raster.waterHead(x & 15, z & 15) - + " terrain=" + (raster.empty() ? "natural" : raster.terrainHeight(x & 15, z & 15)) + " natural=" - + engine.getComplex().naturalTrueHeight(x, z) + " rock=" + engine.getComplex().getRockStream().get(x, z).key()); - for (int y = sea + configuration.wz1(); y >= sea - 12; y--) { - HydrologyCaveCell cell = HydrologyCaveStorage.getIfPresent(engine.getMantle().getMantle(), x, y, z); - NativeBlockState state = blocks.get(x & 15, y, z & 15); - System.out.println("DUMP y=" + y + " block=" + (state == null ? "null" : state.key()) + " cell=" + (cell == null ? "-" : cell.action())); - } - } - } - - private static int inventory(Configuration configuration) throws Exception { - int failedWindows = 0; - try (RealPackProbeSupport.Workspace workspace = workspace(configuration, configuration.packOn()); - RealPackProbeSupport.EngineSession session = workspace.openEngine(configuration.seed(), false, "inventory")) { - HydrologyRuntime runtime = session.engine().getComplex().getHydrologyRuntime(); - for (int wz = configuration.wz0(); wz <= configuration.wz1(); wz++) { - for (int wx = configuration.wx0(); wx <= configuration.wx1(); wx++) { - int[] coast = coast(session.engine(), wx, wz); - Map owned; - try { - owned = coast[1] == 0 ? Map.of() : owned(runtime, wx, wx, wz, wz); - } catch (RuntimeException failure) { - System.out.println("SEA_INLET_WINDOW_FAILED wx=" + wx + " wz=" + wz + " " + rootMessage(failure)); - failedWindows++; - continue; - } - double length = 0D; - for (SeaInlet inlet : owned.values()) { - length += length(inlet); - } - System.out.printf(Locale.ROOT, "SEA_INLET_WINDOW wx=%d wz=%d belowSea=%d cliffCoast=%d inlets=%d meanLength=%.1f%n", wx, wz, - coast[0], coast[1], owned.size(), owned.isEmpty() ? 0D : length / owned.size()); - } - } - } - return failedWindows; - } - - private static String rootMessage(Throwable failure) { - Throwable root = failure; - while (root.getCause() != null) { - root = root.getCause(); - } - return root.getClass().getSimpleName() + ": " + root.getMessage(); - } - - private static int[] coast(Engine engine, int wx, int wz) { - int sea = engine.getDimension().getFluidHeight(); - int cells = WindowKey.SIZE / 8; - int[] heights = new int[(cells + 2) * (cells + 2)]; - for (int j = 0; j < cells + 2; j++) { - for (int i = 0; i < cells + 2; i++) { - heights[j * (cells + 2) + i] = engine.getComplex().naturalTrueHeight(wx * WindowKey.SIZE + (i - 1) * 8, wz * WindowKey.SIZE + (j - 1) * 8); - } - } - int below = 0; - int cliff = 0; - for (int j = 1; j <= cells; j++) { - for (int i = 1; i <= cells; i++) { - int height = heights[j * (cells + 2) + i]; - if (height < sea) { - below++; - continue; - } - boolean coastal = false; - for (int[] side : SIDES) { - coastal |= heights[(j + side[1]) * (cells + 2) + i + side[0]] < sea; - } - if (coastal && height >= sea + 8) { - cliff++; - } - } - } - return new int[]{below, cliff}; - } - - private static Gate gate(Configuration configuration) throws Exception { - List tiles = tileChunks(configuration); - Run forward = run(configuration, configuration.packOn(), tiles, null, false, true, 1, "on-forward"); - List all = new ArrayList<>(forward.order); - List scanned = new ArrayList<>(); - for (long scan : forward.scanChunks) { - scanned.add(new long[]{chunkX(scan), chunkZ(scan)}); - } - System.out.println(LOG + " scan chunks " + forward.scanChunks.size() + ", generated chunks " + all.size()); - Run reverse = run(configuration, configuration.packOn(), all, null, true, false, configuration.threads(), "on-reverse"); - Run baseline = run(configuration, configuration.packOff(), scanned, forward.scanChunks, false, false, configuration.threads(), "off"); - return report(configuration, forward.inlets, forward, reverse, baseline); - } - - private static Run run(Configuration configuration, File pack, List chunks, Set scanChunks, boolean reverse, boolean inventory, - int threads, String label) throws Exception { - List ordered = new ArrayList<>(chunks); - if (reverse) { - Collections.reverse(ordered); - } - Run run = new Run(label); - try (RealPackProbeSupport.Workspace workspace = workspace(configuration, pack); - RealPackProbeSupport.EngineSession session = workspace.openEngine(configuration.seed(), false, label)) { - Engine engine = session.engine(); - HydrologyRuntime runtime = engine.getComplex().getHydrologyRuntime(); - if (inventory) { - run.inlets.putAll(touching(runtime, configuration)); - run.scanChunks.addAll(scanChunks(run.inlets, configuration)); - Set listed = new TreeSet<>(); - for (long[] chunk : ordered) { - listed.add(key((int) chunk[0], (int) chunk[1])); - } - for (long scan : run.scanChunks) { - if (!listed.contains(scan)) { - ordered.add(new long[]{chunkX(scan), chunkZ(scan)}); - } - } - System.out.printf(Locale.ROOT, "%s %s: %d inlets touch the tiles%n", LOG, label, run.inlets.size()); - } - run.order.addAll(ordered); - Set capture = scanChunks != null ? scanChunks : run.scanChunks; - int height = engine.getTarget().getHeight(); - int sea = engine.getDimension().getFluidHeight(); - AtomicInteger done = new AtomicInteger(); - ExecutorService pool = Executors.newFixedThreadPool(threads); - try { - List> futures = new ArrayList<>(ordered.size()); - for (long[] chunk : ordered) { - futures.add(pool.submit(() -> { - int chunkX = (int) chunk[0]; - int chunkZ = (int) chunk[1]; - Hunk blocks = Hunk.newArrayHunk(16, height, 16); - Hunk biomes = Hunk.newArrayHunk(16, height, 16); - engine.generate(chunkX << 4, chunkZ << 4, blocks, biomes, false); - long key = key(chunkX, chunkZ); - run.hashes.put(key, hash(blocks, biomes, height)); - if (capture.contains(key)) { - run.bands.put(key, Band.capture(engine, blocks, chunkX, chunkZ, sea, height)); - } - int count = done.incrementAndGet(); - if (count % 1024 == 0 || count == ordered.size()) { - System.out.println(LOG + " " + label + " generated " + count + "/" + ordered.size()); - } - return null; - })); - if (threads == 1) { - futures.get(futures.size() - 1).get(); - } - } - for (Future future : futures) { - future.get(); - } - } finally { - pool.shutdown(); - } - List reports = RealPackProbeSupport.settleAndDrain(engine); - if (!reports.isEmpty()) { - RealPackProbeSupport.printReports(LOG, label, reports); - throw new IllegalStateException(label + " reported " + reports.size() + " generation errors"); - } - run.sea = sea; - run.roofClearance = 6; - } - return run; - } - - record Checks(int inlets, long leaks, long missingWater, long waterAbove, long roofViolations, long roofBreaches, long openRoofViolations, - long disconnected, long shellOpen, long shellLoose, long looseBeds, List examples) { - static final Checks NONE = new Checks(0, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, List.of()); - - long failures() { - return leaks + missingWater + waterAbove + roofViolations + roofBreaches + openRoofViolations + disconnected + shellOpen + shellLoose; - } - } - - record Gate(Checks checks, int orderMismatches, int inletsWithOtherLevel, int addedLeaks) { - long failures() { - return checks.failures() + orderMismatches + inletsWithOtherLevel + addedLeaks; - } - - String line() { - return String.format(Locale.ROOT, "SEA_INLET_GATE status=%s failures=%d checkFailures=%d orderMismatches=%d inletsWithOtherLevel=%d" - + " addedLeaks=%d", failures() == 0L ? "PASS" : "FAIL", failures(), checks.failures(), orderMismatches, - inletsWithOtherLevel, addedLeaks); - } - } - - static Checks check(Engine engine, List inlets, ExecutorService workers) throws Exception { - if (inlets.isEmpty()) { - return Checks.NONE; - } - Run run = new Run("hydrology"); - run.sea = engine.getDimension().getFluidHeight(); - run.roofClearance = 6; - int height = engine.getTarget().getHeight(); - Set chunks = new TreeSet<>(); - for (SeaInlet inlet : inlets) { - int[] bounds = SeaInletRasterizer.bounds(inlet); - 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.add(key(chunkX, chunkZ)); - } - } - } - List> futures = new ArrayList<>(chunks.size()); - for (long chunk : chunks) { - futures.add(workers.submit(() -> { - int chunkX = chunkX(chunk); - int chunkZ = chunkZ(chunk); - Hunk blocks = Hunk.newArrayHunk(16, height, 16); - Hunk biomes = Hunk.newArrayHunk(16, height, 16); - engine.generate(chunkX << 4, chunkZ << 4, blocks, biomes, false); - run.bands.put(chunk, Band.capture(engine, blocks, chunkX, chunkZ, run.sea, height)); - return null; - })); - } - for (Future future : futures) { - future.get(); - } - Scan scan = new Scan(run, run.sea, run.roofClearance, inlets); - scan.run(); - return checks(scan); - } - - private static Checks checks(Scan scan) { - Scan.InletStats total = scan.total; - return new Checks(scan.inlets.size(), total.leaks, total.missingWater, total.waterAbove, total.roofViolations, total.roofBreaches, - total.openRoofViolations, total.disconnected, scan.shellOpen, scan.shellLoose, total.looseBeds, List.copyOf(scan.examples)); - } - - private static Map touching(HydrologyRuntime runtime, Configuration configuration) { - Map inlets = new TreeMap<>(); - for (int chunkZ = configuration.wz0() * CHUNKS_PER_WINDOW; chunkZ < (configuration.wz1() + 1) * CHUNKS_PER_WINDOW; chunkZ++) { - for (int chunkX = configuration.wx0() * CHUNKS_PER_WINDOW; chunkX < (configuration.wx1() + 1) * CHUNKS_PER_WINDOW; chunkX++) { - for (SeaInlet inlet : runtime.inlets(chunkX, chunkZ)) { - inlets.putIfAbsent(inlet.id(), inlet); - } - } - } - return inlets; - } - - private static Map owned(HydrologyRuntime runtime, int wx0, int wx1, int wz0, int wz1) { - Map owned = new TreeMap<>(); - for (int chunkZ = wz0 * CHUNKS_PER_WINDOW; chunkZ < (wz1 + 1) * CHUNKS_PER_WINDOW; chunkZ++) { - for (int chunkX = wx0 * CHUNKS_PER_WINDOW; chunkX < (wx1 + 1) * CHUNKS_PER_WINDOW; chunkX++) { - for (SeaInlet inlet : runtime.inlets(chunkX, chunkZ)) { - WindowKey owner = owner(inlet); - if (owner.wx() >= wx0 && owner.wx() <= wx1 && owner.wz() >= wz0 && owner.wz() <= wz1) { - owned.putIfAbsent(inlet.id(), inlet); - } - } - } - } - return owned; - } - - private static WindowKey owner(SeaInlet inlet) { - return WindowKey.containing((int) Math.floor(inlet.xs()[1]), (int) Math.floor(inlet.zs()[1])); - } - - private static Set scanChunks(Map inlets, Configuration configuration) { - Set chunks = new TreeSet<>(); - for (SeaInlet inlet : inlets.values()) { - if (!ownedByTiles(inlet, configuration)) { - continue; - } - int[] bounds = SeaInletRasterizer.bounds(inlet); - 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.add(key(chunkX, chunkZ)); - } - } - } - return chunks; - } - - private static boolean ownedByTiles(SeaInlet inlet, Configuration configuration) { - WindowKey owner = owner(inlet); - return owner.wx() >= configuration.wx0() && owner.wx() <= configuration.wx1() && owner.wz() >= configuration.wz0() - && owner.wz() <= configuration.wz1(); - } - - private static List tileChunks(Configuration configuration) { - List chunks = new ArrayList<>(); - for (int chunkZ = configuration.wz0() * CHUNKS_PER_WINDOW; chunkZ < (configuration.wz1() + 1) * CHUNKS_PER_WINDOW; chunkZ++) { - for (int chunkX = configuration.wx0() * CHUNKS_PER_WINDOW; chunkX < (configuration.wx1() + 1) * CHUNKS_PER_WINDOW; chunkX++) { - chunks.add(new long[]{chunkX, chunkZ}); - } - } - return chunks; - } - - private static Gate report(Configuration configuration, Map touching, Run on, Run reverse, Run off) { - int sea = on.sea; - int clearance = on.roofClearance; - List owned = new ArrayList<>(); - for (SeaInlet inlet : touching.values()) { - if (ownedByTiles(inlet, configuration)) { - owned.add(inlet); - } - } - Scan scan = new Scan(on, sea, clearance, owned); - scan.run(); - Set onLeaks = scan.allLeaks(); - Set offLeaks = new Scan(off, sea, clearance, owned).allLeaks(); - int addedLeaks = addedLeaks(onLeaks, offLeaks); - int mismatches = mismatches(on.hashes, reverse.hashes); - - System.out.println("SEA_INLET_INVENTORY owned=" + owned.size() + " touching=" + touching.size()); - for (SeaInlet inlet : owned) { - Scan.InletStats stats = scan.stats.get(inlet.id()); - WindowKey window = owner(inlet); - System.out.printf(Locale.ROOT, - "SEA_INLET id=%d window=%d,%d mouth=%.0f,%.0f stations=%d open=%d length=%.1f chamber=%d columns=%d wet=%d dry=%d" - + " chunks=%d crossesWindows=%s leaks=%d missingWater=%d seaPlants=%d nonSource=%d waterAboveSea=%d roofMin=%d" - + " roofViolations=%d roofBreaches=%d openRoofViolations=%d disconnectedWet=%d%n", - inlet.id(), window.wx(), window.wz(), inlet.xs()[0], inlet.zs()[0], inlet.stations(), openStations(inlet), length(inlet), - inlet.chamberRadius(), stats.columns, stats.wet, stats.dry, stats.chunks.size(), stats.windows.size() > 1, stats.leaks, - stats.missingWater, stats.seaPlants, stats.nonSource, stats.waterAbove, stats.roofMin, stats.roofViolations, stats.roofBreaches, - stats.openRoofViolations, stats.disconnected); - } - for (String example : scan.examples) { - System.out.println("SEA_INLET_EXAMPLE " + example); - } - int offLevel = 0; - for (SeaInlet inlet : owned) { - offLevel += inlet.waterLevel() == sea ? 0 : 1; - } - System.out.printf(Locale.ROOT, "SEA_INLET_CONTAINMENT leaks=%d missingWater=%d seaPlantCells=%d slotSeaLayerCells=%d" - + " slotDecorationCells=%d nonSource=%d waterAboveSea=%d wetCells=%d dryCells=%d%n", scan.total.leaks, - scan.total.missingWater, scan.total.seaPlants, scan.total.seaLayers, scan.total.decorations, scan.total.nonSource, - scan.total.waterAbove, scan.total.wet, scan.total.dry); - System.out.printf(Locale.ROOT, "SEA_INLET_LEVEL sea=%d inletsWithOtherLevel=%d%n", sea, offLevel); - System.out.printf(Locale.ROOT, "SEA_INLET_ALL_WATER_LEAKS scanChunks=%d inletsOn=%d inletsOff=%d added=%d%n", on.bands.size(), - onLeaks.size(), offLeaks.size(), addedLeaks); - System.out.printf(Locale.ROOT, "SEA_INLET_ROOF min=%d violations=%d breaches=%d openRoofViolations=%d coveredColumns=%d openColumns=%d%n", - scan.total.roofMin, scan.total.roofViolations, scan.total.roofBreaches, scan.total.openRoofViolations, scan.total.covered, - scan.total.open); - System.out.printf(Locale.ROOT, "SEA_INLET_OCEAN connected=%d partial=%d disconnected=%d disconnectedWetCells=%d%n", scan.connected, - scan.partial, scan.unconnected, scan.total.disconnected); - System.out.printf(Locale.ROOT, "SEA_INLET_SEAL cells=%d open=%d loose=%d maxOpenLandStations=%d slotLooseBeds=%d%n", scan.shellCells, - scan.shellOpen, scan.shellLoose, maxOpenLandStations(owned), scan.total.looseBeds); - System.out.printf(Locale.ROOT, "SEA_INLET_DETERMINISM chunks=%d reverseChunks=%d mismatches=%d crossChunkInlets=%d crossWindowInlets=%d%n", - on.hashes.size(), reverse.hashes.size(), mismatches, scan.crossChunk(), scan.crossWindow()); - Gate gate = new Gate(checks(scan), mismatches, offLevel, addedLeaks); - System.out.println(gate.line()); - return gate; - } - - private static int openStations(SeaInlet inlet) { - int open = 0; - for (int station = 1; station < inlet.stations(); station++) { - open += inlet.open(station) ? 1 : 0; - } - return open; - } - - private static int maxOpenLandStations(List inlets) { - int most = 0; - for (SeaInlet inlet : inlets) { - most = Math.max(most, openStations(inlet)); - } - return most; - } - - private static double length(SeaInlet inlet) { - double length = 0D; - for (int station = 1; station < inlet.stations(); station++) { - length += Math.hypot(inlet.xs()[station] - inlet.xs()[station - 1], inlet.zs()[station] - inlet.zs()[station - 1]); - } - return length; - } - - private static int mismatches(Map expected, Map observed) { - int mismatches = 0; - for (Map.Entry entry : expected.entrySet()) { - Long other = observed.get(entry.getKey()); - if (other == null || !other.equals(entry.getValue())) { - mismatches++; - if (mismatches <= 8) { - System.out.println("SEA_INLET_MISMATCH chunk=" + chunkX(entry.getKey()) + "," + chunkZ(entry.getKey())); - } - } - } - return mismatches + Math.max(0, observed.size() - expected.size()); - } - - private static long hash(Hunk blocks, Hunk biomes, int height) { - long hash = 0xcbf29ce484222325L; - for (int x = 0; x < 16; x++) { - for (int z = 0; z < 16; z++) { - for (int y = 0; y < height; y++) { - NativeBlockState state = blocks.get(x, y, z); - NativeBiome biome = biomes.get(x, y, z); - hash = (hash ^ (state == null ? 0 : state.key().hashCode())) * 0x100000001b3L; - hash = (hash ^ (biome == null ? 0 : biome.key().hashCode())) * 0x100000001b3L; - } - } - } - return hash; - } - - private static RealPackProbeSupport.Workspace workspace(Configuration configuration, File pack) throws Exception { - return RealPackProbeSupport.openWorkspace(new RealPackProbeSupport.WorkspaceOptions(pack, configuration.dimension(), LOG, null, - configuration.work())); - } - - static long key(int chunkX, int chunkZ) { - return ((long) chunkX << 32) | (chunkZ & 0xFFFFFFFFL); - } - - static int chunkX(long key) { - return (int) (key >> 32); - } - - static int chunkZ(long key) { - return (int) key; - } - - static int addedLeaks(Set on, Set off) { - int added = 0; - for (long leak : on) { - added += off.contains(leak) ? 0 : 1; - } - return added; - } - - static long cellKey(int x, int y, int z) { - return ((long) x & 0x3FFFFFFL) << 38 | ((long) z & 0x3FFFFFFL) << 12 | (y & 0xFFFL); - } - - static byte classify(NativeBlockState state, String seaFluid) { - if (state == null || state.isAir()) { - return AIR; - } - String key = state.key(); - String material = IrisProceduralBlocks.materialKey(state); - if (material.equals(seaFluid)) { - String level = IrisProceduralBlocks.propertyValue(state, "level"); - return level == null || "0".equals(level) ? SOURCE : FLOWING; - } - if (material.equals("minecraft:water") || material.equals("minecraft:lava")) { - return FOREIGN; - } - boolean holdsWater = key.contains("seagrass") || key.contains("kelp") || key.contains("bubble_column") - || "true".equals(IrisProceduralBlocks.propertyValue(state, "waterlogged")); - if (holdsWater) { - return seaFluid.equals("minecraft:water") ? LOGGED : FOREIGN; - } - if (!state.isSolid()) { - return OTHER; - } - return IrisProceduralBlocks.isGravityAffected(state) ? LOOSE : SOLID; - } - - private record Configuration(File packOn, File packOff, String dimension, long seed, int wx0, int wx1, int wz0, int wz1, String mode, - Path work, int threads) { - static Configuration parse(String[] arguments) { - if (arguments.length != 11) { - throw new IllegalArgumentException("Expected: " - + " "); - } - return new Configuration(new File(arguments[0]), new File(arguments[1]), arguments[2], Long.parseLong(arguments[3]), - Integer.parseInt(arguments[4]), Integer.parseInt(arguments[5]), Integer.parseInt(arguments[6]), Integer.parseInt(arguments[7]), - arguments[8], Path.of(arguments[9]), Integer.parseInt(arguments[10])); - } - } - - static final class Band { - final int chunkX; - final int chunkZ; - final int bottom; - final int levels; - final byte[] cells; - final int[] terrain; - final int[] ground; - final int[] skyTop; - final byte[] placed; - - private Band(int chunkX, int chunkZ, int bottom, int levels) { - this.chunkX = chunkX; - this.chunkZ = chunkZ; - this.bottom = bottom; - this.levels = levels; - this.cells = new byte[256 * levels]; - this.placed = new byte[256 * levels]; - this.terrain = new int[256]; - this.ground = new int[256]; - this.skyTop = new int[256]; - } - - static Band capture(Engine engine, Hunk blocks, int chunkX, int chunkZ, int sea, int height) { - Band band = new Band(chunkX, chunkZ, sea - BAND_BELOW, BAND_BELOW + BAND_ABOVE + 1); - String seaFluid = IrisProceduralBlocks.materialKey(engine.getComplex().getFluidStream().get((chunkX << 4) + 8, (chunkZ << 4) + 8)); - for (int lz = 0; lz < 16; lz++) { - for (int lx = 0; lx < 16; lx++) { - int column = lz << 4 | lx; - IrisBiome biome = engine.getComplex().getTrueBiomeStream().get((chunkX << 4) + lx, (chunkZ << 4) + lz); - Set layers = layerKeys(engine, biome); - Set decorations = decorationKeys(engine, biome); - for (int level = 0; level < band.levels; level++) { - NativeBlockState state = blocks.get(lx, band.bottom + level, lz); - band.cells[column * band.levels + level] = classify(state, seaFluid); - if (band.bottom + level <= sea && state != null) { - band.placed[column * band.levels + level] = layers.contains(state.key()) ? SEA_LAYER - : decorations.contains(state.key()) ? DECORATION : 0; - } - } - band.terrain[column] = engine.getMantle().trueHeight((chunkX << 4) + lx, (chunkZ << 4) + lz); - band.ground[column] = -1; - band.skyTop[column] = -1; - int airTop = engine.getComplex().naturalTrueHeight((chunkX << 4) + lx, (chunkZ << 4) + lz); - for (int y = height - 1; y >= 0; y--) { - NativeBlockState state = blocks.get(lx, y, lz); - if (state == null || state.isAir()) { - continue; - } - if (band.skyTop[column] < 0) { - band.skyTop[column] = y; - } - String key = state.key(); - if (y <= airTop && state.isSolid() && !key.contains("leaves") && !key.contains("_log") && !key.contains("_wood") - && !key.contains("mushroom_block") && !key.contains("stem") && !key.contains("vine") && !key.contains("lichen") - && !key.contains("lily_pad") && !key.equals("minecraft:snow") && !key.startsWith("minecraft:snow[")) { - band.ground[column] = y; - break; - } - } - } - } - return band; - } - - byte at(int lx, int y, int lz) { - int level = y - bottom; - if (level < 0 || level >= levels) { - return -1; - } - return cells[(lz << 4 | lx) * levels + level]; - } - - byte placed(int lx, int y, int lz) { - int level = y - bottom; - return level >= 0 && level < levels ? placed[(lz << 4 | lx) * levels + level] : 0; - } - - int layerBottom(int lx, int lz, int floor, int water) { - int bottom = water + 1; - while (bottom - 1 > floor && placed(lx, bottom - 1, lz) == SEA_LAYER) { - bottom--; - } - return bottom; - } - - private static Set layerKeys(Engine engine, IrisBiome biome) { - if (biome == null) { - return Set.of(); - } - return LAYER_KEYS.computeIfAbsent(biome.getLoadKey(), ignored -> { - Set keys = new HashSet<>(); - for (IrisBiomePaletteLayer layer : biome.getSeaLayers()) { - for (NativeBlockState state : layer.getBlockData(engine.getData())) { - keys.add(state.key()); - } - } - return keys; - }); - } - - private static Set decorationKeys(Engine engine, IrisBiome biome) { - if (biome == null) { - return Set.of(); - } - return DECORATION_KEYS.computeIfAbsent(biome.getLoadKey(), ignored -> { - Set keys = new HashSet<>(); - for (IrisDecorator decorator : biome.getDecorators()) { - for (NativeBlockState state : decorator.getBlockData(engine.getData())) { - keys.add(state.key()); - } - for (NativeBlockState state : decorator.getBlockDataTops(engine.getData())) { - keys.add(state.key()); - } - } - for (IrisProceduralPlacement placement : biome.getProceduralObjects().getAllPlacements()) { - for (IrisObject object : placement.getVariantObjects(engine.getData())) { - for (NativeBlockState state : object.getBlocks().values()) { - keys.add(state.key()); - } - } - } - return keys; - }); - } - } - - private static final class Run { - private final String label; - private final Map hashes = new ConcurrentHashMap<>(); - private final Map bands = new ConcurrentHashMap<>(); - private final List order = new ArrayList<>(); - private final Map inlets = new TreeMap<>(); - private final Set scanChunks = new TreeSet<>(); - private int sea; - private int roofClearance; - - private Run(String label) { - this.label = label; - } - } - - private static final class Scan { - private final Run run; - private final int sea; - private final int clearance; - private final List inlets; - private final Map stats = new LinkedHashMap<>(); - private final InletStats total = new InletStats(); - private final List examples = new ArrayList<>(); - private final Map geometry = new HashMap<>(); - private int connected; - private int partial; - private int unconnected; - private int shellCells; - private int shellOpen; - private int shellLoose; - - private Scan(Run run, int sea, int clearance, List inlets) { - this.run = run; - this.sea = sea; - this.clearance = clearance; - this.inlets = inlets; - } - - private void run() { - for (SeaInlet inlet : inlets) { - 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)) { - long key = columnKey(x, z); - int[] known = geometry.get(key); - geometry.put(key, known == null ? new int[]{column[0], column[1]} - : new int[]{Math.min(known[0], column[0]), Math.max(known[1], column[1])}); - } - } - } - } - for (SeaInlet inlet : inlets) { - InletStats inletStats = new InletStats(); - stats.put(inlet.id(), inletStats); - scanInlet(inlet, inletStats); - total.add(inletStats); - } - shell(); - connectivity(); - } - - private void scanInlet(SeaInlet inlet, InletStats stats) { - 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)) { - continue; - } - Band band = band(x, z); - if (band == null) { - throw new IllegalStateException("Inlet " + inlet.id() + " column " + x + "," + z + " was not generated"); - } - stats.columns++; - stats.chunks.add(key(x >> 4, z >> 4)); - stats.windows.add(columnKey(Math.floorDiv(x, WindowKey.SIZE), Math.floorDiv(z, WindowKey.SIZE))); - int floor = column[0]; - int ceiling = column[1]; - boolean open = ceiling == SeaInlet.OPEN; - int layers = open ? band.layerBottom(x & 15, z & 15, floor, inlet.waterLevel()) : inlet.waterLevel() + 1; - if (open && at(x, floor, z) == LOOSE) { - stats.looseBeds++; - } - for (int y = floor + 1; y <= inlet.waterLevel(); y++) { - stats.wet++; - byte cell = at(x, y, z); - if (y >= layers) { - stats.seaLayers++; - continue; - } - if (open && cell != LOGGED && band.placed(x & 15, y, z & 15) == DECORATION) { - stats.decorations++; - continue; - } - if (cell == LOGGED) { - stats.seaPlants++; - } else if (cell != SOURCE) { - stats.missingWater++; - if (cell == FLOWING) { - stats.nonSource++; - } - example("missing water " + cell, x, y, z); - } - for (int[] side : SIDES) { - leak(stats, x, y, z, x + side[0], y, z + side[1]); - } - leak(stats, x, y, z, x, y - 1, z); - } - int lx = x & 15; - int lz = z & 15; - int index = lz << 4 | lx; - int top = open ? Math.min(band.bottom + band.levels - 2, Math.max(inlet.waterLevel(), band.skyTop[index])) : ceiling; - for (int y = inlet.waterLevel() + 1; y <= top; y++) { - stats.dry++; - byte cell = at(x, y, z); - if (cell == SOURCE || cell == FLOWING || cell == LOGGED) { - stats.waterAbove++; - example("water above sea level", x, y, z); - } - if (cell == AIR || cell == OTHER) { - for (int[] side : SIDES) { - airLeak(stats, x, y, z, x + side[0], y, z + side[1]); - } - airLeak(stats, x, y, z, x, y + 1, z); - } - } - int terrain = band.terrain[index]; - if (!open) { - stats.covered++; - int roof = terrain - ceiling; - stats.roofMin = Math.min(stats.roofMin, roof); - if (roof < clearance) { - stats.roofViolations++; - example("roof " + roof, x, ceiling, z); - } - for (int y = ceiling + 1; y <= ceiling + clearance && y <= terrain; y++) { - byte cell = at(x, y, z); - if (cell != SOLID && cell != LOOSE) { - stats.roofBreaches++; - break; - } - } - } else { - stats.open++; - if (band.ground[index] > inlet.waterLevel()) { - stats.openRoofViolations++; - example("ground " + band.ground[index] + " left over the open slot", x, inlet.waterLevel(), z); - } - } - } - } - } - - private void shell() { - Map low = new HashMap<>(); - for (Map.Entry entry : geometry.entrySet()) { - int x = (int) (entry.getKey() >> 32); - int z = (int) (long) entry.getKey(); - for (int dz = -SeaInletRasterizer.SHELL; dz <= SeaInletRasterizer.SHELL; dz++) { - for (int dx = -SeaInletRasterizer.SHELL; dx <= SeaInletRasterizer.SHELL; dx++) { - low.merge(columnKey(x + dx, z + dz), entry.getValue()[0], Math::min); - } - } - } - for (Map.Entry entry : low.entrySet()) { - int x = (int) (entry.getKey() >> 32); - int z = (int) (long) entry.getKey(); - int[] column = geometry.get(entry.getKey()); - int top = column == null ? sea : column[1] == SeaInlet.OPEN ? column[0] - 1 : Math.min(sea, column[0]); - for (int y = entry.getValue() - SeaInletRasterizer.SHELL; y <= top; y++) { - byte cell = at(x, y, z); - shellCells++; - if (cell == AIR || cell == OTHER || cell == FOREIGN) { - shellOpen++; - example("open cell in the seal", x, y, z); - } else if (cell == LOOSE) { - shellLoose++; - example("loose block in the seal", x, y, z); - } - } - } - } - - private void leak(InletStats stats, int x, int y, int z, int nx, int ny, int nz) { - byte cell = at(nx, ny, nz); - if (cell == AIR || cell == OTHER || cell == FOREIGN) { - stats.leaks++; - example("water beside " + (cell == AIR ? "air" : cell == FOREIGN ? "another fluid" : "open block"), x, y, z); - } - } - - private void airLeak(InletStats stats, int x, int y, int z, int nx, int ny, int nz) { - byte cell = at(nx, ny, nz); - if (cell == SOURCE || cell == FLOWING || cell == LOGGED) { - stats.leaks++; - example("inlet air beside water", x, y, z); - } - } - - private void connectivity() { - Map reached = new HashMap<>(); - ArrayDeque queue = new ArrayDeque<>(); - for (Band band : run.bands.values()) { - for (int lz = 0; lz < 16; lz++) { - for (int lx = 0; lx < 16; lx++) { - int x = (band.chunkX << 4) + lx; - int z = (band.chunkZ << 4) + lz; - int columnIndex = lz << 4 | lx; - if (geometry.containsKey(columnKey(x, z)) || band.terrain[columnIndex] >= sea - 2 || band.skyTop[columnIndex] > sea) { - continue; - } - if (band.at(lx, sea - 1, lz) == SOURCE) { - visit(reached, queue, x, sea - 1, z); - } else if (band.placed(lx, sea, lz) == SEA_LAYER) { - visit(reached, queue, x, sea, z); - } - } - } - } - while (!queue.isEmpty()) { - int[] cell = queue.poll(); - int[][] around = {{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}, {0, 1, 0}, {0, -1, 0}}; - for (int[] step : around) { - int x = cell[0] + step[0]; - int y = cell[1] + step[1]; - int z = cell[2] + step[2]; - byte kind = at(x, y, z); - if (kind == SOURCE || kind == FLOWING || kind == LOGGED || frozenSea(x, y, z)) { - visit(reached, queue, x, y, z); - } - } - } - for (SeaInlet inlet : inlets) { - InletStats inletStats = stats.get(inlet.id()); - int[] bounds = SeaInletRasterizer.bounds(inlet); - int[] column = new int[2]; - int wet = 0; - int missing = 0; - 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; - } - for (int y = column[0] + 1; y <= inlet.waterLevel(); y++) { - byte kind = at(x, y, z); - if (kind != SOURCE && kind != FLOWING && kind != LOGGED) { - continue; - } - wet++; - if (!reachedAt(reached, x, y, z)) { - missing++; - } - } - } - } - inletStats.disconnected = missing; - total.disconnected += missing; - if (missing > 0) { - for (int station = 0; station < inlet.stations(); station++) { - int x = Math.round(inlet.xs()[station]); - int z = Math.round(inlet.zs()[station]); - int y = inlet.waterLevel(); - example("inlet " + inlet.id() + " station " + station + " kind " + at(x, y, z) + " reached " + reachedAt(reached, x, y, z), - x, y, z); - } - } - if (missing == 0) { - connected++; - } else if (missing < wet) { - partial++; - } else { - unconnected++; - } - } - } - - private boolean frozenSea(int x, int y, int z) { - Band band = band(x, z); - if (band == null || geometry.containsKey(columnKey(x, z))) { - return false; - } - int columnIndex = (z & 15) << 4 | (x & 15); - return band.terrain[columnIndex] < sea - 2 && band.skyTop[columnIndex] <= sea && band.placed(x & 15, y, z & 15) == SEA_LAYER; - } - - private void visit(Map reached, ArrayDeque queue, int x, int y, int z) { - Band band = band(x, z); - if (band == null) { - return; - } - int level = y - band.bottom; - if (level < 0 || level >= band.levels) { - return; - } - boolean[] seen = reached.computeIfAbsent(key(x >> 4, z >> 4), ignored -> new boolean[256 * band.levels]); - int index = ((z & 15) << 4 | (x & 15)) * band.levels + level; - if (!seen[index]) { - seen[index] = true; - queue.add(new int[]{x, y, z}); - } - } - - private boolean reachedAt(Map reached, int x, int y, int z) { - Band band = band(x, z); - boolean[] seen = reached.get(key(x >> 4, z >> 4)); - if (band == null || seen == null) { - return false; - } - int level = y - band.bottom; - return level >= 0 && level < band.levels && seen[((z & 15) << 4 | (x & 15)) * band.levels + level]; - } - - private Set allLeaks() { - Set leaks = new HashSet<>(); - for (Band band : run.bands.values()) { - for (int lz = 0; lz < 16; lz++) { - for (int lx = 0; lx < 16; lx++) { - int x = (band.chunkX << 4) + lx; - int z = (band.chunkZ << 4) + lz; - for (int level = 1; level < band.levels; level++) { - int y = band.bottom + level; - byte cell = band.at(lx, y, lz); - if (cell != SOURCE) { - continue; - } - boolean open = false; - for (int[] side : SIDES) { - byte neighbour = at(x + side[0], y, z + side[1]); - open |= neighbour == AIR || neighbour == OTHER; - } - byte below = band.at(lx, y - 1, lz); - open |= below == AIR || below == OTHER; - if (open) { - leaks.add(cellKey(x, y, z)); - } - } - } - } - } - return leaks; - } - - private Band band(int x, int z) { - return run.bands.get(key(x >> 4, z >> 4)); - } - - private int crossChunk() { - int crossing = 0; - for (InletStats inletStats : stats.values()) { - crossing += inletStats.chunks.size() > 1 ? 1 : 0; - } - return crossing; - } - - private int crossWindow() { - int crossing = 0; - for (InletStats inletStats : stats.values()) { - crossing += inletStats.windows.size() > 1 ? 1 : 0; - } - return crossing; - } - - private byte at(int x, int y, int z) { - Band band = band(x, z); - return band == null ? -1 : band.at(x & 15, y, z & 15); - } - - private void example(String what, int x, int y, int z) { - if (examples.size() < 40) { - examples.add(what + " at " + x + "," + y + "," + z); - } - } - - private static long columnKey(int x, int z) { - return ((long) x << 32) | (z & 0xFFFFFFFFL); - } - - private static final class InletStats { - private int columns; - private int wet; - private int dry; - private int leaks; - private int missingWater; - private int seaPlants; - private int seaLayers; - private int looseBeds; - private int decorations; - private int nonSource; - private int waterAbove; - private int roofMin = Integer.MAX_VALUE; - private int roofViolations; - private int roofBreaches; - private int openRoofViolations; - private int covered; - private int open; - private int disconnected; - private final Set chunks = new TreeSet<>(); - private final Set windows = new TreeSet<>(); - - private void add(InletStats other) { - columns += other.columns; - wet += other.wet; - dry += other.dry; - leaks += other.leaks; - missingWater += other.missingWater; - seaPlants += other.seaPlants; - seaLayers += other.seaLayers; - looseBeds += other.looseBeds; - decorations += other.decorations; - nonSource += other.nonSource; - waterAbove += other.waterAbove; - roofMin = Math.min(roofMin, other.roofMin); - roofViolations += other.roofViolations; - roofBreaches += other.roofBreaches; - openRoofViolations += other.openRoofViolations; - covered += other.covered; - open += other.open; - disconnected += other.disconnected; - chunks.addAll(other.chunks); - } - } - } -} diff --git a/probe/src/test/java/art/arcane/iris/probe/SeaInletChecksTest.java b/probe/src/test/java/art/arcane/iris/probe/SeaInletChecksTest.java deleted file mode 100644 index fe36fb0ec..000000000 --- a/probe/src/test/java/art/arcane/iris/probe/SeaInletChecksTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package art.arcane.iris.probe; - -import art.arcane.volmlib.nativelib.terrain.NativeBlockState; -import org.junit.Test; - -import java.util.List; -import java.util.Set; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class SeaInletChecksTest { - @Test - public void roofBreachesFailWithTheContainmentSealAndRoofChecks() { - SeaInletProbe.Checks breached = new SeaInletProbe.Checks(3, 0L, 0L, 0L, 0L, 1939L, 0L, 0L, 0L, 0L, 0L, List.of()); - assertEquals(1939L, breached.failures()); - SeaInletProbe.Checks failing = new SeaInletProbe.Checks(3, 1L, 2L, 3L, 4L, 9L, 5L, 6L, 7L, 8L, 0L, List.of()); - assertEquals(45L, failing.failures()); - } - - @Test - public void looseBedsAreReportedButDoNotFail() { - SeaInletProbe.Checks reported = new SeaInletProbe.Checks(3, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 952L, List.of()); - assertEquals(0L, reported.failures()); - } - - @Test - public void theGateFailsOnEveryCheckIncludingOrderSeaLevelAndAddedLeaks() { - SeaInletProbe.Checks clean = new SeaInletProbe.Checks(3, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 952L, List.of()); - SeaInletProbe.Gate passing = new SeaInletProbe.Gate(clean, 0, 0, 0); - assertEquals(0L, passing.failures()); - assertTrue(passing.line(), passing.line().startsWith("SEA_INLET_GATE status=PASS failures=0 ")); - assertEquals(2L, new SeaInletProbe.Gate(clean, 0, 0, 2).failures()); - assertEquals(1L, new SeaInletProbe.Gate(clean, 1, 0, 0).failures()); - assertEquals(1L, new SeaInletProbe.Gate(clean, 0, 1, 0).failures()); - SeaInletProbe.Checks breached = new SeaInletProbe.Checks(3, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 0L, 0L, 0L, List.of()); - SeaInletProbe.Gate failing = new SeaInletProbe.Gate(breached, 0, 0, 0); - assertEquals(4L, failing.failures()); - assertTrue(failing.line(), failing.line().startsWith("SEA_INLET_GATE status=FAIL failures=4 ")); - } - - @Test - public void addedLeaksAreTheLeaksMissingWithoutInlets() { - long kept = SeaInletProbe.cellKey(10, 300, -20); - long removed = SeaInletProbe.cellKey(11, 300, -20); - long added = SeaInletProbe.cellKey(10, 301, -20); - assertEquals(0, SeaInletProbe.addedLeaks(Set.of(kept), Set.of(kept))); - assertEquals("inlets that remove natural leaks do not fail", 0, SeaInletProbe.addedLeaks(Set.of(kept), Set.of(kept, removed))); - assertEquals("a leak the inlets move counts although the totals match", 1, SeaInletProbe.addedLeaks(Set.of(kept, added), - Set.of(kept, removed))); - assertEquals(2, SeaInletProbe.addedLeaks(Set.of(added, removed), Set.of())); - assertNotEquals(SeaInletProbe.cellKey(-1, 300, 0), SeaInletProbe.cellKey(0, 300, -1)); - assertNotEquals(SeaInletProbe.cellKey(5, 0, 5), SeaInletProbe.cellKey(5, 4095, 5)); - } - - @Test - public void inletCellsAreClassifiedAgainstTheDimensionSeaFluid() { - assertEquals(SeaInletProbe.classify(state("minecraft:water"), "minecraft:water"), SeaInletProbe.classify(state("minecraft:lava"), - "minecraft:lava")); - assertEquals(SeaInletProbe.classify(state("minecraft:water[level=8]"), "minecraft:water"), - SeaInletProbe.classify(state("minecraft:lava[level=8]"), "minecraft:lava")); - assertEquals(SeaInletProbe.classify(state("minecraft:lava"), "minecraft:water"), SeaInletProbe.classify(state("minecraft:water"), - "minecraft:lava")); - assertNotEquals(SeaInletProbe.classify(state("minecraft:lava"), "minecraft:lava"), SeaInletProbe.classify(state("minecraft:lava"), - "minecraft:water")); - } - - private static NativeBlockState state(String key) { - NativeBlockState state = mock(NativeBlockState.class); - when(state.key()).thenReturn(key); - return state; - } -}