feat: implement chunk unloading infrastructure
Chunk unloading system with cleanly abstracted decision layer. - ChunkMap: replace (bool, i32) timer tuple with () presence marker; remove FIFO cycle fields pending_unload/unload_cycle/unload_cursor/ unload_countdown. loaded_chunks is now HashMap<IVec2, ()>. - handle_chunk_events: simplify re-entrancy check to contains_key; remove parallel Mutex dedup machinery — load detection is now trivial. - is_standable: single HashMap get; return false for unloaded chunks instead of falling back to is_standable_slow (pathfinding correctness). - remove_chunk_data: bounds-iteration tile cleanup for chunk unload. - ChunkOwner component + chunk_entity_index: static terrain entities (floor tiles, fixtures, trees) tagged at spawn and despawned by chunk. Mobile entities (dorfs, pigs, rabbits) not tracked — safe by design since they were never indexed. - unload_chunk: canonical single-chunk unload function; cleans loaded_chunks, despawns entities, removes tilemap data, marks render chunk dirty via ChunkZKey::from_world, updates connectivity, fires rebake. Full docstring with step-by-step state map, working example for dynamic unload, and "what it does NOT handle" section. - dynamic_chunk_unloading_system: no-op stub. Re-enable by writing a system that diffs wanted vs loaded chunks and calls unload_chunk. Wired out of FixedUpdate during foundation work. - render chunk fix: ChunkZKey::from_world now pub(crate) so unload can derive the correct render chunk key (spans 4x4 world chunks) matching what build_quilted_terrain_sprites uses at spawn. - FloorTilePrefab::spawn: pre-existing bug — return Entity not ().
This commit is contained in:
+6
-2
@@ -37,15 +37,19 @@ impl Plugin for WorldPlugin {
|
||||
.add_systems(
|
||||
FixedUpdate,
|
||||
(
|
||||
// === CHUNK LOADING PIPELINE ===
|
||||
handle_chunk_events,
|
||||
update_chunk_connectivity,
|
||||
|
||||
// === CHUNK GENERATION (triggered by events above) ===
|
||||
spawn_terrain_tasks,
|
||||
apply_terrain_blobs,
|
||||
generate_chunk_weathering_and_precipitation,
|
||||
generate_chunk_forrestry,
|
||||
generate_chunk_foliage,
|
||||
generate_chunk_fauna,
|
||||
chunkmap_despawn_timer_system,
|
||||
update_chunk_connectivity,
|
||||
|
||||
// === DYNAMIC UNLOAD (disabled — see dynamic_chunk_unloading_system) ===
|
||||
),
|
||||
)
|
||||
.add_systems(
|
||||
|
||||
Reference in New Issue
Block a user