mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
26 lines
620 B
Rust
26 lines
620 B
Rust
|
// Library
|
||
|
use specs::{Join, Read, ReadStorage, System, WriteStorage};
|
||
|
|
||
|
// Crate
|
||
|
use crate::{
|
||
|
comp::phys::{Pos, Vel},
|
||
|
state::DeltaTime,
|
||
|
};
|
||
|
|
||
|
// Basic ECS physics system
|
||
|
pub struct MovementSys;
|
||
|
|
||
|
impl<'a> System<'a> for MovementSys {
|
||
|
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()
|
||
|
.for_each(|(pos, vel)| pos.0 += vel.0 * dt.0 as f32 * 100.0);
|
||
|
}
|
||
|
}
|