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.

43 lines
1.2 KiB

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