1.7 KiB
1.7 KiB
Chunk Storage And Streaming
What It Does
World data is stored as per-chunk JSON files and loaded into the editor as chunk neighborhoods around a center chunk. The runtime caches chunk payloads, shifts neighborhoods as the viewport moves, and saves dirty chunks in batches.
Key Files
server.jssrc/worldChunking.tssrc/worldshaperStudio/bootstrap.tssrc/worldshaperStudio/runtime.tssrc/worldshaperStudio/persistenceController.ts
Endpoints It Uses
GET /api/world/:worldId/chunk/:chunkX/:chunkYPOST /api/world/:worldId/chunk/:chunkX/:chunkYGET /api/world/:worldId/chunksPOST /api/world/:worldId/chunks/batch-save
Important Data And Rules
- chunks are stored as
content/worlds/<worldId>/chunks/<x>_<y>.json - world neighborhoods are requested as a square around a center chunk
- runtime keeps a chunk cache and tracks dirty chunk keys
- chunk payloads include
roomLayers,heightLayers,instances, and optionalbackgroundTileId
Invariants And Constraints
- Exact chunk lookup is grid-based and direct.
- The editor does not load the entire world for normal editing.
- Small tile edits must sync back into the correct cached chunk.
- Save flow should preserve chunk-local edits without rebuilding unrelated chunks.
Common Request Themes
- chunk loading speed
- chunk streaming behavior
- per-chunk backgrounds
- chunk transforms, duplication, deletion
- performance questions around indexing and caching
Triage Questions
- Is the request about storage, fetch patterns, cache behavior, or save behavior?
- Does it affect only visible chunks or the full world?
- Is the user asking for chunk-local data, or freeform world overlays that break chunk assumptions?