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

Computed State & Sub States #11426

Merged
merged 198 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
198 commits
Select commit Hold shift + click to select a range
40d02bd
adjust apply_state_transition to support a non-existant state resource
lee-orr Jan 18, 2024
8aaf5b0
adjust
lee-orr Jan 18, 2024
f063ef1
adjust run_enter_schedule
lee-orr Jan 18, 2024
f7241e0
fmt
lee-orr Jan 18, 2024
4bc20af
adjust documentation to note changes
lee-orr Jan 18, 2024
31f4148
add version
lee-orr Jan 18, 2024
f08da6b
remove redundant target
lee-orr Jan 18, 2024
ab6402d
debounce warning
lee-orr Jan 18, 2024
a49bcfb
fmt
lee-orr Jan 18, 2024
3a98377
move once from bevy_log to bevy_utils, to allow for it's use in bevy_ecs
lee-orr Jan 19, 2024
2acb47c
Merge branch 'log_once_in_utils' of https://github.com/lee-orr/bevy i…
lee-orr Jan 19, 2024
f8256cb
use `warn_once!`
lee-orr Jan 19, 2024
7ada728
fmt + clippy
lee-orr Jan 19, 2024
a89e0e6
clippy
lee-orr Jan 19, 2024
942d2b1
additional clippy
lee-orr Jan 19, 2024
a52da60
fix docs
lee-orr Jan 19, 2024
b34efb6
Merge branch 'log_once_in_utils' of https://github.com/lee-orr/bevy i…
lee-orr Jan 19, 2024
4dd0a1f
derived state from a single other state
lee-orr Jan 19, 2024
b090746
allow for tuples of states in derived state
lee-orr Jan 19, 2024
854e1f7
fmt
lee-orr Jan 19, 2024
ffc8446
add derived state to app
lee-orr Jan 19, 2024
cfa4634
add example
lee-orr Jan 19, 2024
25ef188
format and clippy
lee-orr Jan 19, 2024
8f2e115
Replace NextState struct with an enum containing "Unchanged", "Set" a…
lee-orr Jan 19, 2024
6d2e935
fix docs & add derived state to prelude
lee-orr Jan 19, 2024
ac41c13
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Jan 19, 2024
0db3e27
doc string fixes
lee-orr Jan 19, 2024
8facb45
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Jan 20, 2024
ed83299
rename DeriveStates schedule label to ComputeDependantStates
lee-orr Jan 20, 2024
91bf17e
some more renamig/clarifying
lee-orr Jan 20, 2024
db2d541
renames and improved docs
lee-orr Jan 20, 2024
4cbef90
rename file and fmt
lee-orr Jan 20, 2024
01ff3ff
update example readme
lee-orr Jan 20, 2024
9ee6fa0
fix compile errors in example
lee-orr Jan 20, 2024
d581bcd
better example
lee-orr Jan 21, 2024
2ce503d
formatting, clippy
lee-orr Jan 21, 2024
2019313
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Jan 21, 2024
3f253a3
fix doc error
lee-orr Jan 21, 2024
f5f6bf1
doc fixes and println! removed
lee-orr Jan 21, 2024
5871781
replace NextState for ComputedStates, adjust state change flow:
lee-orr Jan 21, 2024
76cbe46
fmt, clippy, and docs
lee-orr Jan 21, 2024
8ed76b3
initial definitions
lee-orr Jan 21, 2024
50c355b
fix docs
lee-orr Jan 21, 2024
d5b8ac6
get strict types working
lee-orr Jan 21, 2024
3bf9290
fmt
lee-orr Jan 21, 2024
4751610
Merge branch 'derived_state' of https://github.com/lee-orr/bevy into …
lee-orr Jan 21, 2024
4fd7cd4
doc fixes
lee-orr Jan 21, 2024
ff4e605
simplify strict typing
lee-orr Jan 22, 2024
15382a9
format
lee-orr Jan 22, 2024
1f0172b
Merge pull request #2 from lee-orr/derived_state_strict_types
lee-orr Jan 22, 2024
a5187d7
docs improvements
lee-orr Jan 22, 2024
d7ec741
format
lee-orr Jan 22, 2024
a3b1ecd
Update examples/ecs/computed_states.rs
lee-orr Jan 22, 2024
2c38888
added doc test
lee-orr Jan 22, 2024
7b409cd
fixes to docs
lee-orr Jan 22, 2024
18bfdde
remove "Remove" fron next state
lee-orr Jan 26, 2024
b66d793
deduplicate computes and make consistent transitions
lee-orr Jan 26, 2024
c111a4d
clippy + remove dependncy depth logs in example
lee-orr Jan 26, 2024
2e76040
improve docs in example
lee-orr Jan 26, 2024
8675b38
add some documentation to `internal_apply_state_transition`
lee-orr Jan 26, 2024
11b5132
Add optionals for transition events to support added/removed states
lee-orr Jan 26, 2024
9d1a98f
format
lee-orr Jan 26, 2024
3bddcca
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Jan 26, 2024
389c28b
Update crates/bevy_app/src/app.rs
lee-orr Jan 26, 2024
a5e1c76
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Jan 26, 2024
0c76a88
rename `NextState::Set(S)` to `NextState::Planned(S)`
lee-orr Jan 26, 2024
0906290
Merge branch 'derived_state' of https://github.com/lee-orr/bevy into …
lee-orr Jan 26, 2024
7bb1a79
remove unnecessary `StateTransitionsHaveBeenSetup` resource, chech th…
lee-orr Jan 26, 2024
a13b86d
remove blanket match
lee-orr Jan 26, 2024
d491139
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Jan 26, 2024
8b620f8
Merge branch 'derived_state' of https://github.com/lee-orr/bevy into …
lee-orr Jan 26, 2024
076cc89
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Jan 26, 2024
fc67810
Optional to OptionalStateSet, improve docs around SET_DEPENDENCY_DEPTH
lee-orr Jan 26, 2024
decc1e1
another docs adjustment
lee-orr Jan 26, 2024
669cece
Update examples/ecs/computed_states.rs
lee-orr Jan 26, 2024
b3fd8ca
Merge branch 'derived_state' of https://github.com/lee-orr/bevy into …
lee-orr Jan 26, 2024
f17ed3f
Move `StateTransition` from `bevy_app` prelude to `bevy_ecs` prelude.
lee-orr Jan 26, 2024
dcc3499
fmt fix
lee-orr Jan 26, 2024
d28e967
cleanup types in compute_state example
lee-orr Jan 27, 2024
5f29047
Planned to Pending
lee-orr Jan 27, 2024
3d9c0f9
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Jan 27, 2024
b52747d
fmt
lee-orr Jan 27, 2024
97d4abd
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Jan 27, 2024
ba31544
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Jan 27, 2024
8c09703
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Jan 27, 2024
5b4d825
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Jan 27, 2024
656a98e
remove outdated comment
lee-orr Jan 27, 2024
3b6613f
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Jan 27, 2024
c87746a
Merge branch 'main' into derived_state
lee-orr Jan 28, 2024
466a4ba
Merge branch 'main' into derived_state
lee-orr Jan 28, 2024
e765467
Merge branch 'main' into derived_state
lee-orr Jan 29, 2024
5da69c0
Merge branch 'main' into derived_state
lee-orr Jan 31, 2024
bc00c00
Merge branch 'main' into derived_state
lee-orr Jan 31, 2024
264b275
reverse the order of exit schedules - computed states exit before the…
lee-orr Jan 31, 2024
67714b4
substates initial
lee-orr Feb 1, 2024
683bef6
fmt, clippy, docs
lee-orr Feb 1, 2024
05e9ad8
add app method
lee-orr Feb 1, 2024
d8874aa
Merge branch 'main' into derived_state
lee-orr Feb 1, 2024
35e80d6
Merge branch 'derived_state' of https://github.com/lee-orr/bevy into …
lee-orr Feb 1, 2024
5153171
sub states example
lee-orr Feb 2, 2024
6b0914f
fix typo
lee-orr Feb 2, 2024
41c98a0
fix docs
lee-orr Feb 2, 2024
3e68a5d
Merge pull request #4 from lee-orr/sub_states
lee-orr Feb 2, 2024
c4fdd33
fix docs
lee-orr Feb 2, 2024
3cf86ca
fix type error in docs
lee-orr Feb 2, 2024
539e36e
Merge branch 'main' into derived_state
lee-orr Feb 3, 2024
8d23479
Merge branch 'main' into derived_state
lee-orr Feb 5, 2024
03e6d40
Merge branch 'main' into derived_state
lee-orr Feb 6, 2024
625d1ac
Merge branch 'main' into derived_state
lee-orr Feb 9, 2024
6e4f70d
Merge branch 'main' into derived_state
lee-orr Feb 17, 2024
7503d32
Merge branch 'main' into derived_state
lee-orr Feb 17, 2024
21799b9
Merge branch 'main' into derived_state
lee-orr Feb 17, 2024
a66df88
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Feb 25, 2024
2cb72cf
fix compilation
lee-orr Feb 25, 2024
9cab35f
fmt + clippy
lee-orr Feb 25, 2024
21a7ff0
Merge branch 'main' into derived_state
lee-orr Feb 25, 2024
7f4868a
Merge branch 'main' into derived_state
lee-orr Feb 25, 2024
9117501
Merge branch 'main' into derived_state
lee-orr Feb 28, 2024
24bfdbc
fix typos
lee-orr Feb 28, 2024
0c4055f
final typo
lee-orr Feb 28, 2024
ef502d6
Merge branch 'main' into derived_state
lee-orr Feb 28, 2024
8dbfc4e
Update examples/ecs/sub_states.rs
lee-orr Feb 29, 2024
669c874
Merge branch 'main' into derived_state
lee-orr Mar 1, 2024
4030940
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Mar 4, 2024
755efe4
rebuild example page
lee-orr Mar 4, 2024
366758f
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Mar 5, 2024
315035a
Merge branch 'main' into derived_state
lee-orr Mar 6, 2024
639cdff
fix compilation errors
lee-orr Mar 6, 2024
7973871
Merge branch 'main' into derived_state
lee-orr Mar 17, 2024
302b231
Merge branch 'main' into derived_state
lee-orr Mar 18, 2024
13e7c06
SourceStates are no longer forced to be optional!
lee-orr Mar 18, 2024
0b2517a
added a doc comment
lee-orr Mar 18, 2024
bcbba95
Merge pull request #8 from lee-orr/adjust_state_set
lee-orr Mar 18, 2024
95b3510
use `matches!` instead of `==` in the derive for substates, to allow …
lee-orr Mar 18, 2024
cd33cd9
typos
lee-orr Mar 18, 2024
b1c732b
typos ,fmt, clippy, doc fixes
lee-orr Mar 18, 2024
6633e57
Merge branch 'adjust_state_set' of https://github.com/lee-orr/bevy in…
lee-orr Mar 18, 2024
3ee9160
Merge branch 'main' into derived_state
lee-orr Mar 18, 2024
3e88af7
Merge branch 'main' into derived_state
lee-orr Mar 26, 2024
ca3bf1b
Merge branch 'main' into derived_state
lee-orr Mar 28, 2024
5c9a35d
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Apr 1, 2024
894b635
move state creation to sub app
lee-orr Apr 1, 2024
9f678f4
fix docs & fmt
lee-orr Apr 1, 2024
45d3f0b
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Apr 1, 2024
29f22b8
Merge branch 'main' into derived_state
lee-orr Apr 1, 2024
8651d66
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Apr 9, 2024
15d6444
remove unneeded comment
lee-orr Apr 9, 2024
594a9a7
improve doc
lee-orr Apr 9, 2024
104f851
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Apr 14, 2024
1be2fd0
get compiling
lee-orr Apr 15, 2024
85459fb
tests passing
lee-orr Apr 15, 2024
bdf74f5
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr Apr 15, 2024
f86f401
Merge branch 'main' into derived_state
lee-orr Apr 15, 2024
364230c
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
98ac10d
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
b36d98d
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
c2d2787
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
456ad80
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
c785812
remove documentation paragraph that details internal workings
lee-orr Apr 15, 2024
3506723
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
3548aa5
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
4f9fa98
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
9419818
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
258a4dd
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
f7d4a1a
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
4ade890
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
bb79780
rename "exists" function in SubStates and the registration functions …
lee-orr Apr 15, 2024
ed179d6
Merge branch 'derived_state' of https://github.com/lee-orr/bevy into …
lee-orr Apr 15, 2024
3258488
adjust description of ComputedStates "compute" method
lee-orr Apr 15, 2024
5c9d231
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
a6cf0f9
initial pass at module-level documentation
lee-orr Apr 15, 2024
dc325bc
fix sub state docs
lee-orr Apr 15, 2024
de8167c
typo
lee-orr Apr 15, 2024
625f9d1
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
7dbe9c9
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr Apr 15, 2024
4924d77
Adjusted module docs to provide more details about the provided utilites
lee-orr Apr 15, 2024
0382712
fmt
lee-orr Apr 15, 2024
e223199
typo
lee-orr Apr 15, 2024
d82e9fb
Merge branch 'main' into derived_state
lee-orr Apr 15, 2024
ec5ee62
Merge branch 'main' into derived_state
lee-orr Apr 16, 2024
6b69644
Merge branch 'main' into derived_state
lee-orr Apr 16, 2024
c609228
Merge branch 'main' into derived_state
lee-orr Apr 16, 2024
3e57373
Merge branch 'main' into derived_state
lee-orr Apr 17, 2024
48e07c7
Merge branch 'main' into derived_state
lee-orr Apr 18, 2024
104ae5e
Merge branch 'main' into derived_state
lee-orr Apr 21, 2024
060ea4e
Merge branch 'main' into derived_state
lee-orr Apr 22, 2024
edd07e8
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr May 2, 2024
12e7ed7
Update crates/bevy_app/src/app.rs
lee-orr May 2, 2024
6642023
adjust description of "add_systems"
lee-orr May 2, 2024
976a9f6
Merge branch 'derived_state' of https://github.com/lee-orr/bevy into …
lee-orr May 2, 2024
57ab903
adjust description of init_state & insert_state,
lee-orr May 2, 2024
b98e230
remove unneeded comment
lee-orr May 2, 2024
5d3570d
Update crates/bevy_ecs/src/schedule/state.rs
lee-orr May 2, 2024
0d341e3
Adjust documentation around next state
lee-orr May 2, 2024
1cb7173
remove unneeded copy-paste in docs
lee-orr May 2, 2024
4d8b3d0
fix fmt
lee-orr May 2, 2024
ca5f4f5
Merge branch 'main' of https://github.com/bevyengine/bevy into derive…
lee-orr May 2, 2024
8a0799a
fixing bevy_ecs without default features build
lee-orr May 2, 2024
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
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,17 @@ description = "Illustrates how to use States to control transitioning from a Men
category = "ECS (Entity Component System)"
wasm = false

[[example]]
name = "computed_states"
path = "examples/ecs/computed_states.rs"
doc-scrape-examples = true

[package.metadata.example.computed_states]
name = "Computed States"
description = "Advanced state patterns using Computed States"
category = "ECS (Entity Component System)"
wasm = false

[[example]]
name = "system_piping"
path = "examples/ecs/system_piping.rs"
Expand Down
47 changes: 35 additions & 12 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::{First, Main, MainSchedulePlugin, Plugin, Plugins, StateTransition};
use crate::{First, Main, MainSchedulePlugin, Plugin, Plugins};
pub use bevy_derive::AppLabel;
use bevy_ecs::{
prelude::*,
schedule::{
apply_state_transition, common_conditions::run_once as run_once_condition,
run_enter_schedule, InternedScheduleLabel, IntoSystemConfigs, IntoSystemSetConfigs,
run_enter_schedule, setup_state_transitions_in_world, ComputedStates, FreelyMutableState,
InternedScheduleLabel, IntoSystemConfigs, IntoSystemSetConfigs, ManualStateTransitions,
ScheduleBuildSettings, ScheduleLabel, StateTransitionEvent,
},
};
Expand Down Expand Up @@ -354,23 +355,24 @@ impl App {
///
/// Adds [`State<S>`] and [`NextState<S>`] resources, [`OnEnter`] and [`OnExit`] schedules
/// for each state variant (if they don't already exist), an instance of [`apply_state_transition::<S>`] in
lee-orr marked this conversation as resolved.
Show resolved Hide resolved
/// [`StateTransition`] so that transitions happen before [`Update`](crate::Update) and
/// a instance of [`run_enter_schedule::<S>`] in [`StateTransition`] with a
/// [`ManualStateTransitions`] so that transitions happen before [`Update`](crate::Update) and
/// a instance of [`run_enter_schedule::<S>`] in [`ManualStateTransitions`] with a
/// [`run_once`](`run_once_condition`) condition to run the on enter schedule of the
/// initial state.
///
/// If you would like to control how other systems run based on the current state,
/// you can emulate this behavior using the [`in_state`] [`Condition`].
///
/// Note that you can also apply state transitions at other points in the schedule
/// by adding the [`apply_state_transition`] system manually.
pub fn init_state<S: States + FromWorld>(&mut self) -> &mut Self {
/// by triggering the [`StateTransition`](`bevy_ecs::schedule::StateTransition`) schedule manually.
pub fn init_state<S: FreelyMutableState + FromWorld>(&mut self) -> &mut Self {
if !self.world.contains_resource::<State<S>>() {
setup_state_transitions_in_world(&mut self.world);
self.init_resource::<State<S>>()
.init_resource::<NextState<S>>()
.add_event::<StateTransitionEvent<S>>()
.add_systems(
StateTransition,
ManualStateTransitions,
(
run_enter_schedule::<S>.run_if(run_once_condition()),
apply_state_transition::<S>,
Expand All @@ -391,22 +393,23 @@ impl App {
///
/// Adds [`State<S>`] and [`NextState<S>`] resources, [`OnEnter`] and [`OnExit`] schedules
/// for each state variant (if they don't already exist), an instance of [`apply_state_transition::<S>`] in
/// [`StateTransition`] so that transitions happen before [`Update`](crate::Update) and
/// a instance of [`run_enter_schedule::<S>`] in [`StateTransition`] with a
/// [`ManualStateTransitions`] so that transitions happen before [`Update`](crate::Update) and
/// a instance of [`run_enter_schedule::<S>`] in [`ManualStateTransitions`] with a
/// [`run_once`](`run_once_condition`) condition to run the on enter schedule of the
/// initial state.
///
/// If you would like to control how other systems run based on the current state,
/// you can emulate this behavior using the [`in_state`] [`Condition`].
///
/// Note that you can also apply state transitions at other points in the schedule
/// by adding the [`apply_state_transition`] system manually.
pub fn insert_state<S: States>(&mut self, state: S) -> &mut Self {
/// by triggering the [`StateTransition`](`bevy_ecs::schedule::StateTransition`) schedule manually.
pub fn insert_state<S: FreelyMutableState>(&mut self, state: S) -> &mut Self {
setup_state_transitions_in_world(&mut self.world);
self.insert_resource(State::new(state))
.init_resource::<NextState<S>>()
.add_event::<StateTransitionEvent<S>>()
.add_systems(
StateTransition,
ManualStateTransitions,
(
run_enter_schedule::<S>.run_if(run_once_condition()),
apply_state_transition::<S>,
Expand All @@ -421,6 +424,26 @@ impl App {
self
}

/// Sets up a type implementing [`ComputedStates`].
///
/// This method is idempotent: it has no effect when called again using the same generic type.
///
/// For each source state the derived state depends on, it adds this state's derivation
/// to it's [`ComputeDependantStates<Source>`](bevy_ecs::schedule::ComputeDependantStates<S>) schedule.
pub fn add_computed_state<S: ComputedStates>(&mut self) -> &mut Self {
if !self
.world
.contains_resource::<Events<StateTransitionEvent<S>>>()
{
setup_state_transitions_in_world(&mut self.world);
self.add_event::<StateTransitionEvent<S>>();
let mut schedules = self.world.resource_mut::<Schedules>();
S::register_state_compute_systems_in_schedule(schedules.as_mut());
}

self
}

/// Adds a system to the given schedule in this app's [`Schedules`].
///
lee-orr marked this conversation as resolved.
Show resolved Hide resolved
/// # Examples
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ pub mod prelude {
app::App,
main_schedule::{
First, FixedFirst, FixedLast, FixedPostUpdate, FixedPreUpdate, FixedUpdate, Last, Main,
PostStartup, PostUpdate, PreStartup, PreUpdate, SpawnScene, Startup, StateTransition,
Update,
PostStartup, PostUpdate, PreStartup, PreUpdate, SpawnScene, Startup, Update,
},
DynamicPlugin, Plugin, PluginGroup,
};
Expand Down
8 changes: 1 addition & 7 deletions crates/bevy_app/src/main_schedule.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{App, Plugin};
use bevy_ecs::{
schedule::{ExecutorKind, InternedScheduleLabel, Schedule, ScheduleLabel},
schedule::{ExecutorKind, InternedScheduleLabel, Schedule, ScheduleLabel, StateTransition},
system::{Local, Resource},
world::{Mut, World},
};
Expand Down Expand Up @@ -72,12 +72,6 @@ pub struct First;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct PreUpdate;

/// Runs [state transitions](bevy_ecs::schedule::States).
///
/// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct StateTransition;

/// Runs the [`FixedMain`] schedule in a loop according until all relevant elapsed time has been "consumed".
///
/// See the [`Main`] schedule for some details about how schedules are run.
Expand Down
18 changes: 16 additions & 2 deletions crates/bevy_ecs/macros/src/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,30 @@ use crate::bevy_ecs_path;

pub fn derive_states(input: TokenStream) -> TokenStream {
let ast = parse_macro_input!(input as DeriveInput);

let generics = ast.generics;
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

let mut trait_path = bevy_ecs_path();
trait_path.segments.push(format_ident!("schedule").into());
let mut base_trait_path = bevy_ecs_path();
base_trait_path
.segments
.push(format_ident!("schedule").into());

let mut trait_path = base_trait_path.clone();
trait_path.segments.push(format_ident!("States").into());

let mut state_mutation_trait_path = base_trait_path.clone();
state_mutation_trait_path
.segments
.push(format_ident!("FreelyMutableState").into());

let struct_name = &ast.ident;

quote! {
impl #impl_generics #trait_path for #struct_name #ty_generics #where_clause {}

impl #impl_generics #state_mutation_trait_path for #struct_name #ty_generics #where_clause {
}
}
.into()
}
7 changes: 4 additions & 3 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ pub mod prelude {
query::{Added, AnyOf, Changed, Has, Or, QueryBuilder, QueryState, With, Without},
removal_detection::RemovedComponents,
schedule::{
apply_deferred, apply_state_transition, common_conditions::*, Condition,
IntoSystemConfigs, IntoSystemSet, IntoSystemSetConfigs, NextState, OnEnter, OnExit,
OnTransition, Schedule, Schedules, State, StateTransitionEvent, States, SystemSet,
apply_deferred, apply_state_transition, common_conditions::*, ComputedStates,
Condition, IntoSystemConfigs, IntoSystemSet, IntoSystemSetConfigs, NextState, OnEnter,
OnExit, OnTransition, Schedule, Schedules, State, StateSet, StateTransition,
StateTransitionEvent, States, SystemSet,
},
system::{
Commands, Deferred, In, IntoSystem, Local, NonSend, NonSendMut, ParallelCommands,
Expand Down
Loading
Loading