Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Some small changes related to run criteria piping #3923

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
42 changes: 4 additions & 38 deletions crates/bevy_ecs/src/schedule/run_criteria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,6 @@ where
}
}

impl IntoRunCriteria<BoxedRunCriteriaLabel> for BoxedRunCriteriaLabel {
fn into(self) -> RunCriteriaDescriptorOrLabel {
RunCriteriaDescriptorOrLabel::Label(self)
}
}

impl<L> IntoRunCriteria<BoxedRunCriteriaLabel> for L
where
L: RunCriteriaLabel,
Expand Down Expand Up @@ -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<P>(
label: impl RunCriteriaLabel,
system: impl System<In = ShouldRun, Out = ShouldRun>,
system: impl IntoSystem<ShouldRun, ShouldRun, P>,
) -> 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 {
system: RunCriteriaSystem::Piped(Box::new(system)),
label: None,
duplicate_label_strategy: DuplicateLabelStrategy::Panic,
before: vec![],
after: vec![self],
}
}
}

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)),
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)],
}
}
}
Expand Down
44 changes: 22 additions & 22 deletions crates/bevy_ecs/src/schedule/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,10 +947,10 @@ 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},
system::{In, IntoExclusiveSystem, Local, Query, ResMut},
world::World,
};

Expand Down Expand Up @@ -1506,25 +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(
"every other time"
.pipe(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);
}
Expand Down
5 changes: 1 addition & 4 deletions examples/ecs/system_sets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down