mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Delete grotto remnants
- Remove SealedPassage, PassageRasterizer, PassageSpace and HydrologyRuntime.passages - Remove the passage loop, passage space and headroom plumbing from mantle and carve - Keep WET_SOURCE and DRY_AIR readable for mantle data already written
This commit is contained in:
18 files changed
+10
-1262
No files matched your search
@@ -19,7 +19,6 @@ 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.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,10 +437,6 @@ public final class HydrologyRuntime {
|
||||
return HydrologyFeatureSearch.channelType(settings, tier);
|
||||
}
|
||||
|
||||
public List<SealedPassage> passages(int chunkX, int chunkZ) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
public Set<HydrologyFeatureType> standingWaterTypes(int chunkX, int chunkZ, long featureId) {
|
||||
if (cache == null) {
|
||||
throw new IllegalStateException("Hydrology is disabled, so it has no standing water.");
|
||||
|
||||
-169
@@ -1,169 +0,0 @@
|
||||
package art.arcane.iris.generation.hydrology.underground;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveAction;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.mantle.MantleWriter;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
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(SealedPassage passage, int chunkX, int chunkZ, MantleWriter writer, String fluid, SubterrainFluid subterrain,
|
||||
HistoricalChunks historical) {
|
||||
if (!touches(passage, chunkX, chunkZ)) {
|
||||
return;
|
||||
}
|
||||
int[] floors = new int[GRID * GRID];
|
||||
int[] ceilings = new int[GRID * GRID];
|
||||
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 = passage.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;
|
||||
int x = (chunkX << 4) + lx;
|
||||
int z = (chunkZ << 4) + lz;
|
||||
int low = nearby(floors, GRID, cell, true);
|
||||
if (low == NONE) {
|
||||
continue;
|
||||
}
|
||||
int floor = floors[cell];
|
||||
if (floor == NONE) {
|
||||
guard(writer, x, low - SHELL, water, 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);
|
||||
writer.clearData(x, y, z, NativeBlockState.class);
|
||||
}
|
||||
for (int y = water + 1; y <= ceilings[cell]; y++) {
|
||||
writer.setData(x, y, z, dry);
|
||||
}
|
||||
guard(writer, x, low - SHELL, floor, z, guard);
|
||||
}
|
||||
int roof = nearbyRoof(ceilings, cell, water);
|
||||
for (int y = water + 1; y <= roof + SHELL; y++) {
|
||||
if (subterrain.at(x, y, z)) {
|
||||
guard(writer, x, y, y, z, guard);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface SubterrainFluid {
|
||||
SubterrainFluid NOWHERE = (x, y, z) -> false;
|
||||
|
||||
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(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;
|
||||
}
|
||||
|
||||
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 (passage.column(originX + gx, originZ + gz, column)) {
|
||||
floors[gz * size + gx] = column[0];
|
||||
ceilings[gz * size + gx] = column[1];
|
||||
any = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return any;
|
||||
}
|
||||
|
||||
static int nearby(int[] values, int size, int cell, boolean lowest) {
|
||||
int found = NONE;
|
||||
int gx = cell % size;
|
||||
int gz = cell / size;
|
||||
for (int dz = -SHELL; dz <= SHELL; dz++) {
|
||||
for (int dx = -SHELL; dx <= SHELL; dx++) {
|
||||
int value = values[(gz + dz) * size + gx + dx];
|
||||
if (value != NONE && (found == NONE || (lowest ? value < found : value > found))) {
|
||||
found = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
private static int nearbyRoof(int[] ceilings, int cell, int water) {
|
||||
int roof = water - SHELL;
|
||||
int gx = cell % GRID;
|
||||
int gz = cell / GRID;
|
||||
for (int dz = -SHELL; dz <= SHELL; dz++) {
|
||||
for (int dx = -SHELL; dx <= SHELL; dx++) {
|
||||
int ceiling = ceilings[(gz + dz) * GRID + gx + dx];
|
||||
if (ceiling > water && ceiling > roof) {
|
||||
roof = ceiling;
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
writer.setData(x, y, z, guard);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package art.arcane.iris.generation.hydrology.underground;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
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;
|
||||
private final int size;
|
||||
private final int[] lows;
|
||||
private final int[] highs;
|
||||
|
||||
private PassageSpace(int originX, int originZ, int size, int[] lows, int[] highs) {
|
||||
this.originX = originX;
|
||||
this.originZ = originZ;
|
||||
this.size = size;
|
||||
this.lows = lows;
|
||||
this.highs = highs;
|
||||
}
|
||||
|
||||
public static PassageSpace of(Collection<SealedPassage> passages, int originX, int originZ, int size) {
|
||||
int[] lows = new int[size * size];
|
||||
int[] highs = new int[size * size];
|
||||
Arrays.fill(lows, NONE);
|
||||
Arrays.fill(highs, NONE);
|
||||
int grid = size + 2 * SHELL;
|
||||
int[] floors = new int[grid * grid];
|
||||
int[] ceilings = new int[grid * grid];
|
||||
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 = PassageRasterizer.nearby(floors, grid, cell, true);
|
||||
if (low == NONE) {
|
||||
continue;
|
||||
}
|
||||
int column = z * size + x;
|
||||
int bottom = low - SHELL;
|
||||
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 PassageSpace(originX, originZ, size, lows, highs);
|
||||
}
|
||||
|
||||
public boolean contains(int x, int y, int z) {
|
||||
int localX = x - originX;
|
||||
int localZ = z - originZ;
|
||||
if (localX < 0 || localX >= size || localZ < 0 || localZ >= size) {
|
||||
return false;
|
||||
}
|
||||
int column = localZ * size + localX;
|
||||
return lows[column] != NONE && y >= lows[column] && y <= highs[column];
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
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.SealedPassage;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public final class CaveCeilingMask {
|
||||
static final int CONTAINMENT = 2;
|
||||
@@ -58,68 +54,6 @@ public final class CaveCeilingMask {
|
||||
return masked;
|
||||
}
|
||||
|
||||
public static long[] headroom(int chunkX, int chunkZ, HydrologyRuntime runtime, long[] bands) {
|
||||
List<SealedPassage> passages = runtime.passages(chunkX, chunkZ);
|
||||
if (passages.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return fillHeadroom(chunkX, chunkZ, passages, bands) ? bands : null;
|
||||
}
|
||||
|
||||
static boolean fillHeadroom(int chunkX, int chunkZ, List<SealedPassage> passages, long[] bands) {
|
||||
if (passages.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 (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 (!passage.column(x, z, column)) {
|
||||
continue;
|
||||
}
|
||||
int index = (z - originZ) * FIELD + x - originX;
|
||||
bottoms[index] = Math.min(bottoms[index], passage.waterLevel() + 1);
|
||||
tops[index] = Math.max(tops[index], column[1] + passage.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
|
||||
|
||||
@@ -5,8 +5,6 @@ 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.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;
|
||||
@@ -23,10 +21,7 @@ import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
final class MantleCarvedTerrain implements CarvedTerrain {
|
||||
private static final int SPAN = 48;
|
||||
@@ -49,7 +44,6 @@ final class MantleCarvedTerrain implements CarvedTerrain {
|
||||
private final SubterrainPlanner planner;
|
||||
private final List<SubterrainPlan> features;
|
||||
private final boolean terrain3D;
|
||||
private final PassageSpace passages;
|
||||
private final MantleChunk<Matter>[] chunks;
|
||||
private final boolean[] existing;
|
||||
private final int[] surfaces = new int[SPAN * SPAN];
|
||||
@@ -71,7 +65,6 @@ final class MantleCarvedTerrain implements CarvedTerrain {
|
||||
this.minimumY = engine.getWorld().minHeight();
|
||||
HydrologyRuntime runtime = complex.getHydrologyRuntime();
|
||||
this.caveFluids = runtime.caveFluidPolicies();
|
||||
this.passages = PassageSpace.of(passages(runtime, chunkX, chunkZ), originX, originZ, SPAN);
|
||||
SubterrainPlanner subterrain = complex.getSubterrainPlanner();
|
||||
List<SubterrainPlan> plans = subterrain == null || subterrain.isEmpty() ? List.of()
|
||||
: subterrain.plansForBounds(originX, originZ, originX + SPAN - 1, originZ + SPAN - 1);
|
||||
@@ -88,7 +81,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) || passages.contains(x, y, z)) {
|
||||
if (y <= 0 || y >= height || existing(x, z) || y > surface(x, z, column)) {
|
||||
return CaveVoxel.FOREIGN;
|
||||
}
|
||||
if (planner != null && planner.sample(features, x, y + minimumY, z).owned()) {
|
||||
@@ -149,18 +142,6 @@ final class MantleCarvedTerrain implements CarvedTerrain {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Collection<SealedPassage> passages(HydrologyRuntime runtime, int chunkX, int chunkZ) {
|
||||
Map<Long, SealedPassage> passages = new LinkedHashMap<>();
|
||||
for (int offsetZ = -1; offsetZ <= 1; offsetZ++) {
|
||||
for (int offsetX = -1; offsetX <= 1; offsetX++) {
|
||||
for (SealedPassage passage : runtime.passages(chunkX + offsetX, chunkZ + offsetZ)) {
|
||||
passages.putIfAbsent(passage.id(), passage);
|
||||
}
|
||||
}
|
||||
}
|
||||
return passages.values();
|
||||
}
|
||||
|
||||
private int surface(int x, int z, int column) {
|
||||
int known = surfaces[column];
|
||||
if (known == UNKNOWN) {
|
||||
|
||||
@@ -169,10 +169,6 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
);
|
||||
int[] caveCeilings = CaveCeilingMask.fill(x, z, complex.getHydrologyRuntime()::raster,
|
||||
blendScratch.caveCeilingField, blendScratch.caveCeilings) ? blendScratch.caveCeilings : null;
|
||||
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) {
|
||||
carveProfile(weightedProfile, writer, x, z, chunkSurfaceHeights, surfaceFluidBoundaries, caveCeilings, fluidSupportPlan);
|
||||
@@ -194,10 +190,10 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
caveCeilings
|
||||
);
|
||||
}
|
||||
rasterizeSubterrain(writer, x, z, complex, caveCeilings, passageHeadroom);
|
||||
rasterizeSubterrain(writer, x, z, complex, caveCeilings);
|
||||
}
|
||||
|
||||
private void rasterizeSubterrain(MantleWriter writer, int chunkX, int chunkZ, IrisComplex complex, int[] caveCeilings, long[] passageHeadroom) {
|
||||
private void rasterizeSubterrain(MantleWriter writer, int chunkX, int chunkZ, IrisComplex complex, int[] caveCeilings) {
|
||||
SubterrainPlanner planner = complex.getSubterrainPlanner();
|
||||
if (planner == null || planner.isEmpty()) {
|
||||
return;
|
||||
@@ -211,7 +207,7 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
if (cell.solid() && !cell.room().reservedSolid()) {
|
||||
return;
|
||||
}
|
||||
if (!cell.solid() && CaveCeilingMask.masked(caveCeilings, passageHeadroom, PowerOfTwoCoordinates.packLocal16(x & 15, z & 15), y)) {
|
||||
if (!cell.solid() && caveCeilings != null && y > caveCeilings[PowerOfTwoCoordinates.packLocal16(x & 15, z & 15)]) {
|
||||
return;
|
||||
}
|
||||
if (cell.solid()) {
|
||||
@@ -767,7 +763,6 @@ 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[] 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];
|
||||
|
||||
@@ -12,8 +12,6 @@ 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.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 +33,6 @@ 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 PassageRasterizer PASSAGES = new PassageRasterizer();
|
||||
|
||||
public MantleHydrologyComponent(EngineMantle engineMantle) {
|
||||
super(engineMantle, ReservedFlag.RIVER_HYDROLOGY, PRIORITY);
|
||||
@@ -84,13 +81,6 @@ public final class MantleHydrologyComponent extends IrisMantleComponent {
|
||||
}
|
||||
HydrologyRuntime runtime = complex.getHydrologyRuntime();
|
||||
ChunkWaterRaster own = CaveCeilingMask.ready(runtime.raster(chunkX, chunkZ), chunkX, chunkZ);
|
||||
List<SealedPassage> 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);
|
||||
if (caveWaterActive()) {
|
||||
HydrologySettings settings = runtime.settings();
|
||||
@@ -107,19 +97,6 @@ public final class MantleHydrologyComponent extends IrisMantleComponent {
|
||||
}
|
||||
}
|
||||
|
||||
private static PassageRasterizer.SubterrainFluid subterrainFluid(MantleWriter writer, IrisComplex complex, int chunkX, int chunkZ) {
|
||||
SubterrainPlanner planner = complex.getSubterrainPlanner();
|
||||
if (planner == null || planner.isEmpty()) {
|
||||
return PassageRasterizer.SubterrainFluid.NOWHERE;
|
||||
}
|
||||
List<SubterrainPlan> plans = planner.plansForBounds(chunkX << 4, chunkZ << 4, (chunkX << 4) + 15, (chunkZ << 4) + 15);
|
||||
if (plans.isEmpty()) {
|
||||
return PassageRasterizer.SubterrainFluid.NOWHERE;
|
||||
}
|
||||
int minimumY = writer.getEngine().getWorld().minHeight();
|
||||
return (x, y, z) -> planner.sample(plans, x, y + minimumY, z).fluid();
|
||||
}
|
||||
|
||||
private void generateFalls(MantleWriter writer, IrisComplex complex, HydrologyRuntime runtime, ChunkWaterRaster own, int chunkX,
|
||||
int chunkZ) {
|
||||
if (!holdsWater(own)) {
|
||||
|
||||
@@ -73,17 +73,6 @@ 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,8 +164,7 @@ 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 ? passageHeadroom(resolverState.complex, x, z) : null
|
||||
subterrain ? caveCeilings(resolverState.complex, x, z) : null
|
||||
);
|
||||
CarveResolver carveResolver = new CarveResolver(resolutionContext);
|
||||
terrain.forEachCell(carveResolver::apply);
|
||||
@@ -263,17 +262,16 @@ 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[] passageHeadroom = passageHeadroom(getComplex(), blockX >> 4, blockZ >> 4);
|
||||
MantleChunk<Matter> chunk = getEngine().getMantle().getMantle().useChunk(blockX >> 4, blockZ >> 4);
|
||||
try {
|
||||
preserveSubterrain(planner, materials, caveCeilings, passageHeadroom, minimumY, blockX, blockZ, output,
|
||||
preserveSubterrain(planner, materials, caveCeilings, 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[] passageHeadroom,
|
||||
private void preserveSubterrain(SubterrainPlanner planner, SubterrainSurfaceMaterials materials, int[] caveCeilings,
|
||||
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;
|
||||
@@ -282,7 +280,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
}
|
||||
int x = worldX & 15;
|
||||
int z = worldZ & 15;
|
||||
if (!cell.solid() && CaveCeilingMask.masked(caveCeilings, passageHeadroom, PowerOfTwoCoordinates.packLocal16(x, z), y)) {
|
||||
if (!cell.solid() && caveCeilings != null && y > caveCeilings[PowerOfTwoCoordinates.packLocal16(x, z)]) {
|
||||
return;
|
||||
}
|
||||
if (hydrology.at(worldX, y, worldZ) != null) {
|
||||
@@ -310,10 +308,6 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
new int[CaveCeilingMask.FIELD * CaveCeilingMask.FIELD], ceilings) ? ceilings : null;
|
||||
}
|
||||
|
||||
private static long[] passageHeadroom(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();
|
||||
@@ -476,7 +470,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() && CaveCeilingMask.masked(context.caveCeilings(), context.passageHeadroom(), columnIndex, y)) {
|
||||
if (!feature.solid() && context.caveCeilings() != null && y > context.caveCeilings()[columnIndex]) {
|
||||
return;
|
||||
}
|
||||
context.output().setRaw(localX, y, localZ, SubterrainRasterizer.state(feature));
|
||||
@@ -566,8 +560,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
int minimumY,
|
||||
IrisComplex complex,
|
||||
SubterrainPlanner.ChunkSampler subterrainSampler,
|
||||
int[] caveCeilings,
|
||||
long[] passageHeadroom
|
||||
int[] caveCeilings
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
-381
@@ -1,381 +0,0 @@
|
||||
package art.arcane.iris.generation.hydrology.underground;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveAction;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.mantle.MantleWriter;
|
||||
import art.arcane.iris.testsupport.TestPassage;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class 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<Long, HydrologyCaveCell> cells = rasterize(List.of(passage(1L, 15f)), order(false));
|
||||
int wetColumns = 0;
|
||||
Map<Long, Integer> tops = new TreeMap<>();
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
int y = y(entry.getKey());
|
||||
HydrologyCaveAction action = entry.getValue().action();
|
||||
if (action == HydrologyCaveAction.WET_SOURCE) {
|
||||
assertTrue("water at " + y, y <= SEA);
|
||||
tops.merge(column(entry.getKey()), y, Math::max);
|
||||
} else if (action == HydrologyCaveAction.DRY_AIR) {
|
||||
assertTrue("air at " + y, y > SEA);
|
||||
}
|
||||
assertEquals(FLUID, entry.getValue().fluidProfileKey());
|
||||
}
|
||||
for (int top : tops.values()) {
|
||||
assertEquals(SEA, top);
|
||||
wetColumns++;
|
||||
}
|
||||
assertTrue("wet columns " + wetColumns, wetColumns > 300);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyWaterCellIsHeldBySealedOrWetNeighbours() {
|
||||
List<TestPassage> passages = List.of(passage(1L, 15f), passage(2L, 30f));
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(passages, order(false));
|
||||
int checked = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
if (entry.getValue().action() != HydrologyCaveAction.WET_SOURCE) {
|
||||
continue;
|
||||
}
|
||||
int x = x(entry.getKey());
|
||||
int y = y(entry.getKey());
|
||||
int z = z(entry.getKey());
|
||||
for (int[] side : new int[][]{{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}, {0, -1, 0}}) {
|
||||
HydrologyCaveCell neighbour = cells.get(key(x + side[0], y + side[1], z + side[2]));
|
||||
assertNotNull("water at " + x + "," + y + "," + z + " has an open side " + side[0] + "," + side[1] + "," + side[2], neighbour);
|
||||
assertTrue(neighbour.action() == HydrologyCaveAction.WET_SOURCE || neighbour.action() == HydrologyCaveAction.SEAL_GUARD);
|
||||
}
|
||||
checked++;
|
||||
}
|
||||
assertTrue(checked > 1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sealKeepsCavesTwoBlocksFromTheWater() {
|
||||
List<TestPassage> passages = List.of(passage(1L, 15f));
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(passages, order(false));
|
||||
int checked = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
if (entry.getValue().action() != HydrologyCaveAction.WET_SOURCE) {
|
||||
continue;
|
||||
}
|
||||
int x = x(entry.getKey());
|
||||
int y = y(entry.getKey());
|
||||
int z = z(entry.getKey());
|
||||
for (int below = 0; below <= CAVE_CLEARANCE; below++) {
|
||||
for (int dz = -CAVE_CLEARANCE; dz <= CAVE_CLEARANCE; dz++) {
|
||||
for (int dx = -CAVE_CLEARANCE; dx <= CAVE_CLEARANCE; dx++) {
|
||||
HydrologyCaveCell held = cells.get(key(x + dx, y - below, z + dz));
|
||||
assertNotNull("no seal at " + (x + dx) + "," + (y - below) + "," + (z + dz) + " near water at " + x + "," + y + "," + z,
|
||||
held);
|
||||
assertTrue(held.action() == HydrologyCaveAction.WET_SOURCE || held.action() == HydrologyCaveAction.SEAL_GUARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cells.get(key(x, y - 1, z)).action() == HydrologyCaveAction.SEAL_GUARD) {
|
||||
for (int under = 1; under <= CAVE_CLEARANCE + 1; under++) {
|
||||
assertEquals("bed and two blocks under the water at " + x + "," + y + "," + z, HydrologyCaveAction.SEAL_GUARD,
|
||||
cells.get(key(x, y - under, z)).action());
|
||||
}
|
||||
}
|
||||
checked++;
|
||||
}
|
||||
assertTrue(checked > 1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subterrainFluidWithinTwoBlocksOfPassageAirAboveSeaLevelIsSealed() {
|
||||
TestPassage passage = passage(1L, 15f);
|
||||
PassageRasterizer.SubterrainFluid flooded = (x, y, z) -> Math.floorMod(x + 2 * z + y, 5) != 0;
|
||||
Map<Long, HydrologyCaveCell> plain = rasterize(List.of(passage), order(false));
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : plain.entrySet()) {
|
||||
assertTrue("without subterrain fluid nothing above sea level is sealed",
|
||||
y(entry.getKey()) <= SEA || entry.getValue().action() == HydrologyCaveAction.DRY_AIR);
|
||||
}
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(passage), order(false), flooded);
|
||||
int checked = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
if (entry.getValue().action() != HydrologyCaveAction.DRY_AIR) {
|
||||
continue;
|
||||
}
|
||||
int x = x(entry.getKey());
|
||||
int y = y(entry.getKey());
|
||||
int z = z(entry.getKey());
|
||||
for (int dy = -2; dy <= 2; dy++) {
|
||||
for (int dz = -2; dz <= 2; dz++) {
|
||||
for (int dx = -2; dx <= 2; dx++) {
|
||||
if (y + dy <= SEA || !flooded.at(x + dx, y + dy, z + dz)) {
|
||||
continue;
|
||||
}
|
||||
HydrologyCaveCell held = cells.get(key(x + dx, y + dy, z + dz));
|
||||
assertNotNull("subterrain fluid at " + (x + dx) + "," + (y + dy) + "," + (z + dz) + " beside passage air at " + x + "," + y
|
||||
+ "," + z, held);
|
||||
assertTrue(held.action() == HydrologyCaveAction.DRY_AIR || held.action() == HydrologyCaveAction.SEAL_GUARD);
|
||||
checked++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int sealed = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
int x = x(entry.getKey());
|
||||
int y = y(entry.getKey());
|
||||
int z = z(entry.getKey());
|
||||
if (y <= SEA || entry.getValue().action() != HydrologyCaveAction.SEAL_GUARD) {
|
||||
continue;
|
||||
}
|
||||
assertTrue("only subterrain fluid is sealed above sea level, not " + x + "," + y + "," + z, flooded.at(x, y, z));
|
||||
assertTrue("the seal at " + x + "," + y + "," + z + " lies within two blocks of passage air", nearAir(cells, x, y, z));
|
||||
sealed++;
|
||||
}
|
||||
assertTrue("checked " + checked, checked > 1000);
|
||||
assertTrue("sealed " + sealed, sealed > 200);
|
||||
assertEquals(cells, rasterize(List.of(passage), order(true), flooded));
|
||||
}
|
||||
|
||||
private static boolean nearAir(Map<Long, HydrologyCaveCell> cells, int x, int y, int z) {
|
||||
for (int dy = -2; dy <= 2; dy++) {
|
||||
for (int dz = -2; dz <= 2; dz++) {
|
||||
for (int dx = -2; dx <= 2; dx++) {
|
||||
HydrologyCaveCell cell = cells.get(key(x + dx, y + dy, z + dz));
|
||||
if (cell != null && cell.action() == HydrologyCaveAction.DRY_AIR) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Test(timeout = 20_000L)
|
||||
public void thinDiagonalPassagesSealTheirBedWithoutRunningAway() {
|
||||
float[] xs = {0f, 8f, 16f, 24f, 32f};
|
||||
float[] zs = {0f, 8f, 16f, 24f, 32f};
|
||||
float[] halfWidth = {0.6f, 0.6f, 0.6f, 0.6f, 0.6f};
|
||||
int[] floor = {SEA - 3, SEA - 3, SEA - 3, SEA - 3, SEA - 3};
|
||||
int[] ceiling = {SEA + 4, SEA + 4, SEA + 4, SEA + 4, SEA + 4};
|
||||
TestPassage thin = new TestPassage(9L, xs, zs, halfWidth, SEA, floor, ceiling, 32, 32, 2);
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(thin), order(false));
|
||||
int wet = 0;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
assertTrue("no cell runs away below the shell", y(entry.getKey()) >= SEA - 3 - CAVE_CLEARANCE - 1);
|
||||
if (entry.getValue().action() == HydrologyCaveAction.WET_SOURCE) {
|
||||
wet++;
|
||||
assertEquals(HydrologyCaveAction.SEAL_GUARD, cells.get(key(x(entry.getKey()), SEA - 3, z(entry.getKey()))).action());
|
||||
}
|
||||
}
|
||||
assertTrue(wet > 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void passageEndingAtAnOldChunkIsSealed() {
|
||||
TestPassage passage = passage(1L, 15f);
|
||||
PassageRasterizer.HistoricalChunks old = (chunkX, chunkZ) -> chunkX == 2;
|
||||
Map<Long, HydrologyCaveCell> open = rasterize(List.of(passage), order(false), PassageRasterizer.SubterrainFluid.NOWHERE,
|
||||
PassageRasterizer.HistoricalChunks.NONE);
|
||||
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(passage), newChunks(order(false), old), PassageRasterizer.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 (!passage.column(x, z, column)) {
|
||||
continue;
|
||||
}
|
||||
assertEquals("without old chunks the seam column " + x + "," + z + " holds water", HydrologyCaveAction.WET_SOURCE,
|
||||
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());
|
||||
}
|
||||
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}}) {
|
||||
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(passage), newChunks(order(true), old), PassageRasterizer.SubterrainFluid.NOWHERE, old));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<int[]> newChunks(List<int[]> chunks, PassageRasterizer.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 chunkOrderAndPassageOrderDoNotChangeTheCells() {
|
||||
List<TestPassage> passages = List.of(passage(1L, 15f), passage(2L, 22f));
|
||||
Map<Long, HydrologyCaveCell> forward = rasterize(passages, order(false));
|
||||
Map<Long, HydrologyCaveCell> reverse = rasterize(List.of(passages.get(1), passages.get(0)), order(true));
|
||||
assertEquals(forward, reverse);
|
||||
assertFalse(forward.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chunksWriteOnlyTheirOwnColumns() {
|
||||
TestPassage passage = passage(1L, 15f);
|
||||
Map<Long, HydrologyCaveCell> cells = new TreeMap<>();
|
||||
MantleWriter writer = writer(cells, 1, 0);
|
||||
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<Long, HydrologyCaveCell> far = new TreeMap<>();
|
||||
new PassageRasterizer().write(passage, 20, 20, writer(far, 20, 20), FLUID, PassageRasterizer.SubterrainFluid.NOWHERE,
|
||||
PassageRasterizer.HistoricalChunks.NONE);
|
||||
assertTrue(far.isEmpty());
|
||||
assertFalse(PassageRasterizer.touches(passage, 20, 20));
|
||||
}
|
||||
|
||||
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];
|
||||
int[] floor = new int[xs.length];
|
||||
int[] ceiling = new int[xs.length];
|
||||
for (int station = 0; station < xs.length; station++) {
|
||||
zs[station] = z + (station % 2 == 0 ? 0f : 3f);
|
||||
halfWidth[station] = 5f - station * 0.4f;
|
||||
floor[station] = SEA - 2 - station % 3;
|
||||
ceiling[station] = SEA + 4 + station % 4;
|
||||
}
|
||||
return new TestPassage(id, xs, zs, halfWidth, SEA, floor, ceiling, 48, (int) z, 7);
|
||||
}
|
||||
|
||||
private static List<int[]> order(boolean reverse) {
|
||||
List<int[]> chunks = new ArrayList<>();
|
||||
for (int chunkZ = -1; chunkZ <= 3; chunkZ++) {
|
||||
for (int chunkX = -2; chunkX <= 4; chunkX++) {
|
||||
chunks.add(new int[]{chunkX, chunkZ});
|
||||
}
|
||||
}
|
||||
if (reverse) {
|
||||
Collections.reverse(chunks);
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
private static Map<Long, HydrologyCaveCell> rasterize(List<TestPassage> passages, List<int[]> chunks) {
|
||||
return rasterize(passages, chunks, PassageRasterizer.SubterrainFluid.NOWHERE);
|
||||
}
|
||||
|
||||
private static Map<Long, HydrologyCaveCell> rasterize(List<TestPassage> passages, List<int[]> chunks, PassageRasterizer.SubterrainFluid subterrain) {
|
||||
return rasterize(passages, chunks, subterrain, PassageRasterizer.HistoricalChunks.NONE);
|
||||
}
|
||||
|
||||
private static Map<Long, HydrologyCaveCell> rasterize(List<TestPassage> passages, List<int[]> chunks, PassageRasterizer.SubterrainFluid subterrain,
|
||||
PassageRasterizer.HistoricalChunks old) {
|
||||
Map<Long, HydrologyCaveCell> cells = new TreeMap<>();
|
||||
PassageRasterizer rasterizer = new PassageRasterizer();
|
||||
for (int[] chunk : chunks) {
|
||||
MantleWriter writer = writer(cells, chunk[0], chunk[1]);
|
||||
for (TestPassage passage : passages) {
|
||||
rasterizer.write(passage, chunk[0], chunk[1], writer, FLUID, subterrain, old);
|
||||
}
|
||||
}
|
||||
return cells;
|
||||
}
|
||||
|
||||
private static MantleWriter writer(Map<Long, HydrologyCaveCell> cells, int chunkX, int chunkZ) {
|
||||
MantleWriter writer = mock(MantleWriter.class);
|
||||
doAnswer(call -> {
|
||||
int x = call.getArgument(0);
|
||||
int z = call.getArgument(2);
|
||||
if (x >> 4 != chunkX || z >> 4 != chunkZ) {
|
||||
throw new AssertionError("chunk " + chunkX + "," + chunkZ + " wrote " + x + "," + z);
|
||||
}
|
||||
cells.put(key(x, call.getArgument(1), z), call.getArgument(3));
|
||||
return null;
|
||||
}).when(writer).setData(anyInt(), anyInt(), anyInt(), any(HydrologyCaveCell.class));
|
||||
when(writer.getDataIfPresent(anyInt(), anyInt(), anyInt(), eq(HydrologyCaveCell.class)))
|
||||
.thenAnswer(call -> cells.get(key(call.getArgument(0), call.getArgument(1), call.getArgument(2))));
|
||||
return writer;
|
||||
}
|
||||
|
||||
private static long key(int x, int y, int z) {
|
||||
return ((long) (x + 4096) << 40) | ((long) (z + 4096) << 20) | (y + 4096);
|
||||
}
|
||||
|
||||
private static long column(long key) {
|
||||
return key >>> 20;
|
||||
}
|
||||
|
||||
private static int x(long key) {
|
||||
return (int) (key >>> 40) - 4096;
|
||||
}
|
||||
|
||||
private static int z(long key) {
|
||||
return (int) ((key >>> 20) & 0xFFFFF) - 4096;
|
||||
}
|
||||
|
||||
private static int y(long key) {
|
||||
return (int) (key & 0xFFFFF) - 4096;
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@ package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.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;
|
||||
@@ -101,99 +99,6 @@ public class CaveCeilingMaskTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
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(passage), 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(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 passage",
|
||||
CaveCeilingMask.masked(null, headroom, index, y));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
expectedMasked = true;
|
||||
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, passage.waterLevel()));
|
||||
assertFalse("caves stay possible above the passage roof at " + x + "," + z,
|
||||
CaveCeilingMask.masked(null, headroom, index, top + 1));
|
||||
if (passage.column(x, z, column)) {
|
||||
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(), 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(passage()), 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 TestPassage passage() {
|
||||
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] = SEA + 4 + station % 4;
|
||||
}
|
||||
return new TestPassage(1L, xs, zs, halfWidth, SEA, floor, ceiling, 48, 6, 7);
|
||||
}
|
||||
|
||||
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 (passage.column(x + dx, z + dz, column)) {
|
||||
top = Math.max(top, column[1] + ROOF_CLEARANCE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
static WaterScene scene(IrisHydrology config) {
|
||||
IntBinaryOperator natural = (x, z) -> 80;
|
||||
return new WaterScene(config, natural)
|
||||
|
||||
@@ -11,9 +11,6 @@ import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.underground.CavePoolFiller;
|
||||
import art.arcane.iris.generation.hydrology.underground.CaveVoxel;
|
||||
import art.arcane.iris.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,48 +186,6 @@ public class MantleCarvedTerrainTest {
|
||||
assertThrows(IllegalStateException.class, () -> carved.voxel(1, 20, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
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));
|
||||
assertEquals("seal under the passage", CaveVoxel.FOREIGN, carved.voxel(10, 24, 21));
|
||||
assertEquals("seal beside the passage", CaveVoxel.FOREIGN, carved.voxel(7, 25, 18));
|
||||
assertEquals(CaveVoxel.SOLID, carved.voxel(7, 23, 18));
|
||||
assertEquals(CaveVoxel.AIR, carved.voxel(7, 25, 17));
|
||||
assertEquals(CaveVoxel.SOLID, carved.voxel(10, 34, 21));
|
||||
assertEquals(CaveVoxel.SOLID, carved.voxel(10, 25, 26));
|
||||
|
||||
Map<Long, HydrologyCaveCell> forward = passageScene().generate(0, 1);
|
||||
Map<Long, HydrologyCaveCell> reverse = passageScene().generate(1, 0);
|
||||
|
||||
assertEquals(forward, reverse);
|
||||
int top = Integer.MIN_VALUE;
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : forward.entrySet()) {
|
||||
if (entry.getValue().action() != HydrologyCaveAction.POOL_SOURCE) {
|
||||
continue;
|
||||
}
|
||||
long cell = entry.getKey();
|
||||
top = Math.max(top, cellY(cell));
|
||||
for (int[] face : FACES) {
|
||||
HydrologyCaveCell neighbour = forward.get(cell(cellX(cell) + face[0], cellY(cell) + face[1], cellZ(cell) + face[2]));
|
||||
assertFalse("pool water at " + cellX(cell) + "," + cellY(cell) + "," + cellZ(cell) + " touches the passage",
|
||||
neighbour != null && HydrologyCaveCell.SEA_FLUID.equals(neighbour.fluidProfileKey()));
|
||||
}
|
||||
}
|
||||
assertEquals("the pool stops one level below the passage seal its next level would reach", 24, top);
|
||||
for (int y = 24; y <= 30; y++) {
|
||||
assertPassage(forward, 7, y, 19, HydrologyCaveAction.SEAL_GUARD);
|
||||
}
|
||||
for (int y = 27; y <= 30; y++) {
|
||||
assertPassage(forward, 7, y, 21, HydrologyCaveAction.WET_SOURCE);
|
||||
}
|
||||
for (int y = 31; y <= 33; y++) {
|
||||
assertPassage(forward, 7, y, 21, HydrologyCaveAction.DRY_AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shallowPoolsUnderVolcanicSurfacesStayWater() {
|
||||
IrisBiome volcanoes = biome("tropical/volcanoes", 0, "lava");
|
||||
@@ -379,35 +334,6 @@ public class MantleCarvedTerrainTest {
|
||||
return region;
|
||||
}
|
||||
|
||||
private static Scene passageScene() {
|
||||
Scene scene = new Scene();
|
||||
Matter[] room = scene.chunk(0, 0);
|
||||
for (int x = 2; x <= 13; x++) {
|
||||
for (int z = 4; z <= 15; z++) {
|
||||
for (int y = 22; y <= 36; y++) {
|
||||
cavern(room, x, y, z, (byte) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Matter[] channel = scene.chunk(0, 1);
|
||||
for (int x = 6; x <= 8; x++) {
|
||||
for (int z = 16; z <= 19; z++) {
|
||||
for (int y = 25; y <= 30; y++) {
|
||||
cavern(channel, x, y, z, (byte) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
scene.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 assertPassage(Map<Long, HydrologyCaveCell> written, int x, int y, int z, HydrologyCaveAction action) {
|
||||
HydrologyCaveCell cell = written.get(cell(x, y, z));
|
||||
assertTrue("passage " + action + " at " + x + "," + y + "," + z + " but found " + cell,
|
||||
cell != null && cell.action() == action && HydrologyCaveCell.SEA_FLUID.equals(cell.fluidProfileKey()));
|
||||
}
|
||||
|
||||
private static long cell(int x, int y, int z) {
|
||||
return ((long) (x + 4096) << 40) | ((long) y << 20) | (z + 4096);
|
||||
}
|
||||
@@ -451,7 +377,6 @@ public class MantleCarvedTerrainTest {
|
||||
private final MantleWriter writer = mock(MantleWriter.class);
|
||||
private final IrisComplex complex = mock(IrisComplex.class);
|
||||
private final Engine engine;
|
||||
private final List<TestPassage> passages = new ArrayList<>();
|
||||
private final Map<Long, HydrologyCaveCell> cells = new HashMap<>();
|
||||
|
||||
private Scene() {
|
||||
@@ -487,7 +412,6 @@ public class MantleCarvedTerrainTest {
|
||||
when(complex.allowsMantleChunkWrite(anyInt(), anyInt())).thenReturn(true);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
when(runtime.caveFluidPolicies()).thenReturn(true);
|
||||
when(runtime.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;
|
||||
@@ -505,27 +429,12 @@ public class MantleCarvedTerrainTest {
|
||||
return new MantleCarvedTerrain(writer, complex, engine, 0, 0);
|
||||
}
|
||||
|
||||
private List<SealedPassage> touching(int chunkX, int chunkZ) {
|
||||
List<SealedPassage> touching = new ArrayList<>();
|
||||
for (TestPassage passage : passages) {
|
||||
if (PassageRasterizer.touches(passage, chunkX, chunkZ)) {
|
||||
touching.add(passage);
|
||||
}
|
||||
}
|
||||
return touching;
|
||||
}
|
||||
|
||||
private Map<Long, HydrologyCaveCell> generate(int... chunkZs) {
|
||||
IrisHydrology config = new IrisHydrology().setEnabled(true);
|
||||
config.getFluids().add(new IrisFluidProfile().setName("lava").setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava")));
|
||||
config.getUnderground().getCavePools().setDensity(8D).setFreeboard(new KList<>(0, 0));
|
||||
HydrologySettings settings = HydrologySettings.compile(config, SEED, 63, 0, 384);
|
||||
PassageRasterizer rasterizer = new PassageRasterizer();
|
||||
for (int chunkZ : chunkZs) {
|
||||
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);
|
||||
}
|
||||
return cells;
|
||||
|
||||
-86
@@ -8,8 +8,6 @@ import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.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;
|
||||
@@ -148,90 +146,6 @@ public class MantleCarvingComponentWaterMaskTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void passageHeadroomJoinsTheProfilePassProtection() throws Exception {
|
||||
TestPassage passage = coveredPassage(32, 40, 40);
|
||||
installPassage(passage);
|
||||
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 (!passage.column(32 + lx, 32 + lz, column)) {
|
||||
continue;
|
||||
}
|
||||
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, passage.waterLevel()));
|
||||
covered++;
|
||||
}
|
||||
}
|
||||
assertTrue("covered columns " + covered, covered > 80);
|
||||
}
|
||||
|
||||
@Test
|
||||
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));
|
||||
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];
|
||||
TestPassage passage = coveredPassage(chunkX << 4, (chunkZ << 4) + 8, water);
|
||||
int[] column = new int[2];
|
||||
int inside = 0;
|
||||
for (int[] cell : open) {
|
||||
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 passage " + inside, inside > 20);
|
||||
|
||||
installPassage(passage);
|
||||
List<int[]> sealed = openedCells(chunkX, chunkZ);
|
||||
assertTrue(sealed.size() > 0);
|
||||
for (int[] cell : sealed) {
|
||||
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 passage headroom", headroom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 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 TestPassage(5L, xs, zs, halfWidth, water, floor, ceiling, startX + 20, z, 3);
|
||||
}
|
||||
|
||||
private List<int[]> openedCells(int chunkX, int chunkZ) {
|
||||
List<int[]> opened = new ArrayList<>();
|
||||
Mantle<Matter> storage = writer.getMantle();
|
||||
|
||||
-70
@@ -9,7 +9,6 @@ import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.underground.CavePoolFiller;
|
||||
import art.arcane.iris.testsupport.TestPassage;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainCell;
|
||||
@@ -262,75 +261,6 @@ public class MantleHydrologyComponentTest {
|
||||
verifyNoInteractions(closed.writer, closed.runtime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void passagesAreWrittenEvenWhereNoSurfaceWaterFlows() {
|
||||
Fixture dry = new Fixture(ChunkWaterRaster.EMPTY, (x, z) -> 99);
|
||||
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.passages(0, 0)).thenReturn(List.of(passage));
|
||||
List<HydrologyCaveCell> written = new ArrayList<>();
|
||||
List<Integer> heights = new ArrayList<>();
|
||||
doAnswer(call -> {
|
||||
written.add(call.getArgument(3));
|
||||
heights.add(call.getArgument(1));
|
||||
return null;
|
||||
}).when(dry.writer).setData(anyInt(), anyInt(), anyInt(), any(HydrologyCaveCell.class));
|
||||
dry.generate();
|
||||
verify(dry.complex, never()).effectiveWaterHeads(anyInt(), anyInt(), any(), any());
|
||||
int wet = 0;
|
||||
for (int index = 0; index < written.size(); index++) {
|
||||
HydrologyCaveCell cell = written.get(index);
|
||||
assertEquals(HydrologyCaveCell.SEA_FLUID, cell.fluidProfileKey());
|
||||
if (cell.action() == HydrologyCaveAction.WET_SOURCE) {
|
||||
wet++;
|
||||
assertTrue(heights.get(index) <= 63);
|
||||
}
|
||||
}
|
||||
assertTrue("wet passage cells " + wet, wet > 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subterrainFluidBesidePassageAirIsSealedAboveSeaLevel() {
|
||||
Fixture dry = new Fixture(ChunkWaterRaster.EMPTY, (x, z) -> 99);
|
||||
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.passages(0, 0)).thenReturn(List.of(passage));
|
||||
SubterrainPlanner planner = mock(SubterrainPlanner.class);
|
||||
List<SubterrainPlan> plans = List.of(mock(SubterrainPlan.class));
|
||||
SubterrainCell water = new SubterrainCell(SubterrainCell.Kind.WATER, "", null);
|
||||
when(planner.isEmpty()).thenReturn(false);
|
||||
when(planner.plansForBounds(0, 0, 15, 15)).thenReturn(plans);
|
||||
when(planner.sample(eq(plans), anyInt(), anyInt(), anyInt())).thenAnswer(call ->
|
||||
(int) call.getArgument(2) == 69 + MINIMUM_Y ? water : SubterrainCell.OUTSIDE);
|
||||
when(dry.complex.getSubterrainPlanner()).thenReturn(planner);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisWorld world = mock(IrisWorld.class);
|
||||
when(dry.writer.getEngine()).thenReturn(engine);
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
when(world.minHeight()).thenReturn(MINIMUM_Y);
|
||||
Map<Long, HydrologyCaveCell> cells = new HashMap<>();
|
||||
doAnswer(call -> {
|
||||
cells.put(cell(call.getArgument(0), call.getArgument(1), call.getArgument(2)), call.getArgument(3));
|
||||
return null;
|
||||
}).when(dry.writer).setData(anyInt(), anyInt(), anyInt(), any(HydrologyCaveCell.class));
|
||||
when(dry.writer.getDataIfPresent(anyInt(), anyInt(), anyInt(), eq(HydrologyCaveCell.class))).thenAnswer(call ->
|
||||
cells.get(cell(call.getArgument(0), call.getArgument(1), call.getArgument(2))));
|
||||
|
||||
dry.generate();
|
||||
|
||||
assertEquals("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)));
|
||||
assertNull("rock beside the passage above sea level", cells.get(cell(8, 70, 13)));
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
|
||||
int y = (int) ((entry.getKey() >>> 20) & 0xFFFFF);
|
||||
if (y > 63 && entry.getValue().action() == HydrologyCaveAction.SEAL_GUARD) {
|
||||
assertEquals(69, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void provisionalRastersFailTheChunk() {
|
||||
Fixture own = new Fixture(ChunkWaterRaster.PROVISIONAL, (x, z) -> 99);
|
||||
|
||||
-26
@@ -16,32 +16,6 @@ public class SurfaceFluidBoundaryPlanTest {
|
||||
private static final int PADDING = 3;
|
||||
private static final int FLUID_HEIGHT = 64;
|
||||
|
||||
@Test
|
||||
public void joinedBandsWidenTheProtectionToCoverBoth() {
|
||||
long none = SurfaceFluidBoundaryPlan.boundary(SurfaceFluidBoundaryPlan.NO_BOUNDARY, Integer.MIN_VALUE);
|
||||
long[] boundaries = new long[CHUNK_SIZE * CHUNK_SIZE];
|
||||
long[] bands = new long[CHUNK_SIZE * CHUNK_SIZE];
|
||||
Arrays.fill(boundaries, none);
|
||||
Arrays.fill(bands, none);
|
||||
boundaries[0] = SurfaceFluidBoundaryPlan.boundary(60, 64);
|
||||
bands[0] = SurfaceFluidBoundaryPlan.boundary(65, 80);
|
||||
bands[1] = SurfaceFluidBoundaryPlan.boundary(70, 75);
|
||||
boundaries[2] = SurfaceFluidBoundaryPlan.boundary(60, 64);
|
||||
|
||||
SurfaceFluidBoundaryPlan.join(boundaries, bands);
|
||||
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries, 0, 59));
|
||||
assertTrue(SurfaceFluidBoundaryPlan.protects(boundaries, 0, 60));
|
||||
assertTrue(SurfaceFluidBoundaryPlan.protects(boundaries, 0, 80));
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries, 0, 81));
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries, 1, 69));
|
||||
assertTrue(SurfaceFluidBoundaryPlan.protects(boundaries, 1, 70));
|
||||
assertTrue(SurfaceFluidBoundaryPlan.protects(boundaries, 1, 75));
|
||||
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries, 1, 76));
|
||||
assertEquals(SurfaceFluidBoundaryPlan.boundary(60, 64), boundaries[2]);
|
||||
assertEquals(none, boundaries[3]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void submergedColumnProtectsItsSeabedWithoutBlockingTheCaveBelow() {
|
||||
Fixture fixture = new Fixture();
|
||||
|
||||
-52
@@ -7,8 +7,6 @@ import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.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;
|
||||
@@ -86,56 +84,6 @@ public class IrisCarveModifierSubterrainMaskTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
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));
|
||||
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];
|
||||
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.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<int[]> sealed = reopenedCells(modifier, planner, blockX, blockZ);
|
||||
assertTrue(sealed.size() > 0);
|
||||
assertEquals("subterrain reopened cells in the passage headroom", List.of(), inHeadroom(passage, sealed));
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> inHeadroom(TestPassage passage, List<int[]> cells) {
|
||||
List<String> inside = new ArrayList<>();
|
||||
int[] column = new int[2];
|
||||
for (int[] cell : cells) {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
|
||||
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 TestPassage(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<>();
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user