API reference / @jsprismarine/chunkgen / GenerationScheduler
Class: GenerationScheduler<TChunk>
Defined in: GenerationScheduler.ts:65
Drives chunks up the ladder, one layer of the neighborhood at a time.
Java's ChunkGenerationTask.runUntilWait, with one run per call to generate. To bring a chunk to a status, the neighborhood has to reach that status's dependencies first, so the run walks the ladder from empty upward and at each rung applies the step to the square of chunks the accumulated dependency table sizes. Driving one chunk to terrain is therefore five layers at radii 9, 9, 1, 1 and 0, and driving one to full is ten at 11, 11, 3, 3, 2, 1, 1, 0, 0, 0.
Concurrent runs share work rather than duplicate it, because a holder keeps one promise per status and the second run to reach a rung awaits the first run's promise. Nine chunks asked for at once build terrain over the union of their windows, not over nine separate windows: at a full target that is 49 terrain bodies rather than 225.
The result does not depend on the order runs arrive or how many are outstanding. Every body reads through StepRegion, which refuses an input the step table did not declare, and nothing re-enters a rung, so a status's inputs are the same set whichever run happened to create its promise.
Each run acquires its whole neighborhood before it runs a step and releases it at the end, including when a body throws. A caller that needs the chunk to stay resident afterwards acquires its own reference on the holder first; otherwise the holders are dropped and the returned chunk is all that survives.
Type Parameters
TChunk
TChunk extends StagedChunk
Constructors
Constructor
new GenerationScheduler<
TChunk>(options):GenerationScheduler<TChunk>
Defined in: GenerationScheduler.ts:71
Parameters
options
GenerationSchedulerOptions<TChunk>
The holder map, the status bodies, and optionally a pyramid to replace the generation one.
Returns
GenerationScheduler<TChunk>
Methods
generate()
generate(
chunkX,chunkZ,target):Promise<TChunk>
Defined in: GenerationScheduler.ts:98
Brings one chunk to a status, bringing its neighborhood to that status's dependencies first.
Parameters
chunkX
number
chunkZ
number
target
"empty" | "structure_starts" | "structure_references" | "biomes" | "terrain" | "features" | "initialize_light" | "light" | "spawn" | "full"
Returns
Promise<TChunk>
The chunk at target. It is the live chunk the holder owns, so a later run that drives it further changes the same object.
Throws
MissingGenerationLayerError when the step table leaves a layer below the target without a radius.
layersFor()
layersFor(
target): readonly (readonly ["empty"|"structure_starts"|"structure_references"|"biomes"|"terrain"|"features"|"initialize_light"|"light"|"spawn"|"full",number])[]
Defined in: GenerationScheduler.ts:83
The layers a run walks for a target, from empty up to the target itself.
Parameters
target
"empty" | "structure_starts" | "structure_references" | "biomes" | "terrain" | "features" | "initialize_light" | "light" | "spawn" | "full"
Returns
readonly (readonly ["empty" | "structure_starts" | "structure_references" | "biomes" | "terrain" | "features" | "initialize_light" | "light" | "spawn" | "full", number])[]
One entry per status, in ladder order, with the radius in chunks of the square that layer applies its step to.