ChunkManager

Manages streaming 2D tile/entity chunks. Handles radius-based loading, prefetching, unloading, async cancellation, and chunk state mutation persistence across unloads.

Constructor

new ChunkManager(optionsopt)

Parameters:
NameTypeAttributesDescription
optionsObject<optional>
Properties
NameTypeAttributesDefaultDescription
chunkSizenumber<optional>
16

Size of a chunk in world units/tiles

loadRadiusnumber<optional>
1

Radius of chunks to keep loaded and active

prefetchRadiusnumber<optional>
2

Radius of chunks to fetch in advance

unloadRadiusnumber<optional>
3

Radius beyond which chunks are unloaded

Classes

ChunkManager

Methods

recordChange()

Record a persistent change to a chunk (e.g. chest opened, wall destroyed). Changes survive chunk unload and reload.

(async) updatePosition(worldX, worldY, sceneopt) → {Promise.<{loaded: Array.<string>, unloaded: Array.<string>}>}

Update center position (e.g. player location) and stream chunks.

Parameters:
NameTypeAttributesDefaultDescription
worldXnumber
worldYnumber
sceneobject<optional>
null

Parent scene to attach loaded chunk entities

Returns:
Type: 
Promise.<{loaded: Array.<string>, unloaded: Array.<string>}>