perf: targeted z-scroll dirty marking, per-frame populate budget

on_camera_z_changed: only dirty z-levels whose z_diff changed
(both old and new camera positions, within 0..=8 window).
Previously dirtied all 20k entities on every z-change.

populate_tilemap_chunk_data: process up to MAX_POPULATE_PER_FRAME
(512) keys per frame, sorted by z-distance from current camera.
Spreads z-scroll cost across multiple frames instead of one spike.

TilemapBenchmark: added z-change spike instrumentation
(last_z_change_dirty_ms, last_z_change_dirty_count,
last_z_change_populate_ms, z_change_history_ms).
F9 report now shows z-scroll metrics.

PreviousZIndex resource tracks prior camera z for targeted dirty calc.
This commit is contained in:
2026-03-20 14:50:13 +00:00
parent b48459fceb
commit ac0e8bc1c7
3 changed files with 103 additions and 11 deletions
+1
View File
@@ -27,6 +27,7 @@ impl Plugin for WorldPlugin {
.init_resource::<tiles::TilemapBenchmark>()
.init_resource::<tiles::TilemapChunkRegistry>()
.init_resource::<tiles::TilemapChunkSpawner>()
.init_resource::<tiles::PreviousZIndex>()
.add_message::<GenerateChunkEvent>()
.add_message::<ChunkTerrainEvent>()
.add_message::<ChunkWeatheringAndPrecipitationEvent>()