diff --git a/ecs/src/world.rs b/ecs/src/world.rs index 785d7af..efd5172 100644 --- a/ecs/src/world.rs +++ b/ecs/src/world.rs @@ -15,15 +15,19 @@ pub struct WorldBuilder { pub events: Events, pub resources: Resources, archetypes: Archetypes, - systems: Vec Result + Send + Sync + 'static>>, + systems: Vec<( + u32, + Box Result + Send + Sync + 'static>, + )>, } impl WorldBuilder { - pub fn add_system(&mut self, f: F) + pub fn add_system(&mut self, priority: u32, f: F) where F: Fn(&mut World) -> Result + Send + Sync + 'static, { - self.systems.push(Box::new(f)); + self.systems.push((priority, Box::new(f))); + self.systems.sort_by_key(|(priority, _)| *priority); } pub fn add_archetype(&mut self, name: impl ToString, archetype: Archetype) { @@ -49,7 +53,7 @@ impl WorldBuilder { start_time: Instant::now(), - systems: self.systems, + systems: self.systems.into_iter().map(|(_, f)| f).collect(), } } }