Skip to content

Commit 138dfaa

Browse files
committed
remove label declaration macros
1 parent 65c5a7c commit 138dfaa

File tree

13 files changed

+262
-317
lines changed

13 files changed

+262
-317
lines changed

benches/benches/bevy_ecs/scheduling/run_criteria.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use bevy_ecs::{
22
component::Component,
33
prelude::{ParallelSystemDescriptorCoercion, Res, Resource, RunCriteriaDescriptorCoercion},
4-
run_criteria_label,
5-
schedule::{ShouldRun, Stage, SystemStage},
4+
schedule::{RunCriteriaLabel, ShouldRun, Stage, SystemStage},
65
system::Query,
76
world::World,
87
};
@@ -12,6 +11,13 @@ fn run_stage(stage: &mut SystemStage, world: &mut World) {
1211
stage.run(world);
1312
}
1413

14+
/// Labels for run criteria which either always return yes, or always return no.
15+
#[derive(RunCriteriaLabel)]
16+
enum Always {
17+
Yes,
18+
No,
19+
}
20+
1521
pub fn run_criteria_yes(criterion: &mut Criterion) {
1622
let mut world = World::new();
1723
let mut group = criterion.benchmark_group("run_criteria/yes");
@@ -87,15 +93,14 @@ pub fn run_criteria_yes_with_labels(criterion: &mut Criterion) {
8793
for amount in 0..21 {
8894
let mut stage = SystemStage::parallel();
8995

90-
run_criteria_label!(always_yes_label);
91-
stage.add_system(empty.with_run_criteria(always_yes.label(always_yes_label)));
96+
stage.add_system(empty.with_run_criteria(always_yes.label(Always::Yes)));
9297
for _ in 0..amount {
9398
stage
94-
.add_system(empty.with_run_criteria(always_yes_label))
95-
.add_system(empty.with_run_criteria(always_yes_label))
96-
.add_system(empty.with_run_criteria(always_yes_label))
97-
.add_system(empty.with_run_criteria(always_yes_label))
98-
.add_system(empty.with_run_criteria(always_yes_label));
99+
.add_system(empty.with_run_criteria(Always::Yes))
100+
.add_system(empty.with_run_criteria(Always::Yes))
101+
.add_system(empty.with_run_criteria(Always::Yes))
102+
.add_system(empty.with_run_criteria(Always::Yes))
103+
.add_system(empty.with_run_criteria(Always::Yes));
99104
}
100105
// run once to initialize systems
101106
run_stage(&mut stage, &mut world);
@@ -120,15 +125,14 @@ pub fn run_criteria_no_with_labels(criterion: &mut Criterion) {
120125
for amount in 0..21 {
121126
let mut stage = SystemStage::parallel();
122127

123-
run_criteria_label!(always_no_label);
124-
stage.add_system(empty.with_run_criteria(always_no.label(always_no_label)));
128+
stage.add_system(empty.with_run_criteria(always_no.label(Always::No)));
125129
for _ in 0..amount {
126130
stage
127-
.add_system(empty.with_run_criteria(always_no_label))
128-
.add_system(empty.with_run_criteria(always_no_label))
129-
.add_system(empty.with_run_criteria(always_no_label))
130-
.add_system(empty.with_run_criteria(always_no_label))
131-
.add_system(empty.with_run_criteria(always_no_label));
131+
.add_system(empty.with_run_criteria(Always::No))
132+
.add_system(empty.with_run_criteria(Always::No))
133+
.add_system(empty.with_run_criteria(Always::No))
134+
.add_system(empty.with_run_criteria(Always::No))
135+
.add_system(empty.with_run_criteria(Always::No));
132136
}
133137
// run once to initialize systems
134138
run_stage(&mut stage, &mut world);

crates/bevy_app/src/app.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ impl App {
151151
/// # use bevy_ecs::prelude::*;
152152
/// # let mut app = App::new();
153153
/// #
154-
/// // Define a new, private `StageLabel`.
155-
/// stage_label!(my_stage);
156-
/// app.add_stage(my_stage, SystemStage::parallel());
154+
/// #[derive(StageLabel)]
155+
/// struct MyStage;
156+
/// app.add_stage(MyStage, SystemStage::parallel());
157157
/// ```
158158
pub fn add_stage<S: Stage>(&mut self, label: impl StageLabel, stage: S) -> &mut Self {
159159
self.schedule.add_stage(label, stage);
@@ -170,9 +170,9 @@ impl App {
170170
/// # use bevy_ecs::prelude::*;
171171
/// # let mut app = App::new();
172172
/// #
173-
/// // Define a new, private `StageLabel`.
174-
/// stage_label!(my_stage);
175-
/// app.add_stage_after(CoreStage::Update, my_stage, SystemStage::parallel());
173+
/// #[derive(StageLabel)]
174+
/// struct MyStage;
175+
/// app.add_stage_after(CoreStage::Update, MyStage, SystemStage::parallel());
176176
/// ```
177177
pub fn add_stage_after<S: Stage>(
178178
&mut self,
@@ -194,9 +194,9 @@ impl App {
194194
/// # use bevy_ecs::prelude::*;
195195
/// # let mut app = App::new();
196196
/// #
197-
/// // Define a new, private `StageLabel`.
198-
/// stage_label!(my_stage);
199-
/// app.add_stage_before(CoreStage::Update, my_stage, SystemStage::parallel());
197+
/// #[derive(StageLabel)]
198+
/// struct MyStage;
199+
/// app.add_stage_before(CoreStage::Update, MyStage, SystemStage::parallel());
200200
/// ```
201201
pub fn add_stage_before<S: Stage>(
202202
&mut self,
@@ -218,9 +218,9 @@ impl App {
218218
/// # use bevy_ecs::prelude::*;
219219
/// # let mut app = App::new();
220220
/// #
221-
/// // Define a new, private `StageLabel`.
222-
/// stage_label!(my_startup_stage);
223-
/// app.add_startup_stage(my_startup_stage, SystemStage::parallel());
221+
/// #[derive(StageLabel)]
222+
/// struct MyStartupStage;
223+
/// app.add_startup_stage(MyStartupStage, SystemStage::parallel());
224224
/// ```
225225
pub fn add_startup_stage<S: Stage>(&mut self, label: impl StageLabel, stage: S) -> &mut Self {
226226
self.schedule
@@ -242,11 +242,11 @@ impl App {
242242
/// # use bevy_ecs::prelude::*;
243243
/// # let mut app = App::new();
244244
/// #
245-
/// // Define a new, private `StageLabel`.
246-
/// stage_label!(my_startup_stage);
245+
/// #[derive(StageLabel)]
246+
/// struct MyStartupStage;
247247
/// app.add_startup_stage_after(
248248
/// StartupStage::Startup,
249-
/// my_startup_stage,
249+
/// MyStartupStage,
250250
/// SystemStage::parallel()
251251
/// );
252252
/// ```
@@ -275,11 +275,11 @@ impl App {
275275
/// # use bevy_ecs::prelude::*;
276276
/// # let mut app = App::new();
277277
/// #
278-
/// // Define a new, private `StageLabel`.
279-
/// stage_label!(my_startup_stage);
278+
/// #[derive(StageLabel)]
279+
/// struct MyStartupStage;
280280
/// app.add_startup_stage_before(
281281
/// StartupStage::Startup,
282-
/// my_startup_stage,
282+
/// MyStartupStage,
283283
/// SystemStage::parallel()
284284
/// );
285285
/// ```

crates/bevy_ecs/examples/change_detection.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bevy_ecs::{prelude::*, stage_label};
1+
use bevy_ecs::prelude::*;
22
use rand::Rng;
33
use std::ops::Deref;
44

@@ -30,7 +30,8 @@ fn main() {
3030
update.add_system(remove_old_entities.after(SimulationSystem::Age));
3131
update.add_system(print_changed_entities.after(SimulationSystem::Age));
3232
// Add the Stage with our systems to the Schedule
33-
stage_label!(Update);
33+
#[derive(StageLabel)]
34+
struct Update;
3435
schedule.add_stage(Update, update);
3536

3637
// Simulate 10 frames in our world

crates/bevy_ecs/examples/events.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bevy_ecs::{event::Events, prelude::*, stage_label};
1+
use bevy_ecs::{event::Events, prelude::*};
22

33
// In this example a system sends a custom event with a 50/50 chance during any frame.
44
// If an event was send, it will be printed by the console in a receiving system.
@@ -10,7 +10,11 @@ fn main() {
1010
// Create a schedule and a stage
1111
let mut schedule = Schedule::default();
1212

13-
stage_label!(_1st, _2nd);
13+
#[derive(StageLabel)]
14+
enum Stages {
15+
First,
16+
Second,
17+
}
1418

1519
// Events need to be updated in every frame. This update should happen before we use
1620
// the events. To guarantee this, we can let the update run in an earlier stage than our logic.
@@ -19,15 +23,15 @@ fn main() {
1923
// sending and receiving events.
2024
let mut first = SystemStage::parallel();
2125
first.add_system(Events::<MyEvent>::update_system);
22-
schedule.add_stage(_1st, first);
26+
schedule.add_stage(Stages::First, first);
2327

2428
// Add systems sending and receiving events to a "second" Stage
2529
let mut second = SystemStage::parallel();
2630
second.add_system(sending_system);
2731
second.add_system(receiving_system.after(sending_system));
2832

2933
// Run the "second" Stage after the "first" Stage, so our Events always get updated before we use them
30-
schedule.add_stage_after(_1st, _2nd, second);
34+
schedule.add_stage_after(Stages::First, Stages::Second, second);
3135

3236
// Simulate 10 frames of our world
3337
for iteration in 1..=10 {

crates/bevy_ecs/examples/resources.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bevy_ecs::{prelude::*, stage_label};
1+
use bevy_ecs::prelude::*;
22
use rand::Rng;
33
use std::ops::Deref;
44

@@ -15,14 +15,15 @@ fn main() {
1515
let mut schedule = Schedule::default();
1616
let mut update = SystemStage::parallel();
1717

18-
// Declare a private stage label
19-
2018
// Add systems to increase the counter and to print out the current value
2119
update.add_system(increase_counter);
2220
update.add_system(print_counter.after(increase_counter));
2321

22+
// Declare a unique label for the stage.
23+
#[derive(StageLabel)]
24+
struct Update;
25+
2426
// Add the stage to the schedule.
25-
stage_label!(Update);
2627
schedule.add_stage(Update, update);
2728

2829
for iteration in 1..=10 {

crates/bevy_ecs/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,22 @@ pub mod prelude {
2727
pub use crate::reflect::{ReflectComponent, ReflectResource};
2828
#[doc(hidden)]
2929
pub use crate::{
30-
ambiguity_set_label,
3130
bundle::Bundle,
3231
change_detection::DetectChanges,
3332
component::Component,
3433
entity::Entity,
3534
event::{EventReader, EventWriter, Events},
3635
query::{Added, AnyOf, ChangeTrackers, Changed, Or, QueryState, With, Without},
37-
run_criteria_label,
3836
schedule::{
3937
AmbiguitySetLabel, ExclusiveSystemDescriptorCoercion, ParallelSystemDescriptorCoercion,
4038
RunCriteria, RunCriteriaDescriptorCoercion, RunCriteriaLabel, Schedule, Stage,
4139
StageLabel, State, SystemLabel, SystemSet, SystemStage,
4240
},
43-
stage_label,
4441
system::{
4542
Commands, In, IntoChainSystem, IntoExclusiveSystem, IntoSystem, Local, NonSend,
4643
NonSendMut, ParallelCommands, ParamSet, Query, RemovedComponents, Res, ResMut,
4744
Resource, System, SystemParamFunction,
4845
},
49-
system_label,
5046
world::{FromWorld, Mut, World},
5147
};
5248
}

crates/bevy_ecs/src/schedule/label.rs

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -25,75 +25,3 @@ define_label!(
2525
/// Strongly-typed identifier for a [`RunCriteriaLabel`].
2626
RunCriteriaLabelId,
2727
);
28-
29-
/// Defines one or more local, unique types implementing [`StageLabel`].
30-
#[macro_export]
31-
macro_rules! stage_label {
32-
($($name:ident),* $(,)*) => {
33-
$(
34-
/// A macro-generated local `StageLabel`.
35-
#[allow(non_camel_case_types)]
36-
struct $name;
37-
38-
impl $crate::schedule::StageLabel for $name {
39-
fn as_str(&self) -> &'static str {
40-
std::stringify!($name)
41-
}
42-
}
43-
)*
44-
}
45-
}
46-
47-
/// Defines one or more local, unique types implementing [`SystemLabel`].
48-
#[macro_export]
49-
macro_rules! system_label {
50-
($($name:ident),* $(,)*) => {
51-
$(
52-
/// A macro-generated local `SystemLabel`.
53-
#[allow(non_camel_case_types)]
54-
struct $name;
55-
56-
impl $crate::schedule::SystemLabel for $name {
57-
fn as_str(&self) -> &'static str {
58-
std::stringify!($name)
59-
}
60-
}
61-
)*
62-
}
63-
}
64-
65-
/// Defines one or more local, unique types implementing [`AmbiguitySetLabel`].
66-
#[macro_export]
67-
macro_rules! ambiguity_set_label {
68-
($($name:ident),* $(,)*) => {
69-
$(
70-
/// A macro-generated local `AmbiguitySetLabel`.
71-
#[allow(non_camel_case_types)]
72-
struct $name;
73-
74-
impl $crate::schedule::AmbiguitySetLabel for $name {
75-
fn as_str(&self) -> &'static str {
76-
std::stringify!($name)
77-
}
78-
}
79-
)*
80-
}
81-
}
82-
83-
/// Defines one or more local, unique types implementing [`RunCriteriaLabel`].
84-
#[macro_export]
85-
macro_rules! run_criteria_label {
86-
($($name:ident),* $(,)*) => {
87-
$(
88-
/// A macro-generated local `RunCriteria`.
89-
#[allow(non_camel_case_types)]
90-
struct $name;
91-
92-
impl $crate::schedule::RunCriteriaLabel for $name {
93-
fn as_str(&self) -> &'static str {
94-
std::stringify!($name)
95-
}
96-
}
97-
)*
98-
}
99-
}

0 commit comments

Comments
 (0)