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] - Optional .system(), part 4 (run criteria) #2431

Closed
wants to merge 1 commit 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
28 changes: 15 additions & 13 deletions crates/bevy_ecs/src/schedule/run_criteria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
component::ComponentId,
query::Access,
schedule::{BoxedRunCriteriaLabel, GraphNode, RunCriteriaLabel},
system::{BoxedSystem, System, SystemId},
system::{BoxedSystem, IntoSystem, System, SystemId},
world::World,
};
use std::borrow::Cow;
Expand Down Expand Up @@ -197,12 +197,14 @@ impl IntoRunCriteria<BoxedSystem<(), ShouldRun>> for BoxedSystem<(), ShouldRun>
}
}

impl<S> IntoRunCriteria<BoxedSystem<(), ShouldRun>> for S
impl<S, Param> IntoRunCriteria<(BoxedSystem<(), ShouldRun>, Param)> for S
where
S: System<In = (), Out = ShouldRun>,
S: IntoSystem<(), ShouldRun, Param>,
{
fn into(self) -> RunCriteriaDescriptorOrLabel {
RunCriteriaDescriptorOrLabel::Descriptor(new_run_criteria_descriptor(Box::new(self)))
RunCriteriaDescriptorOrLabel::Descriptor(new_run_criteria_descriptor(Box::new(
self.system(),
)))
}
}

Expand All @@ -227,7 +229,7 @@ impl IntoRunCriteria<RunCriteria> for RunCriteria {
}
}

pub trait RunCriteriaDescriptorCoercion {
pub trait RunCriteriaDescriptorCoercion<Param> {
/// Assigns a label to the criteria. Must be unique.
fn label(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor;

Expand All @@ -242,7 +244,7 @@ pub trait RunCriteriaDescriptorCoercion {
fn after(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor;
}

impl RunCriteriaDescriptorCoercion for RunCriteriaDescriptor {
impl RunCriteriaDescriptorCoercion<()> for RunCriteriaDescriptor {
fn label(mut self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
self.label = Some(Box::new(label));
self.duplicate_label_strategy = DuplicateLabelStrategy::Panic;
Expand Down Expand Up @@ -276,7 +278,7 @@ fn new_run_criteria_descriptor(system: BoxedSystem<(), ShouldRun>) -> RunCriteri
}
}

impl RunCriteriaDescriptorCoercion for BoxedSystem<(), ShouldRun> {
impl RunCriteriaDescriptorCoercion<()> for BoxedSystem<(), ShouldRun> {
fn label(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
new_run_criteria_descriptor(self).label(label)
}
Expand All @@ -294,24 +296,24 @@ impl RunCriteriaDescriptorCoercion for BoxedSystem<(), ShouldRun> {
}
}

impl<S> RunCriteriaDescriptorCoercion for S
impl<S, Param> RunCriteriaDescriptorCoercion<Param> for S
where
S: System<In = (), Out = ShouldRun>,
S: IntoSystem<(), ShouldRun, Param>,
{
fn label(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
new_run_criteria_descriptor(Box::new(self)).label(label)
new_run_criteria_descriptor(Box::new(self.system())).label(label)
}

fn label_discard_if_duplicate(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
new_run_criteria_descriptor(Box::new(self)).label_discard_if_duplicate(label)
new_run_criteria_descriptor(Box::new(self.system())).label_discard_if_duplicate(label)
}

fn before(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
new_run_criteria_descriptor(Box::new(self)).before(label)
new_run_criteria_descriptor(Box::new(self.system())).before(label)
}

fn after(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor {
new_run_criteria_descriptor(Box::new(self)).after(label)
new_run_criteria_descriptor(Box::new(self.system())).after(label)
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/src/schedule/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ mod tests {
.with_system(make_exclusive(0).exclusive_system().before("1"))
.with_system_set(
SystemSet::new()
.with_run_criteria(every_other_time.system())
.with_run_criteria(every_other_time)
.with_system(make_exclusive(1).exclusive_system().label("1")),
)
.with_system(make_exclusive(2).exclusive_system().after("1"));
Expand Down Expand Up @@ -1392,7 +1392,7 @@ mod tests {
make_parallel!(0)
.system()
.label("0")
.with_run_criteria(every_other_time.system()),
.with_run_criteria(every_other_time),
)
.with_system(make_parallel!(1).system().after("0"));
stage.run(&mut world);
Expand Down Expand Up @@ -1427,7 +1427,7 @@ mod tests {
// Reusing criteria.
world.get_resource_mut::<Vec<usize>>().unwrap().clear();
let mut stage = SystemStage::parallel()
.with_system_run_criteria(every_other_time.system().label("every other time"))
.with_system_run_criteria(every_other_time.label("every other time"))
.with_system(make_parallel!(0).system().before("1"))
.with_system(
make_parallel!(1)
Expand Down