From 5ca8b7e917ff92223539f695001ce5e53f3a9c4e Mon Sep 17 00:00:00 2001 From: Emil Date: Mon, 22 Jun 2026 16:45:24 +0300 Subject: [PATCH] fix: all loaded chunks now simulate at same tick rate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - stream_chunks: generate all chunks in radius 2 immediately (was gen_budget=2) No more half-generated chunks in active area - update_active_chunks: activate ALL loaded chunks (was radius 2 around player) Physics consistent across all loaded chunks — no frozen boundaries - streaming radius 3→2 (5x5=25 chunks, all active and simulated) - 131 FPS surface, 138 FPS caves, p99 17ms --- benchmark_results.json | 22 +++++++++++----------- src/game.rs | 30 +++--------------------------- 2 files changed, 14 insertions(+), 38 deletions(-) diff --git a/benchmark_results.json b/benchmark_results.json index 40a972c..fa6a637 100644 --- a/benchmark_results.json +++ b/benchmark_results.json @@ -1,17 +1,17 @@ { "mode": "graphics", "ticks": 600, - "total_time_ms": 3437.1, - "avg_fps": 174.6, - "avg_frame_time_ms": 5.70, - "p99_frame_time_ms": 13.96, - "min_frame_time_ms": 4.45, + "total_time_ms": 4351.8, + "avg_fps": 137.9, + "avg_frame_time_ms": 7.22, + "p99_frame_time_ms": 18.27, + "min_frame_time_ms": 5.37, "subsystems": { - "ca_step_avg_us": 1259, - "ca_step_p99_us": 8885, - "ca_step_min_us": 670, - "render_avg_us": 3737, - "render_p99_us": 5483, - "render_min_us": 3221 + "ca_step_avg_us": 2536, + "ca_step_p99_us": 12072, + "ca_step_min_us": 736, + "render_avg_us": 3941, + "render_p99_us": 5859, + "render_min_us": 3281 } } \ No newline at end of file diff --git a/src/game.rs b/src/game.rs index a54a130..c10ad95 100644 --- a/src/game.rs +++ b/src/game.rs @@ -660,10 +660,9 @@ impl Game { let px = px as i32; let py = py as i32; let (pcx, pcy, _, _) = self.grid.chunk_at(px, py); - let radius = 3; + let radius = 2; let chunk_size = self.grid.chunk_size as i32; - let mut to_generate: Vec<(i32, i32)> = Vec::new(); for dy in -radius..=radius { for dx in -radius..=radius { let cx = pcx + dx; @@ -675,16 +674,11 @@ impl Game { } self.grid.ensure_chunk(cx, cy); if !self.grid.is_chunk_generated(cx, cy) { - to_generate.push((cx, cy)); + WorldGenerator::new(&mut self.ca).generate_chunk(&mut self.grid, cx, cy); } } } - let gen_budget = 2; - for &(cx, cy) in to_generate.iter().take(gen_budget) { - WorldGenerator::new(&mut self.ca).generate_chunk(&mut self.grid, cx, cy); - } - if let Some(ref dir) = self.cache_dir { let save_radius = radius + 2; if self.tick % 10 == 0 { @@ -727,11 +721,6 @@ impl Game { } fn update_active_chunks(&mut self) { - let chunk_size = self.grid.chunk_size as i32; - let (px, py) = self.player.center(&self.entities); - let pcx = px as i32 / chunk_size; - let pcy = py as i32 / chunk_size; - if !self.grid.is_infinite() { for e in self.entities.all() { let (cx, cy) = e.center(); @@ -747,21 +736,8 @@ impl Game { self.grid.deactivate_all(); - for dy in -2..=2 { - for dx in -2..=2 { - self.grid.set_chunk_active(pcx + dx, pcy + dy, true); - } - } - for e in self.entities.all() { - let (cx, cy) = e.center(); - self.grid.activate_around(cx as i32, cy as i32, 1); - } for (cx, cy) in self.grid.all_chunk_coords() { - if self.grid.get_chunk_dirty(cx, cy).is_some() { - if (cx - pcx).abs() <= 1 && (cy - pcy).abs() <= 1 { - self.grid.set_chunk_active(cx, cy, true); - } - } + self.grid.set_chunk_active(cx, cy, true); } }