Skip to content

Commit

Permalink
Replace multiple calls to add_system with add_systems (#8001)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoJoJet authored Mar 10, 2023
1 parent 7294588 commit fd1af7c
Show file tree
Hide file tree
Showing 124 changed files with 498 additions and 533 deletions.
32 changes: 8 additions & 24 deletions benches/benches/bevy_ecs/scheduling/run_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ pub fn run_condition_yes(criterion: &mut Criterion) {
let mut schedule = Schedule::new();
schedule.add_system(empty.run_if(yes));
for _ in 0..amount {
schedule
.add_system(empty.run_if(yes))
.add_system(empty.run_if(yes))
.add_system(empty.run_if(yes))
.add_system(empty.run_if(yes))
.add_system(empty.run_if(yes));
schedule.add_systems((empty, empty, empty, empty, empty).distributive_run_if(yes));
}
// run once to initialize systems
schedule.run(&mut world);
Expand All @@ -49,12 +44,7 @@ pub fn run_condition_no(criterion: &mut Criterion) {
let mut schedule = Schedule::new();
schedule.add_system(empty.run_if(no));
for _ in 0..amount {
schedule
.add_system(empty.run_if(no))
.add_system(empty.run_if(no))
.add_system(empty.run_if(no))
.add_system(empty.run_if(no))
.add_system(empty.run_if(no));
schedule.add_systems((empty, empty, empty, empty, empty).distributive_run_if(no));
}
// run once to initialize systems
schedule.run(&mut world);
Expand Down Expand Up @@ -84,12 +74,9 @@ pub fn run_condition_yes_with_query(criterion: &mut Criterion) {
let mut schedule = Schedule::new();
schedule.add_system(empty.run_if(yes_with_query));
for _ in 0..amount {
schedule
.add_system(empty.run_if(yes_with_query))
.add_system(empty.run_if(yes_with_query))
.add_system(empty.run_if(yes_with_query))
.add_system(empty.run_if(yes_with_query))
.add_system(empty.run_if(yes_with_query));
schedule.add_systems(
(empty, empty, empty, empty, empty).distributive_run_if(yes_with_query),
);
}
// run once to initialize systems
schedule.run(&mut world);
Expand All @@ -116,12 +103,9 @@ pub fn run_condition_yes_with_resource(criterion: &mut Criterion) {
let mut schedule = Schedule::new();
schedule.add_system(empty.run_if(yes_with_resource));
for _ in 0..amount {
schedule
.add_system(empty.run_if(yes_with_resource))
.add_system(empty.run_if(yes_with_resource))
.add_system(empty.run_if(yes_with_resource))
.add_system(empty.run_if(yes_with_resource))
.add_system(empty.run_if(yes_with_resource));
schedule.add_systems(
(empty, empty, empty, empty, empty).distributive_run_if(yes_with_resource),
);
}
// run once to initialize systems
schedule.run(&mut world);
Expand Down
15 changes: 5 additions & 10 deletions benches/benches/bevy_ecs/scheduling/running_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ pub fn empty_systems(criterion: &mut Criterion) {
for amount in 1..21 {
let mut schedule = Schedule::new();
for _ in 0..amount {
schedule
.add_system(empty)
.add_system(empty)
.add_system(empty)
.add_system(empty)
.add_system(empty);
schedule.add_systems((empty, empty, empty, empty, empty));
}
schedule.run(&mut world);
group.bench_function(&format!("{:03}_systems", 5 * amount), |bencher| {
Expand Down Expand Up @@ -79,9 +74,9 @@ pub fn busy_systems(criterion: &mut Criterion) {
world.spawn_batch((0..ENTITY_BUNCH).map(|_| (A(0.0), B(0.0), C(0.0), E(0.0))));
for system_amount in 0..5 {
let mut schedule = Schedule::new();
schedule.add_system(ab).add_system(cd).add_system(ce);
schedule.add_systems((ab, cd, ce));
for _ in 0..system_amount {
schedule.add_system(ab).add_system(cd).add_system(ce);
schedule.add_systems((ab, cd, ce));
}
schedule.run(&mut world);
group.bench_function(
Expand Down Expand Up @@ -130,9 +125,9 @@ pub fn contrived(criterion: &mut Criterion) {
world.spawn_batch((0..ENTITY_BUNCH).map(|_| (C(0.0), D(0.0))));
for system_amount in 0..5 {
let mut schedule = Schedule::new();
schedule.add_system(s_0).add_system(s_1).add_system(s_2);
schedule.add_systems((s_0, s_1, s_2));
for _ in 0..system_amount {
schedule.add_system(s_0).add_system(s_1).add_system(s_2);
schedule.add_systems((s_0, s_1, s_2));
}
schedule.run(&mut world);
group.bench_function(
Expand Down
4 changes: 1 addition & 3 deletions benches/benches/bevy_ecs/scheduling/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ pub fn schedule(c: &mut Criterion) {
world.spawn_batch((0..10000).map(|_| (A(0.0), B(0.0), C(0.0), E(0.0))));

let mut schedule = Schedule::new();
schedule.add_system(ab);
schedule.add_system(cd);
schedule.add_system(ce);
schedule.add_systems((ab, cd, ce));
schedule.run(&mut world);

b.iter(move || schedule.run(&mut world));
Expand Down
40 changes: 26 additions & 14 deletions crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub mod prelude {

use bevy_ecs::{
schedule::{
apply_system_buffers, IntoSystemConfig, IntoSystemSetConfig, IntoSystemSetConfigs,
Schedule, ScheduleLabel, SystemSet,
apply_system_buffers, IntoSystemConfig, IntoSystemSetConfigs, Schedule, ScheduleLabel,
SystemSet,
},
system::Local,
world::World,
Expand Down Expand Up @@ -136,11 +136,13 @@ impl CoreSet {
// Create "stage-like" structure using buffer flushes + ordering
schedule
.set_default_base_set(Update)
.add_system(apply_system_buffers.in_base_set(FirstFlush))
.add_system(apply_system_buffers.in_base_set(PreUpdateFlush))
.add_system(apply_system_buffers.in_base_set(UpdateFlush))
.add_system(apply_system_buffers.in_base_set(PostUpdateFlush))
.add_system(apply_system_buffers.in_base_set(LastFlush))
.add_systems((
apply_system_buffers.in_base_set(FirstFlush),
apply_system_buffers.in_base_set(PreUpdateFlush),
apply_system_buffers.in_base_set(UpdateFlush),
apply_system_buffers.in_base_set(PostUpdateFlush),
apply_system_buffers.in_base_set(LastFlush),
))
.configure_sets(
(
First,
Expand Down Expand Up @@ -197,13 +199,23 @@ impl StartupSet {
schedule.set_default_base_set(Startup);

// Create "stage-like" structure using buffer flushes + ordering
schedule.add_system(apply_system_buffers.in_base_set(PreStartupFlush));
schedule.add_system(apply_system_buffers.in_base_set(StartupFlush));
schedule.add_system(apply_system_buffers.in_base_set(PostStartupFlush));

schedule.configure_set(PreStartup.before(PreStartupFlush));
schedule.configure_set(Startup.after(PreStartupFlush).before(StartupFlush));
schedule.configure_set(PostStartup.after(StartupFlush).before(PostStartupFlush));
schedule.add_systems((
apply_system_buffers.in_base_set(PreStartupFlush),
apply_system_buffers.in_base_set(StartupFlush),
apply_system_buffers.in_base_set(PostStartupFlush),
));

schedule.configure_sets(
(
PreStartup,
PreStartupFlush,
Startup,
StartupFlush,
PostStartup,
PostStartupFlush,
)
.chain(),
);

schedule
}
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,10 @@ mod test {
let mut app = App::new();
app.insert_resource(assets);
app.insert_resource(asset_server);
app.add_system(free_unused_assets_system.in_set(FreeUnusedAssets));
app.add_system(update_asset_storage_system::<PngAsset>.after(FreeUnusedAssets));
app.add_systems((
free_unused_assets_system.in_set(FreeUnusedAssets),
update_asset_storage_system::<PngAsset>.after(FreeUnusedAssets),
));

fn load_asset(path: AssetPath, world: &World) -> HandleUntyped {
let asset_server = world.resource::<AssetServer>();
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,10 @@ impl AddAsset for App {
};

self.insert_resource(assets)
.add_system(Assets::<T>::asset_event_system.in_base_set(AssetSet::AssetEvents))
.add_system(update_asset_storage_system::<T>.in_base_set(AssetSet::LoadAssets))
.add_systems((
Assets::<T>::asset_event_system.in_base_set(AssetSet::AssetEvents),
update_asset_storage_system::<T>.in_base_set(AssetSet::LoadAssets),
))
.register_type::<Handle<T>>()
.add_event::<AssetEvent<T>>()
}
Expand Down
10 changes: 6 additions & 4 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ impl Plugin for BloomPlugin {
.init_resource::<BloomUpsamplingPipeline>()
.init_resource::<SpecializedRenderPipelines<BloomDownsamplingPipeline>>()
.init_resource::<SpecializedRenderPipelines<BloomUpsamplingPipeline>>()
.add_system(prepare_bloom_textures.in_set(RenderSet::Prepare))
.add_system(prepare_downsampling_pipeline.in_set(RenderSet::Prepare))
.add_system(prepare_upsampling_pipeline.in_set(RenderSet::Prepare))
.add_system(queue_bloom_bind_groups.in_set(RenderSet::Queue));
.add_systems((
prepare_bloom_textures.in_set(RenderSet::Prepare),
prepare_downsampling_pipeline.in_set(RenderSet::Prepare),
prepare_upsampling_pipeline.in_set(RenderSet::Prepare),
queue_bloom_bind_groups.in_set(RenderSet::Queue),
));

// Add bloom to the 3d render graph
{
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_core_pipeline/src/core_2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ impl Plugin for Core2dPlugin {

render_app
.init_resource::<DrawFunctions<Transparent2d>>()
.add_system(extract_core_2d_camera_phases.in_schedule(ExtractSchedule))
.add_system(sort_phase_system::<Transparent2d>.in_set(RenderSet::PhaseSort))
.add_system(
.add_systems((
extract_core_2d_camera_phases.in_schedule(ExtractSchedule),
sort_phase_system::<Transparent2d>.in_set(RenderSet::PhaseSort),
batch_phase_system::<Transparent2d>
.after(sort_phase_system::<Transparent2d>)
.in_set(RenderSet::PhaseSort),
);
));

let pass_node_2d = MainPass2dNode::new(&mut render_app.world);
let tonemapping = TonemappingNode::new(&mut render_app.world);
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ impl Plugin for Core3dPlugin {
.init_resource::<DrawFunctions<Opaque3d>>()
.init_resource::<DrawFunctions<AlphaMask3d>>()
.init_resource::<DrawFunctions<Transparent3d>>()
.add_system(extract_core_3d_camera_phases.in_schedule(ExtractSchedule))
.add_system(
.add_systems((
extract_core_3d_camera_phases.in_schedule(ExtractSchedule),
prepare_core_3d_depth_textures
.in_set(RenderSet::Prepare)
.after(bevy_render::view::prepare_windows),
)
.add_system(sort_phase_system::<Opaque3d>.in_set(RenderSet::PhaseSort))
.add_system(sort_phase_system::<AlphaMask3d>.in_set(RenderSet::PhaseSort))
.add_system(sort_phase_system::<Transparent3d>.in_set(RenderSet::PhaseSort));
sort_phase_system::<Opaque3d>.in_set(RenderSet::PhaseSort),
sort_phase_system::<AlphaMask3d>.in_set(RenderSet::PhaseSort),
sort_phase_system::<Transparent3d>.in_set(RenderSet::PhaseSort),
));

let prepass_node = PrepassNode::new(&mut render_app.world);
let pass_node_3d = MainPass3dNode::new(&mut render_app.world);
Expand Down
14 changes: 8 additions & 6 deletions crates/bevy_ecs/examples/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ fn main() {

// Add systems to the Schedule to execute our app logic
// We can label our systems to force a specific run-order between some of them
schedule.add_system(spawn_entities.in_set(SimulationSystem::Spawn));
schedule.add_system(print_counter_when_changed.after(SimulationSystem::Spawn));
schedule.add_system(age_all_entities.in_set(SimulationSystem::Age));
schedule.add_system(remove_old_entities.after(SimulationSystem::Age));
schedule.add_system(print_changed_entities.after(SimulationSystem::Age));
schedule.add_systems((
spawn_entities.in_set(SimulationSet::Spawn),
print_counter_when_changed.after(SimulationSet::Spawn),
age_all_entities.in_set(SimulationSet::Age),
remove_old_entities.after(SimulationSet::Age),
print_changed_entities.after(SimulationSet::Age),
));

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

// System sets can be used to group systems and configured to control relative ordering
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
enum SimulationSystem {
enum SimulationSet {
Spawn,
Age,
}
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_ecs/examples/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ fn main() {
schedule.add_system(Events::<MyEvent>::update_system.in_set(FlushEvents));

// Add systems sending and receiving events after the events are flushed.
schedule.add_system(sending_system.after(FlushEvents));
schedule.add_system(receiving_system.after(sending_system));
schedule.add_systems((
sending_system.after(FlushEvents),
receiving_system.after(sending_system),
));

// Simulate 10 frames of our world
for iteration in 1..=10 {
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_ecs/examples/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ fn main() {
let mut schedule = Schedule::default();

// Add systems to increase the counter and to print out the current value
schedule.add_system(increase_counter);
schedule.add_system(print_counter.after(increase_counter));
schedule.add_systems((increase_counter, print_counter).chain());

for iteration in 1..=10 {
println!("Simulating frame {iteration}/10");
Expand Down
33 changes: 18 additions & 15 deletions crates/bevy_ecs/src/schedule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ mod tests {

world.init_resource::<SystemOrder>();

schedule.add_system(named_system);
schedule.add_system(make_function_system(1).before(named_system));
schedule.add_system(
schedule.add_systems((
named_system,
make_function_system(1).before(named_system),
make_function_system(0)
.after(named_system)
.in_set(TestSet::A),
);
));
schedule.run(&mut world);

assert_eq!(world.resource::<SystemOrder>().0, vec![1, u32::MAX, 0]);
Expand All @@ -144,12 +144,12 @@ mod tests {

// modify the schedule after it's been initialized and test ordering with sets
schedule.configure_set(TestSet::A.after(named_system));
schedule.add_system(
schedule.add_systems((
make_function_system(3)
.before(TestSet::A)
.after(named_system),
);
schedule.add_system(make_function_system(4).after(TestSet::A));
make_function_system(4).after(TestSet::A),
));
schedule.run(&mut world);

assert_eq!(
Expand Down Expand Up @@ -275,10 +275,12 @@ mod tests {

world.init_resource::<Counter>();

schedule.add_system(counting_system.run_if(|| false).run_if(|| false));
schedule.add_system(counting_system.run_if(|| true).run_if(|| false));
schedule.add_system(counting_system.run_if(|| false).run_if(|| true));
schedule.add_system(counting_system.run_if(|| true).run_if(|| true));
schedule.add_systems((
counting_system.run_if(|| false).run_if(|| false),
counting_system.run_if(|| true).run_if(|| false),
counting_system.run_if(|| false).run_if(|| true),
counting_system.run_if(|| true).run_if(|| true),
));

schedule.run(&mut world);
assert_eq!(world.resource::<Counter>().0.load(Ordering::Relaxed), 1);
Expand Down Expand Up @@ -535,8 +537,7 @@ mod tests {
let mut schedule = Schedule::new();

// Schedule `bar` to run after `foo`.
schedule.add_system(foo);
schedule.add_system(bar.after(foo));
schedule.add_systems((foo, bar.after(foo)));

// There's only one `foo`, so it's fine.
let result = schedule.initialize(&mut world);
Expand Down Expand Up @@ -790,8 +791,10 @@ mod tests {
schedule
.set_default_base_set(Base::A)
.configure_set(Base::A.before(Base::B))
.add_system(make_function_system(0).in_base_set(Base::B))
.add_system(make_function_system(1));
.add_systems((
make_function_system(0).in_base_set(Base::B),
make_function_system(1),
));
schedule.run(&mut world);

assert_eq!(world.resource::<SystemOrder>().0, vec![1, 0]);
Expand Down
Loading

0 comments on commit fd1af7c

Please sign in to comment.