From 11c8cf19d1daf83263dc977e2cdd380ca7976dd7 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 10 Oct 2021 02:21:39 -0400 Subject: [PATCH] Switch to for loops in default for_each_in (small perf increase), add inline to sprite methods (no perf change) --- common/src/terrain/sprite.rs | 7 +++++++ common/src/vol.rs | 19 ++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/common/src/terrain/sprite.rs b/common/src/terrain/sprite.rs index cf67732a01..05f046f092 100644 --- a/common/src/terrain/sprite.rs +++ b/common/src/terrain/sprite.rs @@ -181,6 +181,7 @@ make_case_elim!( ); impl SpriteKind { + #[inline] pub fn solid_height(&self) -> Option { // Beware: the height *must* be <= `MAX_HEIGHT` or the collision system will not // properly detect it! @@ -268,6 +269,7 @@ impl SpriteKind { } /// What loot table does collecting this sprite draw from? + #[inline] pub fn collectible_id(&self) -> Option> { let item = |id: &'static str| LootSpec::Item(id); let table = |id: &'static str| LootSpec::LootTable(id); @@ -336,16 +338,19 @@ impl SpriteKind { } /// Can this sprite be picked up to yield an item without a tool? + #[inline] pub fn is_collectible(&self) -> bool { self.collectible_id().is_some() && self.mine_tool().is_none() } /// Is the sprite a container that will emit a mystery item? + #[inline] pub fn is_container(&self) -> bool { matches!(self.collectible_id(), Some(LootSpec::LootTable(_))) } /// Which tool (if any) is needed to collect this sprite? + #[inline] pub fn mine_tool(&self) -> Option { match self { SpriteKind::Velorite @@ -375,6 +380,7 @@ impl SpriteKind { } } + #[inline] pub fn has_ori(&self) -> bool { matches!( self, @@ -446,5 +452,6 @@ lazy_static! { impl<'a> TryFrom<&'a str> for SpriteKind { type Error = (); + #[inline] fn try_from(s: &'a str) -> Result { SPRITE_KINDS.get(s).copied().ok_or(()) } } diff --git a/common/src/vol.rs b/common/src/vol.rs index 2a261659ef..4d1d4a305e 100644 --- a/common/src/vol.rs +++ b/common/src/vol.rs @@ -119,18 +119,15 @@ pub trait ReadVol: BaseVol { where Self::Vox: Copy, { - (aabb.min.x..=aabb.max.x) - .map(|x| { - (aabb.min.y..=aabb.max.y) - .map(move |y| (aabb.min.z..=aabb.max.z).map(move |z| Vec3::new(x, y, z))) - }) - .flatten() - .flatten() - .for_each(|pos| { - if let Ok(vox) = self.get(pos) { - f(pos, *vox); + for x in aabb.min.x..aabb.max.x + 1 { + for y in aabb.min.y..aabb.max.y + 1 { + for z in aabb.min.z..aabb.max.z + 1 { + if let Ok(block) = self.get(Vec3::new(x, y, z)) { + f(Vec3::new(x, y, z), *block); + } } - }); + } + } } }