Add priority to systems
This commit is contained in:
parent
b827d47b2c
commit
e9b81f8217
1 changed files with 8 additions and 4 deletions
|
@ -15,15 +15,19 @@ pub struct WorldBuilder {
|
||||||
pub events: Events,
|
pub events: Events,
|
||||||
pub resources: Resources,
|
pub resources: Resources,
|
||||||
archetypes: Archetypes,
|
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 {
|
impl WorldBuilder {
|
||||||
pub fn add_system<F>(&mut self, f: F)
|
pub fn add_system<F>(&mut self, priority: u32, f: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut World) -> Result<bool> + Send + Sync + 'static,
|
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) {
|
pub fn add_archetype(&mut self, name: impl ToString, archetype: Archetype) {
|
||||||
|
@ -49,7 +53,7 @@ impl WorldBuilder {
|
||||||
|
|
||||||
start_time: Instant::now(),
|
start_time: Instant::now(),
|
||||||
|
|
||||||
systems: self.systems,
|
systems: self.systems.into_iter().map(|(_, f)| f).collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue