|
@@ -1,14 +1,12 @@
|
|
|
-use crate::com::{Blocking, Collision, Velocity, Position};
|
|
|
-use crate::types::{NPhase,BPhase};
|
|
|
+use crate::com::{Blocking, Collision, Position, Velocity};
|
|
|
use crate::game::MyGame;
|
|
|
+use crate::types::{BPhase, NPhase};
|
|
|
|
|
|
use nalgebra::{Isometry2, Vector2};
|
|
|
use ncollide2d::broad_phase::{
|
|
|
- broad_phase::BroadPhase,
|
|
|
- broad_phase::BroadPhaseProxyHandle,
|
|
|
- BroadPhaseInterferenceHandler,
|
|
|
+ broad_phase::BroadPhase, broad_phase::BroadPhaseProxyHandle, BroadPhaseInterferenceHandler,
|
|
|
};
|
|
|
-use specs::{Join,RunNow};
|
|
|
+use specs::{Join, RunNow};
|
|
|
|
|
|
struct InterferenceHandler<'a> {
|
|
|
collisions: specs::WriteStorage<'a, Collision>,
|
|
@@ -21,15 +19,13 @@ impl<'a> BroadPhaseInterferenceHandler<specs::Entity> for InterferenceHandler<'a
|
|
|
}
|
|
|
|
|
|
fn interference_started(&mut self, a: &specs::Entity, b: &specs::Entity) {
|
|
|
- self.collisions.get_mut(*a).map (|r| r.has_collision = true );
|
|
|
- self.collisions.get_mut(*b).map (|r| r.has_collision = true );
|
|
|
+ self.collisions.get_mut(*a).map(|r| r.has_collision = true);
|
|
|
+ self.collisions.get_mut(*b).map(|r| r.has_collision = true);
|
|
|
}
|
|
|
|
|
|
- fn interference_stopped(&mut self, _: &specs::Entity, _: &specs::Entity) {
|
|
|
- }
|
|
|
+ fn interference_stopped(&mut self, _: &specs::Entity, _: &specs::Entity) {}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
struct Collide;
|
|
|
|
|
|
impl<'a> specs::System<'a> for Collide {
|
|
@@ -43,20 +39,29 @@ impl<'a> specs::System<'a> for Collide {
|
|
|
specs::WriteExpect<'a, NPhase>,
|
|
|
);
|
|
|
|
|
|
- fn run(&mut self, (entities, position, velocity, blocking, mut collisions, mut bf, _narrow): Self::SystemData) {
|
|
|
- let _: Vec<()> = (&mut collisions).join().map( |c| c.has_collision = false ).collect();
|
|
|
- let handles: Vec<BroadPhaseProxyHandle> =
|
|
|
- (&entities, &position, &blocking).join().map( |(e, pos, bl)| {
|
|
|
+ fn run(
|
|
|
+ &mut self,
|
|
|
+ (entities, position, velocity, blocking, mut collisions, mut bf, _narrow): Self::SystemData,
|
|
|
+ ) {
|
|
|
+ let _: Vec<()> = (&mut collisions)
|
|
|
+ .join()
|
|
|
+ .map(|c| c.has_collision = false)
|
|
|
+ .collect();
|
|
|
+ let handles: Vec<BroadPhaseProxyHandle> = (&entities, &position, &blocking)
|
|
|
+ .join()
|
|
|
+ .map(|(e, pos, bl)| {
|
|
|
let np = if let Some(vel) = velocity.get(e) {
|
|
|
pos.moved(vel)
|
|
|
} else {
|
|
|
pos.clone()
|
|
|
};
|
|
|
bf.create_proxy(
|
|
|
- bl.volume.aabb(&Isometry2::new(Vector2::new(np.x, np.y), nalgebra::zero())),
|
|
|
+ bl.volume
|
|
|
+ .aabb(&Isometry2::new(Vector2::new(np.x, np.y), nalgebra::zero())),
|
|
|
e,
|
|
|
)
|
|
|
- }).collect();
|
|
|
+ })
|
|
|
+ .collect();
|
|
|
|
|
|
bf.update(&mut InterferenceHandler {
|
|
|
collisions: collisions,
|
|
@@ -93,7 +98,7 @@ impl<'a> specs::System<'a> for Intersection {
|
|
|
|
|
|
struct Physics;
|
|
|
|
|
|
-impl <'a> specs::System<'a> for Physics {
|
|
|
+impl<'a> specs::System<'a> for Physics {
|
|
|
type SystemData = (
|
|
|
specs::ReadStorage<'a, Velocity>,
|
|
|
specs::ReadStorage<'a, Collision>,
|
|
@@ -113,8 +118,7 @@ impl <'a> specs::System<'a> for Physics {
|
|
|
struct ResetCollision;
|
|
|
|
|
|
impl<'a> specs::System<'a> for ResetCollision {
|
|
|
- type SystemData =
|
|
|
- specs::WriteStorage<'a, Collision>;
|
|
|
+ type SystemData = specs::WriteStorage<'a, Collision>;
|
|
|
|
|
|
fn run(&mut self, mut collision: Self::SystemData) {
|
|
|
for mut e in (&mut collision).join() {
|