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, mut f: impl FnMut(Vec3, 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 ReadVol for VolGrid2d { }) } - // /// 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, mut f: impl FnMut(Vec3, Self::Vox)) where Self::Vox: Copy, @@ -155,7 +154,6 @@ impl VolGrid2d { #[inline(always)] pub fn chunk_size() -> Vec2 { V::RECT_SIZE } - //#[inline] pub fn insert(&mut self, key: Vec2, chunk: Arc) -> Option> { self.chunks.insert(key, chunk) } @@ -165,14 +163,12 @@ impl VolGrid2d { self.chunks.get(&key).map(|arc_chunk| arc_chunk.as_ref()) } - //#[inline] pub fn get_key_arc(&self, key: Vec2) -> Option<&Arc> { self.chunks.get(&key) } pub fn clear(&mut self) { self.chunks.clear(); } pub fn drain(&mut self) -> hash_map::Drain, Arc> { self.chunks.drain() } - //#[inline] pub fn remove(&mut self, key: Vec2) -> Option> { self.chunks.remove(&key) } #[inline(always)] @@ -181,14 +177,12 @@ impl VolGrid2d { #[inline(always)] pub fn pos_key(&self, pos: Vec3) -> Vec2 { Self::chunk_key(pos) } - //#[inline] pub fn iter(&self) -> ChunkIter { ChunkIter { iter: self.chunks.iter(), } } - //#[inline] pub fn cached(&self) -> CachedVolGrid2d { 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 + 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, radius: f32, z_range: Range) -> Aabb { @@ -1362,9 +1362,9 @@ fn box_voxel_collision<'a, T: BaseVol + ReadVol>( // Function for determining whether the player at a specific position collides // with blocks with the given criteria - fn collision_with<'a, T: BaseVol + ReadVol>( + fn collision_with + ReadVol>( pos: Vec3, - terrain: &'a T, + terrain: &T, hit: impl Fn(&Block) -> bool, near_aabb: Aabb, radius: f32, @@ -1430,12 +1430,12 @@ fn box_voxel_collision<'a, T: BaseVol + 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 + 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 + 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 + 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 + 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 + 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 + ReadVol>( } } }); - drop(guard); + //drop(guard); // Use wall collision results to determine if we are against a wall let mut on_wall = None;