Give every stage its own random stream derived from the invocation seed and stage id

Stages no longer share one RandomGenerator. StageContext.random() is the
running stage's own stream: java.util.Random seeded with
mix(mix(invocationSeed) ^ fnv1a64(utf8(stageId))), mix being the
SplitMix64 finalizer. Adding, removing or reordering modules, or how much
other stages draw, no longer changes a stage's draws. A block stage keeps
one stream across the blocks of its pass.

The host passes a long invocation seed to PlacementRunner.place and
ChunkRunner.generate instead of a RandomGenerator on the inputs;
InvocationContext loses random(), so stages cannot reach a shared stream.
ObjectGenerationContext keeps its own random() for geometry generators.
StageRandom documents the derivation, and a test pins it to values
computed from the specification.
This commit is contained in:
piexel committed 2026-10-05 21:34:19 +02:00
1 parent 4cb718f706
commit 307e488d1a
17 files changed
+293 -34

No files matched your search

@@ -37,7 +37,7 @@ class ChunkPipelineTest {
private static Hunk<BlockState> generate(ConfiguredSettings settings) {
var blocks = new ArrayHunk<>(BlockState.class, SIZE, HEIGHT, SIZE, AIR);
runner().generate(TestContexts.generation(Map.of(BlockState.class, blocks)), settings);
runner().generate(TestContexts.generation(Map.of(BlockState.class, blocks)), TestContexts.SEED, settings);
return blocks;
}
@@ -10,6 +10,7 @@ import com.volmit.host.LoadedModules;
import com.volmit.host.PlacementRunner;
import com.volmit.host.ResolvedGraph;
import com.volmit.host.StageGraphBuilder;
import com.volmit.host.StageRandom;
import com.volmit.mantle.BlockBox;
import com.volmit.object.GeneratedObject;
import com.volmit.object.ObjectBlock;
@@ -110,14 +111,16 @@ class PlacementLifecyclePortTest {
private static MemoryEdit place(ResolvedGraph graph, ConfiguredSettings settings) {
var terrain = terrain();
var edit = new MemoryEdit(terrain);
var outcome = new PlacementRunner(graph).place(request(), edit, TestContexts.placement(terrain), settings);
var outcome = new PlacementRunner(graph).place(request(), edit, TestContexts.placement(terrain), TestContexts.SEED, settings);
assertTrue(outcome.isPlaced());
return edit;
}
/** World position of a local block after the seeded rotation and surface anchoring. */
/** World position of a local block after the seeded rotation and surface anchoring. The rotation
* is the first draw of the transforms stage's own stream.
*/
private static BlockPosition placed(int x, int y, int z) {
var transforms = new Transforms(new Random(TestContexts.SEED).nextInt(4));
var transforms = new Transforms(StageRandom.stream(TestContexts.SEED, PrepareModule.TRANSFORMS.id()).nextInt(4));
var rotated = transforms.rotate(new BlockPosition(x, y, z), new BlockPosition(0, 0, 0));
return rotated.add(SURFACE_ANCHOR);
}