# Objective - Make it possible to use `System`s outside of the scheduler/executor without having to define logic to track new archetypes and call `System::add_archetype()` for each. ## Solution - Replace `System::add_archetype(&Archetype)` with `System::update_archetypes(&World)`, making systems responsible for tracking their own most recent archetype generation the way that `SystemState` already does. This has minimal (or simplifying) effect on most of the code with the exception of `FunctionSystem`, which must now track the latest `ArchetypeGeneration` it saw instead of relying on the executor to do it. Co-authored-by: Carter Anderson <mcanders1@gmail.com>
30 lines
1.0 KiB
Rust
30 lines
1.0 KiB
Rust
use crate::{schedule::ParallelSystemContainer, world::World};
|
|
use downcast_rs::{impl_downcast, Downcast};
|
|
|
|
pub trait ParallelSystemExecutor: Downcast + Send + Sync {
|
|
/// Called by `SystemStage` whenever `systems` have been changed.
|
|
fn rebuild_cached_data(&mut self, systems: &[ParallelSystemContainer]);
|
|
|
|
fn run_systems(&mut self, systems: &mut [ParallelSystemContainer], world: &mut World);
|
|
}
|
|
|
|
impl_downcast!(ParallelSystemExecutor);
|
|
|
|
#[derive(Default)]
|
|
pub struct SingleThreadedExecutor;
|
|
|
|
impl ParallelSystemExecutor for SingleThreadedExecutor {
|
|
fn rebuild_cached_data(&mut self, _: &[ParallelSystemContainer]) {}
|
|
|
|
fn run_systems(&mut self, systems: &mut [ParallelSystemContainer], world: &mut World) {
|
|
for system in systems {
|
|
if system.should_run() {
|
|
#[cfg(feature = "trace")]
|
|
let _system_span =
|
|
bevy_utils::tracing::info_span!("system", name = &*system.name()).entered();
|
|
system.system_mut().run((), world);
|
|
}
|
|
}
|
|
}
|
|
}
|