summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/lib/force.rs6
-rw-r--r--src/sim/sim_manager/mod.rs4
2 files changed, 8 insertions, 2 deletions
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<EntityId> = self.entities.drain().map(|(id, _)| id).collect();
+ // TODO drain doesn't work here?
+ let entities: Vec<EntityId> = 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();