mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 09:15:27 +00:00
Serve Mantle.carved over the cavern slice, delete the MatterMantle offers
CarvedVoids is IrisApi's carved-void layer over the mantle's MatterCavern slice, which stays the storage form every other reader uses: the liquid byte is the fill and a custom biome key is a pack biome id. It remembers the slices it touched last, writes the shared constants and reads an area in order from a flat grid, so the carver's per-block writes and the apply stage's visit stay cheap. Placements and edits see it read-only. MatterMantle, OwnChunkMatter and the loaded-chunk reads behind them are gone.
This commit is contained in:
1 parent
a6f1ccd1e7
commit
a3cbb0e053
21 files changed
+901
-363
No files matched your search
@@ -13,9 +13,13 @@ import art.arcane.volmlib.util.matter.IrisMatter;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import com.volmit.data.Codec;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.MantleKey;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -25,6 +29,8 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
/** A mantle held in memory, for tests of what stages write into it. Bind an engine to it before the engine's mantle is used. */
|
||||
public final class InMemoryMantle {
|
||||
public static final int REACH_BLOCKS = 1024;
|
||||
|
||||
private final int sections;
|
||||
private final Map<Long, MantleChunk<Matter>> chunks = new HashMap<>();
|
||||
|
||||
@@ -34,6 +40,12 @@ public final class InMemoryMantle {
|
||||
this.sections = sections;
|
||||
}
|
||||
|
||||
/** The carved voids of this mantle as a mantle stage writes them, over the columns from -{@link #REACH_BLOCKS} up to {@link #REACH_BLOCKS}. */
|
||||
public MantleLayer<CarvedVoid> carved() {
|
||||
BlockBox reach = new BlockBox(-REACH_BLOCKS, 0, -REACH_BLOCKS, REACH_BLOCKS, sections * 16, REACH_BLOCKS);
|
||||
return new CarvedVoids(reach, this::chunk, new PackResourceIds(new File("test")), true);
|
||||
}
|
||||
|
||||
public MantleChunk<Matter> chunk(int chunkX, int chunkZ) {
|
||||
return chunks.computeIfAbsent(((long) chunkX << 32) ^ (chunkZ & 0xffffffffL), ignored ->
|
||||
new MantleChunk<>(sections, chunkX, chunkZ, new Sections(), MantleHooks.NONE));
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
@@ -37,7 +36,9 @@ import art.arcane.volmlib.util.mantle.runtime.MantleHooks;
|
||||
import art.arcane.volmlib.util.matter.IrisMatter;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterBiomeInject;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.IrisModule;
|
||||
@@ -73,7 +74,9 @@ import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
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.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
@@ -85,6 +88,7 @@ public class IrisModuleMantleTest {
|
||||
private static final int WORLD_MIN_HEIGHT = -64;
|
||||
private static final int SECTIONS = 4;
|
||||
private static final int HEIGHT = SECTIONS * 16;
|
||||
private static final PackResourceIds IDS = new PackResourceIds(new java.io.File("pack"));
|
||||
private static final MantleKey<String> MARKS = new MantleKey<>("iris:marks/mark", String.class);
|
||||
private static final MantleKey<Integer> DEPTHS = new MantleKey<>("iris:marks/depth", Integer.class);
|
||||
private static final Codec<String> TEXT = new Codec<>() {
|
||||
@@ -117,7 +121,7 @@ public class IrisModuleMantleTest {
|
||||
}
|
||||
|
||||
private IrisModuleMantle mantle(BlockBox bounds) {
|
||||
return new IrisModuleMantle(bounds, this::chunk, LAYERS, PlannedBlocks.none(bounds));
|
||||
return new IrisModuleMantle(bounds, this::chunk, LAYERS, PlannedBlocks.none(bounds), IDS);
|
||||
}
|
||||
|
||||
/** The form the floating islands' sky biomes always had: the platform's id for the biome, as a custom inject, at the height above the bottom. */
|
||||
@@ -148,22 +152,111 @@ public class IrisModuleMantleTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theMatterSideGivesTheMantleChunksTheInvocationReachesAndNoOthers() {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
|
||||
MatterMantle matter = mantle;
|
||||
public void carvedVoidsAreKeptAsTheCavernsIrisReadsAndReadBackAsTheirFills() {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(-16, 0, -16, 32, HEIGHT, 32));
|
||||
|
||||
org.junit.Assert.assertSame(chunk(3, 4), matter.chunk(3, 4));
|
||||
org.junit.Assert.assertNull("nothing is loaded that the host did not say is", matter.loadedChunk(3, 4));
|
||||
mantle.carved().set(-3, 7, 20, CarvedVoid.OPEN);
|
||||
mantle.carved().set(5, 40, 5, CarvedVoid.FLUID);
|
||||
mantle.carved().set(6, 40, 5, CarvedVoid.LAVA);
|
||||
mantle.carved().set(7, 40, 5, CarvedVoid.AIR);
|
||||
|
||||
assertEquals(new MatterCavern(true, "", (byte) 0), chunk(-1, 1).get(13, 7, 4, MatterCavern.class));
|
||||
assertEquals(new MatterCavern(true, "", (byte) 1), chunk(0, 0).get(5, 40, 5, MatterCavern.class));
|
||||
assertEquals(new MatterCavern(true, "", (byte) 2), chunk(0, 0).get(6, 40, 5, MatterCavern.class));
|
||||
assertEquals(new MatterCavern(true, "", (byte) 3), chunk(0, 0).get(7, 40, 5, MatterCavern.class));
|
||||
assertSame(CarvedVoid.OPEN, mantle.carved().get(-3, 7, 20));
|
||||
assertSame(CarvedVoid.FLUID, mantle.carved().get(5, 40, 5));
|
||||
assertSame(CarvedVoid.LAVA, mantle.carved().get(6, 40, 5));
|
||||
assertSame(CarvedVoid.AIR, mantle.carved().get(7, 40, 5));
|
||||
assertNull(mantle.carved().get(8, 40, 5));
|
||||
assertTrue(mantle.isCarved(5, 40, 5));
|
||||
assertFalse(mantle.isCarved(8, 40, 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aChunkInvocationsMatterHoldsItsOwnChunkAndReadsNeighboursOnlyWhenLoaded() {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(-16, 0, -16, 48, HEIGHT, 48));
|
||||
MatterMantle own = new OwnChunkMatter(mantle, 1, 1);
|
||||
public void cavernsOfAnyOtherLiquidReadAsOpenAndKeepTheirCustomBiomeAsAPackId() {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
|
||||
chunk(0, 0).getOrCreate(0).<MatterCavern>slice(MatterCavern.class).set(1, 2, 3, new MatterCavern(true, "", (byte) 9));
|
||||
chunk(0, 0).getOrCreate(0).<MatterCavern>slice(MatterCavern.class).set(2, 2, 3, new MatterCavern(true, "cave/lush", (byte) 3));
|
||||
|
||||
org.junit.Assert.assertSame(chunk(1, 1), own.chunk(1, 1));
|
||||
org.junit.Assert.assertNull("a neighbour is no chunk of the invocation's own", own.chunk(2, 1));
|
||||
org.junit.Assert.assertNull("a neighbour the world does not hold is not read", own.loadedChunk(2, 1));
|
||||
assertSame(CarvedVoid.OPEN, mantle.carved().get(1, 2, 3));
|
||||
assertEquals(CarvedVoid.AIR.withBiome(IDS.of("cave/lush")), mantle.carved().get(2, 2, 3));
|
||||
|
||||
mantle.carved().set(3, 2, 3, CarvedVoid.LAVA.withBiome(IDS.of("cave/lush")));
|
||||
assertEquals(new MatterCavern(true, "cave/lush", (byte) 2), chunk(0, 0).get(3, 2, 3, MatterCavern.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void carvedVoidsVisitInOrderAndClearOnlyTheirArea() {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(-16, 0, -16, 32, HEIGHT, 32));
|
||||
mantle.carved().set(17, 5, 3, CarvedVoid.LAVA);
|
||||
mantle.carved().set(-2, 9, 3, CarvedVoid.OPEN);
|
||||
mantle.carved().set(-2, 4, 20, CarvedVoid.FLUID);
|
||||
mantle.carved().set(-2, 4, 3, CarvedVoid.AIR);
|
||||
List<String> visited = new java.util.ArrayList<>();
|
||||
|
||||
mantle.carved().visit(new BlockBox(-16, 0, -16, 32, HEIGHT, 32), (x, y, z, carved) -> visited.add(x + "," + y + "," + z + " " + carved.fill()));
|
||||
|
||||
assertEquals(List.of("-2,4,3 AIR", "-2,4,20 FLUID", "-2,9,3 OPEN", "17,5,3 LAVA"), visited);
|
||||
|
||||
mantle.carved().clear(new BlockBox(-16, 0, -16, 0, HEIGHT, 32));
|
||||
assertNull(mantle.carved().get(-2, 9, 3));
|
||||
assertSame(CarvedVoid.LAVA, mantle.carved().get(17, 5, 3));
|
||||
mantle.carved().remove(17, 5, 3);
|
||||
assertFalse(mantle.isCarved(17, 5, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void carvedVoidsOfAnAreaTooLargeToLayOutVisitInTheSameOrder() {
|
||||
BlockBox wide = new BlockBox(0, 0, 0, 1024, HEIGHT, 80);
|
||||
IrisModuleMantle mantle = mantle(wide);
|
||||
CarvedVoid lush = CarvedVoid.AIR.withBiome(IDS.of("cave/lush"));
|
||||
mantle.carved().set(1000, 5, 70, CarvedVoid.LAVA);
|
||||
mantle.carved().set(3, 9, 70, lush);
|
||||
mantle.carved().set(3, 9, 5, CarvedVoid.OPEN);
|
||||
mantle.carved().set(3, 2, 75, CarvedVoid.FLUID);
|
||||
mantle.carved().set(500, 63, 0, lush);
|
||||
List<String> visited = new java.util.ArrayList<>();
|
||||
|
||||
mantle.carved().visit(wide, (x, y, z, carved) -> visited.add(x + "," + y + "," + z + " " + carved.fill() + carved.biome().map(id -> " " + id.path()).orElse("")));
|
||||
|
||||
assertEquals(List.of("3,2,75 FLUID", "3,9,5 OPEN", "3,9,70 AIR cave/lush", "500,63,0 AIR cave/lush", "1000,5,70 LAVA"), visited);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aVisitInsideAVisitReadsItsOwnArea() {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
|
||||
mantle.carved().set(1, 2, 3, CarvedVoid.OPEN);
|
||||
mantle.carved().set(4, 5, 6, CarvedVoid.LAVA);
|
||||
List<String> visited = new java.util.ArrayList<>();
|
||||
|
||||
mantle.carved().visit(new BlockBox(0, 0, 0, 16, HEIGHT, 16), (x, y, z, outer) -> {
|
||||
visited.add("outer " + outer.fill());
|
||||
mantle.carved().visit(new BlockBox(4, 5, 6, 5, 6, 7), (nx, ny, nz, inner) -> visited.add("inner " + inner.fill()));
|
||||
});
|
||||
|
||||
assertEquals(List.of("outer OPEN", "inner LAVA", "outer LAVA", "inner LAVA"), visited);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void carvedVoidsStayInsideTheMantleAnInvocationPrepared() {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
|
||||
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> mantle.carved().set(16, 5, 5, CarvedVoid.OPEN));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> mantle.carved().get(5, HEIGHT, 5));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> mantle.carved().visit(new BlockBox(0, 0, 0, 17, 1, 1), (x, y, z, carved) -> { }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anEditOnlyReadsTheCarvedVoids() {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
|
||||
mantle.carved().set(1, 2, 3, CarvedVoid.OPEN);
|
||||
|
||||
try (MantleEdit edit = mantle.edit()) {
|
||||
assertSame(CarvedVoid.OPEN, edit.carved().get(1, 2, 3));
|
||||
assertThrows(UnsupportedOperationException.class, () -> edit.carved().set(1, 2, 4, CarvedVoid.OPEN));
|
||||
assertThrows(UnsupportedOperationException.class, () -> edit.carved().remove(1, 2, 3));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -278,7 +371,7 @@ public class IrisModuleMantleTest {
|
||||
public void aCommitThatCannotReachEveryChunkPublishesNothing() {
|
||||
BlockBox bounds = new BlockBox(0, 0, 0, 32, HEIGHT, 16);
|
||||
IrisModuleMantle mantle = new IrisModuleMantle(bounds, (chunkX, chunkZ) -> chunkX == 0 ? chunk(chunkX, chunkZ) : null, LAYERS,
|
||||
PlannedBlocks.none(bounds));
|
||||
PlannedBlocks.none(bounds), IDS);
|
||||
MantleEdit edit = mantle.edit();
|
||||
edit.layer(MARKS).set(1, 4, 1, "first");
|
||||
edit.layer(MARKS).set(20, 4, 1, "unprepared");
|
||||
@@ -344,7 +437,7 @@ public class IrisModuleMantleTest {
|
||||
new IrisMantleChunk(engine, null, 0, 0, null));
|
||||
|
||||
BlockBox neighborBounds = new BlockBox(16, 0, 0, 32, HEIGHT, 16);
|
||||
IrisModuleMantle neighbor = new IrisModuleMantle(neighborBounds, this::chunk, pack.catalog().mantle(), PlannedBlocks.none(neighborBounds));
|
||||
IrisModuleMantle neighbor = new IrisModuleMantle(neighborBounds, this::chunk, pack.catalog().mantle(), PlannedBlocks.none(neighborBounds), IDS);
|
||||
assertEquals("vein", neighbor.layer(planned).get(20, 34, 3));
|
||||
}
|
||||
assertTrue(chunks.containsKey(1L << 32));
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.host.MantleRegistration;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
@@ -14,6 +17,7 @@ import org.junit.Test;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -21,6 +25,7 @@ import java.util.List;
|
||||
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.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -55,6 +60,9 @@ public class PlacementMantleTest {
|
||||
private Engine engine() {
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(HEIGHT);
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getDataFolder()).thenReturn(new File("pack"));
|
||||
when(engine.getData()).thenReturn(data);
|
||||
storage.bindTo(engine);
|
||||
return engine;
|
||||
}
|
||||
@@ -67,6 +75,18 @@ public class PlacementMantleTest {
|
||||
return storage.value(MARKS, TEXT, x, Y, z);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPlacementReadsTheCarvedVoidsButNeverWritesThem() {
|
||||
storage.chunk(0, 0).getOrCreate(Y >> 4).<MatterCavern>slice(MatterCavern.class).set(1, Y & 15, 1, new MatterCavern(true, "", (byte) 1));
|
||||
TerrainEdit placement = edit(engine());
|
||||
|
||||
assertSame(CarvedVoid.FLUID, placement.mantle().carved().get(1, Y, 1));
|
||||
assertNull(placement.mantle().carved().get(2, Y, 1));
|
||||
assertThrows(UnsupportedOperationException.class, () -> placement.mantle().carved().set(2, Y, 1, CarvedVoid.OPEN));
|
||||
assertThrows(UnsupportedOperationException.class, () -> placement.mantle().carved().remove(1, Y, 1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> placement.mantle().carved().get(100, Y, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writesReachTheMantleTogetherWhenThePlacementCommits() {
|
||||
TerrainEdit placement = edit(engine());
|
||||
|
||||
@@ -2,7 +2,7 @@ package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.carve.CaveAnchorMode;
|
||||
import art.arcane.iris.modules.objects.CarvedSpace;
|
||||
import art.arcane.iris.modules.objects.Cavern;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BiomeSample;
|
||||
@@ -92,8 +92,8 @@ public class CaveAnchorsTest {
|
||||
}
|
||||
return column;
|
||||
});
|
||||
when(cave.cavernAt(anyInt(), anyInt(), anyInt())).thenAnswer(call ->
|
||||
isCarved(call.getArgument(1)) ? Optional.of(new Cavern(true, (byte) 0)) : Optional.empty());
|
||||
when(cave.voidAt(anyInt(), anyInt(), anyInt())).thenAnswer(call ->
|
||||
isCarved(call.getArgument(1)) ? Optional.of(CarvedVoid.OPEN) : Optional.empty());
|
||||
return cave;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,14 +18,11 @@
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.iris.modules.carve.CaveProfile;
|
||||
import art.arcane.iris.core.modules.CarveTestTerrain;
|
||||
import art.arcane.iris.core.modules.CarveTestWorld;
|
||||
import art.arcane.iris.core.modules.InMemoryMantle;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.config.Range;
|
||||
@@ -102,20 +99,9 @@ public class CaveCarvingTest {
|
||||
BiomeSample sample = new BiomeSample(CarveTestWorld.id("region"), CarveTestWorld.id("plains"), Optional.of(CarveTestWorld.id("cave/lush")));
|
||||
return new BiomeSample(sample.region(), sample.surfaceBiome(), Optional.of(caveBiomeOf.apply(sample)));
|
||||
});
|
||||
MatterMantle matter = new MatterMantle() {
|
||||
@Override
|
||||
public MantleChunk<Matter> chunk(int chunkX, int chunkZ) {
|
||||
return mantle.chunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleChunk<Matter> loadedChunk(int chunkX, int chunkZ) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
CarveWorld carveWorld = new CarveWorld(world.resources().noise(), 1337L, HEIGHT, FLUID_HEIGHT, LAVA_HEIGHT, CarveTestWorld.MIN_HEIGHT);
|
||||
|
||||
new CaveCarving(world, carveWorld, false, (x, z) -> false).carve(matter, terrain, 0, 0);
|
||||
new CaveCarving(world, carveWorld, false, (x, z) -> false).carve(mantle.carved(), terrain, 0, 0);
|
||||
|
||||
int[] count = new int[1];
|
||||
mantle.chunk(0, 0).iterate(MatterCavern.class, (x, y, z, cavern) -> count[0]++);
|
||||
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.core.modules.CarveTestTerrain;
|
||||
import art.arcane.iris.core.modules.CarveTestWorld;
|
||||
import art.arcane.iris.core.modules.InMemoryMantle;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.placement.PlacedMarker;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/** The floors of the caves a chunk was planned with are marked for the spawners: one in sixteen of the runs of three or more voids, by seed and position alone. */
|
||||
public class CaveFloorMarkingTest {
|
||||
private static final int HEIGHT = 128;
|
||||
private static final int FLUID_HEIGHT = 40;
|
||||
private static final int SURFACE = 100;
|
||||
private static final int FLOOR_Y = 10;
|
||||
private static final int CEILING_Y = 13;
|
||||
|
||||
private final InMemoryMantle mantle = new InMemoryMantle(HEIGHT / 16);
|
||||
private final List<PlacedMarker> marks = new ArrayList<>();
|
||||
private final PlacementTerrain placement = mock(PlacementTerrain.class);
|
||||
private CarveTestTerrain terrain;
|
||||
private MantleLayer<CarvedVoid> voids;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
voids = mantle.carved();
|
||||
terrain = new CarveTestTerrain(0, 0, HEIGHT, FLUID_HEIGHT, (x, z) -> SURFACE);
|
||||
doAnswer(call -> marks.add(call.getArgument(0))).when(placement).mark(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyMarkIsTheLowestBlockOfARunAndTheSameSeedMarksTheSameFloors() {
|
||||
carveEveryColumn(FLOOR_Y, CEILING_Y, CarvedVoid.OPEN);
|
||||
|
||||
mark(1L);
|
||||
List<PlacedMarker> first = List.copyOf(marks);
|
||||
marks.clear();
|
||||
mark(1L);
|
||||
|
||||
assertTrue("about one in sixteen of the 256 floors", !first.isEmpty() && first.size() < 64);
|
||||
assertEquals(first, marks);
|
||||
for (PlacedMarker marker : first) {
|
||||
PlacedMarker.PackMarker floor = (PlacedMarker.PackMarker) marker;
|
||||
assertEquals("cave_floor", floor.key());
|
||||
assertEquals(FLOOR_Y, floor.position().y());
|
||||
}
|
||||
marks.clear();
|
||||
mark(2L);
|
||||
assertTrue("another seed rolls other floors", !marks.equals(first));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runsShorterThanThreeBlocksHaveNoFloor() {
|
||||
carveEveryColumn(FLOOR_Y, FLOOR_Y + 1, CarvedVoid.OPEN);
|
||||
|
||||
mark(1L);
|
||||
|
||||
assertTrue(marks.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openVoidsHeldByTheTerrainsFluidAreNotCaveFloorsButExplicitOnesAre() {
|
||||
terrain = new CarveTestTerrain(0, 0, HEIGHT, 60, (x, z) -> 20);
|
||||
carveEveryColumn(FLUID_HEIGHT + 5, FLUID_HEIGHT + 8, CarvedVoid.OPEN);
|
||||
mark(1L);
|
||||
assertTrue("water above the sea floor", marks.isEmpty());
|
||||
|
||||
carveEveryColumn(FLUID_HEIGHT + 5, FLUID_HEIGHT + 8, CarvedVoid.AIR);
|
||||
mark(1L);
|
||||
assertTrue(!marks.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothingBelowADimensionStackedAboveItsFloorIsMarked() {
|
||||
terrain = new CarveTestTerrain(0, 0, HEIGHT, FLUID_HEIGHT, (x, z) -> SURFACE).upperDimension((x, z) -> FLOOR_Y + 2);
|
||||
carveEveryColumn(FLOOR_Y, CEILING_Y, CarvedVoid.OPEN);
|
||||
|
||||
mark(1L);
|
||||
|
||||
assertTrue("only two blocks of the run lie below the dimension above", marks.isEmpty());
|
||||
}
|
||||
|
||||
private void mark(long seed) {
|
||||
CarveWorld world = new CarveWorld(new CarveTestWorld().resources().noise(), seed, HEIGHT, FLUID_HEIGHT, 8, CarveTestWorld.MIN_HEIGHT);
|
||||
new CaveFloorMarking(world, false).mark(voids, terrain, placement, 0, 0);
|
||||
}
|
||||
|
||||
private void carveEveryColumn(int floorY, int ceilingY, CarvedVoid carvedVoid) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = floorY; y <= ceilingY; y++) {
|
||||
voids.set(x, y, z, carvedVoid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+76
-115
@@ -1,17 +1,16 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.iris.builtin.carve.CaveFieldModule;
|
||||
import art.arcane.iris.modules.carve.CaveProfile;
|
||||
import art.arcane.iris.core.modules.CarveTestWorld;
|
||||
import art.arcane.iris.modules.terrain.FluidPaletteSettings;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import com.volmit.config.Range;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.mantle.MantleVisitor;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -30,11 +29,6 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class IrisCaveCarver3DNearParityTest {
|
||||
private static final int SURFACE_CEILING_FADE_DEPTH = 12;
|
||||
@@ -50,10 +44,6 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
private static Field profileField;
|
||||
private static Field surfaceBreakDensityField;
|
||||
private static Field thresholdNoiseField;
|
||||
private static Field carveAirField;
|
||||
private static Field carveFluidField;
|
||||
private static Field carveLavaField;
|
||||
private static Field carveForcedAirField;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupReflection() throws Exception {
|
||||
@@ -67,14 +57,6 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
surfaceBreakDensityField.setAccessible(true);
|
||||
thresholdNoiseField = IrisCaveCarver3D.class.getDeclaredField("thresholdNoise");
|
||||
thresholdNoiseField.setAccessible(true);
|
||||
carveAirField = IrisCaveCarver3D.class.getDeclaredField("carveAir");
|
||||
carveAirField.setAccessible(true);
|
||||
carveFluidField = IrisCaveCarver3D.class.getDeclaredField("carveFluid");
|
||||
carveFluidField.setAccessible(true);
|
||||
carveLavaField = IrisCaveCarver3D.class.getDeclaredField("carveLava");
|
||||
carveLavaField.setAccessible(true);
|
||||
carveForcedAirField = IrisCaveCarver3D.class.getDeclaredField("carveForcedAir");
|
||||
carveForcedAirField.setAccessible(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -299,7 +281,7 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
new IrisCaveCarver3D(engine, supportedProfile).carve(
|
||||
firstCapture.writer, chunkX, chunkZ, fullWeights(), 0D, 0D, null, surfaceHeights, null, null, supportPlan);
|
||||
int candidateCount = countLiquid(firstCapture, (byte) 1);
|
||||
supportPlan.resolve(firstCapture.writer.chunk(chunkX, chunkZ));
|
||||
supportPlan.resolve(firstCapture.writer, chunkX << 4, chunkZ << 4, firstCapture.worldHeight);
|
||||
|
||||
CaveProfile repeatedProfile = TestSettings.with(createFluidProfile(), "densityThreshold", cupThreshold, "fluidMinDepthBelowSurface", 0, "fluidRequiresFloor", true);
|
||||
WriterCapture secondCapture = createWriterCapture(80);
|
||||
@@ -321,19 +303,15 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
@Test
|
||||
public void finalFluidSupportRejectsUnknownNeighborChunkEdges() {
|
||||
WriterCapture capture = createWriterCapture(80);
|
||||
MantleChunk<Matter> chunk = capture.writer.chunk(0, 0);
|
||||
MatterSlice<MatterCavern> slice = chunk.getOrCreate(3).slice(MatterCavern.class);
|
||||
MatterCavern fluid = new MatterCavern(true, "", (byte) 1);
|
||||
MatterCavern air = new MatterCavern(true, "", (byte) 0);
|
||||
int y = 56;
|
||||
int z = 8;
|
||||
slice.set(0, y & 15, z, fluid);
|
||||
slice.set(8, y & 15, z, fluid);
|
||||
capture.writer.set(0, y, z, CarvedVoid.FLUID);
|
||||
capture.writer.set(8, y, z, CarvedVoid.FLUID);
|
||||
CaveFluidSupportPlan supportPlan = new CaveFluidSupportPlan();
|
||||
supportPlan.add(0, y, z, fluid, air);
|
||||
supportPlan.add(8, y, z, fluid, air);
|
||||
supportPlan.add(0, y, z);
|
||||
supportPlan.add(8, y, z);
|
||||
|
||||
supportPlan.resolve(chunk);
|
||||
supportPlan.resolve(capture.writer, 0, 0, capture.worldHeight);
|
||||
|
||||
assertEquals(Byte.valueOf((byte) 0), capture.carvedLiquids.get(cellKey(0, y, z)));
|
||||
assertEquals(Byte.valueOf((byte) 1), capture.carvedLiquids.get(cellKey(8, y, z)));
|
||||
@@ -361,7 +339,7 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
null, Range.of(fluidY - 1D, fluidY - 1D), fluidSupportPlan);
|
||||
|
||||
assertEquals(Byte.valueOf((byte) 1), capture.carvedLiquids.get(fluidCell));
|
||||
fluidSupportPlan.resolve(capture.writer.chunk(chunkX, chunkZ));
|
||||
fluidSupportPlan.resolve(capture.writer, chunkX << 4, chunkZ << 4, capture.worldHeight);
|
||||
assertEquals(Byte.valueOf((byte) 0), capture.carvedLiquids.get(fluidCell));
|
||||
}
|
||||
|
||||
@@ -500,14 +478,10 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
private int carveNaiveExact(IrisCaveCarver3D carver, MatterMantle writer, int worldHeight, int chunkX, int chunkZ, double[] columnWeights, Range worldYRange, int[] precomputedSurfaceHeights) throws Exception {
|
||||
private int carveNaiveExact(IrisCaveCarver3D carver, MantleLayer<CarvedVoid> writer, int worldHeight, int chunkX, int chunkZ, double[] columnWeights, Range worldYRange, int[] precomputedSurfaceHeights) throws Exception {
|
||||
CaveProfile profile = (CaveProfile) profileField.get(carver);
|
||||
NoiseSampler surfaceBreakDensity = (NoiseSampler) surfaceBreakDensityField.get(carver);
|
||||
NoiseSampler thresholdNoise = (NoiseSampler) thresholdNoiseField.get(carver);
|
||||
MatterCavern carveAir = (MatterCavern) carveAirField.get(carver);
|
||||
MatterCavern carveFluid = (MatterCavern) carveFluidField.get(carver);
|
||||
MatterCavern carveLava = (MatterCavern) carveLavaField.get(carver);
|
||||
MatterCavern carveForcedAir = (MatterCavern) carveForcedAirField.get(carver);
|
||||
|
||||
double[] resolvedWeights = columnWeights;
|
||||
if (resolvedWeights == null || resolvedWeights.length < 256) {
|
||||
@@ -539,7 +513,7 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
double[] passThreshold = new double[256];
|
||||
double[] verticalEdgeFade = computeVerticalEdgeFade(profile, minY, maxY);
|
||||
double[] surfaceClosureThreshold = computeSurfaceClosureThresholds(profile, minY, maxY);
|
||||
MatterCavern[] matterByY = computeMatterByY(profile, carveAir, carveLava, carveForcedAir, minY, maxY);
|
||||
CarvedVoid[] voidByY = computeVoidByY(profile, minY, maxY);
|
||||
|
||||
int x0 = chunkX << 4;
|
||||
int z0 = chunkZ << 4;
|
||||
@@ -571,12 +545,6 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
MantleChunk<Matter> chunk = writer.chunk(chunkX, chunkZ);
|
||||
if (chunk == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int carved = 0;
|
||||
for (int localX = 0; localX < 16; localX++) {
|
||||
int x = x0 + localX;
|
||||
@@ -608,14 +576,11 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
continue;
|
||||
}
|
||||
|
||||
Matter sectionMatter = chunk.getOrCreate(y >> 4);
|
||||
MatterSlice<MatterCavern> cavernSlice = sectionMatter.slice(MatterCavern.class);
|
||||
MatterCavern verticalMatter = matterByY[y - minY];
|
||||
boolean aquifer = verticalMatter == carveAir
|
||||
CarvedVoid verticalVoid = voidByY[y - minY];
|
||||
boolean aquifer = verticalVoid == CarvedVoid.OPEN
|
||||
&& y <= fluidMaxY[columnIndex]
|
||||
&& (boolean) aquiferCandidateMethod.invoke(carver, x, y, z, localThreshold);
|
||||
MatterCavern matter = aquifer ? carveFluid : verticalMatter;
|
||||
cavernSlice.set(localX, y & 15, localZ, matter);
|
||||
writer.set(x, y, z, aquifer ? CarvedVoid.FLUID : verticalVoid);
|
||||
carved++;
|
||||
}
|
||||
}
|
||||
@@ -720,26 +685,26 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
return verticalEdgeFade;
|
||||
}
|
||||
|
||||
private MatterCavern[] computeMatterByY(CaveProfile profile, MatterCavern carveAir, MatterCavern carveLava, MatterCavern carveForcedAir, int minY, int maxY) {
|
||||
MatterCavern[] matterByY = new MatterCavern[Math.max(0, maxY - minY + 1)];
|
||||
private CarvedVoid[] computeVoidByY(CaveProfile profile, int minY, int maxY) {
|
||||
CarvedVoid[] voidByY = new CarvedVoid[Math.max(0, maxY - minY + 1)];
|
||||
boolean allowLava = profile.allowLava();
|
||||
int lavaHeight = LAVA_HEIGHT;
|
||||
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
int offset = y - minY;
|
||||
if (allowLava && y <= lavaHeight) {
|
||||
matterByY[offset] = carveLava;
|
||||
voidByY[offset] = CarvedVoid.LAVA;
|
||||
continue;
|
||||
}
|
||||
if (!allowLava && y <= lavaHeight) {
|
||||
matterByY[offset] = carveForcedAir;
|
||||
voidByY[offset] = CarvedVoid.AIR;
|
||||
continue;
|
||||
}
|
||||
|
||||
matterByY[offset] = carveAir;
|
||||
voidByY[offset] = CarvedVoid.OPEN;
|
||||
}
|
||||
|
||||
return matterByY;
|
||||
return voidByY;
|
||||
}
|
||||
|
||||
private CarveWorld createEngine(int worldHeight, int sampledHeight) {
|
||||
@@ -826,68 +791,62 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
}
|
||||
|
||||
private WriterCapture createWriterCapture(int worldHeight) {
|
||||
@SuppressWarnings("unchecked")
|
||||
MantleChunk<Matter> chunk = mock(MantleChunk.class);
|
||||
Map<Integer, Matter> sections = new HashMap<>();
|
||||
Map<Integer, Map<Integer, MatterCavern>> sectionCells = new HashMap<>();
|
||||
Set<String> carvedCells = new HashSet<>();
|
||||
Map<String, Byte> carvedLiquids = new HashMap<>();
|
||||
|
||||
doAnswer(invocation -> sections.get(invocation.getArgument(0, Integer.class))).when(chunk).get(anyInt());
|
||||
doAnswer(invocation -> {
|
||||
int sectionIndex = invocation.getArgument(0);
|
||||
Matter section = sections.get(sectionIndex);
|
||||
if (section != null) {
|
||||
return section;
|
||||
}
|
||||
|
||||
Matter created = createSection(sectionIndex, sectionCells, carvedCells, carvedLiquids);
|
||||
sections.put(sectionIndex, created);
|
||||
return created;
|
||||
}).when(chunk).getOrCreate(anyInt());
|
||||
|
||||
MatterMantle mantle = new MatterMantle() {
|
||||
@Override
|
||||
public MantleChunk<Matter> chunk(int chunkX, int chunkZ) {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleChunk<Matter> loadedChunk(int chunkX, int chunkZ) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return new WriterCapture(mantle, carvedCells, carvedLiquids);
|
||||
return new WriterCapture(new CapturingVoids(carvedCells, carvedLiquids), worldHeight, carvedCells, carvedLiquids);
|
||||
}
|
||||
|
||||
private Matter createSection(int sectionIndex, Map<Integer, Map<Integer, MatterCavern>> sectionCells, Set<String> carvedCells, Map<String, Byte> carvedLiquids) {
|
||||
Matter matter = mock(Matter.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
MatterSlice<MatterCavern> slice = mock(MatterSlice.class);
|
||||
Map<Integer, MatterCavern> localCells = sectionCells.computeIfAbsent(sectionIndex, key -> new HashMap<>());
|
||||
/** The carved voids of one chunk, recorded by the chunk's local X and Z and the height, with the carver's liquid code of each fill. */
|
||||
private static final class CapturingVoids implements MantleLayer<CarvedVoid> {
|
||||
private final Map<Long, CarvedVoid> voids = new HashMap<>();
|
||||
private final Set<String> carvedCells;
|
||||
private final Map<String, Byte> carvedLiquids;
|
||||
|
||||
doReturn(slice).when(matter).slice(MatterCavern.class);
|
||||
doReturn(slice).when(matter).getSlice(MatterCavern.class);
|
||||
doAnswer(invocation -> {
|
||||
int localX = invocation.getArgument(0);
|
||||
int localY = invocation.getArgument(1);
|
||||
int localZ = invocation.getArgument(2);
|
||||
return localCells.get(packLocal(localX, localY, localZ));
|
||||
}).when(slice).get(anyInt(), anyInt(), anyInt());
|
||||
doAnswer(invocation -> {
|
||||
int localX = invocation.getArgument(0);
|
||||
int localY = invocation.getArgument(1);
|
||||
int localZ = invocation.getArgument(2);
|
||||
MatterCavern value = invocation.getArgument(3);
|
||||
localCells.put(packLocal(localX, localY, localZ), value);
|
||||
int worldY = (sectionIndex << 4) + localY;
|
||||
String cellKey = cellKey(localX, worldY, localZ);
|
||||
carvedCells.add(cellKey);
|
||||
carvedLiquids.put(cellKey, value.getLiquid());
|
||||
return null;
|
||||
}).when(slice).set(anyInt(), anyInt(), anyInt(), any(MatterCavern.class));
|
||||
private CapturingVoids(Set<String> carvedCells, Map<String, Byte> carvedLiquids) {
|
||||
this.carvedCells = carvedCells;
|
||||
this.carvedLiquids = carvedLiquids;
|
||||
}
|
||||
|
||||
return matter;
|
||||
@Override
|
||||
public CarvedVoid get(int x, int y, int z) {
|
||||
return voids.get(position(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, CarvedVoid value) {
|
||||
voids.put(position(x, y, z), value);
|
||||
String cell = x - ((x >> 4) << 4) + ":" + y + ":" + (z - ((z >> 4) << 4));
|
||||
carvedCells.add(cell);
|
||||
carvedLiquids.put(cell, liquidCode(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(int x, int y, int z) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BlockBox area, MantleVisitor<CarvedVoid> visitor) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(BlockBox area) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private static long position(int x, int y, int z) {
|
||||
return ((long) x << 40) ^ ((long) y << 20) ^ (z & 0xfffffL);
|
||||
}
|
||||
|
||||
private static byte liquidCode(CarvedVoid value) {
|
||||
return switch (value.fill()) {
|
||||
case OPEN -> 0;
|
||||
case FLUID -> 1;
|
||||
case LAVA -> 2;
|
||||
case AIR -> 3;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private double[] fullWeights() {
|
||||
@@ -1083,12 +1042,14 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
}
|
||||
|
||||
private static final class WriterCapture {
|
||||
private final MatterMantle writer;
|
||||
private final MantleLayer<CarvedVoid> writer;
|
||||
private final int worldHeight;
|
||||
private final Set<String> carvedCells;
|
||||
private final Map<String, Byte> carvedLiquids;
|
||||
|
||||
private WriterCapture(MatterMantle writer, Set<String> carvedCells, Map<String, Byte> carvedLiquids) {
|
||||
private WriterCapture(MantleLayer<CarvedVoid> writer, int worldHeight, Set<String> carvedCells, Map<String, Byte> carvedLiquids) {
|
||||
this.writer = writer;
|
||||
this.worldHeight = worldHeight;
|
||||
this.carvedCells = carvedCells;
|
||||
this.carvedLiquids = carvedLiquids;
|
||||
}
|
||||
|
||||
+7
-14
@@ -1,6 +1,6 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.modules.objects.Cavern;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -10,9 +10,6 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ObjectPlacingCaveAnchorTest {
|
||||
private static final byte AIR = 0;
|
||||
private static final byte WATER = 1;
|
||||
private static final byte LAVA = 2;
|
||||
|
||||
@Test
|
||||
public void biomeOwnedPlacementsRejectForeignCaveBands() {
|
||||
@@ -27,23 +24,19 @@ public class ObjectPlacingCaveAnchorTest {
|
||||
|
||||
@Test
|
||||
public void dryPlacementsRejectFluidAndDefaultLavaCells() {
|
||||
assertFalse(CaveAnchors.acceptsFluid(false, cavern(WATER), 20, 8));
|
||||
assertFalse(CaveAnchors.acceptsFluid(false, cavern(LAVA), 20, 8));
|
||||
assertFalse(CaveAnchors.acceptsFluid(false, cavern(AIR), 8, 8));
|
||||
assertTrue(CaveAnchors.acceptsFluid(false, cavern(AIR), 9, 8));
|
||||
assertFalse(CaveAnchors.acceptsFluid(false, Optional.of(CarvedVoid.FLUID), 20, 8));
|
||||
assertFalse(CaveAnchors.acceptsFluid(false, Optional.of(CarvedVoid.LAVA), 20, 8));
|
||||
assertFalse(CaveAnchors.acceptsFluid(false, Optional.of(CarvedVoid.OPEN), 8, 8));
|
||||
assertTrue(CaveAnchors.acceptsFluid(false, Optional.of(CarvedVoid.OPEN), 9, 8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitWetAndForcedAirPlacementsRemainEligible() {
|
||||
assertTrue(CaveAnchors.acceptsFluid(true, cavern(WATER), 20, 8));
|
||||
assertTrue(CaveAnchors.acceptsFluid(false, cavern(Cavern.FORCED_AIR_LIQUID), 0, 8));
|
||||
assertTrue(CaveAnchors.acceptsFluid(true, Optional.of(CarvedVoid.FLUID), 20, 8));
|
||||
assertTrue(CaveAnchors.acceptsFluid(false, Optional.of(CarvedVoid.AIR), 0, 8));
|
||||
assertFalse(CaveAnchors.acceptsFluid(true, Optional.empty(), 20, 8));
|
||||
}
|
||||
|
||||
private static Optional<Cavern> cavern(byte liquid) {
|
||||
return Optional.of(new Cavern(liquid == AIR, liquid));
|
||||
}
|
||||
|
||||
private static ResourceId biome(String key) {
|
||||
return new ResourceId("test", key);
|
||||
}
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import art.arcane.iris.builtin.IrisStages;
|
||||
import art.arcane.iris.builtin.IrisSeedPurposes;
|
||||
@@ -65,6 +62,7 @@ import com.volmit.host.StageGraphBuilder;
|
||||
import com.volmit.host.StageTimings;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.item.ItemRegistry;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.mantle.MantleEdit;
|
||||
import com.volmit.mantle.MantleKey;
|
||||
@@ -350,7 +348,7 @@ public final class ApiChunk implements GenerationContext {
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
return type == MatterMantle.class ? Optional.of(type.cast(new ChunkMantle())) : Optional.empty();
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -518,20 +516,7 @@ public final class ApiChunk implements GenerationContext {
|
||||
}
|
||||
}
|
||||
|
||||
private final class ChunkMantle implements Mantle, MatterMantle {
|
||||
private final MantleChunk<Matter> noCaves = mock(MantleChunk.class);
|
||||
|
||||
/** The matter of the chunk: none; a test of caves brings its own mantle. */
|
||||
@Override
|
||||
public MantleChunk<Matter> chunk(int chunkX, int chunkZ) {
|
||||
return noCaves;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleChunk<Matter> loadedChunk(int chunkX, int chunkZ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private final class ChunkMantle implements Mantle {
|
||||
@Override
|
||||
public BlockBox bounds() {
|
||||
return chunkColumns();
|
||||
@@ -547,6 +532,11 @@ public final class ApiChunk implements GenerationContext {
|
||||
return new PlannedLayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<CarvedVoid> carved() {
|
||||
return new CarvedLayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return carved.contains(new BlockPosition(x, y, z));
|
||||
@@ -563,6 +553,40 @@ public final class ApiChunk implements GenerationContext {
|
||||
}
|
||||
}
|
||||
|
||||
/** The carved positions as open voids; a chunk stage only reads them. */
|
||||
private final class CarvedLayer implements MantleLayer<CarvedVoid> {
|
||||
@Override
|
||||
public CarvedVoid get(int x, int y, int z) {
|
||||
return carved.contains(new BlockPosition(x, y, z)) ? CarvedVoid.OPEN : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, CarvedVoid value) {
|
||||
throw new UnsupportedOperationException("Carved voids are read-only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(int x, int y, int z) {
|
||||
throw new UnsupportedOperationException("Carved voids are read-only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BlockBox area, MantleVisitor<CarvedVoid> visitor) {
|
||||
List<BlockPosition> positions = new ArrayList<>(carved);
|
||||
positions.sort(VISIT_ORDER);
|
||||
for (BlockPosition position : positions) {
|
||||
if (area.contains(position.x(), position.y(), position.z())) {
|
||||
visitor.accept(position.x(), position.y(), position.z(), CarvedVoid.OPEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(BlockBox area) {
|
||||
throw new UnsupportedOperationException("Carved voids are read-only");
|
||||
}
|
||||
}
|
||||
|
||||
private final class PlannedLayer implements MantleLayer<BlockState> {
|
||||
@Override
|
||||
public BlockState get(int x, int y, int z) {
|
||||
|
||||
+6
-36
@@ -1,16 +1,13 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.iris.core.modules.CarveTestWorld;
|
||||
import art.arcane.iris.engine.mantle.components.CarveWorld;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.host.ArrayHunk;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.TerrainSample;
|
||||
@@ -44,25 +41,12 @@ public class CaveApplyingBoundarySupportTest {
|
||||
public void boundaryBiomeUsesCustomMatterAtItsOwnY() {
|
||||
ResourceId resolvedCeiling = CarveTestWorld.id("cave/ceiling");
|
||||
CaveApplying modifier = new CaveApplying(world, new CarveWorld(world.resources().noise(), 1L, 384, 127, 8, CarveTestWorld.MIN_HEIGHT), false);
|
||||
MantleChunk<Matter> mantleChunk = mock(MantleChunk.class);
|
||||
Matter floorMatter = mock(Matter.class);
|
||||
Matter ceilingMatter = mock(Matter.class);
|
||||
MatterSlice<MatterCavern> floorSlice = mock(MatterSlice.class);
|
||||
MatterSlice<MatterCavern> ceilingSlice = mock(MatterSlice.class);
|
||||
doReturn(true).when(mantleChunk).exists(0);
|
||||
doReturn(true).when(mantleChunk).exists(2);
|
||||
doReturn(floorMatter).when(mantleChunk).get(0);
|
||||
doReturn(ceilingMatter).when(mantleChunk).get(2);
|
||||
doReturn(true).when(floorMatter).hasSlice(MatterCavern.class);
|
||||
doReturn(true).when(ceilingMatter).hasSlice(MatterCavern.class);
|
||||
doReturn(floorSlice).when(floorMatter).getSlice(MatterCavern.class);
|
||||
doReturn(ceilingSlice).when(ceilingMatter).getSlice(MatterCavern.class);
|
||||
doReturn(new MatterCavern(true, "custom/floor", (byte) 0)).when(floorSlice).get(1, 6, 2);
|
||||
doReturn(null).when(ceilingSlice).get(1, CEILING_Y & 15, 2);
|
||||
MantleLayer<CarvedVoid> voids = mock(MantleLayer.class);
|
||||
doReturn(CarvedVoid.OPEN.withBiome(CarveTestWorld.id("custom/floor"))).when(voids).get(33, 6, 34);
|
||||
TerrainSampler terrain = new CaveBiomeTerrain((x, y, z) -> y == CEILING_Y ? Optional.of(resolvedCeiling) : Optional.empty());
|
||||
CaveApplying.Application application = modifier.new Application(chunkOnly(mantleChunk), mantleChunk, terrain, 2, 2, new ArrayHunk<>(BlockState.class, 16, 64, 16, AIR),
|
||||
CaveApplying.Application application = modifier.new Application(voids, terrain, 2, 2, new ArrayHunk<>(BlockState.class, 16, 64, 16, AIR),
|
||||
new RecordingCaveDressing());
|
||||
Map<String, ResourceId> customBiomeCache = new HashMap<>();
|
||||
Map<ResourceId, ResourceId> customBiomeCache = new HashMap<>();
|
||||
|
||||
ResourceId floor = application.resolveCaveBoundaryBiome(1, 6, 2, 40, 44, customBiomeCache);
|
||||
ResourceId ceiling = application.resolveCaveBoundaryBiome(1, CEILING_Y, 2, 40, 44, customBiomeCache);
|
||||
@@ -91,20 +75,6 @@ public class CaveApplyingBoundarySupportTest {
|
||||
assertTrue(CaveApplying.hasStableCaveFloorSupport(output, 0, 6, 0, classes));
|
||||
}
|
||||
|
||||
private static MatterMantle chunkOnly(MantleChunk<Matter> chunk) {
|
||||
return new MatterMantle() {
|
||||
@Override
|
||||
public MantleChunk<Matter> chunk(int chunkX, int chunkZ) {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleChunk<Matter> loadedChunk(int chunkX, int chunkZ) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** Terrain that knows cave biomes only. */
|
||||
private record CaveBiomeTerrain(CaveBiomeAt biomes) implements TerrainSampler {
|
||||
interface CaveBiomeAt {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -12,10 +12,10 @@ import static org.junit.Assert.assertTrue;
|
||||
public class CaveApplyingFluidIntentTest {
|
||||
@Test
|
||||
public void explicitCavernIntentsOverrideExistingFluid() {
|
||||
MatterCavern airIntent = new MatterCavern(true, "", (byte) 0);
|
||||
MatterCavern fluidIntent = new MatterCavern(true, "", (byte) 1);
|
||||
MatterCavern lavaIntent = new MatterCavern(true, "", (byte) 2);
|
||||
MatterCavern forcedAirIntent = new MatterCavern(true, "", (byte) 3);
|
||||
CarvedVoid airIntent = CarvedVoid.OPEN;
|
||||
CarvedVoid fluidIntent = CarvedVoid.FLUID;
|
||||
CarvedVoid lavaIntent = CarvedVoid.LAVA;
|
||||
CarvedVoid forcedAirIntent = CarvedVoid.AIR;
|
||||
BlockState fluid = new BlockState("minecraft:water");
|
||||
BlockState lava = new BlockState("minecraft:lava");
|
||||
BlockState air = new BlockState("minecraft:cave_air");
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.iris.core.modules.CarveTestTerrain;
|
||||
import art.arcane.iris.core.modules.CarveTestWorld;
|
||||
import art.arcane.iris.core.modules.InMemoryMantle;
|
||||
@@ -26,7 +25,6 @@ import art.arcane.iris.engine.mantle.components.CarveWorld;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterMarker;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.host.ArrayHunk;
|
||||
import com.volmit.hunk.Hunk;
|
||||
@@ -121,48 +119,29 @@ public class CaveApplyingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void markersAreStampedFromTheSeedAndPositionAlone() {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
carve(x, z, CAVE_FLOOR_Y, CAVE_CEILING_Y, AIR_CAVERN);
|
||||
}
|
||||
}
|
||||
public void aCaveInTheNeighbouringChunkWallsTheBorderBlocksNextToIt() {
|
||||
carve(1, 0, 0, CAVE_Z, CAVE_FLOOR_Y, CAVE_CEILING_Y, AIR_CAVERN);
|
||||
|
||||
apply(false);
|
||||
int first = markers();
|
||||
blocks = new ArrayHunk<>(BlockState.class, 16, HEIGHT, 16, STONE);
|
||||
apply(false);
|
||||
|
||||
assertTrue("about one in sixteen of the 512 floors and ceilings", first > 0 && first < 128);
|
||||
assertEquals(first, markers());
|
||||
assertEquals("the wall against the neighbour's cave", WALL, blocks.get(15, CAVE_FLOOR_Y + 1, CAVE_Z));
|
||||
assertEquals("rock one block further in", STONE, blocks.get(14, CAVE_FLOOR_Y + 1, CAVE_Z));
|
||||
assertEquals("rock beside the cave's rows", STONE, blocks.get(15, CAVE_FLOOR_Y + 1, CAVE_Z + 3));
|
||||
}
|
||||
|
||||
private void carve(int x, int z, int floorY, int ceilingY, MatterCavern cavern) {
|
||||
MantleChunk<Matter> chunk = mantle.chunk(0, 0);
|
||||
carve(0, 0, x, z, floorY, ceilingY, cavern);
|
||||
}
|
||||
|
||||
private void carve(int chunkX, int chunkZ, int x, int z, int floorY, int ceilingY, MatterCavern cavern) {
|
||||
MantleChunk<Matter> chunk = mantle.chunk(chunkX, chunkZ);
|
||||
for (int y = floorY; y <= ceilingY; y++) {
|
||||
chunk.getOrCreate(y >> 4).<MatterCavern>slice(MatterCavern.class).set(x, y & 15, z, cavern);
|
||||
}
|
||||
}
|
||||
|
||||
private void apply(boolean upperDimensionCarving) {
|
||||
MatterMantle matter = new MatterMantle() {
|
||||
@Override
|
||||
public MantleChunk<Matter> chunk(int chunkX, int chunkZ) {
|
||||
return mantle.chunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleChunk<Matter> loadedChunk(int chunkX, int chunkZ) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
CarveWorld carveWorld = new CarveWorld(world.resources().noise(), 1337L, HEIGHT, FLUID_HEIGHT, LAVA_HEIGHT, CarveTestWorld.MIN_HEIGHT);
|
||||
new CaveApplying(world, carveWorld, upperDimensionCarving).apply(matter, terrain, 0, 0, blocks, dressing);
|
||||
}
|
||||
|
||||
private int markers() {
|
||||
int[] count = new int[1];
|
||||
mantle.chunk(0, 0).iterate(MatterMarker.class, (x, y, z, marker) -> count[0]++);
|
||||
return count[0];
|
||||
new CaveApplying(world, carveWorld, upperDimensionCarving).apply(mantle.carved(), terrain, 0, 0, blocks, dressing);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -16,27 +17,27 @@ public class IrisCarveScratchTest {
|
||||
@Test
|
||||
public void wallBufferResizesAndReplacesWithoutLosingEntries() {
|
||||
CarveWallBuffer buffer = new CarveWallBuffer(2);
|
||||
Map<String, MatterCavern> expected = new HashMap<>();
|
||||
Map<String, CarvedVoid> expected = new HashMap<>();
|
||||
for (int index = 0; index < 24; index++) {
|
||||
int x = index & 15;
|
||||
int y = 20 + index;
|
||||
int z = (index * 3) & 15;
|
||||
MatterCavern cavern = new MatterCavern(true, "cave-" + index, (byte) 0);
|
||||
CarvedVoid cavern = CarvedVoid.OPEN.withBiome(new ResourceId("test", "cave-" + index));
|
||||
buffer.put(x, y, z, cavern);
|
||||
expected.put(key(x, y, z), cavern);
|
||||
}
|
||||
|
||||
MatterCavern replacement = new MatterCavern(true, "replacement", (byte) 0);
|
||||
CarvedVoid replacement = CarvedVoid.OPEN.withBiome(new ResourceId("test", "replacement"));
|
||||
buffer.put(5, 25, 15, replacement);
|
||||
expected.put(key(5, 25, 15), replacement);
|
||||
|
||||
assertSame(replacement, buffer.get(5, 25, 15));
|
||||
assertNull(buffer.get(5, 26, 15));
|
||||
|
||||
Map<String, MatterCavern> actual = new HashMap<>();
|
||||
Map<String, CarvedVoid> actual = new HashMap<>();
|
||||
buffer.forEach((x, y, z, cavern) -> actual.put(key(x, y, z), cavern));
|
||||
assertEquals(expected.keySet(), actual.keySet());
|
||||
for (Map.Entry<String, MatterCavern> entry : expected.entrySet()) {
|
||||
for (Map.Entry<String, CarvedVoid> entry : expected.entrySet()) {
|
||||
assertSame(entry.getValue(), actual.get(entry.getKey()));
|
||||
}
|
||||
}
|
||||
@@ -44,11 +45,10 @@ public class IrisCarveScratchTest {
|
||||
@Test
|
||||
public void resetClearsReusableState() {
|
||||
IrisCarveScratch scratch = new IrisCarveScratch();
|
||||
MatterCavern cavern = new MatterCavern(true, "cave", (byte) 0);
|
||||
scratch.columnMasks[0].add(12);
|
||||
scratch.boundaryMasks[0].add(13);
|
||||
scratch.walls.put(1, 12, 2, cavern);
|
||||
scratch.customBiomeCache.put("cave", null);
|
||||
scratch.walls.put(1, 12, 2, CarvedVoid.OPEN);
|
||||
scratch.customBiomeCache.put(new ResourceId("test", "cave"), null);
|
||||
scratch.customCaveBiomePresent = true;
|
||||
|
||||
scratch.reset();
|
||||
|
||||
Reference in new issue
Block a user