mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Key cave pool walls
- Cave pool walls carry the pool's fluid key instead of the unknown default profile - A wall shared by two pools keeps the lowest fluid key, whatever the chunk order - The carve waterlogging pass resolves a fluid only for wet hydrology cells - Tests cover unknown-fluid logging for pool walls and shared-wall chunk-order independence
This commit is contained in:
1 parent
bb6f3ca40b
commit
8bc1ed760e
4 files changed
+214
-8
No files matched your search
+9
-3
@@ -21,7 +21,6 @@ public final class CavePoolFiller {
|
||||
private static final long SALT_FLOOR = 0x4341564652L << 20;
|
||||
private static final long SALT_FREEBOARD = 0x43415646524244L;
|
||||
private static final long SALT_DENSITY = 0x43415644454e53L;
|
||||
private static final HydrologyCaveCell GUARD = HydrologyCaveCell.of(HydrologyCaveAction.SEAL_GUARD);
|
||||
private static final CaveVoxel[] VOXELS = CaveVoxel.values();
|
||||
private static final int[] DX = {1, -1, 0, 0, 0, 0};
|
||||
private static final int[] DY = {0, 0, 0, 0, 1, -1};
|
||||
@@ -144,6 +143,7 @@ public final class CavePoolFiller {
|
||||
|
||||
private static void write(int chunkX, int chunkZ, Pool pool, MantleWriter writer) {
|
||||
HydrologyCaveCell wet = new HydrologyCaveCell(HydrologyCaveAction.POOL_SOURCE, pool.fluid(), "");
|
||||
HydrologyCaveCell wall = new HydrologyCaveCell(HydrologyCaveAction.SEAL_GUARD, pool.fluid(), "");
|
||||
for (int offsetX = -1; offsetX <= 1; offsetX++) {
|
||||
for (int offsetZ = -1; offsetZ <= 1; offsetZ++) {
|
||||
int targetX = chunkX + offsetX;
|
||||
@@ -151,7 +151,7 @@ public final class CavePoolFiller {
|
||||
if (pool.touches(targetX, targetZ)) {
|
||||
writer.withChunkFence(targetX, targetZ, () -> {
|
||||
writeCells(targetX, targetZ, pool.cells(), wet, writer);
|
||||
writeCells(targetX, targetZ, pool.walls(), GUARD, writer);
|
||||
writeCells(targetX, targetZ, pool.walls(), wall, writer);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -166,12 +166,18 @@ public final class CavePoolFiller {
|
||||
continue;
|
||||
}
|
||||
int y = unpackY(cell);
|
||||
if (writer.getDataIfPresent(x, y, z, HydrologyCaveCell.class) == null) {
|
||||
HydrologyCaveCell existing = writer.getDataIfPresent(x, y, z, HydrologyCaveCell.class);
|
||||
if (existing == null || replacesSharedWall(existing, value)) {
|
||||
writer.setData(x, y, z, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean replacesSharedWall(HydrologyCaveCell existing, HydrologyCaveCell value) {
|
||||
return existing.action() == HydrologyCaveAction.SEAL_GUARD && value.action() == HydrologyCaveAction.SEAL_GUARD
|
||||
&& value.fluidProfileKey().compareTo(existing.fluidProfileKey()) < 0;
|
||||
}
|
||||
|
||||
private String fluid(CarvedTerrain carved, int x, int y, int z) {
|
||||
String policy = carved.caveFluid(x, y, z);
|
||||
return policy != null ? policy : pools.fluid();
|
||||
|
||||
@@ -1184,11 +1184,9 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
}
|
||||
MatterCavern baseline = terrain.cavern(localX, y, localZ);
|
||||
NativeBlockState current = output.getRaw(localX, y, localZ);
|
||||
NativeBlockState columnFluid = getComplex().resolveCaveCellFluid(
|
||||
hydrology.fluidProfileKey(),
|
||||
worldX,
|
||||
worldZ
|
||||
);
|
||||
NativeBlockState columnFluid = hydrology.isWet()
|
||||
? getComplex().resolveCaveCellFluid(hydrology.fluidProfileKey(), worldX, worldZ)
|
||||
: null;
|
||||
NativeBlockState normalized = normalizeHydrologyWaterlogging(
|
||||
current,
|
||||
baseline,
|
||||
|
||||
+20
@@ -188,6 +188,26 @@ public class CavePoolFillerTest {
|
||||
assertNoMixedBodies(forward);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wallsSharedByTwoFluidsKeepOneKeyWhateverTheChunkOrder() {
|
||||
VoxelWorld world = room(0, 14, 0, 15, FLOOR, 52);
|
||||
world.carve(16, 30, 0, 15, FLOOR, 52);
|
||||
world.policyFluid(x -> x >= 16 ? "lava" : null);
|
||||
HydrologySettings settings = settings(pools -> pools.setDensity(8D).setFreeboard(new KList<>(0, 0)));
|
||||
|
||||
Map<Long, HydrologyCaveCell> forward = new HashMap<>();
|
||||
Map<Long, HydrologyCaveCell> reverse = new HashMap<>();
|
||||
new CavePoolFiller(settings).fill(0, 0, () -> world, writer(forward), SEED);
|
||||
new CavePoolFiller(settings).fill(1, 0, () -> world, writer(forward), SEED);
|
||||
new CavePoolFiller(settings).fill(1, 0, () -> world, writer(reverse), SEED);
|
||||
new CavePoolFiller(settings).fill(0, 0, () -> world, writer(reverse), SEED);
|
||||
|
||||
assertFalse(wetCells(forward, "water").isEmpty());
|
||||
assertFalse(wetCells(forward, "lava").isEmpty());
|
||||
assertGuard(forward, 15, 51, 8);
|
||||
assertEquals(forward, reverse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void depressionsSpanningTwoCaveFluidsGetNoPool() {
|
||||
VoxelWorld mixed = roomWithSill();
|
||||
|
||||
+182
@@ -2,25 +2,71 @@ package art.arcane.iris.generation.stage;
|
||||
|
||||
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.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.underground.CavePoolFiller;
|
||||
import art.arcane.iris.generation.hydrology.underground.CaveVoxel;
|
||||
import art.arcane.iris.generation.hydrology.underground.CarvedTerrain;
|
||||
import art.arcane.iris.generation.mantle.CaveTerrainSnapshot;
|
||||
import art.arcane.iris.generation.mantle.MantleWriter;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.subterrain.IrisSubterrainFamily;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainCell;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainRoom;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.LogLevel;
|
||||
import art.arcane.iris.testsupport.KeyedBlockState;
|
||||
import art.arcane.iris.world.storage.matter.IrisMatterSupport;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.IrisMatter;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
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.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.withSettings;
|
||||
|
||||
public class IrisCarveModifierHydrologyTest {
|
||||
private static final long SEED = 1337L;
|
||||
private static final int SECTIONS = 4;
|
||||
private static final int POOL_FLOOR = 50;
|
||||
private static final int POOL_TOP = 52;
|
||||
|
||||
@BeforeClass
|
||||
public static void registerMatter() {
|
||||
IrisMatterSupport.ensureRegistered();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitHydrologyCanMaterializeIntoAnUninitializedCell() {
|
||||
NativeBlockState air = mock(NativeBlockState.class);
|
||||
@@ -170,10 +216,146 @@ public class IrisCarveModifierHydrologyTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void poolWallsResolveNoUnknownFluid() throws Exception {
|
||||
IrisHydrology config = new IrisHydrology().setEnabled(true);
|
||||
config.getUnderground().getCavePools().setDensity(1D).setFreeboard(new KList<>(0, 0));
|
||||
Map<Long, HydrologyCaveCell> written = new HashMap<>();
|
||||
new CavePoolFiller(HydrologySettings.compile(config, SEED, 63, 0, 384))
|
||||
.fill(0, 0, SealedRoom::new, recordingWriter(written), SEED);
|
||||
Matter[] sections = new Matter[SECTIONS];
|
||||
Set<String> wallFluids = new HashSet<>();
|
||||
for (Map.Entry<Long, HydrologyCaveCell> entry : written.entrySet()) {
|
||||
HydrologyCaveCell cell = entry.getValue();
|
||||
if (cell.action() == HydrologyCaveAction.SEAL_GUARD) {
|
||||
wallFluids.add(cell.fluidProfileKey());
|
||||
}
|
||||
int x = x(entry.getKey());
|
||||
int y = y(entry.getKey());
|
||||
int z = z(entry.getKey());
|
||||
if (x >> 4 == 0 && z >> 4 == 0) {
|
||||
section(sections, y).slice(HydrologyCaveCell.class).set(x, y & 15, z, cell);
|
||||
}
|
||||
}
|
||||
section(sections, POOL_TOP + 1).slice(HydrologyCaveCell.class)
|
||||
.set(0, (POOL_TOP + 1) & 15, 0, HydrologyCaveCell.of(HydrologyCaveAction.SEAL_GUARD));
|
||||
CaveTerrainSnapshot terrain = CaveTerrainSnapshot.capture(chunk(sections), 0, 0);
|
||||
IrisCarveModifier.CaveZone zone = new IrisCarveModifier.CaveZone();
|
||||
zone.setFloor(POOL_FLOOR);
|
||||
zone.setCeiling(POOL_TOP);
|
||||
IrisCarveModifier modifier = mock(IrisCarveModifier.class, CALLS_REAL_METHODS);
|
||||
doReturn(complexWithWater()).when(modifier).getComplex();
|
||||
Method normalize = IrisCarveModifier.class.getDeclaredMethod("normalizeCaveZoneWaterlogging", Hunk.class,
|
||||
CaveTerrainSnapshot.class, IrisCarveModifier.CaveZone.class, int.class, int.class, int.class, int.class);
|
||||
normalize.setAccessible(true);
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, SECTIONS * 16, 16);
|
||||
|
||||
List<String> logged = new ArrayList<>();
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
doAnswer(invocation -> {
|
||||
logged.add(invocation.getArgument(0) + " " + invocation.getArgument(1));
|
||||
return null;
|
||||
}).when(platform).log(any(LogLevel.class), anyString());
|
||||
IrisPlatforms.bind(platform);
|
||||
try {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
normalize.invoke(modifier, output, terrain, zone, x, z, x, z);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
IrisPlatforms.unbind();
|
||||
}
|
||||
|
||||
assertEquals(List.of(), logged.stream().filter(line -> line.contains("unknown fluid profile")).distinct().toList());
|
||||
assertEquals("pool walls carry the pool's fluid", Set.of("water"), wallFluids);
|
||||
}
|
||||
|
||||
private static IrisComplex complexWithWater() throws Exception {
|
||||
IrisComplex complex = mock(IrisComplex.class, CALLS_REAL_METHODS);
|
||||
setField(complex, "waterFluidStreams", Map.of("water", mock(ProceduralStream.class)));
|
||||
setField(complex, "fluidStream", mock(ProceduralStream.class));
|
||||
return complex;
|
||||
}
|
||||
|
||||
private static void setField(Object target, String name, Object value) throws Exception {
|
||||
Field field = IrisComplex.class.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
field.set(target, value);
|
||||
}
|
||||
|
||||
private static MantleWriter recordingWriter(Map<Long, HydrologyCaveCell> written) {
|
||||
MantleWriter writer = mock(MantleWriter.class);
|
||||
doAnswer(invocation -> written.put(key(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2)),
|
||||
invocation.getArgument(3))).when(writer).setData(anyInt(), anyInt(), anyInt(), any());
|
||||
when(writer.getDataIfPresent(anyInt(), anyInt(), anyInt(), eq(HydrologyCaveCell.class))).thenAnswer(invocation ->
|
||||
written.get(key(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2))));
|
||||
doAnswer(invocation -> {
|
||||
invocation.<Runnable>getArgument(2).run();
|
||||
return null;
|
||||
}).when(writer).withChunkFence(anyInt(), anyInt(), any(Runnable.class));
|
||||
return writer;
|
||||
}
|
||||
|
||||
private static Matter section(Matter[] sections, int y) {
|
||||
if (sections[y >> 4] == null) {
|
||||
sections[y >> 4] = new IrisMatter(16, 16, 16);
|
||||
}
|
||||
return sections[y >> 4];
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static MantleChunk<Matter> chunk(Matter[] sections) {
|
||||
MantleChunk<Matter> chunk = mock(MantleChunk.class, withSettings().stubOnly());
|
||||
when(chunk.sectionCount()).thenReturn(sections.length);
|
||||
when(chunk.exists(anyInt())).thenAnswer(call -> sections[call.<Integer>getArgument(0)] != null);
|
||||
when(chunk.get(anyInt())).thenAnswer(call -> sections[call.<Integer>getArgument(0)]);
|
||||
return chunk;
|
||||
}
|
||||
|
||||
private static long key(int x, int y, int z) {
|
||||
return ((long) (x + 4096) << 40) | ((long) y << 20) | (z + 4096);
|
||||
}
|
||||
|
||||
private static int x(long key) {
|
||||
return (int) (key >>> 40) - 4096;
|
||||
}
|
||||
|
||||
private static int z(long key) {
|
||||
return (int) (key & 0xFFFFF) - 4096;
|
||||
}
|
||||
|
||||
private static int y(long key) {
|
||||
return (int) ((key >>> 20) & 0xFFFFF);
|
||||
}
|
||||
|
||||
private static NativeBlockState solid(String key) {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(state.isSolid()).thenReturn(true);
|
||||
when(state.key()).thenReturn(key);
|
||||
return state;
|
||||
}
|
||||
|
||||
private static final class SealedRoom implements CarvedTerrain {
|
||||
private static final int SURFACE = 120;
|
||||
|
||||
@Override
|
||||
public CaveVoxel voxel(int x, int y, int z) {
|
||||
if (y <= 0 || y > SURFACE) {
|
||||
return CaveVoxel.FOREIGN;
|
||||
}
|
||||
boolean inside = x >= 0 && x < 16 && z >= 0 && z < 16 && y >= POOL_FLOOR && y <= POOL_TOP;
|
||||
return inside ? CaveVoxel.AIR : CaveVoxel.SOLID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int surface(int x, int z) {
|
||||
return SURFACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String caveFluid(int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user