mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 14:08:32 +00:00
expose stages and system containers (#1647)
This allows third-party plugins to analyze the schedule, e.g. `bevy_mod_picking` can [display a schedule graph](https://github.com/jakobhellermann/bevy_mod_debugdump/tree/schedule-graph#schedule-graph): ![schedule graph](https://raw.githubusercontent.com/jakobhellermann/bevy_mod_debugdump/schedule-graph/docs/schedule_graph.svg)
This commit is contained in:
parent
de55e05669
commit
48ee167531
3 changed files with 40 additions and 4 deletions
|
@ -201,6 +201,13 @@ impl Schedule {
|
||||||
stage.run(world);
|
stage.run(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Iterates over all of schedule's stages and their labels, in execution order.
|
||||||
|
pub fn iter_stages(&self) -> impl Iterator<Item = (&dyn StageLabel, &dyn Stage)> {
|
||||||
|
self.stage_order
|
||||||
|
.iter()
|
||||||
|
.map(move |label| (&**label, &*self.stages[label]))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Stage for Schedule {
|
impl Stage for Schedule {
|
||||||
|
|
|
@ -59,12 +59,12 @@ pub struct SystemStage {
|
||||||
executor: Box<dyn ParallelSystemExecutor>,
|
executor: Box<dyn ParallelSystemExecutor>,
|
||||||
/// Groups of systems; each set has its own run criterion.
|
/// Groups of systems; each set has its own run criterion.
|
||||||
system_sets: Vec<VirtualSystemSet>,
|
system_sets: Vec<VirtualSystemSet>,
|
||||||
/// Topologically sorted exclusive systems that want to be ran at the start of the stage.
|
/// Topologically sorted exclusive systems that want to be run at the start of the stage.
|
||||||
exclusive_at_start: Vec<ExclusiveSystemContainer>,
|
exclusive_at_start: Vec<ExclusiveSystemContainer>,
|
||||||
/// Topologically sorted exclusive systems that want to be ran after parallel systems but
|
/// Topologically sorted exclusive systems that want to be run after parallel systems but
|
||||||
/// before the application of their command buffers.
|
/// before the application of their command buffers.
|
||||||
exclusive_before_commands: Vec<ExclusiveSystemContainer>,
|
exclusive_before_commands: Vec<ExclusiveSystemContainer>,
|
||||||
/// Topologically sorted exclusive systems that want to be ran at the end of the stage.
|
/// Topologically sorted exclusive systems that want to be run at the end of the stage.
|
||||||
exclusive_at_end: Vec<ExclusiveSystemContainer>,
|
exclusive_at_end: Vec<ExclusiveSystemContainer>,
|
||||||
/// Topologically sorted parallel systems.
|
/// Topologically sorted parallel systems.
|
||||||
parallel: Vec<ParallelSystemContainer>,
|
parallel: Vec<ParallelSystemContainer>,
|
||||||
|
@ -167,6 +167,32 @@ impl SystemStage {
|
||||||
self.add_system_to_set(system, 0)
|
self.add_system_to_set(system, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Topologically sorted parallel systems.
|
||||||
|
///
|
||||||
|
/// Note that systems won't be fully-formed until the stage has been run at least once.
|
||||||
|
pub fn parallel_systems(&self) -> &[impl SystemContainer] {
|
||||||
|
&self.parallel
|
||||||
|
}
|
||||||
|
/// Topologically sorted exclusive systems that want to be run at the start of the stage.
|
||||||
|
///
|
||||||
|
/// Note that systems won't be fully-formed until the stage has been run at least once.
|
||||||
|
pub fn exclusive_at_start_systems(&self) -> &[impl SystemContainer] {
|
||||||
|
&self.exclusive_at_start
|
||||||
|
}
|
||||||
|
/// Topologically sorted exclusive systems that want to be run at the end of the stage.
|
||||||
|
///
|
||||||
|
/// Note that systems won't be fully-formed until the stage has been run at least once.
|
||||||
|
pub fn exclusive_at_end_systems(&self) -> &[impl SystemContainer] {
|
||||||
|
&self.exclusive_at_end
|
||||||
|
}
|
||||||
|
/// Topologically sorted exclusive systems that want to be run after parallel systems but
|
||||||
|
/// before the application of their command buffers.
|
||||||
|
///
|
||||||
|
/// Note that systems won't be fully-formed until the stage has been run at least once.
|
||||||
|
pub fn exclusive_before_commands_systems(&self) -> &[impl SystemContainer] {
|
||||||
|
&self.exclusive_before_commands
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: consider exposing
|
// TODO: consider exposing
|
||||||
fn add_system_to_set(&mut self, system: impl Into<SystemDescriptor>, set: usize) -> &mut Self {
|
fn add_system_to_set(&mut self, system: impl Into<SystemDescriptor>, set: usize) -> &mut Self {
|
||||||
self.systems_modified = true;
|
self.systems_modified = true;
|
||||||
|
|
|
@ -9,9 +9,12 @@ use crate::{
|
||||||
};
|
};
|
||||||
use std::{borrow::Cow, ptr::NonNull};
|
use std::{borrow::Cow, ptr::NonNull};
|
||||||
|
|
||||||
pub(super) trait SystemContainer {
|
/// System metadata like its name, labels, order requirements and component access.
|
||||||
|
pub trait SystemContainer {
|
||||||
fn name(&self) -> Cow<'static, str>;
|
fn name(&self) -> Cow<'static, str>;
|
||||||
|
#[doc(hidden)]
|
||||||
fn dependencies(&self) -> &[usize];
|
fn dependencies(&self) -> &[usize];
|
||||||
|
#[doc(hidden)]
|
||||||
fn set_dependencies(&mut self, dependencies: impl IntoIterator<Item = usize>);
|
fn set_dependencies(&mut self, dependencies: impl IntoIterator<Item = usize>);
|
||||||
fn system_set(&self) -> usize;
|
fn system_set(&self) -> usize;
|
||||||
fn labels(&self) -> &[BoxedSystemLabel];
|
fn labels(&self) -> &[BoxedSystemLabel];
|
||||||
|
|
Loading…
Add table
Reference in a new issue