From f96a8a11abc74395c6dd3ba33bde2f35d5eff23d Mon Sep 17 00:00:00 2001
From: Imbris <imbrisf@gmail.com>
Date: Sun, 10 Oct 2021 02:50:21 -0400
Subject: [PATCH] Remove dead commented code, updated changelog, commented
 profiling spans (but left in for easy reuse later), fix clippy complaint

---
 CHANGELOG.md                      |  1 +
 common/src/vol.rs                 |  1 -
 common/src/volumes/vol_grid_2d.rs | 10 ++--------
 common/systems/src/phys.rs        | 22 +++++++++++-----------
 4 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6fc0d1ffe..21a7fd415c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Sprite spawn rates
 - The Interact button can be used on campfires to sit
 - Made map icons fade out when near the edge of the map display
+- Roughly doubled the speed of entity vs terrain physics checks
 
 ### Removed
 
diff --git a/common/src/vol.rs b/common/src/vol.rs
index 1e008f4e71..42aeecf0be 100644
--- a/common/src/vol.rs
+++ b/common/src/vol.rs
@@ -114,7 +114,6 @@ pub trait ReadVol: BaseVol {
 
     /// Call provided closure with each block in the supplied Aabb
     /// Portions of the Aabb outside the volume are ignored
-    //#[inline]
     fn for_each_in(&self, aabb: Aabb<i32>, mut f: impl FnMut(Vec3<i32>, Self::Vox))
     where
         Self::Vox: Copy,
diff --git a/common/src/volumes/vol_grid_2d.rs b/common/src/volumes/vol_grid_2d.rs
index b6fac1630f..49c91f00fc 100644
--- a/common/src/volumes/vol_grid_2d.rs
+++ b/common/src/volumes/vol_grid_2d.rs
@@ -54,9 +54,8 @@ impl<V: RectRasterableVol + ReadVol + Debug> ReadVol for VolGrid2d<V> {
             })
     }
 
-    // /// Call provided closure with each block in the supplied Aabb
-    // /// Areas outside loaded chunks are ignored
-    #[inline]
+    /// Call provided closure with each block in the supplied Aabb
+    /// Areas outside loaded chunks are ignored
     fn for_each_in(&self, aabb: Aabb<i32>, mut f: impl FnMut(Vec3<i32>, Self::Vox))
     where
         Self::Vox: Copy,
@@ -155,7 +154,6 @@ impl<V: RectRasterableVol> VolGrid2d<V> {
     #[inline(always)]
     pub fn chunk_size() -> Vec2<u32> { V::RECT_SIZE }
 
-    //#[inline]
     pub fn insert(&mut self, key: Vec2<i32>, chunk: Arc<V>) -> Option<Arc<V>> {
         self.chunks.insert(key, chunk)
     }
@@ -165,14 +163,12 @@ impl<V: RectRasterableVol> VolGrid2d<V> {
         self.chunks.get(&key).map(|arc_chunk| arc_chunk.as_ref())
     }
 
-    //#[inline]
     pub fn get_key_arc(&self, key: Vec2<i32>) -> Option<&Arc<V>> { self.chunks.get(&key) }
 
     pub fn clear(&mut self) { self.chunks.clear(); }
 
     pub fn drain(&mut self) -> hash_map::Drain<Vec2<i32>, Arc<V>> { self.chunks.drain() }
 
-    //#[inline]
     pub fn remove(&mut self, key: Vec2<i32>) -> Option<Arc<V>> { self.chunks.remove(&key) }
 
     #[inline(always)]
@@ -181,14 +177,12 @@ impl<V: RectRasterableVol> VolGrid2d<V> {
     #[inline(always)]
     pub fn pos_key(&self, pos: Vec3<i32>) -> Vec2<i32> { Self::chunk_key(pos) }
 
-    //#[inline]
     pub fn iter(&self) -> ChunkIter<V> {
         ChunkIter {
             iter: self.chunks.iter(),
         }
     }
 
-    //#[inline]
     pub fn cached(&self) -> CachedVolGrid2d<V> { CachedVolGrid2d::new(self) }
 }
 
diff --git a/common/systems/src/phys.rs b/common/systems/src/phys.rs
index f40846b582..77c9a509b5 100644
--- a/common/systems/src/phys.rs
+++ b/common/systems/src/phys.rs
@@ -1342,7 +1342,7 @@ fn box_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
         clippy::cast_possible_truncation,
         clippy::cast_sign_loss
     )]
-    prof_span!("box_voxel_collision");
+    //prof_span!("box_voxel_collision");
 
     // Convience function to compute the player aabb
     fn player_aabb(pos: Vec3<f32>, radius: f32, z_range: Range<f32>) -> Aabb<f32> {
@@ -1362,9 +1362,9 @@ fn box_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
 
     // Function for determining whether the player at a specific position collides
     // with blocks with the given criteria
-    fn collision_with<'a, T: BaseVol<Vox = Block> + ReadVol>(
+    fn collision_with<T: BaseVol<Vox = Block> + ReadVol>(
         pos: Vec3<f32>,
-        terrain: &'a T,
+        terrain: &T,
         hit: impl Fn(&Block) -> bool,
         near_aabb: Aabb<i32>,
         radius: f32,
@@ -1430,12 +1430,12 @@ fn box_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
         .clamped(1, MAX_INCREMENTS);
     let old_pos = pos.0;
     for _ in 0..increments {
-        prof_span!("increment");
+        //prof_span!("increment");
         const MAX_ATTEMPTS: usize = 16;
         pos.0 += pos_delta / increments as f32;
 
         let try_colliding_block = |pos: &Pos| {
-            prof_span!("most colliding check");
+            //prof_span!("most colliding check");
             // Calculate the player's AABB
             let player_aabb = player_aabb(pos.0, radius, z_range.clone());
 
@@ -1530,7 +1530,7 @@ fn box_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
             && dir.z < -0.1
             // ...and the space above is free...
             && {
-                prof_span!("space above free");
+                //prof_span!("space above free");
                 !collision_with(
                     Vec3::new(pos.0.x, pos.0.y, (pos.0.z + 0.1).ceil()),
                     &terrain,
@@ -1542,7 +1542,7 @@ fn box_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
             }
             // ...and there is a collision with a block beneath our current hitbox...
             && {
-                prof_span!("collision beneath");
+                //prof_span!("collision beneath");
                 collision_with(
                     pos.0 + resolve_dir - Vec3::unit_z() * 1.25,
                     &terrain,
@@ -1596,7 +1596,7 @@ fn box_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
         physics_state.on_ground = on_ground;
     // If the space below us is free, then "snap" to the ground
     } else if vel.0.z <= 0.0 && was_on_ground && block_snap && {
-        prof_span!("snap check");
+        //prof_span!("snap check");
         collision_with(
             pos.0 - Vec3::unit_z() * 1.1,
             &terrain,
@@ -1606,7 +1606,7 @@ fn box_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
             z_range.clone(),
         )
     } {
-        prof_span!("snap!!");
+        //prof_span!("snap!!");
         let snap_height = terrain
             .get(Vec3::new(pos.0.x, pos.0.y, pos.0.z - 0.1).map(|e| e.floor() as i32))
             .ok()
@@ -1643,7 +1643,7 @@ fn box_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
 
     let mut liquid = None::<(LiquidKind, f32)>;
     let mut wall_dir_collisions = [false; 4];
-    prof_span!(guard, "liquid/walls");
+    //prof_span!(guard, "liquid/walls");
     terrain.for_each_in(near_aabb, |block_pos, block| {
         // Check for liquid blocks
         if let Some(block_liquid) = block.liquid_kind() {
@@ -1680,7 +1680,7 @@ fn box_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
             }
         }
     });
-    drop(guard);
+    //drop(guard);
 
     // Use wall collision results to determine if we are against a wall
     let mut on_wall = None;