2019-03-02 03:48:30 +00:00
|
|
|
// Library
|
|
|
|
use specs::{Join, Read, ReadStorage, System, WriteStorage};
|
|
|
|
|
|
|
|
// Crate
|
|
|
|
use crate::{
|
|
|
|
comp::phys::{Pos, Vel},
|
|
|
|
state::DeltaTime,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Basic ECS physics system
|
2019-04-16 21:06:33 +00:00
|
|
|
pub struct Sys;
|
2019-03-02 03:48:30 +00:00
|
|
|
|
2019-04-16 21:06:33 +00:00
|
|
|
impl<'a> System<'a> for Sys {
|
2019-03-02 03:48:30 +00:00
|
|
|
type SystemData = (
|
|
|
|
WriteStorage<'a, Pos>,
|
|
|
|
ReadStorage<'a, Vel>,
|
|
|
|
Read<'a, DeltaTime>,
|
|
|
|
);
|
|
|
|
|
|
|
|
fn run(&mut self, (mut positions, velocities, dt): Self::SystemData) {
|
|
|
|
(&mut positions, &velocities)
|
|
|
|
.join() // this can be parallelized with par_join()
|
2019-03-02 19:43:51 +00:00
|
|
|
.for_each(|(pos, vel)| pos.0 += vel.0 * dt.0 as f32);
|
2019-03-02 03:48:30 +00:00
|
|
|
}
|
|
|
|
}
|