Architecture
TheSave class (src/save.h/cpp) coordinates:
- Initial world loading with configurable radius
- Chunk streaming during gameplay
- Automatic unloading of distant chunks
- Chunk serialization using NBT gzip format
File Organization
Chunks are stored in a Minecraft-style directory structure using base36 encoding:rx = x % 64,rz = z % 64(region subdivision)- File naming uses base36 encoding (0-9, a-z)
- Each
.datfile contains compressed NBT data for one chunk (16×128×16)
Base36 Encoding
Fromsrc/save.cpp:16-28:
World Loading
Theload() method (src/save.cpp:221-264) implements a two-phase loading strategy:
Phase 1: Eager Loading
Loads a minimal set of chunks around the player with full lighting propagation:Phase 2: Streaming
Remaining chunks are queued for gradual loading during gameplay:src/save.cpp:245-250):
The eager_build Flag
The load_chunk() method accepts an eager_build parameter that controls performance characteristics:
eager_build = true (Initial Load)
From src/save.cpp:198-200:
- Full lighting propagation in one frame
- Immediate mesh generation for all subchunks
- Used for the initial radius around spawn
- Ensures the starting area is fully lit and renderable
eager_build = false (Streaming)
From info.md:16-20:
Приeager_build == false(стриминг во время игры):
- Убраны вызовы полной прогонки освещения. Очереди освещения заполняются, но их обработка происходит уже в
World::tick()с лимитомOptions::LIGHT_STEPS_PER_TICKза кадр.- Убрана немедленная генерация всех мешей чанка.
- Deferred lighting spread across frames (
Options::LIGHT_STEPS_PER_FRAMEper tick) - Deferred meshing via
chunk_building_queue(1 chunk per frame) - Prevents FPS drops during streaming
- Chunks may appear partially lit/built for a few frames
Performance Impact
Frominfo.md:26-28:
Просадки FPS от резких пиков CPU‑нагрузки при появлении новых чанков должны заметно уменьшиться; цена — новые чанки могут «достраиваться» визуально за несколько кадров вместо мгновенного появления, но фреймтайм становится значительно ровнее.Translation: FPS drops from CPU spikes when new chunks appear are significantly reduced; the cost is that new chunks may “build up” visually over several frames instead of appearing instantly, but frametime becomes much smoother.
Chunk Streaming
Dynamic loading/unloading is managed byupdate_streaming() (src/save.cpp:266-328):
Queue Management
Chunk Unloading
Chunks beyondRENDER_DISTANCE + 3 are automatically unloaded and saved:
Chunk Loading Process
Theload_chunk() method (src/save.cpp:89-219) follows this sequence:
1. Chunk Creation
2. Load from Disk (or Generate)
Fromsrc/save.cpp:108-148:
3. Lighting Initialization
4. Mesh Generation
Saving Chunks
Thesave_chunk() method (src/save.cpp:39-69) writes modified chunks to disk:
save() method iterates all chunks and saves modified ones:
Configuration
Relevant settings fromsrc/options.h:
Options::RENDER_DISTANCE- Maximum chunk loading radiusOptions::LIGHT_STEPS_PER_TICK- Lighting propagation steps per frame (default 2048)Options::CHUNK_UPDATES- Subchunk mesh updates per frame
Integration
Fromsrc/main.cpp, the save system is used: