From e9b81f82173160722c8cf2454140dddb66fc3794 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Mon, 7 Apr 2025 16:52:13 +0200 Subject: [PATCH] Add priority to systems --- ecs/src/world.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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(), } } }