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
+10 -10
View File
@@ -3,7 +3,8 @@ use crate::{
config::GameConfig,
world::generation::{
generate_chunk_fauna, generate_chunk_foliage, generate_chunk_forrestry,
generate_chunk_terrain, generate_chunk_weathering_and_precipitation,
generate_chunk_weathering_and_precipitation, apply_terrain_blobs, spawn_terrain_tasks,
TerrainBlobStorage,
},
};
use bevy::prelude::*;
@@ -24,6 +25,7 @@ pub struct WorldPlugin;
impl Plugin for WorldPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<ChunkMap>()
.init_resource::<TerrainBlobStorage>()
.add_message::<GenerateChunkEvent>()
.add_message::<ChunkTerrainEvent>()
.add_message::<ChunkWeatheringAndPrecipitationEvent>()
@@ -35,15 +37,13 @@ impl Plugin for WorldPlugin {
.add_systems(
FixedUpdate,
(
(
handle_chunk_events,
generate_chunk_terrain,
generate_chunk_weathering_and_precipitation,
generate_chunk_forrestry,
generate_chunk_foliage,
generate_chunk_fauna,
)
.chain(),
handle_chunk_events,
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,
),