From 2f8ae8e4e13ddaac51c9d6cc4be6fe1cbc653307 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Sat, 9 Apr 2022 10:11:24 +0100 Subject: [PATCH] Rename to `ShouldRun::once` --- crates/bevy_app/src/app.rs | 6 ++--- crates/bevy_ecs/src/schedule/run_criteria.rs | 25 ++++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 8dda6dcfa49ae..e698b6f61579d 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -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, @@ -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()), diff --git a/crates/bevy_ecs/src/schedule/run_criteria.rs b/crates/bevy_ecs/src/schedule/run_criteria.rs index d99d9fe6c39f8..efe27f673ee20 100644 --- a/crates/bevy_ecs/src/schedule/run_criteria.rs +++ b/crates/bevy_ecs/src/schedule/run_criteria.rs @@ -1,6 +1,6 @@ use crate::{ schedule::{BoxedRunCriteriaLabel, GraphNode, RunCriteriaLabel}, - system::{BoxedSystem, IntoSystem}, + system::{BoxedSystem, IntoSystem, Local}, world::World, }; use std::borrow::Cow; @@ -41,6 +41,17 @@ pub enum ShouldRun { NoAndCheckAgain, } +impl ShouldRun { + pub fn once(mut ran: Local) -> ShouldRun { + if *ran { + ShouldRun::No + } else { + *ran = true; + ShouldRun::Yes + } + } +} + #[derive(Default)] pub(crate) struct BoxedRunCriteria { criteria_system: Option>, @@ -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 - } - } -}