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] - Remove the config api #3633

Closed
wants to merge 7 commits 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
33 changes: 18 additions & 15 deletions crates/bevy_core/src/time/fixed_timestep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
))),
}
}
}
Expand Down Expand Up @@ -116,18 +118,18 @@ impl FixedTimestep {
}

fn prepare_system(
mut state: Local<LocalFixedTimestepState>,
time: Res<Time>,
mut fixed_timesteps: ResMut<FixedTimesteps>,
) -> ShouldRun {
let should_run = state.update(&time);
if let Some(ref label) = state.label {
let res_state = fixed_timesteps.fixed_timesteps.get_mut(label).unwrap();
res_state.step = state.step;
res_state.accumulator = state.accumulator;
mut state: LocalFixedTimestepState,
) -> impl FnMut(Res<Time>, ResMut<FixedTimesteps>) -> ShouldRun {
move |time, mut fixed_timesteps| {
let should_run = state.update(&time);
if let Some(ref label) = state.label {
let res_state = fixed_timesteps.fixed_timesteps.get_mut(label).unwrap();
res_state.step = state.step;
res_state.accumulator = state.accumulator;
}

should_run
}

should_run
}
}

Expand Down Expand Up @@ -202,8 +204,9 @@ impl System for FixedTimestep {
}

fn initialize(&mut self, world: &mut World) {
self.internal_system =
Box::new(Self::prepare_system.config(|c| c.0 = Some(self.state.clone())));
self.internal_system = Box::new(IntoSystem::into_system(Self::prepare_system(
self.state.clone(),
)));
self.internal_system.initialize(world);
if let Some(ref label) = self.state.label {
let mut fixed_timesteps = world.get_resource_mut::<FixedTimesteps>().unwrap();
Expand Down
14 changes: 3 additions & 11 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ pub fn impl_query_set(_input: TokenStream) -> TokenStream {
unsafe impl<#(#query: WorldQuery + 'static,)* #(#filter: WorldQuery + 'static,)*> SystemParamState for QuerySetState<(#(QueryState<#query, #filter>,)*)>
where #(#filter::Fetch: FilterFetch,)*
{
type Config = ();
fn init(world: &mut World, system_meta: &mut SystemMeta, config: Self::Config) -> Self {
fn init(world: &mut World, system_meta: &mut SystemMeta) -> Self {
#(
let mut #query = QueryState::<#query, #filter>::new(world);
assert_component_access_compatibility(
Expand Down Expand Up @@ -253,8 +252,6 @@ pub fn impl_query_set(_input: TokenStream) -> TokenStream {
.extend(&#query.archetype_component_access);
)*
}

fn default_config() {}
}

impl<'w, 's, #(#query: WorldQuery + 'static,)* #(#filter: WorldQuery + 'static,)*> SystemParamFetch<'w, 's> for QuerySetState<(#(QueryState<#query, #filter>,)*)>
Expand Down Expand Up @@ -387,10 +384,9 @@ pub fn derive_system_param(input: TokenStream) -> TokenStream {
}

unsafe impl<TSystemParamState: #path::system::SystemParamState, #punctuated_generics> #path::system::SystemParamState for #fetch_struct_name<TSystemParamState, #punctuated_generic_idents> {
type Config = TSystemParamState::Config;
fn init(world: &mut #path::world::World, system_meta: &mut #path::system::SystemMeta, config: Self::Config) -> Self {
fn init(world: &mut #path::world::World, system_meta: &mut #path::system::SystemMeta) -> Self {
Self {
state: TSystemParamState::init(world, system_meta, config),
state: TSystemParamState::init(world, system_meta),
marker: std::marker::PhantomData,
}
}
Expand All @@ -399,10 +395,6 @@ pub fn derive_system_param(input: TokenStream) -> TokenStream {
self.state.new_archetype(archetype, system_meta)
}

fn default_config() -> TSystemParamState::Config {
TSystemParamState::default_config()
}

fn apply(&mut self, world: &mut #path::world::World) {
self.state.apply(world)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub mod prelude {
Schedule, Stage, StageLabel, State, SystemLabel, SystemSet, SystemStage,
},
system::{
Commands, ConfigurableSystem, In, IntoChainSystem, IntoExclusiveSystem, IntoSystem,
Local, NonSend, NonSendMut, Query, QuerySet, RemovedComponents, Res, ResMut, System,
Commands, In, IntoChainSystem, IntoExclusiveSystem, IntoSystem, Local, NonSend,
NonSendMut, Query, QuerySet, RemovedComponents, Res, ResMut, System,
},
world::{FromWorld, Mut, World},
};
Expand Down
84 changes: 39 additions & 45 deletions crates/bevy_ecs/src/schedule/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,134 +98,128 @@ impl<T> State<T>
where
T: StateData,
{
pub fn on_update(s: T) -> RunCriteriaDescriptor {
(|state: Res<State<T>>, pred: Local<Option<T>>| {
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<T>>| {
state.stack.last().unwrap() == &pred && state.transition.is_none()
})
.config(|(_, pred)| *pred = Some(Some(s.clone())))
.chain(should_run_adapter::<T>)
.after(DriverLabel::of::<T>())
.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<State<T>>, mut is_inactive: Local<bool>, pred: Local<Option<T>>| match &state
.transition
{
pub fn on_inactive_update(pred: T) -> RunCriteriaDescriptor {
let pred_clone = pred.clone();
(move |state: Res<State<T>>, mut is_inactive: Local<bool>| 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
}
Some(_) => false,
None => *is_inactive,
})
.config(|(_, _, pred)| *pred = Some(Some(s.clone())))
.chain(should_run_adapter::<T>)
.after(DriverLabel::of::<T>())
.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<State<T>>, mut is_in_stack: Local<bool>, pred: Local<Option<T>>| match &state
.transition
{
pub fn on_in_stack_update(pred: T) -> RunCriteriaDescriptor {
let pred_clone = pred.clone();
(move |state: Res<State<T>>, mut is_in_stack: Local<bool>| 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
}
Some(_) => false,
None => *is_in_stack,
})
.config(|(_, _, pred)| *pred = Some(Some(s.clone())))
.chain(should_run_adapter::<T>)
.after(DriverLabel::of::<T>())
.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<State<T>>, pred: Local<Option<T>>| {
pub fn on_enter(pred: T) -> RunCriteriaDescriptor {
let pred_clone = pred.clone();
(move |state: Res<State<T>>| {
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::<T>)
.after(DriverLabel::of::<T>())
.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<State<T>>, pred: Local<Option<T>>| {
pub fn on_exit(pred: T) -> RunCriteriaDescriptor {
let pred_clone = pred.clone();
(move |state: Res<State<T>>| {
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::<T>)
.after(DriverLabel::of::<T>())
.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<State<T>>, pred: Local<Option<T>>| {
pub fn on_pause(pred: T) -> RunCriteriaDescriptor {
let pred_clone = pred.clone();
(move |state: Res<State<T>>| {
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::<T>)
.after(DriverLabel::of::<T>())
.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<State<T>>, pred: Local<Option<T>>| {
pub fn on_resume(pred: T) -> RunCriteriaDescriptor {
let pred_clone = pred.clone();
(move |state: Res<State<T>>| {
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::<T>)
.after(DriverLabel::of::<T>())
.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 {
Expand Down
Loading