Async Entity Component System based on the ideas of specs (https://github.com/amethyst/specs)
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.

47 line
985 B

  1. use log::info;
  2. use super::{BoxedDispatchable, Receiver, Sender, SharedWorld};
  3. pub async fn execute(
  4. name: String,
  5. dispatchable: BoxedDispatchable,
  6. sender: Sender,
  7. receivers: Vec<Receiver>,
  8. world: SharedWorld,
  9. ) {
  10. info!("System started: {}", &name);
  11. run(&name, dispatchable, sender, receivers, world).await;
  12. info!("System finished: {}", &name);
  13. }
  14. async fn run(
  15. name: &str,
  16. mut dispatchable: BoxedDispatchable,
  17. sender: Sender,
  18. mut receivers: Vec<Receiver>,
  19. world: SharedWorld,
  20. ) {
  21. loop {
  22. for receiver in &mut receivers {
  23. match receiver.changed().await {
  24. Ok(()) => (),
  25. Err(_) => return,
  26. }
  27. }
  28. info!("Run system: {}", &name);
  29. let world = world.borrow();
  30. let world = world.as_ref().unwrap();
  31. dispatchable.run(world);
  32. match sender.send(()) {
  33. Ok(()) => (),
  34. Err(_) => return,
  35. }
  36. }
  37. }