Skip to main content

ChunkStore

Trait ChunkStore 

Source
pub trait ChunkStore:
    Debug
    + Send
    + Sync {
    // Required methods
    fn store(&self, chunk_idx: IVec3, vxl: &Vxl, version: u64);
    fn load(&self, chunk_idx: IVec3) -> Option<(Vxl, u64)>;
}
Expand description

Pluggable persistence for edited streamed chunks (QE.5a).

The ChunkGenerator contract makes evict + re-stream sound for pristine chunks (generation is deterministic), but an edited chunk (chunk_version != 0 — the player dug, built, or a bake wrote into it) would silently revert to generator output when the camera walks away and comes back. A ChunkStore closes that hole:

  • Eviction (crate::Scene::pump_streaming / pump_streaming_sync): every evicted chunk whose version is non-zero is handed to store before it is dropped.
  • Stream-in: before running the generator for a missing chunk, the streaming layer asks load; a hit installs the stored chunk (with its persisted edit version) and the generator is not called. A stored chunk wins even where ChunkGenerator::should_generate declines the index (edits can materialise chunks the generator never would).

Implementations own the actual storage — an in-memory map, a save-file region, a database. load runs on the streaming pool’s background threads under crate::Scene::pump_streaming (so blocking IO is fine there) but inline under the synchronous paths (pump_streaming_sync / Grid::ensure_chunk_generated); store always runs inline during the eviction pass — keep it cheap (e.g. queue bytes for a writer thread).

Note crate::Scene::to_snapshot serialises only materialised chunks — chunks living solely in the store are the host’s to save alongside the snapshot.

Required Methods§

Source

fn store(&self, chunk_idx: IVec3, vxl: &Vxl, version: u64)

Persist an edited chunk that is about to be evicted. version is its crate::Grid::chunk_version (always non-zero here).

Source

fn load(&self, chunk_idx: IVec3) -> Option<(Vxl, u64)>

Load a previously stored chunk. Some((vxl, version)) installs it (restoring version as the chunk’s edit version) instead of generating; None falls through to the generator.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§