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.

42 rivejä
1.3 KiB

  1. use specs::{Dispatcher as Inner, DispatcherBuilder, World, WorldExt};
  2. use crate::{
  3. components::Player,
  4. resources::Global,
  5. systems::{
  6. FleetControl, FleetOrbitingUpdate, FleetOwnedUpdate, Process, ShipControl, ShipsMovement,
  7. ShipsMoving, ShipsOrbiting,
  8. },
  9. Error,
  10. };
  11. pub struct Dispatcher<'a, 'b> {
  12. dispatcher: Inner<'a, 'b>,
  13. }
  14. impl<'a, 'b> Dispatcher<'a, 'b> {
  15. pub fn new(world: &mut World) -> Result<Self, Error> {
  16. world.insert(Global::default());
  17. world.register::<Player>();
  18. let mut dispatcher = DispatcherBuilder::new()
  19. .with(Process::default(), "process", &[])
  20. .with(ShipControl::new(world)?, "ship_control", &[])
  21. .with(ShipsOrbiting::default(), "ships_orbiting", &[])
  22. .with(ShipsMoving::default(), "ships_moving", &[])
  23. .with(ShipsMovement::default(), "ships_movement", &[])
  24. .with(FleetControl::new(world)?, "fleet_control", &[])
  25. .with(FleetOwnedUpdate::new(world), "fleet_owned_update", &[])
  26. .with(FleetOrbitingUpdate::new(world), "fleet_orbiting", &[])
  27. .build();
  28. dispatcher.setup(world);
  29. Ok(Self { dispatcher })
  30. }
  31. pub fn process(&mut self, world: &World) {
  32. self.dispatcher.dispatch(world);
  33. }
  34. }