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] - Implement From<bool> for ShouldRun. #5306

Closed
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
13 changes: 2 additions & 11 deletions benches/benches/bevy_ecs/scheduling/run_criteria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,7 @@ pub fn run_criteria_yes_with_query(criterion: &mut Criterion) {
group.measurement_time(std::time::Duration::from_secs(3));
fn empty() {}
fn yes_with_query(query: Query<&TestBool>) -> ShouldRun {
let test_bool = query.single();
if test_bool.0 {
ShouldRun::Yes
} else {
ShouldRun::No
}
query.single().0.into()
}
for amount in 0..21 {
let mut stage = SystemStage::parallel();
Expand Down Expand Up @@ -184,11 +179,7 @@ pub fn run_criteria_yes_with_resource(criterion: &mut Criterion) {
group.measurement_time(std::time::Duration::from_secs(3));
fn empty() {}
fn yes_with_resource(res: Res<TestBool>) -> ShouldRun {
if res.0 {
ShouldRun::Yes
} else {
ShouldRun::No
}
res.0.into()
}
for amount in 0..21 {
let mut stage = SystemStage::parallel();
Expand Down
10 changes: 10 additions & 0 deletions crates/bevy_ecs/src/schedule/run_criteria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ impl ShouldRun {
}
}

impl From<bool> for ShouldRun {
fn from(value: bool) -> Self {
if value {
ShouldRun::Yes
} else {
ShouldRun::No
}
}
}

#[derive(Default)]
pub(crate) struct BoxedRunCriteria {
criteria_system: Option<BoxedSystem<(), ShouldRun>>,
Expand Down
6 changes: 1 addition & 5 deletions examples/ecs/system_sets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ fn run_for_a_second(time: Res<Time>, mut done: ResMut<Done>) -> ShouldRun {

/// Another run criteria, simply using a resource.
fn is_done(done: Res<Done>) -> ShouldRun {
if done.0 {
ShouldRun::Yes
} else {
ShouldRun::No
}
done.0.into()
}

/// Used with [`RunCritera::pipe`], inverts the result of the
Expand Down