mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Seal inlets and headroom
- Seal covered inlet passages with rock where they come within two blocks of a historical chunk - Add inlet headroom bands from the water up to the passage ceiling plus roofClearance to CaveCeilingMask - Join the headroom bands into the carver and orphan sweep protection - Keep subterrain cells out of the headroom bands in carving, the carve resolver and preserveSubterrain - Apply seal guards inside upper-dimension and dimension-stack protected ranges - Add old-chunk seal, headroom mask, carving wiring, subterrain and protected-range tests
This commit is contained in:
1 parent
0ca3a61046
commit
1ae68646b4
14 files changed
+637
-24
No files matched your search
+41
-1
@@ -13,7 +13,8 @@ public final class SeaInletRasterizer {
|
||||
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, String floodedBiome, SubterrainFluid subterrain) {
|
||||
public void write(SeaInlet inlet, int chunkX, int chunkZ, MantleWriter writer, String fluid, String floodedBiome, SubterrainFluid subterrain,
|
||||
HistoricalChunks historical) {
|
||||
if (!touches(inlet, chunkX, chunkZ)) {
|
||||
return;
|
||||
}
|
||||
@@ -26,6 +27,7 @@ public final class SeaInletRasterizer {
|
||||
HydrologyCaveCell dry = new HydrologyCaveCell(HydrologyCaveAction.DRY_AIR, fluid, floodedBiome);
|
||||
HydrologyCaveCell guard = new HydrologyCaveCell(HydrologyCaveAction.SEAL_GUARD, fluid, floodedBiome);
|
||||
int water = inlet.waterLevel();
|
||||
boolean[] historicalAround = historicalAround(chunkX, chunkZ, historical);
|
||||
for (int lz = 0; lz < CHUNK; lz++) {
|
||||
for (int lx = 0; lx < CHUNK; lx++) {
|
||||
int cell = (lz + SHELL) * GRID + lx + SHELL;
|
||||
@@ -40,6 +42,8 @@ public final class SeaInletRasterizer {
|
||||
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 {
|
||||
for (int y = floor + 1; y <= water; y++) {
|
||||
writer.setData(x, y, z, wet);
|
||||
@@ -66,6 +70,12 @@ public final class SeaInletRasterizer {
|
||||
boolean at(int x, int y, int z);
|
||||
}
|
||||
|
||||
public interface HistoricalChunks {
|
||||
HistoricalChunks NONE = (chunkX, chunkZ) -> false;
|
||||
|
||||
boolean at(int chunkX, int chunkZ);
|
||||
}
|
||||
|
||||
public static boolean touches(SeaInlet inlet, int chunkX, int chunkZ) {
|
||||
int[] bounds = bounds(inlet);
|
||||
int minX = chunkX << 4;
|
||||
@@ -182,6 +192,36 @@ public final class SeaInletRasterizer {
|
||||
return roof;
|
||||
}
|
||||
|
||||
private static boolean[] historicalAround(int chunkX, int chunkZ, HistoricalChunks historical) {
|
||||
boolean[] around = null;
|
||||
for (int dz = -1; dz <= 1; dz++) {
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
if ((dx != 0 || dz != 0) && historical.at(chunkX + dx, chunkZ + dz)) {
|
||||
if (around == null) {
|
||||
around = new boolean[9];
|
||||
}
|
||||
around[(dz + 1) * 3 + dx + 1] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return around;
|
||||
}
|
||||
|
||||
private static boolean besideHistorical(boolean[] historicalAround, int lx, int lz) {
|
||||
int fromX = lx < SHELL ? -1 : 0;
|
||||
int toX = lx >= CHUNK - SHELL ? 1 : 0;
|
||||
int fromZ = lz < SHELL ? -1 : 0;
|
||||
int toZ = lz >= CHUNK - SHELL ? 1 : 0;
|
||||
for (int dz = fromZ; dz <= toZ; dz++) {
|
||||
for (int dx = fromX; dx <= toX; dx++) {
|
||||
if (historicalAround[(dz + 1) * 3 + dx + 1]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void guard(MantleWriter writer, int x, int fromY, int toY, int z, HydrologyCaveCell guard) {
|
||||
for (int y = fromY; y <= toY; y++) {
|
||||
if (writer.getDataIfPresent(x, y, z, HydrologyCaveCell.class) == null) {
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
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.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public final class CaveCeilingMask {
|
||||
static final int CONTAINMENT = 2;
|
||||
static final int ROOF = 2;
|
||||
@@ -53,6 +59,69 @@ public final class CaveCeilingMask {
|
||||
return masked;
|
||||
}
|
||||
|
||||
public static long[] headroom(int chunkX, int chunkZ, HydrologyRuntime runtime, long[] bands) {
|
||||
List<SeaInlet> inlets = runtime.inlets(chunkX, chunkZ);
|
||||
if (inlets.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
int roofClearance = runtime.settings().underground().seaInlets().roofClearance();
|
||||
return fillHeadroom(chunkX, chunkZ, inlets, roofClearance, bands) ? bands : null;
|
||||
}
|
||||
|
||||
static boolean fillHeadroom(int chunkX, int chunkZ, List<SeaInlet> inlets, int roofClearance, long[] bands) {
|
||||
if (inlets.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
int originX = (chunkX << 4) - CONTAINMENT;
|
||||
int originZ = (chunkZ << 4) - CONTAINMENT;
|
||||
int[] bottoms = new int[FIELD * FIELD];
|
||||
int[] tops = new int[FIELD * FIELD];
|
||||
Arrays.fill(bottoms, Integer.MAX_VALUE);
|
||||
Arrays.fill(tops, Integer.MIN_VALUE);
|
||||
int[] column = new int[2];
|
||||
boolean roofed = false;
|
||||
for (SeaInlet inlet : inlets) {
|
||||
int[] bounds = SeaInletRasterizer.bounds(inlet);
|
||||
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) {
|
||||
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);
|
||||
roofed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!roofed) {
|
||||
return false;
|
||||
}
|
||||
boolean masked = false;
|
||||
for (int lz = 0; lz < CHUNK; lz++) {
|
||||
for (int lx = 0; lx < CHUNK; lx++) {
|
||||
int bottom = Integer.MAX_VALUE;
|
||||
int top = Integer.MIN_VALUE;
|
||||
for (int fz = lz; fz <= lz + CONTAINMENT * 2; fz++) {
|
||||
for (int fx = lx; fx <= lx + CONTAINMENT * 2; fx++) {
|
||||
bottom = Math.min(bottom, bottoms[fz * FIELD + fx]);
|
||||
top = Math.max(top, tops[fz * FIELD + fx]);
|
||||
}
|
||||
}
|
||||
bands[PowerOfTwoCoordinates.packLocal16(lx, lz)] = SurfaceFluidBoundaryPlan.boundary(bottom, top);
|
||||
masked |= bottom <= top;
|
||||
}
|
||||
}
|
||||
return masked;
|
||||
}
|
||||
|
||||
public static boolean masked(int[] ceilings, long[] headroom, int column, int y) {
|
||||
return ceilings != null && y > ceilings[column] || SurfaceFluidBoundaryPlan.protects(headroom, column, y);
|
||||
}
|
||||
|
||||
public static ChunkWaterRaster ready(ChunkWaterRaster raster, int chunkX, int chunkZ) {
|
||||
if (raster.provisional()) {
|
||||
throw new IllegalStateException("The water raster for chunk " + chunkX + "," + chunkZ
|
||||
|
||||
@@ -169,6 +169,10 @@ 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);
|
||||
}
|
||||
CaveFluidSupportPlan fluidSupportPlan = new CaveFluidSupportPlan();
|
||||
for (WeightedProfile weightedProfile : weightedProfiles) {
|
||||
carveProfile(weightedProfile, writer, x, z, chunkSurfaceHeights, surfaceFluidBoundaries, caveCeilings, fluidSupportPlan);
|
||||
@@ -190,10 +194,10 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
caveCeilings
|
||||
);
|
||||
}
|
||||
rasterizeSubterrain(writer, x, z, complex, caveCeilings);
|
||||
rasterizeSubterrain(writer, x, z, complex, caveCeilings, inletHeadroom);
|
||||
}
|
||||
|
||||
private void rasterizeSubterrain(MantleWriter writer, int chunkX, int chunkZ, IrisComplex complex, int[] caveCeilings) {
|
||||
private void rasterizeSubterrain(MantleWriter writer, int chunkX, int chunkZ, IrisComplex complex, int[] caveCeilings, long[] inletHeadroom) {
|
||||
SubterrainPlanner planner = complex.getSubterrainPlanner();
|
||||
if (planner == null || planner.isEmpty()) {
|
||||
return;
|
||||
@@ -207,7 +211,7 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
if (cell.solid() && !cell.room().reservedSolid()) {
|
||||
return;
|
||||
}
|
||||
if (!cell.solid() && caveCeilings != null && y > caveCeilings[PowerOfTwoCoordinates.packLocal16(x & 15, z & 15)]) {
|
||||
if (!cell.solid() && CaveCeilingMask.masked(caveCeilings, inletHeadroom, PowerOfTwoCoordinates.packLocal16(x & 15, z & 15), y)) {
|
||||
return;
|
||||
}
|
||||
if (cell.solid()) {
|
||||
@@ -763,6 +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 double[][] neighbourHeights = new double[NEIGHBOURS][CHUNK_AREA];
|
||||
private final Object[][] neighbourObjects = new Object[NEIGHBOURS][CHUNK_AREA];
|
||||
private final long[][] neighbourSubmerged = new long[NEIGHBOURS][4];
|
||||
|
||||
@@ -79,7 +79,7 @@ public final class MantleHydrologyComponent extends IrisMantleComponent {
|
||||
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);
|
||||
INLETS.write(inlet, chunkX, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, "", subterrain, complex::isHistoricalChunk);
|
||||
}
|
||||
}
|
||||
generateFalls(writer, complex, runtime, own, chunkX, chunkZ);
|
||||
|
||||
@@ -73,6 +73,17 @@ final class SurfaceFluidBoundaryPlan {
|
||||
}
|
||||
}
|
||||
|
||||
static void join(long[] boundaries, long[] bands) {
|
||||
for (int columnIndex = 0; columnIndex < CHUNK_AREA; columnIndex++) {
|
||||
long band = bands[columnIndex];
|
||||
if (startY(band) > endY(band)) {
|
||||
continue;
|
||||
}
|
||||
long boundary = boundaries[columnIndex];
|
||||
boundaries[columnIndex] = boundary(Math.min(startY(boundary), startY(band)), Math.max(endY(boundary), endY(band)));
|
||||
}
|
||||
}
|
||||
|
||||
static boolean protects(long[] boundaries, int columnIndex, int y) {
|
||||
if (boundaries == null || columnIndex < 0 || columnIndex >= boundaries.length) {
|
||||
return false;
|
||||
|
||||
@@ -164,7 +164,8 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
getEngine().getWorld().minHeight(),
|
||||
resolverState.complex,
|
||||
subterrainPlanner == null ? null : subterrainPlanner.chunkSampler(x, z),
|
||||
subterrain ? caveCeilings(resolverState.complex, x, z) : null
|
||||
subterrain ? caveCeilings(resolverState.complex, x, z) : null,
|
||||
subterrain ? inletHeadroom(resolverState.complex, x, z) : null
|
||||
);
|
||||
CarveResolver carveResolver = new CarveResolver(resolutionContext);
|
||||
terrain.forEachCell(carveResolver::apply);
|
||||
@@ -262,17 +263,18 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
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);
|
||||
MantleChunk<Matter> chunk = getEngine().getMantle().getMantle().useChunk(blockX >> 4, blockZ >> 4);
|
||||
try {
|
||||
preserveSubterrain(planner, materials, caveCeilings, minimumY, blockX, blockZ, output,
|
||||
preserveSubterrain(planner, materials, caveCeilings, inletHeadroom, 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, int minimumY,
|
||||
int blockX, int blockZ, Hunk<NativeBlockState> output, HydrologyCells hydrology) {
|
||||
private void preserveSubterrain(SubterrainPlanner planner, SubterrainSurfaceMaterials materials, int[] caveCeilings, long[] inletHeadroom,
|
||||
int minimumY, int blockX, int blockZ, Hunk<NativeBlockState> output, HydrologyCells hydrology) {
|
||||
SubterrainRasterizer.rasterize(planner, blockX >> 4, blockZ >> 4, (worldX, worldY, worldZ, cell) -> {
|
||||
int y = worldY - minimumY;
|
||||
if (y <= 0 || y >= output.getHeight()) {
|
||||
@@ -280,7 +282,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
}
|
||||
int x = worldX & 15;
|
||||
int z = worldZ & 15;
|
||||
if (!cell.solid() && caveCeilings != null && y > caveCeilings[PowerOfTwoCoordinates.packLocal16(x, z)]) {
|
||||
if (!cell.solid() && CaveCeilingMask.masked(caveCeilings, inletHeadroom, PowerOfTwoCoordinates.packLocal16(x, z), y)) {
|
||||
return;
|
||||
}
|
||||
if (hydrology.at(worldX, y, worldZ) != null) {
|
||||
@@ -308,6 +310,10 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
new int[CaveCeilingMask.FIELD * CaveCeilingMask.FIELD], ceilings) ? ceilings : null;
|
||||
}
|
||||
|
||||
private static long[] inletHeadroom(IrisComplex complex, int chunkX, int chunkZ) {
|
||||
return CaveCeilingMask.headroom(chunkX, chunkZ, complex.getHydrologyRuntime(), new long[256]);
|
||||
}
|
||||
|
||||
private void restoreSubterrainSolids(Hunk<NativeBlockState> output, int chunkX, int chunkZ, boolean preserveFloorSupports,
|
||||
HydrologyCells hydrology) {
|
||||
SubterrainPlanner planner = getComplex().getSubterrainPlanner();
|
||||
@@ -481,7 +487,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
CarveOwnership.Owner owner = carveOwner(hydrology, feature,
|
||||
context.terrainColumns() == null ? null : context.terrainColumns()[columnIndex], y);
|
||||
if (owner == CarveOwnership.Owner.SUBTERRAIN) {
|
||||
if (!feature.solid() && context.caveCeilings() != null && y > context.caveCeilings()[columnIndex]) {
|
||||
if (!feature.solid() && CaveCeilingMask.masked(context.caveCeilings(), context.inletHeadroom(), columnIndex, y)) {
|
||||
return;
|
||||
}
|
||||
context.output().setRaw(localX, y, localZ, SubterrainRasterizer.state(feature));
|
||||
@@ -494,6 +500,14 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
return;
|
||||
}
|
||||
|
||||
if (hydrology != null && hydrology.action() == HydrologyCaveAction.SEAL_GUARD) {
|
||||
NativeBlockState unsealed = context.output().getRaw(localX, y, localZ);
|
||||
NativeBlockState sealed = sealGuardState(unsealed, context.chunkContext().getRock().get(localX, localZ));
|
||||
if (sealed != unsealed) {
|
||||
context.output().setRaw(localX, y, localZ, sealed);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (context.upperSurfaceHeights() != null && y >= context.upperSurfaceHeights()[columnIndex]) {
|
||||
return;
|
||||
}
|
||||
@@ -506,13 +520,6 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
return;
|
||||
}
|
||||
NativeBlockState current = context.output().getRaw(localX, y, localZ);
|
||||
if (hydrology != null && hydrology.action() == HydrologyCaveAction.SEAL_GUARD) {
|
||||
NativeBlockState sealed = sealGuardState(current, context.chunkContext().getRock().get(localX, localZ));
|
||||
if (sealed != current) {
|
||||
context.output().setRaw(localX, y, localZ, sealed);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
MatterCavern cavern = composeCavern(baseline, hydrology);
|
||||
if (cavern == null || shouldPreserveExistingFluid(cavern, current)) {
|
||||
@@ -570,7 +577,8 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
int minimumY,
|
||||
IrisComplex complex,
|
||||
SubterrainPlanner.ChunkSampler subterrainSampler,
|
||||
int[] caveCeilings
|
||||
int[] caveCeilings,
|
||||
long[] inletHeadroom
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -351,7 +351,8 @@ public class HydrologyRuntimeTest {
|
||||
written.put(((long) x << 40) ^ ((long) (int) call.getArgument(2) << 20) ^ (int) call.getArgument(1), cell);
|
||||
return null;
|
||||
}).when(writer).setData(anyInt(), anyInt(), anyInt(), any(HydrologyCaveCell.class));
|
||||
new SeaInletRasterizer().write(tail.getFirst(), 68, 25, writer, HydrologyCaveCell.SEA_FLUID, "", SeaInletRasterizer.SubterrainFluid.NOWHERE);
|
||||
new SeaInletRasterizer().write(tail.getFirst(), 68, 25, writer, HydrologyCaveCell.SEA_FLUID, "", SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
assertTrue("the chunk past the owner window writes inlet water",
|
||||
written.values().stream().anyMatch(cell -> cell.action() == HydrologyCaveAction.WET_SOURCE));
|
||||
|
||||
|
||||
+88
-3
@@ -258,6 +258,84 @@ public class SeaInletRasterizerTest {
|
||||
assertTrue(wet > 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void passageEndingAtAnOldChunkIsSealed() {
|
||||
SeaInlet inlet = inlet(1L, 15f);
|
||||
SeaInletRasterizer.HistoricalChunks old = (chunkX, chunkZ) -> chunkX == 2;
|
||||
Map<Long, HydrologyCaveCell> open = rasterize(List.of(inlet), order(false), SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(inlet), newChunks(order(false), old), SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
old);
|
||||
int[] column = new int[2];
|
||||
int seamColumns = 0;
|
||||
for (int z = -16; z <= 63; z++) {
|
||||
for (int x = -32; x <= 79; x++) {
|
||||
if (old.at(x >> 4, z >> 4) || !nearOldChunk(old, x, z)) {
|
||||
continue;
|
||||
}
|
||||
if (!SeaInletRasterizer.column(inlet, x, z, column) || column[1] == SeaInlet.OPEN) {
|
||||
continue;
|
||||
}
|
||||
assertEquals("without old chunks the seam column " + x + "," + z + " holds water", HydrologyCaveAction.WET_SOURCE,
|
||||
open.get(key(x, inlet.waterLevel(), z)).action());
|
||||
for (int y = column[0] - SeaInletRasterizer.SHELL; y <= column[1]; y++) {
|
||||
HydrologyCaveCell sealed = cells.get(key(x, y, z));
|
||||
assertNotNull("no seal at " + x + "," + y + "," + z + " beside the old chunk", sealed);
|
||||
assertEquals("seal at " + x + "," + y + "," + z + " beside the old chunk", HydrologyCaveAction.SEAL_GUARD, sealed.action());
|
||||
}
|
||||
seamColumns++;
|
||||
}
|
||||
}
|
||||
int wet = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
int x = x(entry.getKey());
|
||||
int y = y(entry.getKey());
|
||||
int z = z(entry.getKey());
|
||||
assertFalse("old chunk " + (x >> 4) + "," + (z >> 4) + " was written", old.at(x >> 4, z >> 4));
|
||||
HydrologyCaveAction action = entry.getValue().action();
|
||||
if (action == HydrologyCaveAction.SEAL_GUARD) {
|
||||
continue;
|
||||
}
|
||||
assertFalse(action + " at " + x + "," + y + "," + z + " lies within two blocks of an old chunk", nearOldChunk(old, x, z));
|
||||
if (action != HydrologyCaveAction.WET_SOURCE) {
|
||||
continue;
|
||||
}
|
||||
for (int[] side : new int[][]{{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}, {0, -1, 0}}) {
|
||||
if (paintedSlot(List.of(inlet), x + side[0], y + side[1], z + side[2])) {
|
||||
continue;
|
||||
}
|
||||
HydrologyCaveCell neighbour = cells.get(key(x + side[0], y + side[1], z + side[2]));
|
||||
assertNotNull("water at " + x + "," + y + "," + z + " has an open side " + side[0] + "," + side[1] + "," + side[2], neighbour);
|
||||
assertTrue(neighbour.action() == HydrologyCaveAction.WET_SOURCE || neighbour.action() == HydrologyCaveAction.SEAL_GUARD);
|
||||
}
|
||||
wet++;
|
||||
}
|
||||
assertTrue("covered seam columns " + seamColumns, seamColumns > 10);
|
||||
assertTrue("water cells away from the old chunks " + wet, wet > 300);
|
||||
assertEquals(cells, rasterize(List.of(inlet), newChunks(order(true), old), SeaInletRasterizer.SubterrainFluid.NOWHERE, old));
|
||||
}
|
||||
|
||||
private static boolean nearOldChunk(SeaInletRasterizer.HistoricalChunks old, int x, int z) {
|
||||
for (int dz = -SeaInletRasterizer.SHELL; dz <= SeaInletRasterizer.SHELL; dz++) {
|
||||
for (int dx = -SeaInletRasterizer.SHELL; dx <= SeaInletRasterizer.SHELL; dx++) {
|
||||
if (old.at((x + dx) >> 4, (z + dz) >> 4)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<int[]> newChunks(List<int[]> chunks, SeaInletRasterizer.HistoricalChunks old) {
|
||||
List<int[]> fresh = new ArrayList<>();
|
||||
for (int[] chunk : chunks) {
|
||||
if (!old.at(chunk[0], chunk[1])) {
|
||||
fresh.add(chunk);
|
||||
}
|
||||
}
|
||||
return fresh;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chunkOrderAndInletOrderDoNotChangeTheCells() {
|
||||
List<SeaInlet> inlets = List.of(inlet(1L, 15f), inlet(2L, 22f));
|
||||
@@ -272,14 +350,16 @@ public class SeaInletRasterizerTest {
|
||||
SeaInlet inlet = inlet(1L, 15f);
|
||||
Map<Long, HydrologyCaveCell> cells = new TreeMap<>();
|
||||
MantleWriter writer = writer(cells, 1, 0);
|
||||
new SeaInletRasterizer().write(inlet, 1, 0, writer, FLUID, "", SeaInletRasterizer.SubterrainFluid.NOWHERE);
|
||||
new SeaInletRasterizer().write(inlet, 1, 0, writer, FLUID, "", SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
assertFalse(cells.isEmpty());
|
||||
for (long key : cells.keySet()) {
|
||||
assertEquals(1, x(key) >> 4);
|
||||
assertEquals(0, z(key) >> 4);
|
||||
}
|
||||
Map<Long, HydrologyCaveCell> far = new TreeMap<>();
|
||||
new SeaInletRasterizer().write(inlet, 20, 20, writer(far, 20, 20), FLUID, "", SeaInletRasterizer.SubterrainFluid.NOWHERE);
|
||||
new SeaInletRasterizer().write(inlet, 20, 20, writer(far, 20, 20), FLUID, "", SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
assertTrue(far.isEmpty());
|
||||
assertFalse(SeaInletRasterizer.touches(inlet, 20, 20));
|
||||
}
|
||||
@@ -317,12 +397,17 @@ public class SeaInletRasterizerTest {
|
||||
}
|
||||
|
||||
private static Map<Long, HydrologyCaveCell> rasterize(List<SeaInlet> inlets, List<int[]> chunks, SeaInletRasterizer.SubterrainFluid subterrain) {
|
||||
return rasterize(inlets, chunks, subterrain, SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
}
|
||||
|
||||
private static Map<Long, HydrologyCaveCell> rasterize(List<SeaInlet> inlets, List<int[]> chunks, SeaInletRasterizer.SubterrainFluid subterrain,
|
||||
SeaInletRasterizer.HistoricalChunks old) {
|
||||
Map<Long, HydrologyCaveCell> cells = new TreeMap<>();
|
||||
SeaInletRasterizer rasterizer = new SeaInletRasterizer();
|
||||
for (int[] chunk : chunks) {
|
||||
MantleWriter writer = writer(cells, chunk[0], chunk[1]);
|
||||
for (SeaInlet inlet : inlets) {
|
||||
rasterizer.write(inlet, chunk[0], chunk[1], writer, FLUID, "", subterrain);
|
||||
rasterizer.write(inlet, chunk[0], chunk[1], writer, FLUID, "", subterrain, old);
|
||||
}
|
||||
}
|
||||
return cells;
|
||||
|
||||
@@ -2,11 +2,14 @@ package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.testsupport.WaterScene;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
|
||||
@@ -17,6 +20,9 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CaveCeilingMaskTest {
|
||||
private static final int UNMASKED = CaveCeilingMask.UNMASKED;
|
||||
private static final int SEA = 63;
|
||||
private static final int ROOF_CLEARANCE = 6;
|
||||
private static final int NO_ROOF = Integer.MIN_VALUE;
|
||||
|
||||
@Test
|
||||
public void cavesStopTwoBlocksBelowEveryBedAndColumnsWithinTwoBlocksTakeTheLowestCeiling() {
|
||||
@@ -95,6 +101,99 @@ public class CaveCeilingMaskTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cavesStayOutOfInletHeadroom() {
|
||||
SeaInlet inlet = inlet();
|
||||
int[] bounds = SeaInletRasterizer.bounds(inlet);
|
||||
long[] bands = new long[256];
|
||||
int[] column = new int[2];
|
||||
int covered = 0;
|
||||
int around = 0;
|
||||
for (int chunkZ = (bounds[1] >> 4) - 1; chunkZ <= (bounds[3] >> 4) + 1; chunkZ++) {
|
||||
for (int chunkX = (bounds[0] >> 4) - 1; chunkX <= (bounds[2] >> 4) + 1; chunkX++) {
|
||||
boolean masked = CaveCeilingMask.fillHeadroom(chunkX, chunkZ, List.of(inlet), ROOF_CLEARANCE, bands);
|
||||
long[] headroom = masked ? bands : null;
|
||||
boolean expectedMasked = false;
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
int x = (chunkX << 4) + lx;
|
||||
int z = (chunkZ << 4) + lz;
|
||||
int index = PowerOfTwoCoordinates.packLocal16(lx, lz);
|
||||
int top = highestRoofWithinTwo(inlet, x, z);
|
||||
if (top == NO_ROOF) {
|
||||
for (int y = 0; y <= SEA + 64; y++) {
|
||||
assertFalse("caves stay possible at " + x + "," + y + "," + z + " away from the inlet",
|
||||
CaveCeilingMask.masked(null, headroom, index, y));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
expectedMasked = true;
|
||||
for (int y = inlet.waterLevel() + 1; y <= top; y++) {
|
||||
assertTrue("caves stay out of the inlet headroom and roof at " + x + "," + y + "," + z,
|
||||
CaveCeilingMask.masked(null, headroom, index, y));
|
||||
}
|
||||
assertFalse("the seal holds caves at the water level " + x + "," + z,
|
||||
CaveCeilingMask.masked(null, headroom, index, inlet.waterLevel()));
|
||||
assertFalse("caves stay possible above the inlet roof at " + x + "," + z,
|
||||
CaveCeilingMask.masked(null, headroom, index, top + 1));
|
||||
if (SeaInletRasterizer.column(inlet, x, z, column) && column[1] != SeaInlet.OPEN) {
|
||||
covered++;
|
||||
} else {
|
||||
around++;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertEquals("headroom flag for chunk " + chunkX + "," + chunkZ, expectedMasked, masked);
|
||||
}
|
||||
}
|
||||
assertTrue("covered columns " + covered, covered > 300);
|
||||
assertTrue("columns around the passage " + around, around > 100);
|
||||
assertFalse(CaveCeilingMask.fillHeadroom(0, 0, List.of(), ROOF_CLEARANCE, bands));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headroomJoinsTheWaterCeilings() {
|
||||
int[] ceilings = new int[256];
|
||||
Arrays.fill(ceilings, UNMASKED);
|
||||
ceilings[3] = 40;
|
||||
long[] bands = new long[256];
|
||||
assertTrue(CaveCeilingMask.fillHeadroom(0, 0, List.of(inlet()), ROOF_CLEARANCE, bands));
|
||||
int index = PowerOfTwoCoordinates.packLocal16(12, 6);
|
||||
assertTrue(CaveCeilingMask.masked(ceilings, null, 3, 41));
|
||||
assertFalse(CaveCeilingMask.masked(ceilings, null, 3, 40));
|
||||
assertFalse(CaveCeilingMask.masked(ceilings, bands, index, SEA));
|
||||
assertTrue(CaveCeilingMask.masked(ceilings, bands, index, SEA + 1));
|
||||
assertFalse(CaveCeilingMask.masked(null, null, index, SEA + 1));
|
||||
}
|
||||
|
||||
private static SeaInlet inlet() {
|
||||
float[] xs = {-8f, 0f, 8f, 16f, 24f, 32f, 40f, 48f};
|
||||
float[] zs = new float[xs.length];
|
||||
float[] halfWidth = new float[xs.length];
|
||||
int[] floor = new int[xs.length];
|
||||
int[] ceiling = new int[xs.length];
|
||||
for (int station = 0; station < xs.length; station++) {
|
||||
zs[station] = 6f + (station % 2 == 0 ? 0f : 3f);
|
||||
halfWidth[station] = 5f - station * 0.4f;
|
||||
floor[station] = SEA - 2 - station % 3;
|
||||
ceiling[station] = station < 2 ? SeaInlet.OPEN : SEA + 4 + station % 4;
|
||||
}
|
||||
return new SeaInlet(1L, xs, zs, halfWidth, SEA, floor, ceiling, 48, 6, 7);
|
||||
}
|
||||
|
||||
private static int highestRoofWithinTwo(SeaInlet inlet, int x, int z) {
|
||||
int top = NO_ROOF;
|
||||
int[] column = new int[2];
|
||||
for (int dz = -CaveCeilingMask.CONTAINMENT; dz <= CaveCeilingMask.CONTAINMENT; dz++) {
|
||||
for (int dx = -CaveCeilingMask.CONTAINMENT; dx <= CaveCeilingMask.CONTAINMENT; dx++) {
|
||||
if (SeaInletRasterizer.column(inlet, x + dx, z + dz, column) && column[1] != SeaInlet.OPEN) {
|
||||
top = Math.max(top, column[1] + ROOF_CLEARANCE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
static WaterScene scene(IrisHydrology config) {
|
||||
IntBinaryOperator natural = (x, z) -> 80;
|
||||
return new WaterScene(config, natural)
|
||||
|
||||
@@ -441,7 +441,8 @@ public class MantleCarvedTerrainTest {
|
||||
SeaInletRasterizer rasterizer = new SeaInletRasterizer();
|
||||
for (int chunkZ : chunkZs) {
|
||||
for (SeaInlet inlet : complex.getHydrologyRuntime().inlets(0, chunkZ)) {
|
||||
rasterizer.write(inlet, 0, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, "", SeaInletRasterizer.SubterrainFluid.NOWHERE);
|
||||
rasterizer.write(inlet, 0, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, "", SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
}
|
||||
new CavePoolFiller(settings).fill(0, chunkZ, () -> new MantleCarvedTerrain(writer, complex, engine, 0, chunkZ), writer, SEED);
|
||||
}
|
||||
|
||||
+106
@@ -4,8 +4,12 @@ import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.block.B;
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.context.ChunkContext;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.EngineMetrics;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
@@ -21,6 +25,7 @@ import art.arcane.iris.world.IrisWorld;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.Before;
|
||||
@@ -34,6 +39,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -47,6 +53,7 @@ import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class MantleCarvingComponentWaterMaskTest {
|
||||
private static final int ROOF_CLEARANCE = 6;
|
||||
private Engine engine;
|
||||
private MantleCarvingComponent component;
|
||||
private IrisDimension dimension;
|
||||
@@ -141,6 +148,105 @@ public class MantleCarvingComponentWaterMaskTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inletHeadroomJoinsTheProfilePassProtection() throws Exception {
|
||||
SeaInlet inlet = coveredInlet(32, 40, 40);
|
||||
installInlet(inlet);
|
||||
IrisCaveCarver3D carver = installProfile();
|
||||
List<long[]> boundaries = new ArrayList<>();
|
||||
doAnswer(call -> {
|
||||
boundaries.add(((long[]) call.getArgument(8)).clone());
|
||||
return 0;
|
||||
}).when(carver).carve(any(), anyInt(), anyInt(), any(), anyDouble(), anyDouble(), any(), any(), any(), any(), any(), any());
|
||||
|
||||
component.generateLayer(writer, 2, 2, context);
|
||||
|
||||
assertEquals(1, boundaries.size());
|
||||
int[] column = new int[2];
|
||||
int covered = 0;
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
int index = PowerOfTwoCoordinates.packLocal16(lx, lz);
|
||||
if (!SeaInletRasterizer.column(inlet, 32 + lx, 32 + lz, column)) {
|
||||
continue;
|
||||
}
|
||||
for (int y = inlet.waterLevel() + 1; y <= column[1] + ROOF_CLEARANCE; y++) {
|
||||
assertTrue("the carver keeps out of the inlet headroom at " + (32 + lx) + "," + y + "," + (32 + lz),
|
||||
SurfaceFluidBoundaryPlan.protects(boundaries.getFirst(), index, y));
|
||||
}
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries.getFirst(), index, inlet.waterLevel()));
|
||||
covered++;
|
||||
}
|
||||
}
|
||||
assertTrue("covered columns " + covered, covered > 80);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subterrainFeaturesStayOutOfInletHeadroom() {
|
||||
IrisSubterrainFeature feature = new IrisSubterrainFeature().setId("room").setFamily(IrisSubterrainFamily.CENOTE)
|
||||
.setProbability(1).setLength(64).setRadius(12).setHeight(24).setPillarSpacing(0).setFormationFraction(0)
|
||||
.setWorldYRange(new IrisRange(-48, 60));
|
||||
SubterrainPlanner planner = new SubterrainPlanner(new SubterrainPlanner.Options(List.of(feature), 83L, -64, 128, (x, z) -> "region"));
|
||||
SubterrainPlan plan = planner.plansForBounds(-512, -512, 512, 512).getFirst();
|
||||
int chunkX = plan.centerX() >> 4;
|
||||
int chunkZ = plan.centerZ() >> 4;
|
||||
when(complex.getSubterrainPlanner()).thenReturn(planner);
|
||||
try (MockedStatic<B> blocks = mockStatic(B.class)) {
|
||||
blocks.when(() -> B.getState(anyString())).thenReturn(mock(NativeBlockState.class));
|
||||
List<int[]> open = openedCells(chunkX, chunkZ);
|
||||
int[] heights = open.stream().mapToInt(cell -> cell[1]).sorted().toArray();
|
||||
int water = heights[heights.length / 4];
|
||||
SeaInlet inlet = coveredInlet(chunkX << 4, (chunkZ << 4) + 8, water);
|
||||
int[] column = new int[2];
|
||||
int inside = 0;
|
||||
for (int[] cell : open) {
|
||||
if (SeaInletRasterizer.column(inlet, cell[0], cell[2], column) && cell[1] > water && cell[1] <= column[1] + ROOF_CLEARANCE) {
|
||||
inside++;
|
||||
}
|
||||
}
|
||||
assertTrue("subterrain cells in the headroom before the inlet " + inside, inside > 20);
|
||||
|
||||
installInlet(inlet);
|
||||
List<int[]> sealed = openedCells(chunkX, chunkZ);
|
||||
assertTrue(sealed.size() > 0);
|
||||
for (int[] cell : sealed) {
|
||||
boolean headroom = SeaInletRasterizer.column(inlet, cell[0], cell[2], column) && cell[1] > water
|
||||
&& cell[1] <= column[1] + ROOF_CLEARANCE;
|
||||
assertFalse("subterrain opened " + cell[0] + "," + cell[1] + "," + cell[2] + " in the inlet headroom", headroom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void installInlet(SeaInlet inlet) {
|
||||
when(hydrology.inlets(anyInt(), anyInt())).thenAnswer(call -> SeaInletRasterizer.touches(inlet, call.getArgument(0), call.getArgument(1))
|
||||
? List.of(inlet) : List.of());
|
||||
when(hydrology.settings()).thenReturn(HydrologySettings.compile(new IrisHydrology().setEnabled(true), 1L, 63, 0, 128));
|
||||
}
|
||||
|
||||
private static SeaInlet coveredInlet(int startX, int z, int water) {
|
||||
float[] xs = {startX - 4f, startX + 4f, startX + 12f, startX + 20f};
|
||||
float[] zs = {z, z, z, z};
|
||||
float[] halfWidth = {4f, 4f, 3.5f, 3f};
|
||||
int[] floor = {water - 3, water - 3, water - 3, water - 3};
|
||||
int[] ceiling = {water + 5, water + 5, water + 4, water + 4};
|
||||
return new SeaInlet(5L, xs, zs, halfWidth, water, floor, ceiling, startX + 20, z, 3);
|
||||
}
|
||||
|
||||
private List<int[]> openedCells(int chunkX, int chunkZ) {
|
||||
List<int[]> opened = new ArrayList<>();
|
||||
Mantle<Matter> storage = writer.getMantle();
|
||||
MantleWriter capture = mock(MantleWriter.class);
|
||||
when(capture.getMantle()).thenReturn(storage);
|
||||
doAnswer(call -> {
|
||||
if (call.getArgument(3) instanceof MatterCavern) {
|
||||
opened.add(new int[]{call.getArgument(0), call.getArgument(1), call.getArgument(2)});
|
||||
}
|
||||
return null;
|
||||
}).when(capture).setData(anyInt(), anyInt(), anyInt(), any());
|
||||
component.generateLayer(capture, chunkX, chunkZ, context);
|
||||
return opened;
|
||||
}
|
||||
|
||||
private List<Integer> openedHeights(int chunkX, int chunkZ) {
|
||||
List<Integer> opened = new ArrayList<>();
|
||||
Mantle<Matter> storage = writer.getMantle();
|
||||
|
||||
+26
@@ -16,6 +16,32 @@ public class SurfaceFluidBoundaryPlanTest {
|
||||
private static final int PADDING = 3;
|
||||
private static final int FLUID_HEIGHT = 64;
|
||||
|
||||
@Test
|
||||
public void joinedBandsWidenTheProtectionToCoverBoth() {
|
||||
long none = SurfaceFluidBoundaryPlan.boundary(SurfaceFluidBoundaryPlan.NO_BOUNDARY, Integer.MIN_VALUE);
|
||||
long[] boundaries = new long[CHUNK_SIZE * CHUNK_SIZE];
|
||||
long[] bands = new long[CHUNK_SIZE * CHUNK_SIZE];
|
||||
Arrays.fill(boundaries, none);
|
||||
Arrays.fill(bands, none);
|
||||
boundaries[0] = SurfaceFluidBoundaryPlan.boundary(60, 64);
|
||||
bands[0] = SurfaceFluidBoundaryPlan.boundary(65, 80);
|
||||
bands[1] = SurfaceFluidBoundaryPlan.boundary(70, 75);
|
||||
boundaries[2] = SurfaceFluidBoundaryPlan.boundary(60, 64);
|
||||
|
||||
SurfaceFluidBoundaryPlan.join(boundaries, bands);
|
||||
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries, 0, 59));
|
||||
assertTrue(SurfaceFluidBoundaryPlan.protects(boundaries, 0, 60));
|
||||
assertTrue(SurfaceFluidBoundaryPlan.protects(boundaries, 0, 80));
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries, 0, 81));
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries, 1, 69));
|
||||
assertTrue(SurfaceFluidBoundaryPlan.protects(boundaries, 1, 70));
|
||||
assertTrue(SurfaceFluidBoundaryPlan.protects(boundaries, 1, 75));
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries, 1, 76));
|
||||
assertEquals(SurfaceFluidBoundaryPlan.boundary(60, 64), boundaries[2]);
|
||||
assertEquals(none, boundaries[3]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void submergedColumnProtectsItsSeabedWithoutBlockingTheCaveBelow() {
|
||||
Fixture fixture = new Fixture();
|
||||
|
||||
+88
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.stage;
|
||||
|
||||
import art.arcane.iris.generation.context.ChunkContext;
|
||||
import art.arcane.iris.generation.context.ChunkedDataCache;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveAction;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
@@ -10,6 +12,7 @@ import art.arcane.iris.generation.hydrology.underground.CarvedTerrain;
|
||||
import art.arcane.iris.generation.mantle.CarveOwnership;
|
||||
import art.arcane.iris.generation.mantle.CaveTerrainSnapshot;
|
||||
import art.arcane.iris.generation.mantle.MantleWriter;
|
||||
import art.arcane.iris.generation.runtime.DimensionStackLayout;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.subterrain.IrisSubterrainFamily;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainCell;
|
||||
@@ -30,9 +33,12 @@ import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.RecordComponent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -62,6 +68,7 @@ public class IrisCarveModifierHydrologyTest {
|
||||
private static final int SECTIONS = 4;
|
||||
private static final int POOL_FLOOR = 50;
|
||||
private static final int POOL_TOP = 52;
|
||||
private static final int PROTECTED_FROM = 40;
|
||||
|
||||
@BeforeClass
|
||||
public static void registerMatter() {
|
||||
@@ -198,6 +205,87 @@ public class IrisCarveModifierHydrologyTest {
|
||||
assertSame(water, IrisCarveModifier.sealGuardState(water, rock));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sealGuardsHoldInsideProtectedUpperAndStackRanges() throws Exception {
|
||||
NativeBlockState rock = new KeyedBlockState("minecraft:stone");
|
||||
NativeBlockState caveAir = new KeyedBlockState("minecraft:cave_air");
|
||||
NativeBlockState air = mock(NativeBlockState.class);
|
||||
when(air.isAir()).thenReturn(true);
|
||||
NativeBlockState granite = solid("minecraft:granite");
|
||||
int[] upperSurface = new int[256];
|
||||
Arrays.fill(upperSurface, PROTECTED_FROM);
|
||||
DimensionStackLayout layout = mock(DimensionStackLayout.class);
|
||||
when(layout.isHostFeatureProtectedY(anyInt())).thenAnswer(call -> call.<Integer>getArgument(0) >= PROTECTED_FROM);
|
||||
DimensionStackLayout[] stack = new DimensionStackLayout[256];
|
||||
Arrays.fill(stack, layout);
|
||||
for (boolean upper : new boolean[]{true, false}) {
|
||||
String range = upper ? "upper-dimension range" : "dimension-stack range";
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, SECTIONS * 16, 16);
|
||||
for (int y : new int[]{PROTECTED_FROM - 2, PROTECTED_FROM + 2}) {
|
||||
output.setRaw(3, y, 4, air);
|
||||
output.setRaw(3, y + 1, 4, granite);
|
||||
output.setRaw(3, y + 2, 4, granite);
|
||||
}
|
||||
CarveCall apply = resolver(output, rock, caveAir, upper ? upperSurface : null, upper ? null : stack);
|
||||
for (int y : new int[]{PROTECTED_FROM - 2, PROTECTED_FROM + 2}) {
|
||||
apply.at(3, y, 4, null, HydrologyCaveCell.of(HydrologyCaveAction.SEAL_GUARD));
|
||||
apply.at(3, y + 1, 4, null, HydrologyCaveCell.of(HydrologyCaveAction.DRY_AIR));
|
||||
apply.at(3, y + 2, 4, new MatterCavern(true, "", (byte) 0), null);
|
||||
}
|
||||
assertSame("a seal guard below the " + range + " seals", rock, output.getRaw(3, PROTECTED_FROM - 2, 4));
|
||||
assertSame("inlet air below the " + range + " opens", caveAir, output.getRaw(3, PROTECTED_FROM - 1, 4));
|
||||
assertSame("a seal guard inside the " + range + " still seals", rock, output.getRaw(3, PROTECTED_FROM + 2, 4));
|
||||
assertSame("inlet air does not open inside the " + range, granite, output.getRaw(3, PROTECTED_FROM + 3, 4));
|
||||
assertSame("caves do not open inside the " + range, granite, output.getRaw(3, PROTECTED_FROM + 4, 4));
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface CarveCall {
|
||||
void at(int x, int y, int z, MatterCavern baseline, HydrologyCaveCell hydrology) throws Exception;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static CarveCall resolver(Hunk<NativeBlockState> output, NativeBlockState rock, NativeBlockState air, int[] upperSurface,
|
||||
DimensionStackLayout[] stack) throws Exception {
|
||||
ChunkContext chunkContext = mock(ChunkContext.class);
|
||||
ChunkedDataCache<NativeBlockState> rocks = mock(ChunkedDataCache.class);
|
||||
when(rocks.get(anyInt(), anyInt())).thenReturn(rock);
|
||||
when(chunkContext.getRock()).thenReturn(rocks);
|
||||
IrisCarveScratch scratch = new IrisCarveScratch();
|
||||
Map<String, Object> values = new HashMap<>();
|
||||
values.put("output", output);
|
||||
values.put("chunkContext", chunkContext);
|
||||
values.put("scratch", scratch);
|
||||
values.put("columnMasks", scratch.columnMasks);
|
||||
values.put("upperSurfaceHeights", upperSurface);
|
||||
values.put("stackLayouts", stack);
|
||||
values.put("worldHeightSpan", SECTIONS * 16);
|
||||
Class<?> contextType = Class.forName(IrisCarveModifier.class.getName() + "$CarveResolutionContext");
|
||||
RecordComponent[] components = contextType.getRecordComponents();
|
||||
Class<?>[] types = new Class<?>[components.length];
|
||||
Object[] arguments = new Object[components.length];
|
||||
for (int index = 0; index < components.length; index++) {
|
||||
types[index] = components[index].getType();
|
||||
arguments[index] = values.containsKey(components[index].getName()) ? values.get(components[index].getName())
|
||||
: types[index] == int.class ? 0 : null;
|
||||
}
|
||||
Constructor<?> contextConstructor = contextType.getDeclaredConstructor(types);
|
||||
contextConstructor.setAccessible(true);
|
||||
Object context = contextConstructor.newInstance(arguments);
|
||||
IrisCarveModifier modifier = mock(IrisCarveModifier.class, CALLS_REAL_METHODS);
|
||||
Field airField = IrisCarveModifier.class.getDeclaredField("AIR");
|
||||
airField.setAccessible(true);
|
||||
airField.set(modifier, air);
|
||||
Class<?> resolverType = Class.forName(IrisCarveModifier.class.getName() + "$CarveResolver");
|
||||
Constructor<?> resolverConstructor = resolverType.getDeclaredConstructor(IrisCarveModifier.class, contextType);
|
||||
resolverConstructor.setAccessible(true);
|
||||
Object resolver = resolverConstructor.newInstance(modifier, context);
|
||||
Method apply = resolverType.getDeclaredMethod("apply", int.class, int.class, int.class, MatterCavern.class, HydrologyCaveCell.class);
|
||||
apply.setAccessible(true);
|
||||
return (x, y, z, baseline, hydrology) -> apply.invoke(resolver, x, y, z, baseline, hydrology);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subterrainRoomsNeverTakeAnyInletCell() {
|
||||
SubterrainRoom room = new SubterrainRoom("room", "", IrisSubterrainFamily.CENOTE, 0, 0, 0, 0, 0, 0, -10, 10, 1D, 0, false, false,
|
||||
|
||||
+74
@@ -3,8 +3,12 @@ package art.arcane.iris.generation.stage;
|
||||
import art.arcane.iris.generation.block.B;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveAction;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.mantle.EngineMantle;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
@@ -32,6 +36,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -48,6 +53,7 @@ import static org.mockito.Mockito.when;
|
||||
public class IrisCarveModifierSubterrainMaskTest {
|
||||
private static final int MINIMUM_Y = -64;
|
||||
private static final int ROOF = 2;
|
||||
private static final int ROOF_CLEARANCE = 6;
|
||||
|
||||
@Test
|
||||
public void preservedSubterrainNeverReopensACellAboveTheCaveCeiling() {
|
||||
@@ -80,6 +86,74 @@ public class IrisCarveModifierSubterrainMaskTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preservedSubterrainStaysOutOfInletHeadroom() {
|
||||
IrisSubterrainFeature feature = new IrisSubterrainFeature().setId("room").setFamily(IrisSubterrainFamily.CENOTE)
|
||||
.setProbability(1).setLength(64).setRadius(12).setHeight(24).setPillarSpacing(0).setFormationFraction(0)
|
||||
.setWorldYRange(new IrisRange(-48, 60));
|
||||
SubterrainPlanner planner = new SubterrainPlanner(new SubterrainPlanner.Options(List.of(feature), 83L, MINIMUM_Y, 128, (x, z) -> "region"));
|
||||
SubterrainPlan plan = planner.plansForBounds(-512, -512, 512, 512).getFirst();
|
||||
int blockX = plan.centerX() >> 4 << 4;
|
||||
int blockZ = plan.centerZ() >> 4 << 4;
|
||||
HydrologyRuntime hydrology = mock(HydrologyRuntime.class);
|
||||
when(hydrology.raster(anyInt(), anyInt())).thenReturn(ChunkWaterRaster.EMPTY);
|
||||
IrisCarveModifier modifier = modifier(planner, hydrology);
|
||||
try (MockedStatic<B> blocks = mockStatic(B.class)) {
|
||||
blocks.when(() -> B.getState(anyString())).thenReturn(mock(NativeBlockState.class));
|
||||
List<int[]> open = reopenedCells(modifier, planner, blockX, blockZ);
|
||||
int[] heights = open.stream().mapToInt(cell -> cell[1]).sorted().toArray();
|
||||
int water = heights[heights.length / 4];
|
||||
SeaInlet inlet = coveredInlet(blockX, blockZ + 8, water);
|
||||
assertTrue("subterrain cells in the headroom before the inlet " + inHeadroom(inlet, open).size(), inHeadroom(inlet, open).size() > 20);
|
||||
|
||||
when(hydrology.inlets(anyInt(), anyInt())).thenAnswer(call -> SeaInletRasterizer.touches(inlet, call.getArgument(0),
|
||||
call.getArgument(1)) ? List.of(inlet) : List.of());
|
||||
when(hydrology.settings()).thenReturn(HydrologySettings.compile(new IrisHydrology().setEnabled(true), 1L, 63, 0, 128));
|
||||
List<int[]> sealed = reopenedCells(modifier, planner, blockX, blockZ);
|
||||
assertTrue(sealed.size() > 0);
|
||||
assertEquals("subterrain reopened cells in the inlet headroom", List.of(), inHeadroom(inlet, sealed));
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> inHeadroom(SeaInlet inlet, List<int[]> cells) {
|
||||
List<String> inside = new ArrayList<>();
|
||||
int[] column = new int[2];
|
||||
for (int[] cell : cells) {
|
||||
if (SeaInletRasterizer.column(inlet, cell[0], cell[2], column) && cell[1] > inlet.waterLevel()
|
||||
&& cell[1] <= column[1] + ROOF_CLEARANCE) {
|
||||
inside.add(cell[0] + "," + cell[1] + "," + cell[2]);
|
||||
}
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
|
||||
private static SeaInlet coveredInlet(int startX, int z, int water) {
|
||||
float[] xs = {startX - 4f, startX + 4f, startX + 12f, startX + 20f};
|
||||
float[] zs = {z, z, z, z};
|
||||
float[] halfWidth = {4f, 4f, 3.5f, 3f};
|
||||
int[] floor = {water - 3, water - 3, water - 3, water - 3};
|
||||
int[] ceiling = {water + 5, water + 5, water + 4, water + 4};
|
||||
return new SeaInlet(5L, xs, zs, halfWidth, water, floor, ceiling, startX + 20, z, 3);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<int[]> reopenedCells(IrisCarveModifier modifier, SubterrainPlanner planner, int blockX, int blockZ) {
|
||||
List<int[]> open = new ArrayList<>();
|
||||
Hunk<NativeBlockState> output = mock(Hunk.class);
|
||||
when(output.getHeight()).thenReturn(128);
|
||||
doAnswer(call -> {
|
||||
int x = blockX + (int) call.getArgument(0);
|
||||
int y = call.getArgument(1);
|
||||
int z = blockZ + (int) call.getArgument(2);
|
||||
if (!planner.sample(x, y + MINIMUM_Y, z).solid()) {
|
||||
open.add(new int[]{x, y, z});
|
||||
}
|
||||
return null;
|
||||
}).when(output).setRaw(anyInt(), anyInt(), anyInt(), any());
|
||||
modifier.preserveSubterrain(blockX, blockZ, output);
|
||||
return open;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preservedSubterrainLeavesEveryInletCellAlone() {
|
||||
IrisSubterrainFeature feature = new IrisSubterrainFeature().setId("room").setFamily(IrisSubterrainFamily.CENOTE)
|
||||
|
||||
Reference in new issue
Block a user