mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Removed redundant hit code
This commit is contained in:
parent
423e6f0348
commit
f5b24a5953
@ -1389,7 +1389,6 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
|
||||
fn collision_with<T: BaseVol<Vox = Block> + ReadVol>(
|
||||
pos: Vec3<f32>,
|
||||
terrain: &T,
|
||||
hit: impl Fn(&Block) -> bool,
|
||||
near_aabb: Aabb<i32>,
|
||||
radius: f32,
|
||||
z_range: Range<f32>,
|
||||
@ -1403,7 +1402,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
|
||||
let mut collision = false;
|
||||
// TODO: could short-circuit here
|
||||
terrain.for_each_in(near_aabb, |block_pos, block| {
|
||||
if hit(&block) && block.is_solid() {
|
||||
if block.is_solid() {
|
||||
let block_aabb = Aabb {
|
||||
min: block_pos.map(|e| e as f32),
|
||||
max: block_pos.map(|e| e as f32) + Vec3::new(1.0, 1.0, block.solid_height()),
|
||||
@ -1419,10 +1418,6 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
|
||||
collision
|
||||
}
|
||||
|
||||
// Should be easy to just make clippy happy if we want?
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
fn always_hits(_: &Block) -> bool { true }
|
||||
|
||||
let (radius, z_min, z_max) = (Vec3::from(cylinder) * scale).into_tuple();
|
||||
|
||||
// Probe distances
|
||||
@ -1556,7 +1551,6 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
|
||||
!collision_with(
|
||||
Vec3::new(pos.0.x, pos.0.y, (pos.0.z + 0.1).ceil()),
|
||||
&terrain,
|
||||
always_hits,
|
||||
near_aabb,
|
||||
radius,
|
||||
z_range.clone(),
|
||||
@ -1569,7 +1563,6 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
|
||||
collision_with(
|
||||
pos.0 + resolve_dir - Vec3::unit_z() * 1.25,
|
||||
&terrain,
|
||||
always_hits,
|
||||
near_aabb,
|
||||
radius,
|
||||
z_range.clone(),
|
||||
@ -1624,7 +1617,6 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
|
||||
collision_with(
|
||||
pos.0 - Vec3::unit_z() * 1.1,
|
||||
&terrain,
|
||||
always_hits,
|
||||
near_aabb,
|
||||
radius,
|
||||
z_range.clone(),
|
||||
|
@ -1470,22 +1470,22 @@ impl ParticleMgr {
|
||||
}
|
||||
|
||||
enum BlockParticleSlice<'a> {
|
||||
Pos(&'a [Vec3<i32>]),
|
||||
PosAndDirs(&'a [(Vec3<i32>, Vec3<f32>)]),
|
||||
Positions(&'a [Vec3<i32>]),
|
||||
PositionsAndDirs(&'a [(Vec3<i32>, Vec3<f32>)]),
|
||||
}
|
||||
|
||||
impl<'a> BlockParticleSlice<'a> {
|
||||
fn len(&self) -> usize {
|
||||
match self {
|
||||
Self::Pos(blocks) => blocks.len(),
|
||||
Self::PosAndDirs(blocks) => blocks.len(),
|
||||
Self::Positions(blocks) => blocks.len(),
|
||||
Self::PositionsAndDirs(blocks) => blocks.len(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let particles: &[BlockParticles] = &[
|
||||
BlockParticles {
|
||||
blocks: |boi| BlockParticleSlice::Pos(&boi.leaves),
|
||||
blocks: |boi| BlockParticleSlice::Positions(&boi.leaves),
|
||||
range: 4,
|
||||
rate: 0.001,
|
||||
lifetime: 30.0,
|
||||
@ -1493,7 +1493,7 @@ impl ParticleMgr {
|
||||
cond: |_| true,
|
||||
},
|
||||
BlockParticles {
|
||||
blocks: |boi| BlockParticleSlice::Pos(&boi.drip),
|
||||
blocks: |boi| BlockParticleSlice::Positions(&boi.drip),
|
||||
range: 4,
|
||||
rate: 0.004,
|
||||
lifetime: 20.0,
|
||||
@ -1501,7 +1501,7 @@ impl ParticleMgr {
|
||||
cond: |_| true,
|
||||
},
|
||||
BlockParticles {
|
||||
blocks: |boi| BlockParticleSlice::Pos(&boi.fires),
|
||||
blocks: |boi| BlockParticleSlice::Positions(&boi.fires),
|
||||
range: 2,
|
||||
rate: 20.0,
|
||||
lifetime: 0.25,
|
||||
@ -1509,7 +1509,7 @@ impl ParticleMgr {
|
||||
cond: |_| true,
|
||||
},
|
||||
BlockParticles {
|
||||
blocks: |boi| BlockParticleSlice::Pos(&boi.fire_bowls),
|
||||
blocks: |boi| BlockParticleSlice::Positions(&boi.fire_bowls),
|
||||
range: 2,
|
||||
rate: 20.0,
|
||||
lifetime: 0.25,
|
||||
@ -1517,7 +1517,7 @@ impl ParticleMgr {
|
||||
cond: |_| true,
|
||||
},
|
||||
BlockParticles {
|
||||
blocks: |boi| BlockParticleSlice::Pos(&boi.fireflies),
|
||||
blocks: |boi| BlockParticleSlice::Positions(&boi.fireflies),
|
||||
range: 6,
|
||||
rate: 0.004,
|
||||
lifetime: 40.0,
|
||||
@ -1525,7 +1525,7 @@ impl ParticleMgr {
|
||||
cond: |sd| sd.state.get_day_period().is_dark(),
|
||||
},
|
||||
BlockParticles {
|
||||
blocks: |boi| BlockParticleSlice::Pos(&boi.flowers),
|
||||
blocks: |boi| BlockParticleSlice::Positions(&boi.flowers),
|
||||
range: 5,
|
||||
rate: 0.002,
|
||||
lifetime: 40.0,
|
||||
@ -1533,7 +1533,7 @@ impl ParticleMgr {
|
||||
cond: |sd| sd.state.get_day_period().is_dark(),
|
||||
},
|
||||
BlockParticles {
|
||||
blocks: |boi| BlockParticleSlice::Pos(&boi.beehives),
|
||||
blocks: |boi| BlockParticleSlice::Positions(&boi.beehives),
|
||||
range: 3,
|
||||
rate: 0.5,
|
||||
lifetime: 30.0,
|
||||
@ -1541,7 +1541,7 @@ impl ParticleMgr {
|
||||
cond: |sd| sd.state.get_day_period().is_light(),
|
||||
},
|
||||
BlockParticles {
|
||||
blocks: |boi| BlockParticleSlice::Pos(&boi.snow),
|
||||
blocks: |boi| BlockParticleSlice::Positions(&boi.snow),
|
||||
range: 4,
|
||||
rate: 0.025,
|
||||
lifetime: 15.0,
|
||||
@ -1549,7 +1549,7 @@ impl ParticleMgr {
|
||||
cond: |_| true,
|
||||
},
|
||||
BlockParticles {
|
||||
blocks: |boi| BlockParticleSlice::PosAndDirs(&boi.one_way_walls),
|
||||
blocks: |boi| BlockParticleSlice::PositionsAndDirs(&boi.one_way_walls),
|
||||
range: 2,
|
||||
rate: 12.0,
|
||||
lifetime: 1.5,
|
||||
@ -1578,10 +1578,11 @@ impl ParticleMgr {
|
||||
self.particles
|
||||
.resize_with(self.particles.len() + particle_count, || {
|
||||
match blocks {
|
||||
BlockParticleSlice::Pos(blocks) => {
|
||||
BlockParticleSlice::Positions(blocks) => {
|
||||
// Can't fail, resize only occurs if blocks > 0
|
||||
let block_pos = Vec3::from(
|
||||
chunk_pos * TerrainChunk::RECT_SIZE.map(|e| e as i32),
|
||||
) + blocks.choose(&mut rng).copied().unwrap(); // Can't fail
|
||||
) + blocks.choose(&mut rng).copied().unwrap();
|
||||
Particle::new(
|
||||
Duration::from_secs_f32(particles.lifetime),
|
||||
time,
|
||||
@ -1589,9 +1590,10 @@ impl ParticleMgr {
|
||||
block_pos.map(|e: i32| e as f32 + rng.gen::<f32>()),
|
||||
)
|
||||
},
|
||||
BlockParticleSlice::PosAndDirs(blocks) => {
|
||||
BlockParticleSlice::PositionsAndDirs(blocks) => {
|
||||
// Can't fail, resize only occurs if blocks > 0
|
||||
let (block_offset, particle_dir) =
|
||||
blocks.choose(&mut rng).copied().unwrap(); // Can't fail
|
||||
blocks.choose(&mut rng).copied().unwrap();
|
||||
let block_pos = Vec3::from(
|
||||
chunk_pos * TerrainChunk::RECT_SIZE.map(|e| e as i32),
|
||||
) + block_offset;
|
||||
@ -1634,12 +1636,13 @@ impl ParticleMgr {
|
||||
self.particles
|
||||
.resize_with(self.particles.len() + particle_count, || {
|
||||
match blocks {
|
||||
BlockParticleSlice::Pos(blocks) => {
|
||||
BlockParticleSlice::Positions(blocks) => {
|
||||
let rel_pos = blocks
|
||||
.choose(&mut rng)
|
||||
.copied()
|
||||
// Can't fail, resize only occurs if blocks > 0
|
||||
.unwrap()
|
||||
.map(|e: i32| e as f32 + rng.gen::<f32>()); // Can't fail
|
||||
.map(|e: i32| e as f32 + rng.gen::<f32>());
|
||||
let wpos = mat.mul_point(rel_pos);
|
||||
|
||||
Particle::new(
|
||||
@ -1649,9 +1652,10 @@ impl ParticleMgr {
|
||||
wpos,
|
||||
)
|
||||
},
|
||||
BlockParticleSlice::PosAndDirs(blocks) => {
|
||||
BlockParticleSlice::PositionsAndDirs(blocks) => {
|
||||
// Can't fail, resize only occurs if blocks > 0
|
||||
let (block_offset, particle_dir) =
|
||||
blocks.choose(&mut rng).copied().unwrap(); // Can't fail
|
||||
blocks.choose(&mut rng).copied().unwrap();
|
||||
let particle_pos =
|
||||
block_offset.map(|e: i32| e as f32 + rng.gen::<f32>());
|
||||
let wpos = mat.mul_point(particle_pos);
|
||||
|
Loading…
Reference in New Issue
Block a user