wecs_core/schedule/
schedule.rs1use crate::{
2 system::{BoxedSystem, IntoSystem},
3 world::World,
4};
5
6pub struct Schedule {
7 systems: Vec<BoxedSystem>,
8}
9
10impl Default for Schedule {
11 fn default() -> Self {
12 Self::new()
13 }
14}
15
16impl Schedule {
17 pub fn new() -> Self {
18 Self {
19 systems: Vec::new(),
20 }
21 }
22
23 pub fn with_system<Marker, S>(mut self, system: S) -> Self
24 where
25 S: IntoSystem<Marker> + 'static,
26 Marker: 'static,
27 {
28 self.systems.push(Box::new(system.into_system()));
29 self
30 }
31
32 pub fn add_system<Marker, S>(&mut self, system: S)
33 where
34 S: IntoSystem<Marker> + 'static,
35 Marker: 'static,
36 {
37 self.systems.push(Box::new(system.into_system()));
38 }
39
40 pub fn run(&mut self, world: &mut World) {
41 for ele in self.systems.iter_mut() {
42 ele.run(world);
43 }
44 }
45}