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 unnecessary system labels #4340

Closed
wants to merge 2 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
10 changes: 2 additions & 8 deletions crates/bevy_ecs/examples/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ fn main() {

// Add systems sending and receiving events to a "second" Stage
let mut second = SystemStage::parallel();
second.add_system(sending_system.label(EventSystem::Sending));
second.add_system(receiving_system.after(EventSystem::Sending));
second.add_system(sending_system);
second.add_system(receiving_system.after(sending_system));

// Run the "second" Stage after the "first" Stage, so our Events always get updated before we use them
schedule.add_stage_after("first", "second", second);
Expand All @@ -34,12 +34,6 @@ fn main() {
}
}

// System label to enforce a run order of our systems
#[derive(SystemLabel, Debug, Clone, PartialEq, Eq, Hash)]
enum EventSystem {
Sending,
}

// This is our event that we will send and receive in systems
struct MyEvent {
pub message: String,
Expand Down
10 changes: 2 additions & 8 deletions crates/bevy_ecs/examples/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ fn main() {
let mut update = SystemStage::parallel();

// Add systems to increase the counter and to print out the current value
update.add_system(increase_counter.label(CounterSystem::Increase));
update.add_system(print_counter.after(CounterSystem::Increase));
update.add_system(increase_counter);
update.add_system(print_counter.after(increase_counter));
schedule.add_stage("update", update);

for iteration in 1..=10 {
Expand All @@ -32,12 +32,6 @@ struct Counter {
pub value: i32,
}

// System label to enforce a run order of our systems
#[derive(SystemLabel, Debug, Clone, PartialEq, Eq, Hash)]
enum CounterSystem {
Increase,
}

fn increase_counter(mut counter: ResMut<Counter>) {
if rand::thread_rng().gen_bool(0.5) {
counter.value += 1;
Expand Down
4 changes: 2 additions & 2 deletions examples/2d/many_sprites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fn main() {
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.add_system(print_sprite_count.label("Tick"))
.add_system(move_camera.after("Tick"))
.add_system(print_sprite_count)
.add_system(move_camera.after(print_sprite_count))
.run();
}

Expand Down
16 changes: 4 additions & 12 deletions examples/ecs/custom_query_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@ use std::{fmt::Debug, marker::PhantomData};
fn main() {
App::new()
.add_startup_system(spawn)
.add_system(print_components_read_only.label("print_components_read_only"))
.add_system(
print_components_iter_mut
.label("print_components_iter_mut")
.after("print_components_read_only"),
)
.add_system(
print_components_iter
.label("print_components_iter")
.after("print_components_iter_mut"),
)
.add_system(print_components_tuple.after("print_components_iter"))
.add_system(print_components_read_only)
.add_system(print_components_iter_mut.after(print_components_read_only))
.add_system(print_components_iter.after(print_components_iter_mut))
.add_system(print_components_tuple.after(print_components_iter))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so much better...

.run();
}

Expand Down
25 changes: 8 additions & 17 deletions examples/ecs/ecs_guide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,6 @@ enum MyStage {
AfterRound,
}

#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)]
enum MyLabels {
ScoreCheck,
}

// Our Bevy app's entry point
fn main() {
// Bevy apps are created using the builder pattern. We use the builder to add systems,
Expand Down Expand Up @@ -331,22 +326,18 @@ fn main() {
.add_system_to_stage(MyStage::BeforeRound, new_player_system)
.add_system_to_stage(
MyStage::BeforeRound,
// Systems which take `&mut World` as an argument must call `.exclusive_system()`.
// The following will not compile.
//.add_system_to_stage(MyStage::BeforeRound, exclusive_player_system)
exclusive_player_system.exclusive_system(),
)
// Systems which take `&mut World` as an argument must call `.exclusive_system()`.
// The following will not compile.
//.add_system_to_stage(MyStage::BeforeRound, exclusive_player_system)
//
// We can ensure that game_over system runs after score_check_system using explicit ordering
// constraints First, we label the system we want to refer to using `.label`
// Then, we use either `.before` or `.after` to describe the order we want the relationship
.add_system_to_stage(
MyStage::AfterRound,
score_check_system.label(MyLabels::ScoreCheck),
)
.add_system_to_stage(MyStage::AfterRound, score_check_system)
.add_system_to_stage(
// We can ensure that `game_over_system` runs after `score_check_system` using explicit ordering
// To do this we use either `.before` or `.after` to describe the order we want the relationship
// Since we are using `after`, `game_over_system` runs after `score_check_system`
MyStage::AfterRound,
game_over_system.after(MyLabels::ScoreCheck),
game_over_system.after(score_check_system),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on this change: public system labels deserve discussion elsewhere.

)
// We can check our systems for execution order ambiguities by examining the output produced
// in the console by using the `LogPlugin` and adding the following Resource to our App :)
Expand Down
6 changes: 3 additions & 3 deletions examples/tools/scene_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Controls:
.add_startup_system(setup)
.add_system_to_stage(CoreStage::PreUpdate, scene_load_check)
.add_system_to_stage(CoreStage::PreUpdate, camera_spawn_check)
.add_system(camera_controller_check.label(CameraControllerCheckSystem))
.add_system(check_camera_controller)
.add_system(update_lights)
.add_system(camera_controller.after(CameraControllerCheckSystem))
.add_system(camera_controller.after(check_camera_controller))
.run();
}

Expand Down Expand Up @@ -221,7 +221,7 @@ fn camera_spawn_check(
}
}

fn camera_controller_check(
fn check_camera_controller(
mut commands: Commands,
camera: Query<Entity, (With<Camera>, Without<CameraController>)>,
mut found_camera: Local<bool>,
Expand Down
8 changes: 4 additions & 4 deletions tests/how_to_test_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ fn did_hurt_enemy() {

// Setup stage with our two systems
let mut update_stage = SystemStage::parallel();
update_stage.add_system(hurt_enemies.before("death"));
update_stage.add_system(despawn_dead_enemies.label("death"));
update_stage.add_system(hurt_enemies.before(despawn_dead_enemies));
update_stage.add_system(despawn_dead_enemies);

// Setup test entities
let enemy_id = world.spawn().insert(Enemy { hit_points: 5 }).id();
Expand All @@ -53,8 +53,8 @@ fn did_despawn_enemy() {

// Setup stage with our two systems
let mut update_stage = SystemStage::parallel();
update_stage.add_system(hurt_enemies.before("death"));
update_stage.add_system(despawn_dead_enemies.label("death"));
update_stage.add_system(hurt_enemies.before(despawn_dead_enemies));
update_stage.add_system(despawn_dead_enemies);

// Setup test entities
let enemy_id = world.spawn().insert(Enemy { hit_points: 1 }).id();
Expand Down