Some small changes related to run criteria piping (#3923)
Remove the 'chaining' api, as it's peculiar ~~Implement the label traits for `Box<dyn ThatTrait>` (n.b. I'm not confident about this change, but it was the quickest path to not regressing)~~ Remove the need for '`.system`' when using run criteria piping
This commit is contained in:
parent
9d54f33974
commit
21a875d67b
@ -29,8 +29,8 @@ pub mod prelude {
|
|||||||
query::{Added, AnyOf, ChangeTrackers, Changed, Or, QueryState, With, Without},
|
query::{Added, AnyOf, ChangeTrackers, Changed, Or, QueryState, With, Without},
|
||||||
schedule::{
|
schedule::{
|
||||||
AmbiguitySetLabel, ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion,
|
AmbiguitySetLabel, ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion,
|
||||||
RunCriteria, RunCriteriaDescriptorCoercion, RunCriteriaLabel, RunCriteriaPiping,
|
RunCriteria, RunCriteriaDescriptorCoercion, RunCriteriaLabel, Schedule, Stage,
|
||||||
Schedule, Stage, StageLabel, State, SystemLabel, SystemSet, SystemStage,
|
StageLabel, State, SystemLabel, SystemSet, SystemStage,
|
||||||
},
|
},
|
||||||
system::{
|
system::{
|
||||||
Commands, In, IntoChainSystem, IntoExclusiveSystem, IntoSystem, Local, NonSend,
|
Commands, In, IntoChainSystem, IntoExclusiveSystem, IntoSystem, Local, NonSend,
|
||||||
|
@ -240,12 +240,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoRunCriteria<BoxedRunCriteriaLabel> for BoxedRunCriteriaLabel {
|
|
||||||
fn into(self) -> RunCriteriaDescriptorOrLabel {
|
|
||||||
RunCriteriaDescriptorOrLabel::Label(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<L> IntoRunCriteria<BoxedRunCriteriaLabel> for L
|
impl<L> IntoRunCriteria<BoxedRunCriteriaLabel> for L
|
||||||
where
|
where
|
||||||
L: RunCriteriaLabel,
|
L: RunCriteriaLabel,
|
||||||
@ -357,44 +351,16 @@ pub struct RunCriteria {
|
|||||||
impl RunCriteria {
|
impl RunCriteria {
|
||||||
/// Constructs a new run criteria that will retrieve the result of the criteria `label`
|
/// Constructs a new run criteria that will retrieve the result of the criteria `label`
|
||||||
/// and pipe it as input to `system`.
|
/// and pipe it as input to `system`.
|
||||||
pub fn pipe(
|
pub fn pipe<P>(
|
||||||
label: impl RunCriteriaLabel,
|
label: impl RunCriteriaLabel,
|
||||||
system: impl System<In = ShouldRun, Out = ShouldRun>,
|
system: impl IntoSystem<ShouldRun, ShouldRun, P>,
|
||||||
) -> RunCriteriaDescriptor {
|
) -> 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<In = ShouldRun, Out = ShouldRun>) -> RunCriteriaDescriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RunCriteriaPiping for BoxedRunCriteriaLabel {
|
|
||||||
fn pipe(self, system: impl System<In = ShouldRun, Out = ShouldRun>) -> RunCriteriaDescriptor {
|
|
||||||
RunCriteriaDescriptor {
|
RunCriteriaDescriptor {
|
||||||
system: RunCriteriaSystem::Piped(Box::new(system)),
|
system: RunCriteriaSystem::Piped(Box::new(IntoSystem::into_system(system))),
|
||||||
label: None,
|
label: None,
|
||||||
duplicate_label_strategy: DuplicateLabelStrategy::Panic,
|
duplicate_label_strategy: DuplicateLabelStrategy::Panic,
|
||||||
before: vec![],
|
before: vec![],
|
||||||
after: vec![self],
|
after: vec![Box::new(label)],
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<L> RunCriteriaPiping for L
|
|
||||||
where
|
|
||||||
L: RunCriteriaLabel,
|
|
||||||
{
|
|
||||||
fn pipe(self, system: impl System<In = ShouldRun, Out = ShouldRun>) -> RunCriteriaDescriptor {
|
|
||||||
RunCriteriaDescriptor {
|
|
||||||
system: RunCriteriaSystem::Piped(Box::new(system)),
|
|
||||||
label: None,
|
|
||||||
duplicate_label_strategy: DuplicateLabelStrategy::Panic,
|
|
||||||
before: vec![],
|
|
||||||
after: vec![Box::new(self)],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -946,10 +946,10 @@ mod tests {
|
|||||||
query::{ChangeTrackers, Changed},
|
query::{ChangeTrackers, Changed},
|
||||||
schedule::{
|
schedule::{
|
||||||
BoxedSystemLabel, ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion,
|
BoxedSystemLabel, ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion,
|
||||||
RunCriteria, RunCriteriaDescriptorCoercion, RunCriteriaPiping, ShouldRun,
|
RunCriteria, RunCriteriaDescriptorCoercion, ShouldRun, SingleThreadedExecutor, Stage,
|
||||||
SingleThreadedExecutor, Stage, SystemSet, SystemStage,
|
SystemSet, SystemStage,
|
||||||
},
|
},
|
||||||
system::{In, IntoExclusiveSystem, IntoSystem, Local, Query, ResMut},
|
system::{In, IntoExclusiveSystem, Local, Query, ResMut},
|
||||||
world::World,
|
world::World,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1475,25 +1475,25 @@ mod tests {
|
|||||||
ShouldRun::No
|
ShouldRun::No
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut stage = SystemStage::parallel()
|
let mut stage =
|
||||||
.with_system(make_parallel(0).label("0"))
|
SystemStage::parallel()
|
||||||
.with_system(
|
.with_system(make_parallel(0).label("0"))
|
||||||
make_parallel(1)
|
.with_system(
|
||||||
.label("1")
|
make_parallel(1)
|
||||||
.after("0")
|
.label("1")
|
||||||
.with_run_criteria(every_other_time.label("every other time")),
|
.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(2)
|
||||||
.with_system(
|
.label("2")
|
||||||
make_parallel(3).label("3").after("2").with_run_criteria(
|
.after("1")
|
||||||
"every other time"
|
.with_run_criteria(RunCriteria::pipe("every other time", eot_piped)),
|
||||||
.pipe(IntoSystem::into_system(eot_piped))
|
)
|
||||||
.label("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"));
|
.with_system(make_parallel(4).after("3").with_run_criteria("piped"));
|
||||||
for _ in 0..4 {
|
for _ in 0..4 {
|
||||||
stage.run(&mut world);
|
stage.run(&mut world);
|
||||||
}
|
}
|
||||||
|
@ -70,10 +70,7 @@ fn main() {
|
|||||||
// Here we create a _not done_ criteria by piping the output of
|
// Here we create a _not done_ criteria by piping the output of
|
||||||
// the `is_done` system and inverting the output.
|
// the `is_done` system and inverting the output.
|
||||||
// Notice a string literal also works as a label.
|
// Notice a string literal also works as a label.
|
||||||
.with_run_criteria(RunCriteria::pipe(
|
.with_run_criteria(RunCriteria::pipe("is_done_label", inverse))
|
||||||
"is_done_label",
|
|
||||||
IntoSystem::into_system(inverse),
|
|
||||||
))
|
|
||||||
// `collision` and `sfx` are not ordered with respect to
|
// `collision` and `sfx` are not ordered with respect to
|
||||||
// each other, and may run in any order
|
// each other, and may run in any order
|
||||||
.with_system(collision)
|
.with_system(collision)
|
||||||
|
Loading…
Reference in New Issue
Block a user