Skip to content

Commit

Permalink
Rename to ShouldRun::once
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Apr 25, 2022
1 parent cdfb980 commit 2f8ae8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use bevy_ecs::{
event::Events,
prelude::{FromWorld, IntoExclusiveSystem},
schedule::{
run_once_criteria, IntoSystemDescriptor, Schedule, Stage, StageLabel, State, StateData,
SystemSet, SystemStage,
IntoSystemDescriptor, Schedule, ShouldRun, Stage, StageLabel, State, StateData, SystemSet,
SystemStage,
},
system::Resource,
world::World,
Expand Down Expand Up @@ -591,7 +591,7 @@ impl App {
.add_stage(
StartupSchedule,
Schedule::default()
.with_run_criteria(run_once_criteria())
.with_run_criteria(ShouldRun::once)
.with_stage(StartupStage::PreStartup, SystemStage::parallel())
.with_stage(StartupStage::Startup, SystemStage::parallel())
.with_stage(StartupStage::PostStartup, SystemStage::parallel()),
Expand Down
25 changes: 12 additions & 13 deletions crates/bevy_ecs/src/schedule/run_criteria.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
schedule::{BoxedRunCriteriaLabel, GraphNode, RunCriteriaLabel},
system::{BoxedSystem, IntoSystem},
system::{BoxedSystem, IntoSystem, Local},
world::World,
};
use std::borrow::Cow;
Expand Down Expand Up @@ -41,6 +41,17 @@ pub enum ShouldRun {
NoAndCheckAgain,
}

impl ShouldRun {
pub fn once(mut ran: Local<bool>) -> ShouldRun {
if *ran {
ShouldRun::No
} else {
*ran = true;
ShouldRun::Yes
}
}
}

#[derive(Default)]
pub(crate) struct BoxedRunCriteria {
criteria_system: Option<BoxedSystem<(), ShouldRun>>,
Expand Down Expand Up @@ -321,15 +332,3 @@ impl RunCriteria {
}
}
}

pub fn run_once_criteria() -> impl FnMut() -> ShouldRun {
let mut ran = false;
move || {
if ran {
ShouldRun::No
} else {
ran = true;
ShouldRun::Yes
}
}
}

0 comments on commit 2f8ae8e

Please sign in to comment.