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] - Down with the system! #2496

Closed
wants to merge 12 commits into from
34 changes: 11 additions & 23 deletions benches/benches/bevy_ecs/stages.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::ecs::{
world::World,
schedule::{Stage, SystemStage},
system::{IntoSystem, Query},
world::World,
};
use criterion::{criterion_group, criterion_main, Criterion};

Expand Down Expand Up @@ -29,7 +29,7 @@ fn empty_systems(criterion: &mut Criterion) {
for amount in 0..5 {
let mut stage = SystemStage::parallel();
for _ in 0..amount {
stage.add_system(empty.system());
stage.add_system(empty);
}
run_stage(&mut stage, &mut world);
group.bench_function(&format!("{:03}_systems", amount), |bencher| {
Expand All @@ -42,11 +42,11 @@ fn empty_systems(criterion: &mut Criterion) {
let mut stage = SystemStage::parallel();
for _ in 0..amount {
stage
.add_system(empty.system())
.add_system(empty.system())
.add_system(empty.system())
.add_system(empty.system())
.add_system(empty.system());
.add_system(empty)
.add_system(empty)
.add_system(empty)
.add_system(empty)
.add_system(empty);
}
run_stage(&mut stage, &mut world);
group.bench_function(&format!("{:03}_systems", 5 * amount), |bencher| {
Expand Down Expand Up @@ -85,15 +85,9 @@ 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 stage = SystemStage::parallel();
stage
.add_system(ab.system())
.add_system(cd.system())
.add_system(ce.system());
stage.add_system(ab).add_system(cd).add_system(ce);
for _ in 0..system_amount {
stage
.add_system(ab.system())
.add_system(cd.system())
.add_system(ce.system());
stage.add_system(ab).add_system(cd).add_system(ce);
}
run_stage(&mut stage, &mut world);
group.bench_function(
Expand Down Expand Up @@ -142,15 +136,9 @@ 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 stage = SystemStage::parallel();
stage
.add_system(s_0.system())
.add_system(s_1.system())
.add_system(s_2.system());
stage.add_system(s_0).add_system(s_1).add_system(s_2);
for _ in 0..system_amount {
stage
.add_system(s_0.system())
.add_system(s_1.system())
.add_system(s_2.system());
stage.add_system(s_0).add_system(s_1).add_system(s_2);
}
run_stage(&mut stage, &mut world);
group.bench_function(
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupStage};
use bevy_ecs::{
component::{Component, ComponentDescriptor},
prelude::{FromWorld, IntoExclusiveSystem, IntoSystem},
prelude::{FromWorld, IntoExclusiveSystem},
schedule::{
IntoSystemDescriptor, RunOnce, Schedule, Stage, StageLabel, State, SystemSet, SystemStage,
},
Expand All @@ -28,7 +28,7 @@ use bevy_utils::tracing::info_span;
///
/// fn main() {
/// App::new()
/// .add_system(hello_world_system.system())
/// .add_system(hello_world_system)
/// .run();
/// }
///
Expand Down Expand Up @@ -180,7 +180,7 @@ impl App {
/// Adds a system that runs every time `app.update()` is called by the runner
///
/// Systems are the main building block in the Bevy ECS app model. You can define
/// normal rust functions, and call `.system()` to make them be Bevy systems.
/// normal rust functions, and use them as a Bevy system.
///
/// System functions can have parameters, through which one can query and
/// mutate Bevy ECS states.
Expand All @@ -201,7 +201,7 @@ impl App {
/// }
///
/// App::new()
/// .add_system(my_system.system());
/// .add_system(my_system);
/// ```
pub fn add_system<Params>(&mut self, system: impl IntoSystemDescriptor<Params>) -> &mut Self {
self.add_system_to_stage(CoreStage::Update, system)
Expand Down Expand Up @@ -248,7 +248,7 @@ impl App {
/// }
///
/// App::new()
/// .add_startup_system(my_startup_system.system());
/// .add_startup_system(my_startup_system);
/// ```
pub fn add_startup_system<Params>(
&mut self,
Expand Down Expand Up @@ -335,7 +335,7 @@ impl App {
T: Component,
{
self.insert_resource(Events::<T>::default())
.add_system_to_stage(CoreStage::First, Events::<T>::update_system.system())
.add_system_to_stage(CoreStage::First, Events::<T>::update_system)
}

/// Inserts a resource to the current [App] and overwrites any resource previously added of the same type.
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_app/src/ci_testing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use serde::Deserialize;

use crate::{app::AppExit, App};
use bevy_ecs::system::IntoSystem;

/// Configuration for automated testing on CI
#[derive(Deserialize)]
Expand Down Expand Up @@ -32,7 +31,7 @@ pub(crate) fn setup_app(app_builder: &mut App) -> &mut App {
.expect("error deserializing CI testing configuration file");
app_builder
.insert_resource(config)
.add_system(ci_testing_exit_after.system());
.add_system(ci_testing_exit_after);

app_builder
}
15 changes: 3 additions & 12 deletions crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use crate::{
RefChange,
};
use bevy_app::{App, EventWriter, Events};
use bevy_ecs::{
system::{IntoSystem, ResMut},
world::FromWorld,
};
use bevy_ecs::{system::ResMut, world::FromWorld};
use bevy_utils::HashMap;
use crossbeam_channel::Sender;
use std::fmt::Debug;
Expand Down Expand Up @@ -217,14 +214,8 @@ impl AddAsset for App {
};

self.insert_resource(assets)
.add_system_to_stage(
AssetStage::AssetEvents,
Assets::<T>::asset_event_system.system(),
)
.add_system_to_stage(
AssetStage::LoadAssets,
update_asset_storage_system::<T>.system(),
)
.add_system_to_stage(AssetStage::AssetEvents, Assets::<T>::asset_event_system)
.add_system_to_stage(AssetStage::LoadAssets, update_asset_storage_system::<T>)
.register_type::<Handle<T>>()
.add_event::<AssetEvent<T>>()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{Asset, Assets};
use bevy_app::prelude::*;
use bevy_diagnostic::{Diagnostic, DiagnosticId, Diagnostics, MAX_DIAGNOSTIC_NAME_WIDTH};
use bevy_ecs::system::{IntoSystem, Res, ResMut};
use bevy_ecs::system::{Res, ResMut};

/// Adds "asset count" diagnostic to an App
pub struct AssetCountDiagnosticsPlugin<T: Asset> {
Expand All @@ -18,8 +18,8 @@ impl<T: Asset> Default for AssetCountDiagnosticsPlugin<T> {

impl<T: Asset> Plugin for AssetCountDiagnosticsPlugin<T> {
fn build(&self, app: &mut App) {
app.add_startup_system(Self::setup_system.system())
.add_system(Self::diagnostic_system.system());
app.add_startup_system(Self::setup_system)
.add_system(Self::diagnostic_system);
}
}

Expand Down
12 changes: 3 additions & 9 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ pub use loader::*;
pub use path::*;

use bevy_app::{prelude::Plugin, App};
use bevy_ecs::{
schedule::{StageLabel, SystemStage},
system::IntoSystem,
};
use bevy_ecs::schedule::{StageLabel, SystemStage};
use bevy_tasks::IoTaskPool;

/// The names of asset stages in an App Schedule
Expand Down Expand Up @@ -106,16 +103,13 @@ impl Plugin for AssetPlugin {
.register_type::<HandleId>()
.add_system_to_stage(
bevy_app::CoreStage::PreUpdate,
asset_server::free_unused_assets_system.system(),
asset_server::free_unused_assets_system,
);

#[cfg(all(
feature = "filesystem_watcher",
all(not(target_arch = "wasm32"), not(target_os = "android"))
))]
app.add_system_to_stage(
AssetStage::LoadAssets,
io::filesystem_watcher_system.system(),
);
app.add_system_to_stage(AssetStage::LoadAssets, io::filesystem_watcher_system);
}
}
3 changes: 1 addition & 2 deletions crates/bevy_core/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ pub(crate) fn entity_labels_system(
mod tests {
use bevy_ecs::{
schedule::{Schedule, Stage, SystemStage},
system::IntoSystem,
world::World,
};

Expand All @@ -134,7 +133,7 @@ mod tests {
world.insert_resource(EntityLabels::default());
let mut schedule = Schedule::default();
schedule.add_stage("test", SystemStage::single_threaded());
schedule.add_system_to_stage("test", entity_labels_system.system());
schedule.add_system_to_stage("test", entity_labels_system);
(world, schedule)
}

Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use bevy_app::prelude::*;
use bevy_ecs::{
entity::Entity,
schedule::{ExclusiveSystemDescriptorCoercion, SystemLabel},
system::{IntoExclusiveSystem, IntoSystem},
system::IntoExclusiveSystem,
};
use bevy_utils::HashSet;
use std::ops::Range;
Expand Down Expand Up @@ -62,8 +62,8 @@ impl Plugin for CorePlugin {
CoreStage::First,
time_system.exclusive_system().label(CoreSystem::Time),
)
.add_startup_system_to_stage(StartupStage::PostStartup, entity_labels_system.system())
.add_system_to_stage(CoreStage::PostUpdate, entity_labels_system.system());
.add_startup_system_to_stage(StartupStage::PostStartup, entity_labels_system)
.add_system_to_stage(CoreStage::PostUpdate, entity_labels_system);

register_rust_types(app);
register_math_types(app);
Expand Down
9 changes: 3 additions & 6 deletions crates/bevy_core/src/time/fixed_timestep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_ecs::{
component::ComponentId,
query::Access,
schedule::ShouldRun,
system::{IntoSystem, Local, Res, ResMut, System, SystemId},
system::{ConfigurableSystem, IntoSystem, Local, Res, ResMut, System, SystemId},
world::World,
};
use bevy_utils::HashMap;
Expand Down Expand Up @@ -179,11 +179,8 @@ impl System for FixedTimestep {
}

fn initialize(&mut self, world: &mut World) {
self.internal_system = Box::new(
Self::prepare_system
.system()
.config(|c| c.0 = Some(self.state.clone())),
);
self.internal_system =
Box::new(Self::prepare_system.config(|c| c.0 = Some(self.state.clone())));
self.internal_system.initialize(world);
if let Some(ref label) = self.state.label {
let mut fixed_timesteps = world.get_resource_mut::<FixedTimesteps>().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_diagnostic/src/entity_count_diagnostics_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy_app::{App, Plugin};
use bevy_ecs::{
system::{IntoExclusiveSystem, IntoSystem, ResMut},
system::{IntoExclusiveSystem, ResMut},
world::World,
};

Expand All @@ -12,7 +12,7 @@ pub struct EntityCountDiagnosticsPlugin;

impl Plugin for EntityCountDiagnosticsPlugin {
fn build(&self, app: &mut App) {
app.add_startup_system(Self::setup_system.system())
app.add_startup_system(Self::setup_system)
.add_system(Self::diagnostic_system.exclusive_system());
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_diagnostic/src/frame_time_diagnostics_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{Diagnostic, DiagnosticId, Diagnostics};
use bevy_app::prelude::*;
use bevy_core::Time;
use bevy_ecs::system::{IntoSystem, Res, ResMut};
use bevy_ecs::system::{Res, ResMut};

/// Adds "frame time" diagnostic to an App, specifically "frame time", "fps" and "frame count"
#[derive(Default)]
Expand All @@ -13,9 +13,9 @@ pub struct FrameTimeDiagnosticsState {

impl Plugin for FrameTimeDiagnosticsPlugin {
fn build(&self, app: &mut bevy_app::App) {
app.add_startup_system(Self::setup_system.system())
app.add_startup_system(Self::setup_system)
.insert_resource(FrameTimeDiagnosticsState { frame_count: 0.0 })
.add_system(Self::diagnostic_system.system());
.add_system(Self::diagnostic_system);
}
}

Expand Down
9 changes: 3 additions & 6 deletions crates/bevy_diagnostic/src/log_diagnostics_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{Diagnostic, DiagnosticId, Diagnostics};
use bevy_app::prelude::*;
use bevy_core::{Time, Timer};
use bevy_ecs::system::{IntoSystem, Res, ResMut};
use bevy_ecs::system::{Res, ResMut};
use bevy_log::{debug, info};
use bevy_utils::Duration;

Expand Down Expand Up @@ -36,12 +36,9 @@ impl Plugin for LogDiagnosticsPlugin {
});

if self.debug {
app.add_system_to_stage(
CoreStage::PostUpdate,
Self::log_diagnostics_debug_system.system(),
);
app.add_system_to_stage(CoreStage::PostUpdate, Self::log_diagnostics_debug_system);
} else {
app.add_system_to_stage(CoreStage::PostUpdate, Self::log_diagnostics_system.system());
app.add_system_to_stage(CoreStage::PostUpdate, Self::log_diagnostics_system);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn main() {
// Add a Stage to our schedule. Each Stage in a schedule runs all of its systems
// before moving on to the next Stage
schedule.add_stage("update", SystemStage::parallel()
.with_system(movement.system())
.with_system(movement)
);

// Run the schedule once. If your app has a "loop", you would run this once per loop
Expand Down
14 changes: 5 additions & 9 deletions crates/bevy_ecs/examples/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ fn main() {

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

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/examples/component_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
// Setup a schedule and stage to add a system querying for the just spawned entities
let mut schedule = Schedule::default();
let mut update = SystemStage::parallel();
update.add_system(query_entities.system());
update.add_system(query_entities);
schedule.add_stage("update", update);

schedule.run(&mut world);
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/examples/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ fn main() {
// called "second". In "first" we update the events and in "second" we run our systems
// sending and receiving events.
let mut first = SystemStage::parallel();
first.add_system(Events::<MyEvent>::update_system.system());
first.add_system(Events::<MyEvent>::update_system);
schedule.add_stage("first", first);

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

// 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 Down
Loading