feat(optimization): implement data-oriented chunk architecture

Phase 1: Bit-packed standability
- Add ChunkData struct with 4 bitsets per chunk (stand_in/on for floor/fixture)
- Replace 4 HashMap lookups per standability check with O(1) bit operations
- Memory: ~2KB bitsets per chunk vs ~50KB HashMap overhead

Phase 2: Reactive connectivity
- Add dirty_chunks HashSet to ChunkMap for incremental updates
- update_chunk_connectivity now O(d) where d = dirty chunks
- Early exit when no changes, preventing O(N) full rebuilds

Phase 3: Async terrain baking
- Move terrain generation to AsyncComputeTaskPool
- spawn_terrain_tasks: non-blocking task spawn (~34µs)
- apply_terrain_blobs: batched entity spawn on main thread
- Eliminates main-thread stutters during world generation
This commit is contained in:
2026-03-19 17:01:51 +00:00
parent 15c0d1c7a2
commit 50788af3c7
7 changed files with 630 additions and 188 deletions
+1 -24
View File
@@ -550,30 +550,7 @@ fn validate_next_steps(tilemap: &TileMap, path: &[Vec3], start_index: usize, ste
}
fn is_standable_tile(tilemap: &TileMap, pos: IVec3) -> bool {
let can_stand_in_tile = tilemap
.floor_tiles
.get(&pos)
.map(|t| t.can_stand_in())
.unwrap_or(false);
let can_stand_in_fixture = tilemap
.fixture_tiles
.get(&pos)
.map(|t| t.can_stand_in())
.unwrap_or(false);
let pos_below = pos - IVec3::new(0, 0, ITILE_SIZE);
let can_stand_on_tile_below = tilemap
.floor_tiles
.get(&pos_below)
.map(|t| t.can_stand_on())
.unwrap_or(false);
let can_stand_on_fixture_below = tilemap
.fixture_tiles
.get(&pos_below)
.map(|t| t.can_stand_on())
.unwrap_or(false);
(can_stand_in_tile || can_stand_in_fixture)
&& (can_stand_on_tile_below || can_stand_on_fixture_below)
tilemap.is_standable(pos)
}
fn calculate_movement_cost(move_dir: IVec3) -> i32 {