You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
845 B

  1. #![allow(dead_code)]
  2. use specs::{prelude::*, ParJoin, Read, ReadStorage, System, WriteStorage};
  3. use crate::{
  4. components::{Position, Velocity},
  5. resources::Global,
  6. };
  7. #[derive(Default)]
  8. pub struct Movement;
  9. #[derive(SystemData)]
  10. pub struct MovementData<'a> {
  11. position: WriteStorage<'a, Position>,
  12. velocity: ReadStorage<'a, Velocity>,
  13. global: Read<'a, Global>,
  14. }
  15. impl<'a> System<'a> for Movement {
  16. type SystemData = MovementData<'a>;
  17. fn run(&mut self, data: Self::SystemData) {
  18. let MovementData {
  19. mut position,
  20. velocity,
  21. global,
  22. } = data;
  23. (&mut position, &velocity)
  24. .par_join()
  25. .for_each(|(position, velocity)| {
  26. position.pos = position.pos + velocity.dir * velocity.speed * global.delta;
  27. });
  28. }
  29. }