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:
+10
-10
@@ -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,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user