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.

35 lines
987 B

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