Add priority to systems

This commit is contained in:
hodasemi 2025-04-07 16:52:13 +02:00
parent b827d47b2c
commit e9b81f8217

View file

@ -15,15 +15,19 @@ pub struct WorldBuilder {
pub events: Events,
pub resources: Resources,
archetypes: Archetypes,
systems: Vec<Box<dyn Fn(&mut World) -> Result<bool> + Send + Sync + 'static>>,
systems: Vec<(
u32,
Box<dyn Fn(&mut World) -> Result<bool> + Send + Sync + 'static>,
)>,
}
impl WorldBuilder {
pub fn add_system<F>(&mut self, f: F)
pub fn add_system<F>(&mut self, priority: u32, f: F)
where
F: Fn(&mut World) -> Result<bool> + 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(),
}
}
}