mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 02:04:51 +00:00
Objects stop filling channels
- Wet hydrology columns reject solid object blocks between the bed and the surface unless the object is underwater - The column role, head and bed come from the water role, water head and height streams - Object placements tell the destination transaction whether they are underwater - The mutation log and source plans carry the underwater flag so destination replay applies the same rule - Tests cover canopies over channels and ponds, underwater exemptions, replay, piers and sea inlet slots
This commit is contained in:
1 parent
65d06ae83c
commit
0c7b0b7b80
8 files changed
+155
-35
No files matched your search
@@ -21,7 +21,7 @@ public class MutationLogTest {
|
||||
new ObjectDestinationTransaction.SetMutation(new ObjectDestinationTransaction.DataKey(3, 70, -2, String.class), "marker", true),
|
||||
new ObjectDestinationTransaction.CustomBlockMutation(new ObjectDestinationTransaction.DataKey(-17, 4, 40, NativeBlockState.class), state, false)));
|
||||
for (int index = 0; index < 100; index++) {
|
||||
log.add(index, index + 1, -index, "grow" + index, (index & 1) == 0, (index & 2) == 0);
|
||||
log.add(index, index + 1, -index, "grow" + index, (index & 1) == 0, (index & 2) == 0, (index & 4) == 0);
|
||||
}
|
||||
|
||||
assertEquals(102, log.size());
|
||||
@@ -41,6 +41,9 @@ public class MutationLogTest {
|
||||
assertFalse(log.custom(101));
|
||||
assertTrue(log.canopy(98));
|
||||
assertFalse(log.canopy(100));
|
||||
assertFalse(log.underwater(0));
|
||||
assertTrue(log.underwater(98));
|
||||
assertFalse(log.underwater(6));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,7 +62,7 @@ public class MutationLogTest {
|
||||
int z = (index * 5) - 20;
|
||||
String value = "value" + (index % 9);
|
||||
boolean canopy = index % 4 == 0;
|
||||
log.add(x, y, z, value, false, canopy);
|
||||
log.add(x, y, z, value, false, canopy, false);
|
||||
if (index >= 10) {
|
||||
tail.add(new ObjectDestinationTransaction.SetMutation(new ObjectDestinationTransaction.DataKey(x, y, z, String.class), value, canopy));
|
||||
}
|
||||
|
||||
@@ -58,14 +58,14 @@ public class ObjectContinuationTest {
|
||||
public void onlyAcceptedCrossingPlacementsLeaveFutureFragments() throws Exception {
|
||||
Fixture fixture = new Fixture();
|
||||
ObjectDestinationTransaction source = new ObjectDestinationTransaction(fixture.writer, 0, 0);
|
||||
int checkpoint = source.beginObjectPlacement();
|
||||
int checkpoint = source.beginObjectPlacement(false);
|
||||
source.setData(1, 5, 1, "inside");
|
||||
source.endObjectPlacement(checkpoint);
|
||||
checkpoint = source.beginObjectPlacement();
|
||||
checkpoint = source.beginObjectPlacement(false);
|
||||
source.setData(15, 5, 1, "crossing");
|
||||
source.setData(16, 5, 1, "crossing");
|
||||
source.endObjectPlacement(checkpoint);
|
||||
checkpoint = source.beginObjectPlacement();
|
||||
checkpoint = source.beginObjectPlacement(false);
|
||||
source.setData(32, 5, 1, "unrelated");
|
||||
source.setData(48, 5, 1, "unrelated");
|
||||
source.endObjectPlacement(checkpoint);
|
||||
|
||||
+95
-3
@@ -27,6 +27,7 @@ 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.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
@@ -44,6 +45,7 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
@@ -139,7 +141,7 @@ public class ObjectDestinationTransactionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void solidObjectBlocksMayDisplaceWaterButNothingOpenOrCarvedBreaksContainment() {
|
||||
public void onlyUnderwaterObjectsDisplaceWaterAndNothingOpenOrCarvedBreaksContainment() {
|
||||
MantleWriter writer = writer();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
@@ -163,6 +165,7 @@ public class ObjectDestinationTransactionTest {
|
||||
when(raster.terrainHeight(6, 6)).thenReturn(20);
|
||||
when(raster.role(9, 9)).thenReturn(WaterRole.SHORE);
|
||||
when(raster.terrainHeight(9, 9)).thenReturn(20);
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState pier = mock(NativeBlockState.class);
|
||||
when(pier.isSolid()).thenReturn(true);
|
||||
NativeBlockState vine = mock(NativeBlockState.class);
|
||||
@@ -179,10 +182,19 @@ public class ObjectDestinationTransactionTest {
|
||||
assertEquals("open blocks and carves stay out of water, its bed and the bank below the head, and nothing enters a fall", start,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.set(3, 10, 3, pier);
|
||||
transaction.set(4, 15, 3, pier);
|
||||
assertEquals("a land object's pier stays out of the river", start, transaction.mutationCheckpoint());
|
||||
transaction.set(3, 9, 3, pier);
|
||||
transaction.set(6, 18, 6, pier);
|
||||
assertEquals("a pier keeps its blocks on the river bed and the shore", start + 2, transaction.mutationCheckpoint());
|
||||
transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 10, 3, pier);
|
||||
transaction.set(4, 15, 3, pier);
|
||||
assertEquals("a pier into the river keeps its blocks", start + 4, transaction.mutationCheckpoint());
|
||||
assertEquals("an underwater pier keeps its blocks in the river", start + 4, transaction.mutationCheckpoint());
|
||||
transaction.set(3, 12, 3, pier);
|
||||
transaction.set(3, 10, 3, vine);
|
||||
assertEquals("an underwater object still keeps out of falls and open water", start + 4, transaction.mutationCheckpoint());
|
||||
transaction.beginObjectPlacement(false);
|
||||
transaction.set(3, 16, 3, vine);
|
||||
transaction.set(3, 8, 3, vine);
|
||||
transaction.set(6, 19, 6, vine);
|
||||
@@ -208,6 +220,7 @@ public class ObjectDestinationTransactionTest {
|
||||
when(raster.role(3, 3)).thenReturn(WaterRole.INLET);
|
||||
when(raster.waterHead(3, 3)).thenReturn(12);
|
||||
when(raster.terrainHeight(3, 3)).thenReturn(9);
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState boulder = mock(NativeBlockState.class);
|
||||
when(boulder.isSolid()).thenReturn(true);
|
||||
NativeBlockState leaves = mock(NativeBlockState.class);
|
||||
@@ -217,16 +230,72 @@ public class ObjectDestinationTransactionTest {
|
||||
transaction.set(3, 13, 3, boulder);
|
||||
transaction.set(3, 30, 3, boulder);
|
||||
transaction.set(3, 14, 3, leaves);
|
||||
transaction.set(3, 10, 3, boulder);
|
||||
assertEquals("nothing an object places roofs or fills the slot between its water and the cliff top", start,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 10, 3, boulder);
|
||||
assertEquals("a solid block below the water may still sit on the slot bed", start + 1, transaction.mutationCheckpoint());
|
||||
transaction.set(3, 12, 3, boulder);
|
||||
assertEquals("an underwater object's solid block below the water may still sit on the slot bed", start + 1,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.beginObjectPlacement(false);
|
||||
transaction.set(3, 31, 3, leaves);
|
||||
transaction.set(3, 36, 3, leaves);
|
||||
transaction.set(3, 33, 3, boulder);
|
||||
assertEquals("a tree canopy above the cliff top keeps its leaves and wood", start + 4, transaction.mutationCheckpoint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canopiesDoNotFillChannels() {
|
||||
MantleWriter writer = writer();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
when(writer.getEngine().getComplex()).thenReturn(complex);
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
|
||||
when(raster.role(anyInt(), anyInt())).thenReturn(WaterRole.NONE);
|
||||
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
|
||||
when(raster.terrainHeight(anyInt(), anyInt())).thenReturn(20);
|
||||
when(raster.role(3, 3)).thenReturn(WaterRole.CHANNEL);
|
||||
when(raster.waterHead(3, 3)).thenReturn(14);
|
||||
when(raster.terrainHeight(3, 3)).thenReturn(10);
|
||||
when(raster.role(4, 3)).thenReturn(WaterRole.POND);
|
||||
when(raster.waterHead(4, 3)).thenReturn(14);
|
||||
when(raster.terrainHeight(4, 3)).thenReturn(8);
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState leaves = mock(NativeBlockState.class);
|
||||
when(leaves.isSolid()).thenReturn(true);
|
||||
ObjectDestinationTransaction transaction = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
int start = transaction.mutationCheckpoint();
|
||||
for (int y = 11; y <= 14; y++) {
|
||||
setCanopy(transaction, 3, y, 3, leaves);
|
||||
}
|
||||
for (int y = 9; y <= 14; y++) {
|
||||
setCanopy(transaction, 4, y, 3, leaves);
|
||||
}
|
||||
assertEquals("canopy leaves never fill a channel or pond between its bed and its surface", start,
|
||||
transaction.mutationCheckpoint());
|
||||
setCanopy(transaction, 3, 10, 3, leaves);
|
||||
setCanopy(transaction, 3, 15, 3, leaves);
|
||||
setCanopy(transaction, 4, 8, 3, leaves);
|
||||
setCanopy(transaction, 5, 14, 3, leaves);
|
||||
assertEquals("the bed, the air above the surface and dry land keep their leaves", start + 4,
|
||||
transaction.mutationCheckpoint());
|
||||
int underwater = transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 12, 3, leaves);
|
||||
transaction.set(4, 9, 3, leaves);
|
||||
assertEquals("an underwater object keeps its solid blocks in the water", underwater + 2,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.endObjectPlacement(underwater);
|
||||
ObjectDestinationTransaction destination = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
destination.apply(transaction.sourcePlanSince(start));
|
||||
assertEquals("the destination replay keeps the underwater blocks", 6, destination.mutationCheckpoint());
|
||||
assertSame(leaves, destination.get(3, 12, 3));
|
||||
assertSame(leaves, destination.get(4, 9, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sourceCaptureCannotReplaceAuthoredRoomSolids() {
|
||||
MantleWriter writer = writer();
|
||||
@@ -769,6 +838,29 @@ public class ObjectDestinationTransactionTest {
|
||||
verify(writer).restoreData(0, 4, 0, Identifier.class, originalIdentifier);
|
||||
}
|
||||
|
||||
private static void setCanopy(ObjectDestinationTransaction transaction, int x, int y, int z, NativeBlockState state) {
|
||||
assertTrue(transaction.beginTreeCanopy(new BlockPosition(x, y, z)));
|
||||
transaction.set(x, y, z, state);
|
||||
transaction.endTreeCanopy();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void followRasterStreams(IrisComplex complex, ChunkWaterRaster raster) {
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
ProceduralStream<Integer> heights = mock(ProceduralStream.class);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.role(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenAnswer(call -> (double) raster.waterHead(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heights.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.terrainHeight(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(heights);
|
||||
}
|
||||
|
||||
private static int local(Object coordinate) {
|
||||
return (int) Math.floor(((Number) coordinate).doubleValue()) & 15;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static MantleWriter writer() {
|
||||
MantleWriter writer = mock(MantleWriter.class);
|
||||
|
||||
Reference in new issue
Block a user