From 9fedc371cb5b7dde241ff555854930f07f07f91e Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Fri, 23 Sep 2022 17:33:21 -0700 Subject: [PATCH 01/10] Implement System for exclusive systems, add ExclusiveSystemParam --- crates/bevy_animation/src/lib.rs | 2 +- crates/bevy_app/src/app.rs | 4 +- crates/bevy_ecs/src/lib.rs | 11 +- .../src/schedule/ambiguity_detection.rs | 12 +- crates/bevy_ecs/src/schedule/executor.rs | 10 +- .../src/schedule/executor_parallel.rs | 8 +- crates/bevy_ecs/src/schedule/stage.rs | 376 ++++++++-------- .../bevy_ecs/src/schedule/system_container.rs | 152 ++----- .../src/schedule/system_descriptor.rs | 308 ++++--------- crates/bevy_ecs/src/schedule/system_set.rs | 15 +- .../src/system/exclusive_function_system.rs | 411 ++++++++++++++++++ .../bevy_ecs/src/system/exclusive_system.rs | 177 -------- crates/bevy_ecs/src/system/function_system.rs | 9 +- crates/bevy_ecs/src/system/mod.rs | 41 +- crates/bevy_ecs/src/system/system.rs | 3 + crates/bevy_ecs/src/system/system_chaining.rs | 4 + crates/bevy_gilrs/src/lib.rs | 2 +- crates/bevy_input/src/lib.rs | 2 +- crates/bevy_pbr/src/lib.rs | 4 +- crates/bevy_pbr/src/material.rs | 2 +- crates/bevy_render/src/lib.rs | 2 +- crates/bevy_scene/src/lib.rs | 7 +- crates/bevy_sprite/src/lib.rs | 2 +- crates/bevy_sprite/src/mesh2d/material.rs | 2 +- crates/bevy_text/src/lib.rs | 2 +- crates/bevy_time/src/fixed_timestep.rs | 4 + crates/bevy_time/src/lib.rs | 5 +- crates/bevy_ui/src/lib.rs | 2 +- crates/bevy_window/src/lib.rs | 2 +- 29 files changed, 780 insertions(+), 801 deletions(-) create mode 100644 crates/bevy_ecs/src/system/exclusive_function_system.rs delete mode 100644 crates/bevy_ecs/src/system/exclusive_system.rs diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index ee70d801ef952..8dbf71e7faadc 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -12,7 +12,7 @@ use bevy_ecs::{ entity::Entity, prelude::Component, reflect::ReflectComponent, - schedule::ParallelSystemDescriptorCoercion, + schedule::IntoSystemDescriptor, system::{Query, Res}, }; use bevy_hierarchy::Children; diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 428dac0fd54ca..e71cda2229307 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -3,7 +3,7 @@ pub use bevy_derive::AppLabel; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ event::{Event, Events}, - prelude::{FromWorld, IntoExclusiveSystem}, + prelude::FromWorld, schedule::{ IntoSystemDescriptor, Schedule, ShouldRun, Stage, StageLabel, State, StateData, SystemSet, SystemStage, @@ -84,7 +84,7 @@ impl Default for App { app.add_default_stages() .add_event::() - .add_system_to_stage(CoreStage::Last, World::clear_trackers.exclusive_system()); + .add_system_to_stage(CoreStage::Last, World::clear_trackers); #[cfg(feature = "bevy_ci_testing")] { diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index 102df951f89a0..56f9e938e5864 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -34,14 +34,13 @@ pub mod prelude { event::{EventReader, EventWriter, Events}, query::{Added, AnyOf, ChangeTrackers, Changed, Or, QueryState, With, Without}, schedule::{ - ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion, RunCriteria, - RunCriteriaDescriptorCoercion, RunCriteriaLabel, Schedule, Stage, StageLabel, State, - SystemLabel, SystemSet, SystemStage, + IntoSystemDescriptor, RunCriteria, RunCriteriaDescriptorCoercion, RunCriteriaLabel, + Schedule, Stage, StageLabel, State, SystemLabel, SystemSet, SystemStage, }, system::{ - adapter as system_adapter, Commands, In, IntoChainSystem, IntoExclusiveSystem, - IntoSystem, Local, NonSend, NonSendMut, ParallelCommands, ParamSet, Query, - RemovedComponents, Res, ResMut, Resource, System, SystemParamFunction, + adapter as system_adapter, Commands, In, IntoChainSystem, IntoSystem, Local, NonSend, + NonSendMut, ParallelCommands, ParamSet, Query, RemovedComponents, Res, ResMut, + Resource, System, SystemParamFunction, }, world::{FromWorld, Mut, World}, }; diff --git a/crates/bevy_ecs/src/schedule/ambiguity_detection.rs b/crates/bevy_ecs/src/schedule/ambiguity_detection.rs index a1f02ba32a339..f718fe10d5a7c 100644 --- a/crates/bevy_ecs/src/schedule/ambiguity_detection.rs +++ b/crates/bevy_ecs/src/schedule/ambiguity_detection.rs @@ -220,7 +220,7 @@ impl SystemStage { /// Returns vector containing all pairs of indices of systems with ambiguous execution order, /// along with specific components that have triggered the warning. /// Systems must be topologically sorted beforehand. -fn find_ambiguities(systems: &[impl SystemContainer]) -> Vec<(usize, usize, Vec)> { +fn find_ambiguities(systems: &[SystemContainer]) -> Vec<(usize, usize, Vec)> { let mut all_dependencies = Vec::::with_capacity(systems.len()); let mut all_dependants = Vec::::with_capacity(systems.len()); for (index, container) in systems.iter().enumerate() { @@ -467,12 +467,12 @@ mod tests { let mut test_stage = SystemStage::parallel(); test_stage // All 3 of these conflict with each other - .add_system(write_world_system.exclusive_system()) - .add_system(write_world_system.exclusive_system().at_end()) - .add_system(res_system.exclusive_system()) + .add_system(write_world_system) + .add_system(write_world_system.at_end()) + .add_system(res_system.at_start()) // These do not, as they're in different segments of the stage - .add_system(write_world_system.exclusive_system().at_start()) - .add_system(write_world_system.exclusive_system().before_commands()); + .add_system(write_world_system.at_start()) + .add_system(write_world_system.before_commands()); test_stage.run(&mut world); diff --git a/crates/bevy_ecs/src/schedule/executor.rs b/crates/bevy_ecs/src/schedule/executor.rs index 06db889ec2d6c..4e649d47086f9 100644 --- a/crates/bevy_ecs/src/schedule/executor.rs +++ b/crates/bevy_ecs/src/schedule/executor.rs @@ -1,11 +1,11 @@ -use crate::{schedule::ParallelSystemContainer, world::World}; +use crate::{schedule::SystemContainer, 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 rebuild_cached_data(&mut self, systems: &[SystemContainer]); - fn run_systems(&mut self, systems: &mut [ParallelSystemContainer], world: &mut World); + fn run_systems(&mut self, systems: &mut [SystemContainer], world: &mut World); } impl_downcast!(ParallelSystemExecutor); @@ -14,9 +14,9 @@ impl_downcast!(ParallelSystemExecutor); pub struct SingleThreadedExecutor; impl ParallelSystemExecutor for SingleThreadedExecutor { - fn rebuild_cached_data(&mut self, _: &[ParallelSystemContainer]) {} + fn rebuild_cached_data(&mut self, _: &[SystemContainer]) {} - fn run_systems(&mut self, systems: &mut [ParallelSystemContainer], world: &mut World) { + fn run_systems(&mut self, systems: &mut [SystemContainer], world: &mut World) { for system in systems { if system.should_run() { #[cfg(feature = "trace")] diff --git a/crates/bevy_ecs/src/schedule/executor_parallel.rs b/crates/bevy_ecs/src/schedule/executor_parallel.rs index c0eb24a2bae56..1663d26646241 100644 --- a/crates/bevy_ecs/src/schedule/executor_parallel.rs +++ b/crates/bevy_ecs/src/schedule/executor_parallel.rs @@ -1,7 +1,7 @@ use crate::{ archetype::ArchetypeComponentId, query::Access, - schedule::{ParallelSystemContainer, ParallelSystemExecutor}, + schedule::{ParallelSystemExecutor, SystemContainer}, world::World, }; use async_channel::{Receiver, Sender}; @@ -77,7 +77,7 @@ impl Default for ParallelExecutor { } impl ParallelSystemExecutor for ParallelExecutor { - fn rebuild_cached_data(&mut self, systems: &[ParallelSystemContainer]) { + fn rebuild_cached_data(&mut self, systems: &[SystemContainer]) { self.system_metadata.clear(); self.queued.grow(systems.len()); self.running.grow(systems.len()); @@ -104,7 +104,7 @@ impl ParallelSystemExecutor for ParallelExecutor { } } - fn run_systems(&mut self, systems: &mut [ParallelSystemContainer], world: &mut World) { + fn run_systems(&mut self, systems: &mut [SystemContainer], world: &mut World) { #[cfg(test)] if self.events_sender.is_none() { let (sender, receiver) = async_channel::unbounded::(); @@ -167,7 +167,7 @@ impl ParallelExecutor { fn prepare_systems<'scope>( &mut self, scope: &mut Scope<'scope, ()>, - systems: &'scope mut [ParallelSystemContainer], + systems: &'scope mut [SystemContainer], world: &'scope World, ) { // These are used as a part of a unit test. diff --git a/crates/bevy_ecs/src/schedule/stage.rs b/crates/bevy_ecs/src/schedule/stage.rs index 414ebb5e615fa..1937d8adb70c7 100644 --- a/crates/bevy_ecs/src/schedule/stage.rs +++ b/crates/bevy_ecs/src/schedule/stage.rs @@ -5,11 +5,10 @@ use crate::{ prelude::IntoSystem, schedule::{ graph_utils::{self, DependencyGraphError}, - BoxedRunCriteria, DuplicateLabelStrategy, ExclusiveSystemContainer, GraphNode, - InsertionPoint, ParallelExecutor, ParallelSystemContainer, ParallelSystemExecutor, - RunCriteriaContainer, RunCriteriaDescriptor, RunCriteriaDescriptorOrLabel, - RunCriteriaInner, RunCriteriaLabelId, ShouldRun, SingleThreadedExecutor, SystemContainer, - SystemDescriptor, SystemLabelId, SystemSet, + BoxedRunCriteria, DuplicateLabelStrategy, ExclusiveInsertionPoint, GraphNode, + ParallelExecutor, ParallelSystemExecutor, RunCriteriaContainer, RunCriteriaDescriptor, + RunCriteriaDescriptorOrLabel, RunCriteriaInner, RunCriteriaLabelId, ShouldRun, + SingleThreadedExecutor, SystemContainer, SystemDescriptor, SystemLabelId, SystemSet, }, world::{World, WorldId}, }; @@ -62,14 +61,14 @@ pub struct SystemStage { /// Topologically sorted run criteria of systems. run_criteria: Vec, /// Topologically sorted exclusive systems that want to be run at the start of the stage. - pub(super) exclusive_at_start: Vec, + pub(super) exclusive_at_start: Vec, /// Topologically sorted exclusive systems that want to be run after parallel systems but /// before the application of their command buffers. - pub(super) exclusive_before_commands: Vec, + pub(super) exclusive_before_commands: Vec, /// Topologically sorted exclusive systems that want to be run at the end of the stage. - pub(super) exclusive_at_end: Vec, + pub(super) exclusive_at_end: Vec, /// Topologically sorted parallel systems. - pub(super) parallel: Vec, + pub(super) parallel: Vec, /// Determines if the stage was modified and needs to rebuild its graphs and orders. pub(super) systems_modified: bool, /// Determines if the stage's executor was changed. @@ -156,63 +155,63 @@ impl SystemStage { self } - fn add_system_inner(&mut self, system: SystemDescriptor, default_run_criteria: Option) { + fn add_system_inner( + &mut self, + mut descriptor: SystemDescriptor, + default_run_criteria: Option, + ) { self.systems_modified = true; - match system { - SystemDescriptor::Exclusive(mut descriptor) => { - let insertion_point = descriptor.insertion_point; - let criteria = descriptor.run_criteria.take(); - let mut container = ExclusiveSystemContainer::from_descriptor(descriptor); - match criteria { - Some(RunCriteriaDescriptorOrLabel::Label(label)) => { - container.run_criteria_label = Some(label); - } - Some(RunCriteriaDescriptorOrLabel::Descriptor(criteria_descriptor)) => { - container.run_criteria_label = criteria_descriptor.label; - container.run_criteria_index = - Some(self.add_run_criteria_internal(criteria_descriptor)); - } - None => { - container.run_criteria_index = default_run_criteria; - } + if let Some(insertion_point) = descriptor.exclusive_insertion_point { + let criteria = descriptor.run_criteria.take(); + let mut container = SystemContainer::from_descriptor(descriptor); + match criteria { + Some(RunCriteriaDescriptorOrLabel::Label(label)) => { + container.run_criteria_label = Some(label); } - match insertion_point { - InsertionPoint::AtStart => { - let index = self.exclusive_at_start.len(); - self.uninitialized_at_start.push(index); - self.exclusive_at_start.push(container); - } - InsertionPoint::BeforeCommands => { - let index = self.exclusive_before_commands.len(); - self.uninitialized_before_commands.push(index); - self.exclusive_before_commands.push(container); - } - InsertionPoint::AtEnd => { - let index = self.exclusive_at_end.len(); - self.uninitialized_at_end.push(index); - self.exclusive_at_end.push(container); - } + Some(RunCriteriaDescriptorOrLabel::Descriptor(criteria_descriptor)) => { + container.run_criteria_label = criteria_descriptor.label; + container.run_criteria_index = + Some(self.add_run_criteria_internal(criteria_descriptor)); + } + None => { + container.run_criteria_index = default_run_criteria; } } - SystemDescriptor::Parallel(mut descriptor) => { - let criteria = descriptor.run_criteria.take(); - let mut container = ParallelSystemContainer::from_descriptor(descriptor); - match criteria { - Some(RunCriteriaDescriptorOrLabel::Label(label)) => { - container.run_criteria_label = Some(label); - } - Some(RunCriteriaDescriptorOrLabel::Descriptor(criteria_descriptor)) => { - container.run_criteria_label = criteria_descriptor.label; - container.run_criteria_index = - Some(self.add_run_criteria_internal(criteria_descriptor)); - } - None => { - container.run_criteria_index = default_run_criteria; - } + match insertion_point { + ExclusiveInsertionPoint::AtStart => { + let index = self.exclusive_at_start.len(); + self.uninitialized_at_start.push(index); + self.exclusive_at_start.push(container); + } + ExclusiveInsertionPoint::BeforeCommands => { + let index = self.exclusive_before_commands.len(); + self.uninitialized_before_commands.push(index); + self.exclusive_before_commands.push(container); + } + ExclusiveInsertionPoint::AtEnd => { + let index = self.exclusive_at_end.len(); + self.uninitialized_at_end.push(index); + self.exclusive_at_end.push(container); + } + } + } else { + let criteria = descriptor.run_criteria.take(); + let mut container = SystemContainer::from_descriptor(descriptor); + match criteria { + Some(RunCriteriaDescriptorOrLabel::Label(label)) => { + container.run_criteria_label = Some(label); + } + Some(RunCriteriaDescriptorOrLabel::Descriptor(criteria_descriptor)) => { + container.run_criteria_label = criteria_descriptor.label; + container.run_criteria_index = + Some(self.add_run_criteria_internal(criteria_descriptor)); + } + None => { + container.run_criteria_index = default_run_criteria; } - self.uninitialized_parallel.push(self.parallel.len()); - self.parallel.push(container); } + self.uninitialized_parallel.push(self.parallel.len()); + self.parallel.push(container); } } @@ -233,21 +232,21 @@ impl SystemStage { /// 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] { + pub fn parallel_systems(&self) -> &[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] { + pub fn exclusive_at_start_systems(&self) -> &[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] { + pub fn exclusive_at_end_systems(&self) -> &[SystemContainer] { &self.exclusive_at_end } @@ -255,7 +254,7 @@ impl SystemStage { /// 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] { + pub fn exclusive_before_commands_systems(&self) -> &[SystemContainer] { &self.exclusive_before_commands } @@ -270,17 +269,12 @@ impl SystemStage { let (run_criteria, mut systems) = system_set.bake(); let set_run_criteria_index = run_criteria.and_then(|criteria| { // validate that no systems have criteria - for system in &mut systems { - if let Some(name) = match system { - SystemDescriptor::Exclusive(descriptor) => descriptor - .run_criteria - .is_some() - .then(|| descriptor.system.name()), - SystemDescriptor::Parallel(descriptor) => descriptor - .run_criteria - .is_some() - .then(|| descriptor.system.name()), - } { + for descriptor in &mut systems { + if let Some(name) = descriptor + .run_criteria + .is_some() + .then(|| descriptor.system.name()) + { panic!( "The system {} has a run criteria, but its `SystemSet` also has a run \ criteria. This is not supported. Consider moving the system into a \ @@ -295,16 +289,7 @@ impl SystemStage { } RunCriteriaDescriptorOrLabel::Label(label) => { for system in &mut systems { - match system { - SystemDescriptor::Exclusive(descriptor) => { - descriptor.run_criteria = - Some(RunCriteriaDescriptorOrLabel::Label(label)); - } - SystemDescriptor::Parallel(descriptor) => { - descriptor.run_criteria = - Some(RunCriteriaDescriptorOrLabel::Label(label)); - } - } + system.run_criteria = Some(RunCriteriaDescriptorOrLabel::Label(label)); } None @@ -578,8 +563,8 @@ impl SystemStage { } } - fn update_run_criteria_indices( - systems: &mut [T], + fn update_run_criteria_indices( + systems: &mut [SystemContainer], order_inverted: &[(usize, &usize)], ) { for system in systems { @@ -605,7 +590,7 @@ impl SystemStage { /// Sorts given system containers topologically, populates their resolved dependencies /// and run criteria. fn process_systems( - systems: &mut Vec, + systems: &mut Vec, run_criteria_labels: &HashMap, ) -> Result<(), DependencyGraphError>> { let mut graph = graph_utils::build_dependency_graph(systems); @@ -701,7 +686,7 @@ impl Stage for SystemStage { run_system_loop = false; fn should_run( - container: &impl SystemContainer, + container: &SystemContainer, run_criteria: &[RunCriteriaContainer], default: ShouldRun, ) -> bool { @@ -717,13 +702,24 @@ impl Stage for SystemStage { // Run systems that want to be at the start of stage. for container in &mut self.exclusive_at_start { if should_run(container, &self.run_criteria, default_should_run) { - #[cfg(feature = "trace")] - let _system_span = bevy_utils::tracing::info_span!( - "exclusive_system", - name = &*container.name() - ) - .entered(); - container.system_mut().run(world); + { + #[cfg(feature = "trace")] + let _system_span = bevy_utils::tracing::info_span!( + "exclusive_system", + name = &*container.name() + ) + .entered(); + container.system_mut().run((), world); + } + { + #[cfg(feature = "trace")] + let _system_span = bevy_utils::tracing::info_span!( + "system_commands", + name = &*container.name() + ) + .entered(); + container.system_mut().apply_buffers(world); + } } } @@ -738,13 +734,24 @@ impl Stage for SystemStage { // Run systems that want to be between parallel systems and their command buffers. for container in &mut self.exclusive_before_commands { if should_run(container, &self.run_criteria, default_should_run) { - #[cfg(feature = "trace")] - let _system_span = bevy_utils::tracing::info_span!( - "exclusive_system", - name = &*container.name() - ) - .entered(); - container.system_mut().run(world); + { + #[cfg(feature = "trace")] + let _system_span = bevy_utils::tracing::info_span!( + "exclusive_system", + name = &*container.name() + ) + .entered(); + container.system_mut().run((), world); + } + { + #[cfg(feature = "trace")] + let _system_span = bevy_utils::tracing::info_span!( + "system_commands", + name = &*container.name() + ) + .entered(); + container.system_mut().apply_buffers(world); + } } } @@ -766,13 +773,24 @@ impl Stage for SystemStage { // Run systems that want to be at the end of stage. for container in &mut self.exclusive_at_end { if should_run(container, &self.run_criteria, default_should_run) { - #[cfg(feature = "trace")] - let _system_span = bevy_utils::tracing::info_span!( - "exclusive_system", - name = &*container.name() - ) - .entered(); - container.system_mut().run(world); + { + #[cfg(feature = "trace")] + let _system_span = bevy_utils::tracing::info_span!( + "exclusive_system", + name = &*container.name() + ) + .entered(); + container.system_mut().run((), world); + } + { + #[cfg(feature = "trace")] + let _system_span = bevy_utils::tracing::info_span!( + "system_commands", + name = &*container.name() + ) + .entered(); + container.system_mut().apply_buffers(world); + } } } @@ -826,11 +844,10 @@ mod tests { use crate::{ schedule::{ - ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion, RunCriteria, - RunCriteriaDescriptorCoercion, ShouldRun, SingleThreadedExecutor, Stage, SystemLabel, - SystemSet, SystemStage, + IntoSystemDescriptor, RunCriteria, RunCriteriaDescriptorCoercion, ShouldRun, + SingleThreadedExecutor, Stage, SystemLabel, SystemSet, SystemStage, }, - system::{In, IntoExclusiveSystem, Local, Query, ResMut}, + system::{In, Local, Query, ResMut}, world::World, }; @@ -868,10 +885,10 @@ mod tests { let mut world = World::new(); world.init_resource::(); let mut stage = SystemStage::parallel() - .with_system(make_exclusive(0).exclusive_system().at_start()) + .with_system(make_exclusive(0).at_start()) .with_system(make_parallel(1)) - .with_system(make_exclusive(2).exclusive_system().before_commands()) - .with_system(make_exclusive(3).exclusive_system().at_end()); + .with_system(make_exclusive(2).before_commands()) + .with_system(make_exclusive(3).at_end()); stage.run(&mut world); assert_eq!(world.resource_mut::().0, vec![0, 1, 2, 3]); stage.set_executor(Box::new(SingleThreadedExecutor::default())); @@ -883,10 +900,10 @@ mod tests { world.resource_mut::().0.clear(); let mut stage = SystemStage::parallel() - .with_system(make_exclusive(2).exclusive_system().before_commands()) - .with_system(make_exclusive(3).exclusive_system().at_end()) + .with_system(make_exclusive(2).before_commands()) + .with_system(make_exclusive(3).at_end()) .with_system(make_parallel(1)) - .with_system(make_exclusive(0).exclusive_system().at_start()); + .with_system(make_exclusive(0).at_start()); stage.run(&mut world); assert_eq!(world.resource::().0, vec![0, 1, 2, 3]); stage.set_executor(Box::new(SingleThreadedExecutor::default())); @@ -898,10 +915,10 @@ mod tests { world.resource_mut::().0.clear(); let mut stage = SystemStage::parallel() - .with_system(make_parallel(2).exclusive_system().before_commands()) - .with_system(make_parallel(3).exclusive_system().at_end()) + .with_system(make_parallel(2).before_commands()) + .with_system(make_parallel(3).at_end()) .with_system(make_parallel(1)) - .with_system(make_parallel(0).exclusive_system().at_start()); + .with_system(make_parallel(0).at_start()); stage.run(&mut world); assert_eq!(world.resource::().0, vec![0, 1, 2, 3]); stage.set_executor(Box::new(SingleThreadedExecutor::default())); @@ -930,9 +947,9 @@ mod tests { let mut world = World::new(); world.init_resource::(); let mut stage = SystemStage::parallel() - .with_system(make_exclusive(1).exclusive_system().label(L1).after(L0)) - .with_system(make_exclusive(2).exclusive_system().after(L1)) - .with_system(make_exclusive(0).exclusive_system().label(L0)); + .with_system(make_exclusive(1).label(L1).after(L0)) + .with_system(make_exclusive(2).after(L1)) + .with_system(make_exclusive(0).label(L0)); stage.run(&mut world); stage.set_executor(Box::new(SingleThreadedExecutor::default())); stage.run(&mut world); @@ -944,9 +961,9 @@ mod tests { let mut world = World::new(); world.init_resource::(); let mut stage = SystemStage::parallel() - .with_system(make_exclusive(1).exclusive_system().label(L1).before(L2)) - .with_system(make_exclusive(2).exclusive_system().label(L2)) - .with_system(make_exclusive(0).exclusive_system().before(L1)); + .with_system(make_exclusive(1).label(L1).before(L2)) + .with_system(make_exclusive(2).label(L2)) + .with_system(make_exclusive(0).before(L1)); stage.run(&mut world); stage.set_executor(Box::new(SingleThreadedExecutor::default())); stage.run(&mut world); @@ -958,11 +975,11 @@ mod tests { let mut world = World::new(); world.init_resource::(); let mut stage = SystemStage::parallel() - .with_system(make_exclusive(2).exclusive_system().label(L2)) - .with_system(make_exclusive(1).exclusive_system().after(L0).before(L2)) - .with_system(make_exclusive(0).exclusive_system().label(L0)) - .with_system(make_exclusive(4).exclusive_system().label(L4)) - .with_system(make_exclusive(3).exclusive_system().after(L2).before(L4)); + .with_system(make_exclusive(2).label(L2)) + .with_system(make_exclusive(1).after(L0).before(L2)) + .with_system(make_exclusive(0).label(L0)) + .with_system(make_exclusive(4).label(L4)) + .with_system(make_exclusive(3).after(L2).before(L4)); stage.run(&mut world); stage.set_executor(Box::new(SingleThreadedExecutor::default())); stage.run(&mut world); @@ -977,9 +994,9 @@ mod tests { let mut world = World::new(); world.init_resource::(); let mut stage = SystemStage::parallel() - .with_system(make_exclusive(1).exclusive_system().label(First).after(L0)) - .with_system(make_exclusive(2).exclusive_system().after(First)) - .with_system(make_exclusive(0).exclusive_system().label(First).label(L0)); + .with_system(make_exclusive(1).label(First).after(L0)) + .with_system(make_exclusive(2).after(First)) + .with_system(make_exclusive(0).label(First).label(L0)); stage.run(&mut world); stage.set_executor(Box::new(SingleThreadedExecutor::default())); stage.run(&mut world); @@ -987,11 +1004,11 @@ mod tests { world.resource_mut::().0.clear(); let mut stage = SystemStage::parallel() - .with_system(make_exclusive(2).exclusive_system().after(L01).label(L2)) - .with_system(make_exclusive(1).exclusive_system().label(L01).after(L0)) - .with_system(make_exclusive(0).exclusive_system().label(L01).label(L0)) - .with_system(make_exclusive(4).exclusive_system().label(L4)) - .with_system(make_exclusive(3).exclusive_system().after(L2).before(L4)); + .with_system(make_exclusive(2).after(L01).label(L2)) + .with_system(make_exclusive(1).label(L01).after(L0)) + .with_system(make_exclusive(0).label(L01).label(L0)) + .with_system(make_exclusive(4).label(L4)) + .with_system(make_exclusive(3).after(L2).before(L4)); stage.run(&mut world); stage.set_executor(Box::new(SingleThreadedExecutor::default())); stage.run(&mut world); @@ -1002,17 +1019,11 @@ mod tests { world.resource_mut::().0.clear(); let mut stage = SystemStage::parallel() - .with_system(make_exclusive(2).exclusive_system().label(L234).label(L2)) - .with_system(make_exclusive(1).exclusive_system().before(L234).after(L0)) - .with_system(make_exclusive(0).exclusive_system().label(L0)) - .with_system(make_exclusive(4).exclusive_system().label(L234).label(L4)) - .with_system( - make_exclusive(3) - .exclusive_system() - .label(L234) - .after(L2) - .before(L4), - ); + .with_system(make_exclusive(2).label(L234).label(L2)) + .with_system(make_exclusive(1).before(L234).after(L0)) + .with_system(make_exclusive(0).label(L0)) + .with_system(make_exclusive(4).label(L234).label(L4)) + .with_system(make_exclusive(3).label(L234).after(L2).before(L4)); stage.run(&mut world); stage.set_executor(Box::new(SingleThreadedExecutor::default())); stage.run(&mut world); @@ -1027,31 +1038,11 @@ mod tests { let mut world = World::new(); world.init_resource::(); let mut stage = SystemStage::parallel() - .with_system( - make_exclusive(2) - .exclusive_system() - .label(L2) - .after(L1) - .before(L3) - .before(L3), - ) - .with_system( - make_exclusive(1) - .exclusive_system() - .label(L1) - .after(L0) - .after(L0) - .before(L2), - ) - .with_system(make_exclusive(0).exclusive_system().label(L0).before(L1)) - .with_system(make_exclusive(4).exclusive_system().label(L4).after(L3)) - .with_system( - make_exclusive(3) - .exclusive_system() - .label(L3) - .after(L2) - .before(L4), - ); + .with_system(make_exclusive(2).label(L2).after(L1).before(L3).before(L3)) + .with_system(make_exclusive(1).label(L1).after(L0).after(L0).before(L2)) + .with_system(make_exclusive(0).label(L0).before(L1)) + .with_system(make_exclusive(4).label(L4).after(L3)) + .with_system(make_exclusive(3).label(L3).after(L2).before(L4)); stage.run(&mut world); stage.set_executor(Box::new(SingleThreadedExecutor::default())); stage.run(&mut world); @@ -1066,14 +1057,14 @@ mod tests { let mut world = World::new(); world.init_resource::(); let mut stage = SystemStage::parallel() - .with_system(make_exclusive(2).exclusive_system().label(L2)) + .with_system(make_exclusive(2).label(L2)) .with_system_set( SystemSet::new() - .with_system(make_exclusive(0).exclusive_system().label(L0)) - .with_system(make_exclusive(4).exclusive_system().label(L4)) - .with_system(make_exclusive(3).exclusive_system().after(L2).before(L4)), + .with_system(make_exclusive(0).label(L0)) + .with_system(make_exclusive(4).label(L4)) + .with_system(make_exclusive(3).after(L2).before(L4)), ) - .with_system(make_exclusive(1).exclusive_system().after(L0).before(L2)); + .with_system(make_exclusive(1).after(L0).before(L2)); stage.run(&mut world); stage.set_executor(Box::new(SingleThreadedExecutor::default())); stage.run(&mut world); @@ -1088,13 +1079,13 @@ mod tests { let mut world = World::new(); world.init_resource::(); let mut stage = SystemStage::parallel() - .with_system(make_exclusive(0).exclusive_system().before(L1)) + .with_system(make_exclusive(0).before(L1)) .with_system_set( SystemSet::new() .with_run_criteria(every_other_time) - .with_system(make_exclusive(1).exclusive_system().label(L1)), + .with_system(make_exclusive(1).label(L1)), ) - .with_system(make_exclusive(2).exclusive_system().after(L1)); + .with_system(make_exclusive(2).after(L1)); stage.run(&mut world); stage.run(&mut world); stage.set_executor(Box::new(SingleThreadedExecutor::default())); @@ -1111,8 +1102,7 @@ mod tests { fn exclusive_cycle_1() { let mut world = World::new(); world.init_resource::(); - let mut stage = SystemStage::parallel() - .with_system(make_exclusive(0).exclusive_system().label(L0).after(L0)); + let mut stage = SystemStage::parallel().with_system(make_exclusive(0).label(L0).after(L0)); stage.run(&mut world); } @@ -1122,8 +1112,8 @@ mod tests { let mut world = World::new(); world.init_resource::(); let mut stage = SystemStage::parallel() - .with_system(make_exclusive(0).exclusive_system().label(L0).after(L1)) - .with_system(make_exclusive(1).exclusive_system().label(L1).after(L0)); + .with_system(make_exclusive(0).label(L0).after(L1)) + .with_system(make_exclusive(1).label(L1).after(L0)); stage.run(&mut world); } @@ -1133,9 +1123,9 @@ mod tests { let mut world = World::new(); world.init_resource::(); let mut stage = SystemStage::parallel() - .with_system(make_exclusive(0).exclusive_system().label(L0)) - .with_system(make_exclusive(1).exclusive_system().after(L0).before(L2)) - .with_system(make_exclusive(2).exclusive_system().label(L2).before(L0)); + .with_system(make_exclusive(0).label(L0)) + .with_system(make_exclusive(1).after(L0).before(L2)) + .with_system(make_exclusive(2).label(L2).before(L0)); stage.run(&mut world); } diff --git a/crates/bevy_ecs/src/schedule/system_container.rs b/crates/bevy_ecs/src/schedule/system_container.rs index 2318d65ca7b13..291b201210ab5 100644 --- a/crates/bevy_ecs/src/schedule/system_container.rs +++ b/crates/bevy_ecs/src/schedule/system_container.rs @@ -1,42 +1,27 @@ use crate::{ component::ComponentId, query::Access, - schedule::{ - ExclusiveSystemDescriptor, GraphNode, ParallelSystemDescriptor, RunCriteriaLabelId, - SystemLabelId, - }, - system::{ExclusiveSystem, System}, + schedule::{GraphNode, RunCriteriaLabelId, SystemDescriptor, SystemLabelId}, + system::System, }; use std::borrow::Cow; -/// System metadata like its name, labels, order requirements and component access. -pub trait SystemContainer: GraphNode