From da01c6e887d6865f0ad75c8dfe68bbad702afb99 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Tue, 25 Aug 2026 00:41:17 -0700 Subject: tweaks --- src/sim/lib/force.rs | 6 +++++- src/sim/sim_manager/mod.rs | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/sim') diff --git a/src/sim/lib/force.rs b/src/sim/lib/force.rs index d461589..e3150c0 100644 --- a/src/sim/lib/force.rs +++ b/src/sim/lib/force.rs @@ -100,12 +100,13 @@ pub fn apply_explosion( // TODO profile packing entity ID into cells? // TODO sink power in a radius around the impact // might improve performance by a lot if we don't have to raycast for hit entities -pub fn apply_bullet(ctx: &mut SimCtx, from: Vec2, to: Vec2, power: u32) { +pub fn apply_bullet(ctx: &mut SimCtx, from: Vec2, to: Vec2, power: u32) -> Vec2 { let dda = AwDda::new(from, to); let mut p = power as i32; let dir = (to - from).normalize(); + let mut stopped_at = to; for collision in dda { if let Some(cell) = ctx .cell_manager @@ -124,6 +125,7 @@ pub fn apply_bullet(ctx: &mut SimCtx, from: Vec2, to: Vec2, power: u32) { p -= m.density as i32; if p <= 0 { + stopped_at = collision.as_vec2(); break; } @@ -145,4 +147,6 @@ pub fn apply_bullet(ctx: &mut SimCtx, from: Vec2, to: Vec2, power: u32) { } } } + + stopped_at } diff --git a/src/sim/sim_manager/mod.rs b/src/sim/sim_manager/mod.rs index 8cb5eb3..8849a1d 100644 --- a/src/sim/sim_manager/mod.rs +++ b/src/sim/sim_manager/mod.rs @@ -276,8 +276,10 @@ impl SimManager { self.cell_manager = CellManager::from_default_size(); } if input_manager.pressed(Input::ClearEntities) { - let entities: Vec = self.entities.drain().map(|(id, _)| id).collect(); + // TODO drain doesn't work here? + let entities: Vec = self.entities.keys().cloned().collect(); entities.iter().for_each(|&id| self.destroy_entity(id)); + self.entities.clear(); } if input_manager.pressed(Input::ClearParticles) { self.particle_manager.particles = Vec::new(); -- cgit v1.3.1