From 258dd8561df05c8493a14d63d4eaa89074bb780b Mon Sep 17 00:00:00 2001 From: Alexander Krylov Date: Mon, 26 Oct 2026 03:34:33 +0300 Subject: [PATCH] Frames: one scan for breaking progress, and no name formatting per crack `entity_geometry` ran `cracks()` twice per frame: once for the block-entity pass that draws `render_breaking`, once for the overlay near the end of the same function. Each run walked `mining` and the `destroying` map, and formatted `block/destroy_stage_` for every crack it found before looking that string up in the atlas. The list is computed once, at the top of the function, and the passes read it. The ten stage names are a const table, so a crack costs one lookup and no allocation. Nothing between the two passes touches `mining` or `destroying`, which are only read there, so the list the second pass used to rebuild was always identical to the first one. No behaviour change: the same ten sprite names, and a stage above 9 still finds no sprite and skips the crack. Co-Authored-By: Hermes Agent (Nous Research) --- crates/horizon-client/src/game.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 1e6158bc4..bfc90f1ec 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -6750,6 +6750,9 @@ impl Game<'_> { ) -> Vec { self.prepare_entity_culling(camera); self.prepare_trims(); + // One scan for both passes that draw them (block entities below and the + // overlay near the end of this function). + let cracks = self.cracks(camera); let fire_yaw = if self.camera_type == perspective::CameraType::ThirdPersonFront { self.yaw + 180.0 } else { @@ -6964,7 +6967,7 @@ impl Game<'_> { .block_entity_render() .render(&scene, visible, &mut out); } - for (pos, stage) in self.cracks(camera) { + for &(pos, stage) in &cracks { let state = self.world.block(pos[0], pos[1], pos[2]); self.res .block_entity_render() @@ -7089,7 +7092,7 @@ impl Game<'_> { &mut out, ); // Breaking progress overlays (destroy_stage_0..9): ours and the other players'. - for (pos, stage) in self.cracks(camera) { + for &(pos, stage) in &cracks { let o = (glam::DVec3::new(f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2])) - camera) .as_vec3(); @@ -7137,6 +7140,20 @@ impl Game<'_> { /// other players' (`renderBlockDestroyAnimation`: within 32 blocks of the camera, the /// furthest progress on each block). fn cracks(&self, camera: glam::DVec3) -> Vec<([i32; 3], [f32; 2])> { + // `destroy_stage_0` .. `destroy_stage_9`: the sprite name by stage, so the + // lookup does not format a string per crack. + const DESTROY_STAGES: [&str; 10] = [ + "block/destroy_stage_0", + "block/destroy_stage_1", + "block/destroy_stage_2", + "block/destroy_stage_3", + "block/destroy_stage_4", + "block/destroy_stage_5", + "block/destroy_stage_6", + "block/destroy_stage_7", + "block/destroy_stage_8", + "block/destroy_stage_9", + ]; let mut stages: Vec<([i32; 3], u32)> = Vec::new(); let mut add = |pos: [i32; 3], stage: u32| match stages.iter_mut().find(|c| c.0 == pos) { Some(c) => c.1 = c.1.max(stage), @@ -7162,11 +7179,8 @@ impl Game<'_> { d.length_squared() <= 1024.0 }) .filter_map(|(pos, stage)| { - let r = self - .gui - .atlas - .sprites - .get(&format!("block/destroy_stage_{stage}"))?; + let name = DESTROY_STAGES.get(stage as usize)?; + let r = self.gui.atlas.sprites.get(*name)?; Some((pos, [r.u0, r.v0])) }) .collect()