1
1
use crate :: { App , Plugin } ;
2
2
use bevy_ecs:: {
3
3
schedule:: { ExecutorKind , Schedule , ScheduleLabel } ,
4
- system:: { Local , Resource } ,
4
+ system:: Resource ,
5
5
world:: { Mut , World } ,
6
6
} ;
7
7
8
- /// The schedule that contains the app logic that is evaluated each tick of event loop.
9
- ///
10
- /// By default, it will run the following schedules in the given order:
11
- ///
12
8
/// On the first run of the schedule (and only on the first run), it will run:
13
9
/// * [`PreStartup`]
14
10
/// * [`Startup`]
15
11
/// * [`PostStartup`]
16
- ///
17
- /// Then it will run:
18
- /// * [`First`]
19
- /// * [`PreUpdate`]
20
- /// * [`StateTransition`]
21
- /// * [`RunFixedUpdateLoop`]
22
- /// * This will run [`FixedUpdate`] zero to many times, based on how much time has elapsed.
23
- /// * [`Update`]
24
- /// * [`PostUpdate`]
25
- /// * [`Last`]
26
12
#[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
27
- pub struct UpdateFlow ;
13
+ pub struct StartupFlow ;
28
14
29
15
/// The schedule that runs before [`Startup`].
30
- /// This is run by the [`Main `] schedule.
16
+ /// This is run by the [`StartupFlow `] schedule.
31
17
#[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
32
18
pub struct PreStartup ;
33
19
34
20
/// The schedule that runs once when the app starts.
35
- /// This is run by the [`Main `] schedule.
21
+ /// This is run by the [`StartupFlow `] schedule.
36
22
#[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
37
23
pub struct Startup ;
38
24
39
25
/// The schedule that runs once after [`Startup`].
40
- /// This is run by the [`Main `] schedule.
26
+ /// This is run by the [`StartupFlow `] schedule.
41
27
#[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
42
28
pub struct PostStartup ;
43
29
30
+ /// The schedule that contains the app logic that is evaluated each tick of event loop.
31
+ ///
32
+ /// By default, it will run the following schedules in the given order:
33
+ /// * [`First`]
34
+ /// * [`PreUpdate`]
35
+ /// * [`StateTransition`]
36
+ /// * [`RunFixedUpdateLoop`]
37
+ /// * This will run [`FixedUpdate`] zero to many times, based on how much time has elapsed.
38
+ /// * [`Update`]
39
+ /// * [`PostUpdate`]
40
+ /// * [`Last`]
41
+ #[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
42
+ pub struct UpdateFlow ;
43
+
44
44
/// Runs first in the schedule.
45
- /// This is run by the [`Main `] schedule.
45
+ /// This is run by the [`UpdateFlow `] schedule.
46
46
#[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
47
47
pub struct First ;
48
48
@@ -53,17 +53,17 @@ pub struct First;
53
53
/// [`PreUpdate`] exists to do "engine/plugin preparation work" that ensures the APIs consumed in [`Update`] are "ready".
54
54
/// [`PreUpdate`] abstracts out "pre work implementation details".
55
55
///
56
- /// This is run by the [`Main `] schedule.
56
+ /// This is run by the [`UpdateFlow `] schedule.
57
57
#[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
58
58
pub struct PreUpdate ;
59
59
60
60
/// Runs [state transitions](bevy_ecs::schedule::States).
61
- /// This is run by the [`Main `] schedule.
61
+ /// This is run by the [`UpdateFlow `] schedule.
62
62
#[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
63
63
pub struct StateTransition ;
64
64
65
65
/// Runs the [`FixedUpdate`] schedule in a loop according until all relevant elapsed time has been "consumed".
66
- /// This is run by the [`Main `] schedule.
66
+ /// This is run by the [`UpdateFlow `] schedule.
67
67
#[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
68
68
pub struct RunFixedUpdateLoop ;
69
69
@@ -75,7 +75,7 @@ pub struct RunFixedUpdateLoop;
75
75
pub struct FixedUpdate ;
76
76
77
77
/// The schedule that contains app logic.
78
- /// This is run by the [`Main `] schedule.
78
+ /// This is run by the [`UpdateFlow `] schedule.
79
79
#[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
80
80
pub struct Update ;
81
81
@@ -86,16 +86,26 @@ pub struct Update;
86
86
/// [`PostUpdate`] exists to do "engine/plugin response work" to things that happened in [`Update`].
87
87
/// [`PostUpdate`] abstracts out "implementation details" from users defining systems in [`Update`].
88
88
///
89
- /// This is run by the [`Main `] schedule.
89
+ /// This is run by the [`UpdateFlow `] schedule.
90
90
#[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
91
91
pub struct PostUpdate ;
92
92
93
93
/// Runs last in the schedule.
94
- /// This is run by the [`Main `] schedule.
94
+ /// This is run by the [`UpdateFlow `] schedule.
95
95
#[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
96
96
pub struct Last ;
97
97
98
- /// The main render schedule.
98
+ /// Each time an event is received from windows and devices, this schedule is run.
99
+ /// This is useful for responding to events regardless of whether tick updates take place.
100
+ #[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
101
+ pub struct Control ;
102
+
103
+ /// Each time a frame is ready to be updated, this schedule is run.
104
+ /// This is the best place to decide whether to redraw.
105
+ #[ derive( ScheduleLabel , Clone , Debug , PartialEq , Eq , Hash ) ]
106
+ pub struct FrameReady ;
107
+
108
+ /// The schedule that builds and sends drawing queries to the GPU.
99
109
#[ derive( ScheduleLabel , Debug , Hash , PartialEq , Eq , Clone ) ]
100
110
pub struct RenderFlow ;
101
111
@@ -135,16 +145,19 @@ impl UpdateFlowOrder {
135
145
}
136
146
}
137
147
138
- impl UpdateFlow {
139
- /// A system that runs the "main schedule"
140
- pub fn run_main ( world : & mut World , mut run_at_least_once : Local < bool > ) {
141
- if !* run_at_least_once {
142
- let _ = world. try_run_schedule ( PreStartup ) ;
143
- let _ = world. try_run_schedule ( Startup ) ;
144
- let _ = world. try_run_schedule ( PostStartup ) ;
145
- * run_at_least_once = true ;
146
- }
148
+ /// Initializes the [`StartupFlow`] schedule, [`UpdateFlow`] schedule, sub schedules, and resources for a given [`App`].
149
+ pub struct MainSchedulePlugin ;
147
150
151
+ impl MainSchedulePlugin {
152
+ /// A system that runs the `StartupFlow` sub schedules
153
+ pub fn run_startup ( world : & mut World ) {
154
+ let _ = world. try_run_schedule ( PreStartup ) ;
155
+ let _ = world. try_run_schedule ( Startup ) ;
156
+ let _ = world. try_run_schedule ( PostStartup ) ;
157
+ }
158
+
159
+ /// A system that runs the `UpdateFlow` sub schedules
160
+ pub fn run_update ( world : & mut World ) {
148
161
world. resource_scope ( |world, order : Mut < UpdateFlowOrder > | {
149
162
for label in & order. labels {
150
163
let _ = world. try_run_schedule ( & * * label) ;
@@ -153,20 +166,21 @@ impl UpdateFlow {
153
166
}
154
167
}
155
168
156
- /// Initializes the [`Main`] schedule, sub schedules, and resources for a given [`App`].
157
- pub struct MainSchedulePlugin ;
158
-
159
169
impl Plugin for MainSchedulePlugin {
160
170
fn build ( & self , app : & mut App ) {
161
171
// simple "facilitator" schedules benefit from simpler single threaded scheduling
162
- let mut main_schedule = Schedule :: new ( ) ;
163
- main_schedule. set_executor_kind ( ExecutorKind :: SingleThreaded ) ;
172
+ let mut startup_schedule = Schedule :: new ( ) ;
173
+ startup_schedule. set_executor_kind ( ExecutorKind :: SingleThreaded ) ;
174
+ let mut update_schedule = Schedule :: new ( ) ;
175
+ update_schedule. set_executor_kind ( ExecutorKind :: SingleThreaded ) ;
164
176
let mut fixed_update_loop_schedule = Schedule :: new ( ) ;
165
177
fixed_update_loop_schedule. set_executor_kind ( ExecutorKind :: SingleThreaded ) ;
166
178
167
- app. add_schedule ( UpdateFlow , main_schedule)
179
+ app. add_schedule ( StartupFlow , startup_schedule)
180
+ . add_schedule ( UpdateFlow , update_schedule)
168
181
. add_schedule ( RunFixedUpdateLoop , fixed_update_loop_schedule)
169
182
. init_resource :: < UpdateFlowOrder > ( )
170
- . add_systems ( UpdateFlow , UpdateFlow :: run_main) ;
183
+ . add_systems ( StartupFlow , Self :: run_startup)
184
+ . add_systems ( UpdateFlow , Self :: run_update) ;
171
185
}
172
186
}
0 commit comments