mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 09:15:27 +00:00
Buffer module mantle edits and remove short-lived module layers on mantle cleanup
Mantle.edit() is bridged: an edit buffers sets and removals across layers per block, its reads and visits see them over the unchanged mantle, and commit() publishes them all, or none when a chunk it touches was not prepared; the edit can then only be closed. While an edit is open the view itself only reads, a second edit is refused and edits do not nest. Module layers registered with the GENERATION lifetime are now removed when Iris cleans a generated mantle chunk, in both the covered cleanup and the pregenerator's forced cleanup, as Iris deletes its own transient slices (GenerationLayers). Persistent layers and layers no loaded module registers stay, retaining ModuleLayerValues keeps them all, and a pack whose modules fail to load keeps its layers.
This commit is contained in:
1 parent
0a06d5ff29
commit
c0e8b5e7e1
7 files changed
+473
-24
No files matched your search
@@ -41,7 +41,9 @@ import com.volmit.host.MantleRegistration;
|
||||
import com.volmit.host.ModuleHost;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.mantle.MantleCodec;
|
||||
import com.volmit.mantle.MantleEdit;
|
||||
import com.volmit.mantle.MantleKey;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.mantle.MantleLifetime;
|
||||
import com.volmit.stage.Stage;
|
||||
import com.volmit.stage.StageGraph;
|
||||
@@ -169,6 +171,93 @@ public class IrisModuleMantleTest {
|
||||
assertArrayEquals(bytes(ModuleLayerValues.EMPTY.with(DEPTHS, NUMBER, 4)), bytes(withoutCodecs));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anEditBuffersChangesAcrossLayersUntilItCommits() {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(-16, MIN_Y, -16, 32, 0, 32));
|
||||
mantle.layer(MARKS).set(1, -60, 1, "stored");
|
||||
mantle.layer(MARKS).set(2, -60, 1, "removed");
|
||||
List<String> visited = new ArrayList<>();
|
||||
|
||||
try (MantleEdit edit = mantle.edit()) {
|
||||
edit.layer(MARKS).set(20, -50, 0, "added");
|
||||
edit.layer(MARKS).remove(2, -60, 1);
|
||||
edit.layer(DEPTHS).set(20, -50, 0, 3);
|
||||
edit.layer(MARKS).visit(new BlockBox(-16, MIN_Y, -16, 32, 0, 32), (x, y, z, value) -> visited.add(value + "@" + x));
|
||||
|
||||
assertEquals("added", edit.layer(MARKS).get(20, -50, 0));
|
||||
assertNull(edit.layer(MARKS).get(2, -60, 1));
|
||||
assertNull("the mantle is unchanged until the commit", mantle.layer(MARKS).get(20, -50, 0));
|
||||
assertEquals("removed", mantle.layer(MARKS).get(2, -60, 1));
|
||||
edit.commit();
|
||||
}
|
||||
|
||||
assertEquals(List.of("stored@1", "added@20"), visited);
|
||||
assertEquals("added", mantle.layer(MARKS).get(20, -50, 0));
|
||||
assertEquals(Integer.valueOf(3), mantle.layer(DEPTHS).get(20, -50, 0));
|
||||
assertNull(mantle.layer(MARKS).get(2, -60, 1));
|
||||
assertEquals("stored", mantle.layer(MARKS).get(1, -60, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aClosedEditChangesNothingAndAnOpenEditKeepsTheMantleReadOnly() {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(0, MIN_Y, 0, 16, 0, 16));
|
||||
MantleEdit edit = mantle.edit();
|
||||
MantleLayer<String> marks = edit.layer(MARKS);
|
||||
marks.set(1, -60, 1, "discarded");
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> mantle.layer(MARKS).set(0, -60, 0, "direct"));
|
||||
assertThrows(IllegalStateException.class, mantle::edit);
|
||||
assertThrows(UnsupportedOperationException.class, edit::edit);
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> marks.set(16, -60, 0, "out"));
|
||||
edit.close();
|
||||
edit.close();
|
||||
|
||||
assertNull(mantle.layer(MARKS).get(1, -60, 1));
|
||||
IllegalStateException closed = assertThrows(IllegalStateException.class, () -> marks.get(1, -60, 1));
|
||||
assertEquals("This mantle edit is closed; open a new one with edit()", closed.getMessage());
|
||||
assertThrows(IllegalStateException.class, edit::commit);
|
||||
mantle.layer(MARKS).set(0, -60, 0, "direct");
|
||||
mantle.edit().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aCommitThatCannotReachEveryChunkPublishesNothing() {
|
||||
IrisModuleMantle mantle = new IrisModuleMantle(new BlockBox(0, MIN_Y, 0, 32, 0, 16), MIN_Y,
|
||||
(chunkX, chunkZ) -> chunkX == 0 ? chunk(chunkX, chunkZ) : null, LAYERS);
|
||||
MantleEdit edit = mantle.edit();
|
||||
edit.layer(MARKS).set(1, -60, 1, "first");
|
||||
edit.layer(MARKS).set(20, -60, 1, "unprepared");
|
||||
|
||||
assertThrows(IllegalStateException.class, edit::commit);
|
||||
assertNull(mantle.layer(MARKS).get(1, -60, 1));
|
||||
assertThrows(IllegalStateException.class, edit::commit);
|
||||
assertThrows(IllegalStateException.class, () -> mantle.layer(MARKS).set(2, -60, 1, "still open"));
|
||||
edit.close();
|
||||
mantle.layer(MARKS).set(2, -60, 1, "after close");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cleanupRemovesGenerationLayersAndKeepsPersistentAndUnknownOnes() throws IOException {
|
||||
IrisModuleMantle mantle = mantle(new BlockBox(0, MIN_Y, 0, 16, 0, 16));
|
||||
mantle.layer(MARKS).set(1, -60, 1, "short-lived");
|
||||
mantle.layer(DEPTHS).set(1, -60, 1, 7);
|
||||
mantle.layer(MARKS).set(2, -10, 3, "alone");
|
||||
MantleKey<String> unknown = new MantleKey<>("iris:gone/layer", String.class);
|
||||
ModuleLayerValues fromDisk = ModuleLayerValues.read(input(bytes(ModuleLayerValues.EMPTY.with(unknown, TEXT, "kept")
|
||||
.with(MARKS, TEXT, "old"))));
|
||||
chunk(0, 0).getOrCreate((-30 - MIN_Y) >> 4).slice(ModuleLayerValues.class).set(4, (-30 - MIN_Y) & 15, 4, fromDisk);
|
||||
|
||||
GenerationLayers.of(LAYERS).removeFrom(chunk(0, 0));
|
||||
|
||||
assertNull(mantle.layer(MARKS).get(1, -60, 1));
|
||||
assertEquals(Integer.valueOf(7), mantle.layer(DEPTHS).get(1, -60, 1));
|
||||
assertNull("a block left without values holds nothing", chunk(0, 0).get((-10 - MIN_Y) >> 4)
|
||||
.<ModuleLayerValues>slice(ModuleLayerValues.class).get(2, (-10 - MIN_Y) & 15, 3));
|
||||
assertNull(mantle.layer(MARKS).get(4, -30, 4));
|
||||
ModuleLayerValues left = chunk(0, 0).get((-30 - MIN_Y) >> 4).<ModuleLayerValues>slice(ModuleLayerValues.class).get(4, (-30 - MIN_Y) & 15, 4);
|
||||
assertEquals("a layer no module registers stays", "kept", left.get(unknown, TEXT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mantleStagesWriteAroundTheirChunkThroughIrisChunks() throws IOException {
|
||||
MantleKey<String> planned = new MantleKey<>("iris:veins/planned", String.class);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package art.arcane.iris.engine.mantle;
|
||||
|
||||
import art.arcane.iris.core.link.Identifier;
|
||||
import art.arcane.iris.core.modules.GenerationLayers;
|
||||
import art.arcane.iris.core.modules.ModuleLayerValues;
|
||||
import art.arcane.iris.engine.framework.TreeBlockMaterial;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
@@ -26,6 +28,7 @@ import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -116,6 +119,31 @@ public class EngineMantleCleanupTest {
|
||||
verifyCleanup(fixture.chunk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bothCleanupsRemoveThePacksGenerationLayers() {
|
||||
CleanupFixture fixture = cleanupFixture();
|
||||
GenerationLayers layers = mock(GenerationLayers.class);
|
||||
doReturn(layers).when(fixture.engineMantle()).getGenerationLayers();
|
||||
doReturn(true).when(fixture.engineMantle()).isCovered(7, -4);
|
||||
|
||||
fixture.engineMantle().cleanupChunk(7, -4);
|
||||
fixture.engineMantle().forceCleanupChunk(7, -4);
|
||||
|
||||
verify(layers, times(2)).removeFrom(fixture.chunk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retainedModuleLayersSurviveCleanup() {
|
||||
MantleSliceRetention.retain(ModuleLayerValues.class.getCanonicalName());
|
||||
CleanupFixture fixture = cleanupFixture();
|
||||
GenerationLayers layers = mock(GenerationLayers.class);
|
||||
doReturn(layers).when(fixture.engineMantle()).getGenerationLayers();
|
||||
|
||||
fixture.engineMantle().forceCleanupChunk(7, -4);
|
||||
|
||||
verify(layers, never()).removeFrom(any());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private CleanupFixture cleanupFixture() {
|
||||
EngineMantle engineMantle = mock(EngineMantle.class, CALLS_REAL_METHODS);
|
||||
|
||||
Reference in new issue
Block a user