Batch 1 of the API review: one setup entry point, per-pipeline definitions

- IrisModule.setup(ModuleSetup) replaces install(StageGraph) and
  register(FeatureRegistry); ModuleSetups.run is the host entry point.
- The conditional definition variants are gone: a stage body reads the
  settings it is conditioned on through ctx.configured(Type.class).
- Placement, block, chunk and mantle stages each get their own
  definition interface; chunk definitions offer neither reach nor
  writesMantle. MantleStage is no longer generic.
- softAfter/softBefore take stage constants as well as StageRefs.
- A producer that rejected the attempt may return null.
- PlacementRunner, ChunkRunner and MantleRunner all take StageTimings.
- ConfiguredSettings groups entries by the type that declares @Feature.
- README, DESIGN and CONTRACTS updated, with the edge choice table.
This commit is contained in:
piexel committed 2026-10-23 13:00:07 +02:00
1 parent d3c0e4d6cc
commit 1677f4414b
75 files changed
+1201 -838

No files matched your search

@@ -4,6 +4,7 @@ import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.ModuleSetup;
import com.volmit.block.BlockState;
import com.volmit.config.Feature;
import com.volmit.config.FeatureSettings.Entry;
@@ -17,17 +18,17 @@ import com.volmit.host.ChunkRunner;
import com.volmit.host.DiscoveredModule;
import com.volmit.host.LoadedModules;
import com.volmit.host.MantleRunner;
import com.volmit.host.StageGraphBuilder;
import com.volmit.host.StageTimings;
import com.volmit.hunk.Hunk;
import com.volmit.mantle.BlockBox;
import com.volmit.resource.ResourceId;
import com.volmit.stage.Pipeline;
import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import com.volmit.support.ColumnSettings;
import com.volmit.support.DeclaredSettings;
import com.volmit.support.MemoryMantle;
import com.volmit.support.TestContexts;
import com.volmit.support.TestSetups;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -52,10 +53,7 @@ class ChunkPipelineTest {
static final class Marker implements IrisFeature {}
private static ChunkRunner runner() {
var builder = new StageGraphBuilder();
builder.install(DiscoveredModule.builtIn(new GrassModule()));
builder.install(DiscoveredModule.builtIn(new TerrainModule()));
var graph = builder.resolve(Pipeline.CHUNK);
var graph = TestSetups.stages(new GrassModule(), new TerrainModule()).resolve(Pipeline.CHUNK);
assertEquals(List.of("iris:terrain/surface", "example:grass/top"),
graph.stages().stream().map(stage -> stage.stage().id().toString()).toList());
assertTrue(graph.blockPasses().isEmpty());
@@ -64,7 +62,7 @@ class ChunkPipelineTest {
private static Hunk<BlockState> generate(ColumnSettings settings) {
var blocks = new ArrayHunk<>(BlockState.class, SIZE, HEIGHT, SIZE, AIR);
runner().generate(TestContexts.generation(Map.of(BlockState.class, blocks), settings, null), TestContexts.SEED);
runner().generate(TestContexts.generation(Map.of(BlockState.class, blocks), settings, null), TestContexts.SEED, StageTimings.NONE);
return blocks;
}
@@ -116,18 +114,17 @@ class ChunkPipelineTest {
var stage = Stage.chunk("test:levels/read");
IrisModule module = new IrisModule() {
public ModuleInfo info() { return ModuleInfo.of("test:levels", "Levels", "1"); }
public void install(StageGraph graph) {
graph.define(stage).when(Marker.class).run((context, entries) -> {
received.add(entries.stream().map(Entry::source).toList());
public void setup(ModuleSetup setup) {
setup.stages().define(stage).when(Marker.class).run(context -> {
received.add(context.configured(Marker.class).stream().map(Entry::source).toList());
received.add(context.settings().at(Marker.class, 0, 0).stream().map(Entry::source).toList());
});
}
};
var builder = new StageGraphBuilder();
builder.install(DiscoveredModule.builtIn(module));
var settings = new ColumnSettings((x, z) -> List.of(dimension, x < 8 ? swamp : plains));
new ChunkRunner(builder.resolve(Pipeline.CHUNK)).generate(TestContexts.generation(Map.of(), settings, null), TestContexts.SEED);
new ChunkRunner(TestSetups.stages(module).resolve(Pipeline.CHUNK))
.generate(TestContexts.generation(Map.of(), settings, null), TestContexts.SEED, StageTimings.NONE);
assertEquals(List.of(List.of(DIMENSION, SWAMP, PLAINS), List.of(DIMENSION, SWAMP)), received,
"the body sees every level of every column, a column read that column's levels");
@@ -143,13 +140,14 @@ class ChunkPipelineTest {
var reachArea = new BlockBox(-reach, BOTTOM, -reach, CHUNK + reach, TOP, CHUNK + reach);
new MantleRunner(loaded.mantle()).generate(VeinModule.PLAN,
TestContexts.mantle(0, 0, ColumnSettings.everywhere(vein), mantle.within(reachArea)), TestContexts.SEED);
TestContexts.mantle(0, 0, ColumnSettings.everywhere(vein), mantle.within(reachArea)), TestContexts.SEED, StageTimings.NONE);
assertEquals(1, mantle.get(VeinModule.ORE, 18, 4, 7), "the vein runs on into the next chunk");
var blocks = new ArrayHunk<>(BlockState.class, CHUNK, HEIGHT, CHUNK, AIR);
var chunkArea = new BlockBox(0, BOTTOM, 0, CHUNK, TOP, CHUNK);
new ChunkRunner(loaded.chunk()).generate(
TestContexts.generation(Map.of(BlockState.class, blocks), ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED);
TestContexts.generation(Map.of(BlockState.class, blocks), ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED,
StageTimings.NONE);
assertEquals(VeinModule.ORE_BLOCK, blocks.get(7, 4, 7));
assertEquals(VeinModule.ORE_BLOCK, blocks.get(15, 4, 7));
assertEquals(AIR, blocks.get(6, 4, 7));
@@ -165,19 +163,18 @@ class ChunkPipelineTest {
var copy = Stage.chunk("test:copy/insert");
IrisModule module = new IrisModule() {
public ModuleInfo info() { return ModuleInfo.of("test:copy", "Copy", "1"); }
public void install(StageGraph graph) {
graph.define(copy).run(context -> {
public void setup(ModuleSetup setup) {
setup.stages().define(copy).run(context -> {
var blocks = context.hunk(BlockState.class);
context.mantle().blocks().visit(chunkArea, (x, y, z, block) -> blocks.set(x, y, z, block));
});
}
};
var builder = new StageGraphBuilder();
builder.install(DiscoveredModule.builtIn(module));
var blocks = new ArrayHunk<>(BlockState.class, CHUNK, HEIGHT, CHUNK, GRASS);
new ChunkRunner(builder.resolve(Pipeline.CHUNK)).generate(
TestContexts.generation(Map.of(BlockState.class, blocks), ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED);
new ChunkRunner(TestSetups.stages(module).resolve(Pipeline.CHUNK)).generate(
TestContexts.generation(Map.of(BlockState.class, blocks), ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED,
StageTimings.NONE);
assertEquals(stone, blocks.get(3, 2, 5));
assertEquals(AIR, blocks.get(4, 2, 5), "air a placement planned replaces what the chunk had");
@@ -194,20 +191,19 @@ class ChunkPipelineTest {
var probe = Stage.chunk("test:caves/probe");
IrisModule module = new IrisModule() {
public ModuleInfo info() { return ModuleInfo.of("test:caves", "Caves", "1"); }
public void install(StageGraph graph) {
graph.define(probe).run(context -> {
public void setup(ModuleSetup setup) {
setup.stages().define(probe).run(context -> {
var caverns = context.mantle().caverns();
carved.add(String.valueOf(caverns.get(6, 9, 2)));
carved.add(String.valueOf(caverns.get(6, 10, 2)));
});
}
};
var builder = new StageGraphBuilder();
builder.install(DiscoveredModule.builtIn(module));
var blocks = new ArrayHunk<>(BlockState.class, CHUNK, HEIGHT, CHUNK, AIR);
new ChunkRunner(builder.resolve(Pipeline.CHUNK)).generate(
TestContexts.generation(Map.of(BlockState.class, blocks), ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED);
new ChunkRunner(TestSetups.stages(module).resolve(Pipeline.CHUNK)).generate(
TestContexts.generation(Map.of(BlockState.class, blocks), ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED,
StageTimings.NONE);
assertEquals(List.of("true", "null"), carved);
assertThrows(UnsupportedOperationException.class, () -> mantle.within(chunkArea).caverns().set(0, 0, 0, true));
@@ -230,16 +226,15 @@ class ChunkPipelineTest {
var mantle = new MemoryMantle();
IrisModule module = new IrisModule() {
public ModuleInfo info() { return ModuleInfo.of("test:writer", "Writer", "1"); }
public void install(StageGraph graph) {
graph.define(stage).run(context -> context.mantle().layer(VeinModule.ORE).set(0, 0, 0, 1));
public void setup(ModuleSetup setup) {
setup.stages().define(stage).run(context -> context.mantle().layer(VeinModule.ORE).set(0, 0, 0, 1));
}
};
var builder = new StageGraphBuilder();
builder.install(DiscoveredModule.builtIn(module));
var graph = TestSetups.stages(module).resolve(Pipeline.CHUNK);
var inputs = TestContexts.generation(Map.of(), ColumnSettings.NONE, mantle.within(new BlockBox(0, BOTTOM, 0, CHUNK, TOP, CHUNK)));
var failure = assertThrows(UnsupportedOperationException.class,
() -> new ChunkRunner(builder.resolve(Pipeline.CHUNK)).generate(inputs, TestContexts.SEED));
() -> new ChunkRunner(graph).generate(inputs, TestContexts.SEED, StageTimings.NONE));
assertEquals("Chunk stages read the mantle but do not write it; write it from a mantle stage (Stage.mantle),"
+ " which runs before the chunks it reaches", failure.getMessage());
assertNull(mantle.get(VeinModule.ORE, 0, 0, 0));