Skip to content

Commit c2a427f

Browse files
authored
Non-string labels (bevyengine#1423 continued) (bevyengine#1473)
Non-string labels
1 parent 82d0e84 commit c2a427f

File tree

36 files changed

+711
-440
lines changed

36 files changed

+711
-440
lines changed

crates/bevy_app/src/app_builder.rs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use crate::{
22
app::{App, AppExit},
33
event::Events,
44
plugin::Plugin,
5-
stage, startup_stage, PluginGroup, PluginGroupBuilder,
5+
CoreStage, PluginGroup, PluginGroupBuilder, StartupStage,
66
};
77
use bevy_ecs::{
88
clear_trackers_system, FromResources, IntoExclusiveSystem, IntoSystem, Resource, Resources,
9-
RunOnce, Schedule, Stage, StateStage, SystemDescriptor, SystemStage, World,
9+
RunOnce, Schedule, Stage, StageLabel, StateStage, SystemDescriptor, SystemStage, World,
1010
};
1111
use bevy_utils::tracing::debug;
1212

@@ -24,7 +24,7 @@ impl Default for AppBuilder {
2424
app_builder
2525
.add_default_stages()
2626
.add_event::<AppExit>()
27-
.add_system_to_stage(stage::LAST, clear_trackers_system.exclusive_system());
27+
.add_system_to_stage(CoreStage::Last, clear_trackers_system.exclusive_system());
2828
app_builder
2929
}
3030
}
@@ -54,110 +54,110 @@ impl AppBuilder {
5454
self
5555
}
5656

57-
pub fn add_stage<S: Stage>(&mut self, name: &'static str, stage: S) -> &mut Self {
58-
self.app.schedule.add_stage(name, stage);
57+
pub fn add_stage<S: Stage>(&mut self, label: impl StageLabel, stage: S) -> &mut Self {
58+
self.app.schedule.add_stage(label, stage);
5959
self
6060
}
6161

6262
pub fn add_stage_after<S: Stage>(
6363
&mut self,
64-
target: &'static str,
65-
name: &'static str,
64+
target: impl StageLabel,
65+
label: impl StageLabel,
6666
stage: S,
6767
) -> &mut Self {
68-
self.app.schedule.add_stage_after(target, name, stage);
68+
self.app.schedule.add_stage_after(target, label, stage);
6969
self
7070
}
7171

7272
pub fn add_stage_before<S: Stage>(
7373
&mut self,
74-
target: &'static str,
75-
name: &'static str,
74+
target: impl StageLabel,
75+
label: impl StageLabel,
7676
stage: S,
7777
) -> &mut Self {
78-
self.app.schedule.add_stage_before(target, name, stage);
78+
self.app.schedule.add_stage_before(target, label, stage);
7979
self
8080
}
8181

82-
pub fn add_startup_stage<S: Stage>(&mut self, name: &'static str, stage: S) -> &mut Self {
82+
pub fn add_startup_stage<S: Stage>(&mut self, label: impl StageLabel, stage: S) -> &mut Self {
8383
self.app
8484
.schedule
85-
.stage(stage::STARTUP, |schedule: &mut Schedule| {
86-
schedule.add_stage(name, stage)
85+
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
86+
schedule.add_stage(label, stage)
8787
});
8888
self
8989
}
9090

9191
pub fn add_startup_stage_after<S: Stage>(
9292
&mut self,
93-
target: &'static str,
94-
name: &'static str,
93+
target: impl StageLabel,
94+
label: impl StageLabel,
9595
stage: S,
9696
) -> &mut Self {
9797
self.app
9898
.schedule
99-
.stage(stage::STARTUP, |schedule: &mut Schedule| {
100-
schedule.add_stage_after(target, name, stage)
99+
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
100+
schedule.add_stage_after(target, label, stage)
101101
});
102102
self
103103
}
104104

105105
pub fn add_startup_stage_before<S: Stage>(
106106
&mut self,
107-
target: &'static str,
108-
name: &'static str,
107+
target: impl StageLabel,
108+
label: impl StageLabel,
109109
stage: S,
110110
) -> &mut Self {
111111
self.app
112112
.schedule
113-
.stage(stage::STARTUP, |schedule: &mut Schedule| {
114-
schedule.add_stage_before(target, name, stage)
113+
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
114+
schedule.add_stage_before(target, label, stage)
115115
});
116116
self
117117
}
118118

119119
pub fn stage<T: Stage, F: FnOnce(&mut T) -> &mut T>(
120120
&mut self,
121-
name: &str,
121+
label: impl StageLabel,
122122
func: F,
123123
) -> &mut Self {
124-
self.app.schedule.stage(name, func);
124+
self.app.schedule.stage(label, func);
125125
self
126126
}
127127

128128
pub fn add_system(&mut self, system: impl Into<SystemDescriptor>) -> &mut Self {
129-
self.add_system_to_stage(stage::UPDATE, system)
129+
self.add_system_to_stage(CoreStage::Update, system)
130130
}
131131

132132
pub fn add_system_to_stage(
133133
&mut self,
134-
stage_name: &'static str,
134+
stage_label: impl StageLabel,
135135
system: impl Into<SystemDescriptor>,
136136
) -> &mut Self {
137-
self.app.schedule.add_system_to_stage(stage_name, system);
137+
self.app.schedule.add_system_to_stage(stage_label, system);
138138
self
139139
}
140140

141141
pub fn add_startup_system(&mut self, system: impl Into<SystemDescriptor>) -> &mut Self {
142-
self.add_startup_system_to_stage(startup_stage::STARTUP, system)
142+
self.add_startup_system_to_stage(StartupStage::Startup, system)
143143
}
144144

145145
pub fn add_startup_system_to_stage(
146146
&mut self,
147-
stage_name: &'static str,
147+
stage_label: impl StageLabel,
148148
system: impl Into<SystemDescriptor>,
149149
) -> &mut Self {
150150
self.app
151151
.schedule
152-
.stage(stage::STARTUP, |schedule: &mut Schedule| {
153-
schedule.add_system_to_stage(stage_name, system)
152+
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
153+
schedule.add_system_to_stage(stage_label, system)
154154
});
155155
self
156156
}
157157

158158
pub fn on_state_enter<T: Clone + Resource>(
159159
&mut self,
160-
stage: &str,
160+
stage: impl StageLabel,
161161
state: T,
162162
system: impl Into<SystemDescriptor>,
163163
) -> &mut Self {
@@ -168,7 +168,7 @@ impl AppBuilder {
168168

169169
pub fn on_state_update<T: Clone + Resource>(
170170
&mut self,
171-
stage: &str,
171+
stage: impl StageLabel,
172172
state: T,
173173
system: impl Into<SystemDescriptor>,
174174
) -> &mut Self {
@@ -179,7 +179,7 @@ impl AppBuilder {
179179

180180
pub fn on_state_exit<T: Clone + Resource>(
181181
&mut self,
182-
stage: &str,
182+
stage: impl StageLabel,
183183
state: T,
184184
system: impl Into<SystemDescriptor>,
185185
) -> &mut Self {
@@ -190,28 +190,28 @@ impl AppBuilder {
190190

191191
pub fn add_default_stages(&mut self) -> &mut Self {
192192
self.add_stage(
193-
stage::STARTUP,
193+
CoreStage::Startup,
194194
Schedule::default()
195195
.with_run_criteria(RunOnce::default())
196-
.with_stage(startup_stage::PRE_STARTUP, SystemStage::parallel())
197-
.with_stage(startup_stage::STARTUP, SystemStage::parallel())
198-
.with_stage(startup_stage::POST_STARTUP, SystemStage::parallel()),
196+
.with_stage(StartupStage::PreStartup, SystemStage::parallel())
197+
.with_stage(StartupStage::Startup, SystemStage::parallel())
198+
.with_stage(StartupStage::PostStartup, SystemStage::parallel()),
199199
)
200-
.add_stage(stage::FIRST, SystemStage::parallel())
201-
.add_stage(stage::PRE_EVENT, SystemStage::parallel())
202-
.add_stage(stage::EVENT, SystemStage::parallel())
203-
.add_stage(stage::PRE_UPDATE, SystemStage::parallel())
204-
.add_stage(stage::UPDATE, SystemStage::parallel())
205-
.add_stage(stage::POST_UPDATE, SystemStage::parallel())
206-
.add_stage(stage::LAST, SystemStage::parallel())
200+
.add_stage(CoreStage::First, SystemStage::parallel())
201+
.add_stage(CoreStage::PreEvent, SystemStage::parallel())
202+
.add_stage(CoreStage::Event, SystemStage::parallel())
203+
.add_stage(CoreStage::PreUpdate, SystemStage::parallel())
204+
.add_stage(CoreStage::Update, SystemStage::parallel())
205+
.add_stage(CoreStage::PostUpdate, SystemStage::parallel())
206+
.add_stage(CoreStage::Last, SystemStage::parallel())
207207
}
208208

209209
pub fn add_event<T>(&mut self) -> &mut Self
210210
where
211211
T: Send + Sync + 'static,
212212
{
213213
self.insert_resource(Events::<T>::default())
214-
.add_system_to_stage(stage::EVENT, Events::<T>::update_system.system())
214+
.add_system_to_stage(CoreStage::Event, Events::<T>::update_system.system())
215215
}
216216

217217
/// Inserts a resource to the current [App] and overwrites any resource previously added of the same type.

crates/bevy_app/src/lib.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/// The names of the default App stages
2-
pub mod stage;
3-
/// The names of the default App startup stages
4-
pub mod startup_stage;
5-
61
mod app;
72
mod app_builder;
83
mod event;
@@ -23,6 +18,39 @@ pub mod prelude {
2318
app::App,
2419
app_builder::AppBuilder,
2520
event::{EventReader, Events},
26-
stage, DynamicPlugin, Plugin, PluginGroup,
21+
CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupStage,
2722
};
2823
}
24+
25+
use bevy_ecs::StageLabel;
26+
27+
/// The names of the default App stages
28+
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
29+
pub enum CoreStage {
30+
/// Runs once at the beginning of the app.
31+
Startup,
32+
/// Name of app stage that runs before all other app stages
33+
First,
34+
/// Name of app stage that runs before EVENT
35+
PreEvent,
36+
/// Name of app stage that updates events. Runs before UPDATE
37+
Event,
38+
/// Name of app stage responsible for performing setup before an update. Runs before UPDATE.
39+
PreUpdate,
40+
/// Name of app stage responsible for doing most app logic. Systems should be registered here by default.
41+
Update,
42+
/// Name of app stage responsible for processing the results of UPDATE. Runs after UPDATE.
43+
PostUpdate,
44+
/// Name of app stage that runs after all other app stages
45+
Last,
46+
}
47+
/// The names of the default App startup stages
48+
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
49+
pub enum StartupStage {
50+
/// Name of app stage that runs once before the startup stage
51+
PreStartup,
52+
/// Name of app stage that runs once when an app starts up
53+
Startup,
54+
/// Name of app stage that runs once after the startup stage
55+
PostStartup,
56+
}

crates/bevy_app/src/stage.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

crates/bevy_app/src/startup_stage.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

crates/bevy_asset/src/assets.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
2-
update_asset_storage_system, Asset, AssetLoader, AssetServer, Handle, HandleId, RefChange,
2+
update_asset_storage_system, Asset, AssetLoader, AssetServer, AssetStage, Handle, HandleId,
3+
RefChange,
34
};
45
use bevy_app::{prelude::Events, AppBuilder};
56
use bevy_ecs::{FromResources, IntoSystem, ResMut};
@@ -219,11 +220,11 @@ impl AddAsset for AppBuilder {
219220

220221
self.insert_resource(assets)
221222
.add_system_to_stage(
222-
super::stage::ASSET_EVENTS,
223+
AssetStage::AssetEvents,
223224
Assets::<T>::asset_event_system.system(),
224225
)
225226
.add_system_to_stage(
226-
crate::stage::LOAD_ASSETS,
227+
AssetStage::LoadAssets,
227228
update_asset_storage_system::<T>.system(),
228229
)
229230
.register_type::<Handle<T>>()

crates/bevy_asset/src/lib.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,27 @@ mod path;
1414

1515
pub use asset_server::*;
1616
pub use assets::*;
17-
use bevy_ecs::{IntoSystem, SystemStage};
18-
use bevy_reflect::RegisterTypeBuilder;
19-
use bevy_tasks::IoTaskPool;
2017
pub use handle::*;
2118
pub use info::*;
2219
pub use io::*;
2320
pub use loader::*;
2421
pub use path::*;
2522

26-
/// The names of asset stages in an App Schedule
27-
pub mod stage {
28-
pub const LOAD_ASSETS: &str = "load_assets";
29-
pub const ASSET_EVENTS: &str = "asset_events";
30-
}
31-
3223
pub mod prelude {
3324
pub use crate::{AddAsset, AssetEvent, AssetServer, Assets, Handle, HandleUntyped};
3425
}
3526

3627
use bevy_app::{prelude::Plugin, AppBuilder};
28+
use bevy_ecs::{IntoSystem, StageLabel, SystemStage};
29+
use bevy_reflect::RegisterTypeBuilder;
30+
use bevy_tasks::IoTaskPool;
31+
32+
/// The names of asset stages in an App Schedule
33+
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
34+
pub enum AssetStage {
35+
LoadAssets,
36+
AssetEvents,
37+
}
3738

3839
/// Adds support for Assets to an App. Assets are typed collections with change tracking, which are added as App Resources.
3940
/// Examples of assets: textures, sounds, 3d models, maps, scenes
@@ -89,25 +90,28 @@ impl Plugin for AssetPlugin {
8990
}
9091

9192
app.add_stage_before(
92-
bevy_app::stage::PRE_UPDATE,
93-
stage::LOAD_ASSETS,
93+
bevy_app::CoreStage::PreUpdate,
94+
AssetStage::LoadAssets,
9495
SystemStage::parallel(),
9596
)
9697
.add_stage_after(
97-
bevy_app::stage::POST_UPDATE,
98-
stage::ASSET_EVENTS,
98+
bevy_app::CoreStage::PostUpdate,
99+
AssetStage::AssetEvents,
99100
SystemStage::parallel(),
100101
)
101102
.register_type::<HandleId>()
102103
.add_system_to_stage(
103-
bevy_app::stage::PRE_UPDATE,
104+
bevy_app::CoreStage::PreUpdate,
104105
asset_server::free_unused_assets_system.system(),
105106
);
106107

107108
#[cfg(all(
108109
feature = "filesystem_watcher",
109110
all(not(target_arch = "wasm32"), not(target_os = "android"))
110111
))]
111-
app.add_system_to_stage(stage::LOAD_ASSETS, io::filesystem_watcher_system.system());
112+
app.add_system_to_stage(
113+
AssetStage::LoadAssets,
114+
io::filesystem_watcher_system.system(),
115+
);
112116
}
113117
}

0 commit comments

Comments
 (0)