From e5495f0791722de25c0bdfe9ea306f0b0bb78c5d Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Sat, 12 Feb 2022 17:57:18 +0000 Subject: [PATCH 1/3] Some changes related to run criteria piping Remove the 'chaining' api, as it's peculiar Implement the label traits for Box (n.b., I'm not confident about this change, but it was the quickest path to not regressing) Remove the need for '`.system`' within that --- crates/bevy_ecs/src/lib.rs | 4 +- crates/bevy_ecs/src/schedule/run_criteria.rs | 42 ++------------------ crates/bevy_ecs/src/schedule/stage.rs | 7 ++-- crates/bevy_utils/src/label.rs | 6 +++ 4 files changed, 15 insertions(+), 44 deletions(-) diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index d48ea55929773..252bb70de4815 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -29,8 +29,8 @@ pub mod prelude { query::{Added, AnyOf, ChangeTrackers, Changed, Or, QueryState, With, Without}, schedule::{ AmbiguitySetLabel, ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion, - RunCriteria, RunCriteriaDescriptorCoercion, RunCriteriaLabel, RunCriteriaPiping, - Schedule, Stage, StageLabel, State, SystemLabel, SystemSet, SystemStage, + RunCriteria, RunCriteriaDescriptorCoercion, RunCriteriaLabel, Schedule, Stage, + StageLabel, State, SystemLabel, SystemSet, SystemStage, }, system::{ Commands, ConfigurableSystem, In, IntoChainSystem, IntoExclusiveSystem, IntoSystem, diff --git a/crates/bevy_ecs/src/schedule/run_criteria.rs b/crates/bevy_ecs/src/schedule/run_criteria.rs index f5aa1e0e60b92..7c7b9ecee4f55 100644 --- a/crates/bevy_ecs/src/schedule/run_criteria.rs +++ b/crates/bevy_ecs/src/schedule/run_criteria.rs @@ -240,12 +240,6 @@ where } } -impl IntoRunCriteria for BoxedRunCriteriaLabel { - fn into(self) -> RunCriteriaDescriptorOrLabel { - RunCriteriaDescriptorOrLabel::Label(self) - } -} - impl IntoRunCriteria for L where L: RunCriteriaLabel, @@ -357,44 +351,16 @@ pub struct RunCriteria { impl RunCriteria { /// Constructs a new run criteria that will retrieve the result of the criteria `label` /// and pipe it as input to `system`. - pub fn pipe( + pub fn pipe

( label: impl RunCriteriaLabel, - system: impl System, + system: impl IntoSystem, ) -> RunCriteriaDescriptor { - label.pipe(system) - } -} - -pub trait RunCriteriaPiping { - /// See [`RunCriteria::pipe()`]. - // TODO: Support `IntoSystem` here instead, and stop using - // `IntoSystem::into_system` in the call sites - fn pipe(self, system: impl System) -> RunCriteriaDescriptor; -} - -impl RunCriteriaPiping for BoxedRunCriteriaLabel { - fn pipe(self, system: impl System) -> RunCriteriaDescriptor { - RunCriteriaDescriptor { - system: RunCriteriaSystem::Piped(Box::new(system)), - label: None, - duplicate_label_strategy: DuplicateLabelStrategy::Panic, - before: vec![], - after: vec![self], - } - } -} - -impl RunCriteriaPiping for L -where - L: RunCriteriaLabel, -{ - fn pipe(self, system: impl System) -> RunCriteriaDescriptor { RunCriteriaDescriptor { - system: RunCriteriaSystem::Piped(Box::new(system)), + system: RunCriteriaSystem::Piped(Box::new(IntoSystem::into_system(system))), label: None, duplicate_label_strategy: DuplicateLabelStrategy::Panic, before: vec![], - after: vec![Box::new(self)], + after: vec![Box::new(label)], } } } diff --git a/crates/bevy_ecs/src/schedule/stage.rs b/crates/bevy_ecs/src/schedule/stage.rs index 96be9bf1740c0..c7987db6a977f 100644 --- a/crates/bevy_ecs/src/schedule/stage.rs +++ b/crates/bevy_ecs/src/schedule/stage.rs @@ -947,8 +947,8 @@ mod tests { query::{ChangeTrackers, Changed}, schedule::{ BoxedSystemLabel, ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion, - RunCriteria, RunCriteriaDescriptorCoercion, RunCriteriaPiping, ShouldRun, - SingleThreadedExecutor, Stage, SystemSet, SystemStage, + RunCriteria, RunCriteriaDescriptorCoercion, ShouldRun, SingleThreadedExecutor, Stage, + SystemSet, SystemStage, }, system::{In, IntoExclusiveSystem, IntoSystem, Local, Query, ResMut}, world::World, @@ -1519,8 +1519,7 @@ mod tests { )) .with_system( make_parallel(3).label("3").after("2").with_run_criteria( - "every other time" - .pipe(IntoSystem::into_system(eot_piped)) + RunCriteria::pipe("every other time", IntoSystem::into_system(eot_piped)) .label("piped"), ), ) diff --git a/crates/bevy_utils/src/label.rs b/crates/bevy_utils/src/label.rs index 7728ef8b947df..b9e2a90b86227 100644 --- a/crates/bevy_utils/src/label.rs +++ b/crates/bevy_utils/src/label.rs @@ -97,5 +97,11 @@ macro_rules! define_label { Box::new(<&str>::clone(self)) } } + + impl $label_trait_name for Box { + fn dyn_clone(&self) -> Box { + (&*self).dyn_clone() + } + } }; } From 91bd957d1d42269a132cb0a8adf4ab32ce9147f0 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Sat, 12 Feb 2022 18:13:12 +0000 Subject: [PATCH 2/3] Remove the recursive impl --- crates/bevy_utils/src/label.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/crates/bevy_utils/src/label.rs b/crates/bevy_utils/src/label.rs index b9e2a90b86227..7728ef8b947df 100644 --- a/crates/bevy_utils/src/label.rs +++ b/crates/bevy_utils/src/label.rs @@ -97,11 +97,5 @@ macro_rules! define_label { Box::new(<&str>::clone(self)) } } - - impl $label_trait_name for Box { - fn dyn_clone(&self) -> Box { - (&*self).dyn_clone() - } - } }; } From b9ff430033c6365ef41202f6912b9b3feaa3c4c8 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Sat, 12 Feb 2022 18:26:43 +0000 Subject: [PATCH 3/3] You saw nothing --- crates/bevy_ecs/src/schedule/stage.rs | 39 ++++++++++++++------------- examples/ecs/system_sets.rs | 5 +--- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/stage.rs b/crates/bevy_ecs/src/schedule/stage.rs index c7987db6a977f..25d93ea8213c3 100644 --- a/crates/bevy_ecs/src/schedule/stage.rs +++ b/crates/bevy_ecs/src/schedule/stage.rs @@ -950,7 +950,7 @@ mod tests { RunCriteria, RunCriteriaDescriptorCoercion, ShouldRun, SingleThreadedExecutor, Stage, SystemSet, SystemStage, }, - system::{In, IntoExclusiveSystem, IntoSystem, Local, Query, ResMut}, + system::{In, IntoExclusiveSystem, Local, Query, ResMut}, world::World, }; @@ -1506,24 +1506,25 @@ mod tests { ShouldRun::No } } - let mut stage = SystemStage::parallel() - .with_system(make_parallel(0).label("0")) - .with_system( - make_parallel(1) - .label("1") - .after("0") - .with_run_criteria(every_other_time.label("every other time")), - ) - .with_system(make_parallel(2).label("2").after("1").with_run_criteria( - RunCriteria::pipe("every other time", IntoSystem::into_system(eot_piped)), - )) - .with_system( - make_parallel(3).label("3").after("2").with_run_criteria( - RunCriteria::pipe("every other time", IntoSystem::into_system(eot_piped)) - .label("piped"), - ), - ) - .with_system(make_parallel(4).after("3").with_run_criteria("piped")); + let mut stage = + SystemStage::parallel() + .with_system(make_parallel(0).label("0")) + .with_system( + make_parallel(1) + .label("1") + .after("0") + .with_run_criteria(every_other_time.label("every other time")), + ) + .with_system( + make_parallel(2) + .label("2") + .after("1") + .with_run_criteria(RunCriteria::pipe("every other time", eot_piped)), + ) + .with_system(make_parallel(3).label("3").after("2").with_run_criteria( + RunCriteria::pipe("every other time", eot_piped).label("piped"), + )) + .with_system(make_parallel(4).after("3").with_run_criteria("piped")); for _ in 0..4 { stage.run(&mut world); } diff --git a/examples/ecs/system_sets.rs b/examples/ecs/system_sets.rs index 26c2c025e1350..311946319a2cf 100644 --- a/examples/ecs/system_sets.rs +++ b/examples/ecs/system_sets.rs @@ -87,10 +87,7 @@ fn main() { // Here we create a _not done_ criteria by piping the output of // the `is_done` system and inverting the output. // Notice a string literal also works as a label. - .with_run_criteria(RunCriteria::pipe( - "is_done_label", - IntoSystem::into_system(inverse), - )) + .with_run_criteria(RunCriteria::pipe("is_done_label", inverse)) // `collision` and `sfx` are not ordered with respect to // each other, and may run in any order .with_system(collision)