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 line
1.1 KiB

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