mirror of
https://github.com/horizon-rust/horizon.git
synced 2026-11-09 10:39:46 -10:00
HUD paint: build the sprite key in one reused buffer
paint() runs for every drawn HUD call each frame and made a fresh String per
sprite to look it up in the atlas: sprite.to_string() for a mob_effect and
format!("gui/sprites/{sprite}") otherwise. One buffer outside the loop keeps
the same keys without the allocation.
Co-Authored-By: Hermes Agent (Nous Research) <[email protected]>
This commit is contained in:
1 parent
b6c936f82b
commit
4bf633e8a9
1 file changed
+9
-5
@@ -801,6 +801,8 @@ impl HealthHud {
|
||||
/// nausea blits (their blending needs the screen-effect pipeline).
|
||||
pub fn paint(batch: &mut crate::hud::HudBatch, atlas: &crate::hud::HudAtlas, draws: &[GuiDraw]) {
|
||||
let mut stack = vec![IDENTITY];
|
||||
// One buffer for the sprite keys, instead of a string per drawn sprite.
|
||||
let mut name = String::new();
|
||||
for d in draws {
|
||||
let start = batch.vertices.len();
|
||||
let pose = *stack.last().unwrap_or(&IDENTITY);
|
||||
@@ -817,12 +819,14 @@ pub fn paint(batch: &mut crate::hud::HudBatch, atlas: &crate::hud::HudAtlas, dra
|
||||
} => {
|
||||
// Effect sprites belong to the mob_effect atlas directory;
|
||||
// the other blitSprite ids refer to GUI sprites.
|
||||
let name = if sprite.starts_with("mob_effect/") {
|
||||
sprite.to_string()
|
||||
name.clear();
|
||||
if sprite.starts_with("mob_effect/") {
|
||||
name.push_str(sprite);
|
||||
} else {
|
||||
format!("gui/sprites/{sprite}")
|
||||
};
|
||||
let Some(mut r) = atlas.sprites.get(&name).copied() else {
|
||||
name.push_str("gui/sprites/");
|
||||
name.push_str(sprite);
|
||||
}
|
||||
let Some(mut r) = atlas.sprites.get(name.as_str()).copied() else {
|
||||
continue;
|
||||
};
|
||||
if let Some([sw, sh, u, v]) = *region {
|
||||
|
||||
Reference in new issue
Block a user