Skip to content

Commit fd1af7c

Browse files
authored
Replace multiple calls to add_system with add_systems (#8001)
1 parent 7294588 commit fd1af7c

File tree

124 files changed

+498
-533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+498
-533
lines changed

benches/benches/bevy_ecs/scheduling/run_condition.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ pub fn run_condition_yes(criterion: &mut Criterion) {
2121
let mut schedule = Schedule::new();
2222
schedule.add_system(empty.run_if(yes));
2323
for _ in 0..amount {
24-
schedule
25-
.add_system(empty.run_if(yes))
26-
.add_system(empty.run_if(yes))
27-
.add_system(empty.run_if(yes))
28-
.add_system(empty.run_if(yes))
29-
.add_system(empty.run_if(yes));
24+
schedule.add_systems((empty, empty, empty, empty, empty).distributive_run_if(yes));
3025
}
3126
// run once to initialize systems
3227
schedule.run(&mut world);
@@ -49,12 +44,7 @@ pub fn run_condition_no(criterion: &mut Criterion) {
4944
let mut schedule = Schedule::new();
5045
schedule.add_system(empty.run_if(no));
5146
for _ in 0..amount {
52-
schedule
53-
.add_system(empty.run_if(no))
54-
.add_system(empty.run_if(no))
55-
.add_system(empty.run_if(no))
56-
.add_system(empty.run_if(no))
57-
.add_system(empty.run_if(no));
47+
schedule.add_systems((empty, empty, empty, empty, empty).distributive_run_if(no));
5848
}
5949
// run once to initialize systems
6050
schedule.run(&mut world);
@@ -84,12 +74,9 @@ pub fn run_condition_yes_with_query(criterion: &mut Criterion) {
8474
let mut schedule = Schedule::new();
8575
schedule.add_system(empty.run_if(yes_with_query));
8676
for _ in 0..amount {
87-
schedule
88-
.add_system(empty.run_if(yes_with_query))
89-
.add_system(empty.run_if(yes_with_query))
90-
.add_system(empty.run_if(yes_with_query))
91-
.add_system(empty.run_if(yes_with_query))
92-
.add_system(empty.run_if(yes_with_query));
77+
schedule.add_systems(
78+
(empty, empty, empty, empty, empty).distributive_run_if(yes_with_query),
79+
);
9380
}
9481
// run once to initialize systems
9582
schedule.run(&mut world);
@@ -116,12 +103,9 @@ pub fn run_condition_yes_with_resource(criterion: &mut Criterion) {
116103
let mut schedule = Schedule::new();
117104
schedule.add_system(empty.run_if(yes_with_resource));
118105
for _ in 0..amount {
119-
schedule
120-
.add_system(empty.run_if(yes_with_resource))
121-
.add_system(empty.run_if(yes_with_resource))
122-
.add_system(empty.run_if(yes_with_resource))
123-
.add_system(empty.run_if(yes_with_resource))
124-
.add_system(empty.run_if(yes_with_resource));
106+
schedule.add_systems(
107+
(empty, empty, empty, empty, empty).distributive_run_if(yes_with_resource),
108+
);
125109
}
126110
// run once to initialize systems
127111
schedule.run(&mut world);

benches/benches/bevy_ecs/scheduling/running_systems.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ pub fn empty_systems(criterion: &mut Criterion) {
3535
for amount in 1..21 {
3636
let mut schedule = Schedule::new();
3737
for _ in 0..amount {
38-
schedule
39-
.add_system(empty)
40-
.add_system(empty)
41-
.add_system(empty)
42-
.add_system(empty)
43-
.add_system(empty);
38+
schedule.add_systems((empty, empty, empty, empty, empty));
4439
}
4540
schedule.run(&mut world);
4641
group.bench_function(&format!("{:03}_systems", 5 * amount), |bencher| {
@@ -79,9 +74,9 @@ pub fn busy_systems(criterion: &mut Criterion) {
7974
world.spawn_batch((0..ENTITY_BUNCH).map(|_| (A(0.0), B(0.0), C(0.0), E(0.0))));
8075
for system_amount in 0..5 {
8176
let mut schedule = Schedule::new();
82-
schedule.add_system(ab).add_system(cd).add_system(ce);
77+
schedule.add_systems((ab, cd, ce));
8378
for _ in 0..system_amount {
84-
schedule.add_system(ab).add_system(cd).add_system(ce);
79+
schedule.add_systems((ab, cd, ce));
8580
}
8681
schedule.run(&mut world);
8782
group.bench_function(
@@ -130,9 +125,9 @@ pub fn contrived(criterion: &mut Criterion) {
130125
world.spawn_batch((0..ENTITY_BUNCH).map(|_| (C(0.0), D(0.0))));
131126
for system_amount in 0..5 {
132127
let mut schedule = Schedule::new();
133-
schedule.add_system(s_0).add_system(s_1).add_system(s_2);
128+
schedule.add_systems((s_0, s_1, s_2));
134129
for _ in 0..system_amount {
135-
schedule.add_system(s_0).add_system(s_1).add_system(s_2);
130+
schedule.add_systems((s_0, s_1, s_2));
136131
}
137132
schedule.run(&mut world);
138133
group.bench_function(

benches/benches/bevy_ecs/scheduling/schedule.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ pub fn schedule(c: &mut Criterion) {
4747
world.spawn_batch((0..10000).map(|_| (A(0.0), B(0.0), C(0.0), E(0.0))));
4848

4949
let mut schedule = Schedule::new();
50-
schedule.add_system(ab);
51-
schedule.add_system(cd);
52-
schedule.add_system(ce);
50+
schedule.add_systems((ab, cd, ce));
5351
schedule.run(&mut world);
5452

5553
b.iter(move || schedule.run(&mut world));

crates/bevy_app/src/lib.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ pub mod prelude {
3333

3434
use bevy_ecs::{
3535
schedule::{
36-
apply_system_buffers, IntoSystemConfig, IntoSystemSetConfig, IntoSystemSetConfigs,
37-
Schedule, ScheduleLabel, SystemSet,
36+
apply_system_buffers, IntoSystemConfig, IntoSystemSetConfigs, Schedule, ScheduleLabel,
37+
SystemSet,
3838
},
3939
system::Local,
4040
world::World,
@@ -136,11 +136,13 @@ impl CoreSet {
136136
// Create "stage-like" structure using buffer flushes + ordering
137137
schedule
138138
.set_default_base_set(Update)
139-
.add_system(apply_system_buffers.in_base_set(FirstFlush))
140-
.add_system(apply_system_buffers.in_base_set(PreUpdateFlush))
141-
.add_system(apply_system_buffers.in_base_set(UpdateFlush))
142-
.add_system(apply_system_buffers.in_base_set(PostUpdateFlush))
143-
.add_system(apply_system_buffers.in_base_set(LastFlush))
139+
.add_systems((
140+
apply_system_buffers.in_base_set(FirstFlush),
141+
apply_system_buffers.in_base_set(PreUpdateFlush),
142+
apply_system_buffers.in_base_set(UpdateFlush),
143+
apply_system_buffers.in_base_set(PostUpdateFlush),
144+
apply_system_buffers.in_base_set(LastFlush),
145+
))
144146
.configure_sets(
145147
(
146148
First,
@@ -197,13 +199,23 @@ impl StartupSet {
197199
schedule.set_default_base_set(Startup);
198200

199201
// Create "stage-like" structure using buffer flushes + ordering
200-
schedule.add_system(apply_system_buffers.in_base_set(PreStartupFlush));
201-
schedule.add_system(apply_system_buffers.in_base_set(StartupFlush));
202-
schedule.add_system(apply_system_buffers.in_base_set(PostStartupFlush));
203-
204-
schedule.configure_set(PreStartup.before(PreStartupFlush));
205-
schedule.configure_set(Startup.after(PreStartupFlush).before(StartupFlush));
206-
schedule.configure_set(PostStartup.after(StartupFlush).before(PostStartupFlush));
202+
schedule.add_systems((
203+
apply_system_buffers.in_base_set(PreStartupFlush),
204+
apply_system_buffers.in_base_set(StartupFlush),
205+
apply_system_buffers.in_base_set(PostStartupFlush),
206+
));
207+
208+
schedule.configure_sets(
209+
(
210+
PreStartup,
211+
PreStartupFlush,
212+
Startup,
213+
StartupFlush,
214+
PostStartup,
215+
PostStartupFlush,
216+
)
217+
.chain(),
218+
);
207219

208220
schedule
209221
}

crates/bevy_asset/src/asset_server.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,10 @@ mod test {
852852
let mut app = App::new();
853853
app.insert_resource(assets);
854854
app.insert_resource(asset_server);
855-
app.add_system(free_unused_assets_system.in_set(FreeUnusedAssets));
856-
app.add_system(update_asset_storage_system::<PngAsset>.after(FreeUnusedAssets));
855+
app.add_systems((
856+
free_unused_assets_system.in_set(FreeUnusedAssets),
857+
update_asset_storage_system::<PngAsset>.after(FreeUnusedAssets),
858+
));
857859

858860
fn load_asset(path: AssetPath, world: &World) -> HandleUntyped {
859861
let asset_server = world.resource::<AssetServer>();

crates/bevy_asset/src/assets.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,10 @@ impl AddAsset for App {
331331
};
332332

333333
self.insert_resource(assets)
334-
.add_system(Assets::<T>::asset_event_system.in_base_set(AssetSet::AssetEvents))
335-
.add_system(update_asset_storage_system::<T>.in_base_set(AssetSet::LoadAssets))
334+
.add_systems((
335+
Assets::<T>::asset_event_system.in_base_set(AssetSet::AssetEvents),
336+
update_asset_storage_system::<T>.in_base_set(AssetSet::LoadAssets),
337+
))
336338
.register_type::<Handle<T>>()
337339
.add_event::<AssetEvent<T>>()
338340
}

crates/bevy_core_pipeline/src/bloom/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ impl Plugin for BloomPlugin {
7171
.init_resource::<BloomUpsamplingPipeline>()
7272
.init_resource::<SpecializedRenderPipelines<BloomDownsamplingPipeline>>()
7373
.init_resource::<SpecializedRenderPipelines<BloomUpsamplingPipeline>>()
74-
.add_system(prepare_bloom_textures.in_set(RenderSet::Prepare))
75-
.add_system(prepare_downsampling_pipeline.in_set(RenderSet::Prepare))
76-
.add_system(prepare_upsampling_pipeline.in_set(RenderSet::Prepare))
77-
.add_system(queue_bloom_bind_groups.in_set(RenderSet::Queue));
74+
.add_systems((
75+
prepare_bloom_textures.in_set(RenderSet::Prepare),
76+
prepare_downsampling_pipeline.in_set(RenderSet::Prepare),
77+
prepare_upsampling_pipeline.in_set(RenderSet::Prepare),
78+
queue_bloom_bind_groups.in_set(RenderSet::Queue),
79+
));
7880

7981
// Add bloom to the 3d render graph
8082
{

crates/bevy_core_pipeline/src/core_2d/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ impl Plugin for Core2dPlugin {
5252

5353
render_app
5454
.init_resource::<DrawFunctions<Transparent2d>>()
55-
.add_system(extract_core_2d_camera_phases.in_schedule(ExtractSchedule))
56-
.add_system(sort_phase_system::<Transparent2d>.in_set(RenderSet::PhaseSort))
57-
.add_system(
55+
.add_systems((
56+
extract_core_2d_camera_phases.in_schedule(ExtractSchedule),
57+
sort_phase_system::<Transparent2d>.in_set(RenderSet::PhaseSort),
5858
batch_phase_system::<Transparent2d>
5959
.after(sort_phase_system::<Transparent2d>)
6060
.in_set(RenderSet::PhaseSort),
61-
);
61+
));
6262

6363
let pass_node_2d = MainPass2dNode::new(&mut render_app.world);
6464
let tonemapping = TonemappingNode::new(&mut render_app.world);

crates/bevy_core_pipeline/src/core_3d/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ impl Plugin for Core3dPlugin {
6868
.init_resource::<DrawFunctions<Opaque3d>>()
6969
.init_resource::<DrawFunctions<AlphaMask3d>>()
7070
.init_resource::<DrawFunctions<Transparent3d>>()
71-
.add_system(extract_core_3d_camera_phases.in_schedule(ExtractSchedule))
72-
.add_system(
71+
.add_systems((
72+
extract_core_3d_camera_phases.in_schedule(ExtractSchedule),
7373
prepare_core_3d_depth_textures
7474
.in_set(RenderSet::Prepare)
7575
.after(bevy_render::view::prepare_windows),
76-
)
77-
.add_system(sort_phase_system::<Opaque3d>.in_set(RenderSet::PhaseSort))
78-
.add_system(sort_phase_system::<AlphaMask3d>.in_set(RenderSet::PhaseSort))
79-
.add_system(sort_phase_system::<Transparent3d>.in_set(RenderSet::PhaseSort));
76+
sort_phase_system::<Opaque3d>.in_set(RenderSet::PhaseSort),
77+
sort_phase_system::<AlphaMask3d>.in_set(RenderSet::PhaseSort),
78+
sort_phase_system::<Transparent3d>.in_set(RenderSet::PhaseSort),
79+
));
8080

8181
let prepass_node = PrepassNode::new(&mut render_app.world);
8282
let pass_node_3d = MainPass3dNode::new(&mut render_app.world);

crates/bevy_ecs/examples/change_detection.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ fn main() {
2121

2222
// Add systems to the Schedule to execute our app logic
2323
// We can label our systems to force a specific run-order between some of them
24-
schedule.add_system(spawn_entities.in_set(SimulationSystem::Spawn));
25-
schedule.add_system(print_counter_when_changed.after(SimulationSystem::Spawn));
26-
schedule.add_system(age_all_entities.in_set(SimulationSystem::Age));
27-
schedule.add_system(remove_old_entities.after(SimulationSystem::Age));
28-
schedule.add_system(print_changed_entities.after(SimulationSystem::Age));
24+
schedule.add_systems((
25+
spawn_entities.in_set(SimulationSet::Spawn),
26+
print_counter_when_changed.after(SimulationSet::Spawn),
27+
age_all_entities.in_set(SimulationSet::Age),
28+
remove_old_entities.after(SimulationSet::Age),
29+
print_changed_entities.after(SimulationSet::Age),
30+
));
2931

3032
// Simulate 10 frames in our world
3133
for iteration in 1..=10 {
@@ -48,7 +50,7 @@ struct Age {
4850

4951
// System sets can be used to group systems and configured to control relative ordering
5052
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
51-
enum SimulationSystem {
53+
enum SimulationSet {
5254
Spawn,
5355
Age,
5456
}

0 commit comments

Comments
 (0)