Merge branch 'isse/fix-div0' into 'master'

Fix divide by zero in state::apply_terrain_changes_internal

See merge request veloren/veloren!4140
This commit is contained in:
Isse 2023-10-16 11:35:17 +00:00
commit b862a7aa22
4 changed files with 9 additions and 15 deletions

View File

@ -119,7 +119,7 @@ pub enum Outcome {
wielded: bool,
},
SpriteDelete {
pos: Vec3<f32>,
pos: Vec3<i32>,
sprite: SpriteKind,
},
SpriteUnlocked {
@ -171,7 +171,6 @@ impl Outcome {
| Outcome::FireShockwave { pos }
| Outcome::IceCrack { pos }
| Outcome::Utterance { pos, .. }
| Outcome::SpriteDelete { pos, .. }
| Outcome::CyclopsCharge { pos }
| Outcome::FlamethrowerCharge { pos }
| Outcome::LaserBeam { pos }
@ -181,6 +180,7 @@ impl Outcome {
| Outcome::Glider { pos, .. } => Some(*pos),
Outcome::BreakBlock { pos, .. }
| Outcome::SpriteUnlocked { pos }
| Outcome::SpriteDelete { pos, .. }
| Outcome::FailedSpriteUnlock { pos } => Some(pos.map(|e| e as f32 + 0.5)),
Outcome::ExpChange { .. }
| Outcome::ComboChange { .. }

View File

@ -572,17 +572,9 @@ impl State {
}
let outcome = self.ecs.read_resource::<EventBus<Outcome>>();
while let Some(outcomes) = scheduled_changes.outcomes.poll(current_time) {
for (pos, block) in outcomes.iter() {
let offset_dir = Vec3::<i32>::zero() - pos;
let offset = offset_dir
/ Vec3::new(offset_dir.x.abs(), offset_dir.y.abs(), offset_dir.z.abs());
let outcome_pos = Vec3::new(pos.x as f32, pos.y as f32, pos.z as f32)
- (Vec3::new(offset.x as f32, offset.y as f32, offset.z as f32) / 2.0);
for (pos, block) in outcomes.into_iter() {
if let Some(sprite) = block.get_sprite() {
outcome.emit_now(Outcome::SpriteDelete {
pos: outcome_pos,
sprite,
});
outcome.emit_now(Outcome::SpriteDelete { pos, sprite });
}
}
}

View File

@ -740,13 +740,14 @@ impl SfxMgr {
Outcome::SpriteDelete { pos, sprite } => {
match sprite {
SpriteKind::SeaUrchin => {
let pos = pos.map(|e| e as f32 + 0.5);
let power = (0.6 - pos.distance(audio.listener.pos) / 5_000.0)
.max(0.0)
.powi(7);
let sfx_trigger_item = triggers.get_key_value(&SfxEvent::Explosion);
audio.emit_sfx(
sfx_trigger_item,
*pos,
pos,
Some((power.abs() / 2.5).min(0.3)),
underwater,
);

View File

@ -79,13 +79,14 @@ impl ParticleMgr {
},
Outcome::SpriteDelete { pos, sprite } => match sprite {
SpriteKind::SeaUrchin => {
let pos = pos.map(|e| e as f32 + 0.5);
self.particles.resize_with(self.particles.len() + 10, || {
Particle::new_directed(
Duration::from_secs_f32(rng.gen_range(0.1..0.5)),
time,
ParticleMode::Steam,
*pos + Vec3::new(0.0, 0.0, rng.gen_range(0.0..1.5)),
*pos,
pos + Vec3::new(0.0, 0.0, rng.gen_range(0.0..1.5)),
pos,
)
});
},