ChunkedWorldOptions
Options for makeChunkedWorld.
Defined in: engine/src/chunks.ts:101
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
chunk | number | Chunk footprint in voxels. Should be a multiple of the 8-voxel brick. | engine/src/chunks.ts:113 |
fill? | ChunkFillSource | Fill chunks on workers instead of in generate (opt-in; usually makeChunkFillPool from @voxolith/engine/worker). focus queues chunks as before; the world keeps up to fill.capacity requests out, nearest first, and step applies the chunks that have come back, nearest first, within its budget: the main thread only copies bricks in. A chunk counts as built (resident, pendingWithin, whenReady, the ground phase) once it is applied. A chunk freed (beyond keep) while queued or out is dropped, and its result with it. The worker fills each brick from empty and the brick is replaced by the result, which is what generate writes whenever a chunk's bricks start empty, as they do (a chunk is new, or cleared when freed). So chunk must be a multiple of 8 here, or two chunks would share bricks. A request that fails leaves its chunk unbuilt: it is reported to onError, not retried until it has been freed, and whenReady over it rejects. | engine/src/chunks.ts:136 |
load? | LoadTracker | Report into a load tracker under the ground phase: focus adds the chunks it newly queues and step ticks each one it builds, so the total is what was actually asked for. Freed chunks are not counted back; revisiting one queues it again and adds it again. The phase ends when the queue is empty and starts again when the camera moves on. | engine/src/chunks.ts:154 |
seed | number | Mixed with chunk coordinates into each chunk's rng. | engine/src/chunks.ts:115 |
size | object | World extent in voxels; chunks are columns over the full height. | engine/src/chunks.ts:111 |
size.x | number | - | engine/src/chunks.ts:111 |
size.y | number | - | engine/src/chunks.ts:111 |
size.z | number | - | engine/src/chunks.ts:111 |
target | BrickTarget & object | Usually the Renderer. With fill, chunks are applied through editMany when the target has it (one upload per chunk), else through edit per box. | engine/src/chunks.ts:106 |
Methods
boxes()?
optional boxes(chunk: ChunkRef): Box[];Defined in: engine/src/chunks.ts:142
With fill: the boxes to fill for a chunk, clamped to it (default the chunk's whole box).
Tight boxes are what make it cheap, e.g. one per 8x8 brick column from the terrain's
columnSpan. Runs on the main thread when the chunk is sent.
Parameters
| Parameter | Type |
|---|---|
chunk | ChunkRef |
Returns
Box[]
generate()?
optional generate(ctx: ChunkContext): void;Defined in: engine/src/chunks.ts:121
Fills one chunk. Must depend only on ctx, never on call order. Required without fill.
With fill it is optional and runs on the main thread after the chunk's bricks are applied,
for what cannot move to a worker (blitting entities, say).
Parameters
| Parameter | Type |
|---|---|
ctx | ChunkContext |
Returns
void
onError()?
optional onError(error: unknown, chunk: ChunkRef): void;Defined in: engine/src/chunks.ts:147
With fill: called when a chunk's request fails (the fill threw, the worker died), with the
error. Default: console.error. Not called for requests the world cancelled itself.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
chunk | ChunkRef |
Returns
void
ChunkedWorld
A world built around a moving focus, from makeChunkedWorld.
ChunkFillSource
Where a chunked world gets its chunks filled off the main thread: makeChunkFillPool from @voxolith/engine/worker implements it. Anything that fills boxes of bricks asynchronously can stand in (a test, another transport).