From fc5459a7cc8c973dd4b1a31d5fac8273ff2571e6 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Mon, 10 Jan 2022 20:41:49 +0000 Subject: [PATCH 1/7] Stop using the `config` api for states --- crates/bevy_ecs/src/schedule/state.rs | 84 +++++++++++++-------------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/state.rs b/crates/bevy_ecs/src/schedule/state.rs index 7dcbefb6afb87..eb37c97d498ec 100644 --- a/crates/bevy_ecs/src/schedule/state.rs +++ b/crates/bevy_ecs/src/schedule/state.rs @@ -3,7 +3,7 @@ use crate::{ RunCriteriaDescriptor, RunCriteriaDescriptorCoercion, RunCriteriaLabel, ShouldRun, SystemSet, }, - system::{ConfigurableSystem, In, IntoChainSystem, Local, Res, ResMut}, + system::{In, IntoChainSystem, Local, Res, ResMut}, }; use std::{any::TypeId, fmt::Debug, hash::Hash}; use thiserror::Error; @@ -98,23 +98,22 @@ impl State where T: StateData, { - pub fn on_update(s: T) -> RunCriteriaDescriptor { - (|state: Res>, pred: Local>| { - state.stack.last().unwrap() == pred.as_ref().unwrap() && state.transition.is_none() + pub fn on_update(pred: T) -> RunCriteriaDescriptor { + let pred_clone = pred.clone(); + (move |state: Res>| { + state.stack.last().unwrap() == &pred && state.transition.is_none() }) - .config(|(_, pred)| *pred = Some(Some(s.clone()))) .chain(should_run_adapter::) .after(DriverLabel::of::()) - .label_discard_if_duplicate(StateCallback::Update.into_label(s)) + .label_discard_if_duplicate(StateCallback::Update.into_label(pred_clone)) } - pub fn on_inactive_update(s: T) -> RunCriteriaDescriptor { - (|state: Res>, mut is_inactive: Local, pred: Local>| match &state - .transition - { + pub fn on_inactive_update(pred: T) -> RunCriteriaDescriptor { + let pred_clone = pred.clone(); + (move |state: Res>, mut is_inactive: Local| match &state.transition { Some(StateTransition::Pausing(ref relevant, _)) | Some(StateTransition::Resuming(_, ref relevant)) => { - if relevant == pred.as_ref().unwrap() { + if relevant == &pred { *is_inactive = !*is_inactive; } false @@ -122,31 +121,29 @@ where Some(_) => false, None => *is_inactive, }) - .config(|(_, _, pred)| *pred = Some(Some(s.clone()))) .chain(should_run_adapter::) .after(DriverLabel::of::()) - .label_discard_if_duplicate(StateCallback::InactiveUpdate.into_label(s)) + .label_discard_if_duplicate(StateCallback::InactiveUpdate.into_label(pred_clone)) } - pub fn on_in_stack_update(s: T) -> RunCriteriaDescriptor { - (|state: Res>, mut is_in_stack: Local, pred: Local>| match &state - .transition - { + pub fn on_in_stack_update(pred: T) -> RunCriteriaDescriptor { + let pred_clone = pred.clone(); + (move |state: Res>, mut is_in_stack: Local| match &state.transition { Some(StateTransition::Entering(ref relevant, _)) | Some(StateTransition::ExitingToResume(_, ref relevant)) => { - if relevant == pred.as_ref().unwrap() { + if relevant == &pred { *is_in_stack = !*is_in_stack; } false } Some(StateTransition::ExitingFull(_, ref relevant)) => { - if relevant == pred.as_ref().unwrap() { + if relevant == &pred { *is_in_stack = !*is_in_stack; } false } Some(StateTransition::Startup) => { - if state.stack.last().unwrap() == pred.as_ref().unwrap() { + if state.stack.last().unwrap() == &pred { *is_in_stack = !*is_in_stack; } false @@ -154,78 +151,75 @@ where Some(_) => false, None => *is_in_stack, }) - .config(|(_, _, pred)| *pred = Some(Some(s.clone()))) .chain(should_run_adapter::) .after(DriverLabel::of::()) - .label_discard_if_duplicate(StateCallback::InStackUpdate.into_label(s)) + .label_discard_if_duplicate(StateCallback::InStackUpdate.into_label(pred_clone)) } - pub fn on_enter(s: T) -> RunCriteriaDescriptor { - (|state: Res>, pred: Local>| { + pub fn on_enter(pred: T) -> RunCriteriaDescriptor { + let pred_clone = pred.clone(); + (move |state: Res>| { state .transition .as_ref() .map_or(false, |transition| match transition { - StateTransition::Entering(_, entering) => entering == pred.as_ref().unwrap(), - StateTransition::Startup => { - state.stack.last().unwrap() == pred.as_ref().unwrap() - } + StateTransition::Entering(_, entering) => entering == &pred, + StateTransition::Startup => state.stack.last().unwrap() == &pred, _ => false, }) }) - .config(|(_, pred)| *pred = Some(Some(s.clone()))) .chain(should_run_adapter::) .after(DriverLabel::of::()) - .label_discard_if_duplicate(StateCallback::Enter.into_label(s)) + .label_discard_if_duplicate(StateCallback::Enter.into_label(pred_clone)) } - pub fn on_exit(s: T) -> RunCriteriaDescriptor { - (|state: Res>, pred: Local>| { + pub fn on_exit(pred: T) -> RunCriteriaDescriptor { + let pred_clone = pred.clone(); + (move |state: Res>| { state .transition .as_ref() .map_or(false, |transition| match transition { StateTransition::ExitingToResume(exiting, _) - | StateTransition::ExitingFull(exiting, _) => exiting == pred.as_ref().unwrap(), + | StateTransition::ExitingFull(exiting, _) => exiting == &pred, _ => false, }) }) - .config(|(_, pred)| *pred = Some(Some(s.clone()))) .chain(should_run_adapter::) .after(DriverLabel::of::()) - .label_discard_if_duplicate(StateCallback::Exit.into_label(s)) + .label_discard_if_duplicate(StateCallback::Exit.into_label(pred_clone)) } - pub fn on_pause(s: T) -> RunCriteriaDescriptor { - (|state: Res>, pred: Local>| { + pub fn on_pause(pred: T) -> RunCriteriaDescriptor { + let pred_clone = pred.clone(); + (move |state: Res>| { state .transition .as_ref() .map_or(false, |transition| match transition { - StateTransition::Pausing(pausing, _) => pausing == pred.as_ref().unwrap(), + StateTransition::Pausing(pausing, _) => pausing == &pred, _ => false, }) }) - .config(|(_, pred)| *pred = Some(Some(s.clone()))) .chain(should_run_adapter::) .after(DriverLabel::of::()) - .label_discard_if_duplicate(StateCallback::Pause.into_label(s)) + .label_discard_if_duplicate(StateCallback::Pause.into_label(pred_clone)) } - pub fn on_resume(s: T) -> RunCriteriaDescriptor { - (|state: Res>, pred: Local>| { + pub fn on_resume(pred: T) -> RunCriteriaDescriptor { + let pred_clone = pred.clone(); + (move |state: Res>| { state .transition .as_ref() .map_or(false, |transition| match transition { - StateTransition::Resuming(_, resuming) => resuming == pred.as_ref().unwrap(), + StateTransition::Resuming(_, resuming) => resuming == &pred, _ => false, }) }) - .config(|(_, pred)| *pred = Some(Some(s.clone()))) .chain(should_run_adapter::) .after(DriverLabel::of::()) - .label_discard_if_duplicate(StateCallback::Resume.into_label(s)) + .label_discard_if_duplicate(StateCallback::Resume.into_label(pred_clone)) } pub fn on_update_set(s: T) -> SystemSet { From efe2b1a2468af76f6780f5a92c00622af6dcb552 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Mon, 10 Jan 2022 20:45:56 +0000 Subject: [PATCH 2/7] Migrate from `config` in FixedTimestep --- crates/bevy_core/src/time/fixed_timestep.rs | 33 +++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/crates/bevy_core/src/time/fixed_timestep.rs b/crates/bevy_core/src/time/fixed_timestep.rs index bd3384d4ca438..fa39ced311997 100644 --- a/crates/bevy_core/src/time/fixed_timestep.rs +++ b/crates/bevy_core/src/time/fixed_timestep.rs @@ -4,7 +4,7 @@ use bevy_ecs::{ component::ComponentId, query::Access, schedule::ShouldRun, - system::{ConfigurableSystem, IntoSystem, Local, Res, ResMut, System}, + system::{IntoSystem, Res, ResMut, System}, world::World, }; use bevy_utils::HashMap; @@ -79,7 +79,9 @@ impl Default for FixedTimestep { fn default() -> Self { Self { state: LocalFixedTimestepState::default(), - internal_system: Box::new(IntoSystem::into_system(Self::prepare_system)), + internal_system: Box::new(IntoSystem::into_system(Self::prepare_system( + Default::default(), + ))), } } } @@ -116,18 +118,18 @@ impl FixedTimestep { } fn prepare_system( - mut state: Local, - time: Res