Minor cleanup
parent
3784aa3e08
commit
2c953b95a3
|
@ -30,6 +30,11 @@ impl Ship {
|
|||
}
|
||||
}
|
||||
|
||||
/// Has this ship been destroyed?
|
||||
pub fn is_destroyed(&self) -> bool {
|
||||
self.hull <= 0.0
|
||||
}
|
||||
|
||||
pub fn handle_projectile_collision(&mut self, ct: &content::Content, p: &Projectile) -> bool {
|
||||
let f = ct.get_faction(self.faction);
|
||||
let r = f.relationships.get(&p.faction).unwrap();
|
||||
|
|
|
@ -49,8 +49,8 @@ impl ShipWorldObject {
|
|||
}
|
||||
}
|
||||
|
||||
/// Apply the effects of all active controls
|
||||
pub fn tick(&mut self, r: &mut RigidBody, t: f32) {
|
||||
/// Step this ship's state by t seconds
|
||||
pub fn step(&mut self, r: &mut RigidBody, t: f32) {
|
||||
let ship_rot = util::rigidbody_rotation(r);
|
||||
let engine_force = ship_rot * t;
|
||||
|
||||
|
|
|
@ -133,7 +133,6 @@ impl<'a> World {
|
|||
}
|
||||
|
||||
/// Add a ship to this physics system
|
||||
/// TODO: decouple from Ship::new()
|
||||
pub fn add_ship(
|
||||
&mut self,
|
||||
ct: &content::Content,
|
||||
|
@ -149,6 +148,7 @@ impl<'a> World {
|
|||
// (Collider starts pointing east, sprite starts pointing north.)
|
||||
.rotation(PI / -2.0)
|
||||
.mass(ship_content.mass);
|
||||
// TODO: only build colliders once
|
||||
|
||||
let rb = RigidBodyBuilder::dynamic()
|
||||
.angular_damping(ship_content.angular_drag)
|
||||
|
@ -171,26 +171,25 @@ impl<'a> World {
|
|||
/// Step this physics system by `t` seconds
|
||||
pub fn step(&mut self, t: f32, ct: &content::Content) {
|
||||
// Run ship updates
|
||||
// TODO: Clean this mess
|
||||
let mut ps = Vec::new();
|
||||
// TODO: maybe reorganize projectile creation?
|
||||
let mut projectiles = Vec::new();
|
||||
let mut to_remove = Vec::new();
|
||||
for (_, s) in &mut self.ships {
|
||||
if s.ship.hull <= 0.0 {
|
||||
if s.ship.is_destroyed() {
|
||||
to_remove.push(s.physics_handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
let r = &mut self.wrapper.rigid_body_set[s.physics_handle.0];
|
||||
s.tick(r, t);
|
||||
s.step(r, t);
|
||||
if s.controls.guns {
|
||||
ps.push((s.physics_handle, s.ship.fire_guns()));
|
||||
projectiles.push((s.physics_handle, s.ship.fire_guns()));
|
||||
}
|
||||
}
|
||||
for r in to_remove {
|
||||
self.remove_ship(r);
|
||||
}
|
||||
for (s, p) in ps {
|
||||
self.add_projectiles(&s, p);
|
||||
}
|
||||
let _ = projectiles
|
||||
.into_iter()
|
||||
.map(|(s, p)| self.add_projectiles(&s, p));
|
||||
let _ = to_remove.into_iter().map(|s| self.remove_ship(s));
|
||||
|
||||
// Update physics
|
||||
self.wrapper.step(t, &self.collision_handler);
|
||||
|
|
Loading…
Reference in New Issue