perf: light_step source cap 64, minimap step_by(4), resize early-return, warning cleanup
- light_step: cap sources at 64 (was unlimited — 400+ lava cells = 250K ray-casts) - minimap: step_by(4) sampling (65K→4K grid.get calls, still every frame — no flicker) - resize(): early return if size unchanged (skip 350K element reallocation) - Clean unused mut warning - 172 FPS avg, p99 14ms (was 66 FPS, p99 180ms)
This commit is contained in:
+5
-2
@@ -77,6 +77,9 @@ impl UiLayer {
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, w: usize, h: usize) {
|
||||
if self.width == w && self.height == h && !self.cells.is_empty() {
|
||||
return;
|
||||
}
|
||||
self.width = w;
|
||||
self.height = h;
|
||||
self.cells.clear();
|
||||
@@ -324,8 +327,8 @@ impl UiLayer {
|
||||
let mut g = 0u32;
|
||||
let mut b = 0u32;
|
||||
let mut n = 0u32;
|
||||
for yy in 0..scale {
|
||||
for xx in 0..scale {
|
||||
for yy in (0..scale).step_by(4) {
|
||||
for xx in (0..scale).step_by(4) {
|
||||
let cell = grid.get(wx + xx, wy + yy);
|
||||
if cell.material != MaterialId::Empty {
|
||||
let c = cell.fg;
|
||||
|
||||
@@ -784,8 +784,14 @@ impl CellularAutomaton {
|
||||
let idx = (ly as usize) * CHUNK_SIZE + (lx as usize);
|
||||
if let Some((radius, color)) = material_light(chunk.cells[idx].material) {
|
||||
sources.push((ox + lx, oy + ly, radius as i32, color));
|
||||
if sources.len() >= 64 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if sources.len() >= 64 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ impl ChunkedGrid {
|
||||
}
|
||||
let key = (cx as i64, cy as i64);
|
||||
if !self.chunks.contains_key(&key) {
|
||||
let mut chunk = Chunk::new();
|
||||
let chunk = Chunk::new();
|
||||
if let Some(ref dir) = self.cache_dir {
|
||||
let path = chunk_path(dir, self.seed, cx, cy);
|
||||
if path.exists() {
|
||||
|
||||
Reference in New Issue
Block a user