Skip to content

Commit 6d6bc2a

Browse files
bjorn3cart
andcommitted
Merge AppBuilder into App (bevyengine#2531)
This is extracted out of eb8f973 and includes some additional changes to remove all references to AppBuilder and fix examples that still used App::build() instead of App::new(). In addition I didn't extract the sub app feature as it isn't ready yet. You can use `git diff --diff-filter=M eb8f973` to find all differences in this PR. The `--diff-filtered=M` filters all files added in the original commit but not in this commit away. Co-Authored-By: Carter Anderson <[email protected]>
1 parent c83a184 commit 6d6bc2a

File tree

130 files changed

+712
-764
lines changed

Some content is hidden

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

130 files changed

+712
-764
lines changed

crates/bevy_app/src/app.rs

+525-16
Large diffs are not rendered by default.

crates/bevy_app/src/app_builder.rs

-559
This file was deleted.

crates/bevy_app/src/ci_testing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::Deserialize;
22

3-
use crate::{app::AppExit, AppBuilder};
3+
use crate::{app::AppExit, App};
44
use bevy_ecs::system::IntoSystem;
55

66
/// Configuration for automated testing on CI
@@ -23,7 +23,7 @@ fn ci_testing_exit_after(
2323
*current_frame += 1;
2424
}
2525

26-
pub(crate) fn setup_app(app_builder: &mut AppBuilder) -> &mut AppBuilder {
26+
pub(crate) fn setup_app(app_builder: &mut App) -> &mut App {
2727
let filename =
2828
std::env::var("CI_TESTING_CONFIG").unwrap_or_else(|_| "ci_testing_config.ron".to_string());
2929
let config: CiTestingConfig = ron::from_str(

crates/bevy_app/src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
mod app;
2-
mod app_builder;
32
mod plugin;
43
mod plugin_group;
54
mod schedule_runner;
@@ -8,7 +7,6 @@ mod schedule_runner;
87
mod ci_testing;
98

109
pub use app::*;
11-
pub use app_builder::*;
1210
pub use bevy_derive::DynamicPlugin;
1311
pub use bevy_ecs::event::*;
1412
pub use plugin::*;
@@ -17,10 +15,7 @@ pub use schedule_runner::*;
1715

1816
pub mod prelude {
1917
#[doc(hidden)]
20-
pub use crate::{
21-
app::App, app_builder::AppBuilder, CoreStage, DynamicPlugin, Plugin, PluginGroup,
22-
StartupStage,
23-
};
18+
pub use crate::{app::App, CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupStage};
2419
}
2520

2621
use bevy_ecs::schedule::StageLabel;

crates/bevy_app/src/plugin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use crate::AppBuilder;
1+
use crate::App;
22
use std::any::Any;
33

44
/// A collection of Bevy App logic and configuration
55
///
6-
/// Plugins use [AppBuilder] to configure an [App](crate::App). When an [App](crate::App) registers
6+
/// Plugins configure an [App](crate::App). When an [App](crate::App) registers
77
/// a plugin, the plugin's [Plugin::build] function is run.
88
pub trait Plugin: Any + Send + Sync {
9-
fn build(&self, app: &mut AppBuilder);
9+
fn build(&self, app: &mut App);
1010
fn name(&self) -> &str {
1111
std::any::type_name::<Self>()
1212
}

crates/bevy_app/src/plugin_group.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{AppBuilder, Plugin};
1+
use crate::{App, Plugin};
22
use bevy_utils::{tracing::debug, HashMap};
33
use std::any::TypeId;
44

@@ -96,7 +96,7 @@ impl PluginGroupBuilder {
9696
self
9797
}
9898

99-
pub fn finish(self, app: &mut AppBuilder) {
99+
pub fn finish(self, app: &mut App) {
100100
for ty in self.order.iter() {
101101
if let Some(entry) = self.plugins.get(ty) {
102102
if entry.enabled {

crates/bevy_app/src/schedule_runner.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
use super::{App, AppBuilder};
2-
use crate::{app::AppExit, plugin::Plugin, ManualEventReader};
1+
use crate::{
2+
app::{App, AppExit},
3+
plugin::Plugin,
4+
ManualEventReader,
5+
};
36
use bevy_ecs::event::Events;
47
use bevy_utils::{Duration, Instant};
58

@@ -48,9 +51,9 @@ impl ScheduleRunnerSettings {
4851
pub struct ScheduleRunnerPlugin {}
4952

5053
impl Plugin for ScheduleRunnerPlugin {
51-
fn build(&self, app: &mut AppBuilder) {
54+
fn build(&self, app: &mut App) {
5255
let settings = app
53-
.world_mut()
56+
.world
5457
.get_resource_or_insert_with(ScheduleRunnerSettings::default)
5558
.to_owned();
5659
app.set_runner(move |mut app: App| {

crates/bevy_asset/src/assets.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
update_asset_storage_system, Asset, AssetLoader, AssetServer, AssetStage, Handle, HandleId,
33
RefChange,
44
};
5-
use bevy_app::{AppBuilder, EventWriter, Events};
5+
use bevy_app::{App, EventWriter, Events};
66
use bevy_ecs::{
77
system::{IntoSystem, ResMut},
88
world::FromWorld,
@@ -193,7 +193,7 @@ impl<T: Asset> Assets<T> {
193193
}
194194
}
195195

196-
/// [AppBuilder] extension methods for adding new asset types
196+
/// [App] extension methods for adding new asset types
197197
pub trait AddAsset {
198198
fn add_asset<T>(&mut self) -> &mut Self
199199
where
@@ -206,13 +206,13 @@ pub trait AddAsset {
206206
T: AssetLoader;
207207
}
208208

209-
impl AddAsset for AppBuilder {
209+
impl AddAsset for App {
210210
fn add_asset<T>(&mut self) -> &mut Self
211211
where
212212
T: Asset,
213213
{
214214
let assets = {
215-
let asset_server = self.world().get_resource::<AssetServer>().unwrap();
215+
let asset_server = self.world.get_resource::<AssetServer>().unwrap();
216216
asset_server.register_asset_type::<T>()
217217
};
218218

@@ -233,15 +233,15 @@ impl AddAsset for AppBuilder {
233233
where
234234
T: AssetLoader + FromWorld,
235235
{
236-
let result = T::from_world(self.world_mut());
236+
let result = T::from_world(&mut self.world);
237237
self.add_asset_loader(result)
238238
}
239239

240240
fn add_asset_loader<T>(&mut self, loader: T) -> &mut Self
241241
where
242242
T: AssetLoader,
243243
{
244-
self.world_mut()
244+
self.world
245245
.get_resource_mut::<AssetServer>()
246246
.expect("AssetServer does not exist. Consider adding it as a resource.")
247247
.add_loader(loader);

crates/bevy_asset/src/diagnostic/asset_count_diagnostics_plugin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<T: Asset> Default for AssetCountDiagnosticsPlugin<T> {
1717
}
1818

1919
impl<T: Asset> Plugin for AssetCountDiagnosticsPlugin<T> {
20-
fn build(&self, app: &mut AppBuilder) {
20+
fn build(&self, app: &mut App) {
2121
app.add_startup_system(Self::setup_system.system())
2222
.add_system(Self::diagnostic_system.system());
2323
}

crates/bevy_asset/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use io::*;
2626
pub use loader::*;
2727
pub use path::*;
2828

29-
use bevy_app::{prelude::Plugin, AppBuilder};
29+
use bevy_app::{prelude::Plugin, App};
3030
use bevy_ecs::{
3131
schedule::{StageLabel, SystemStage},
3232
system::IntoSystem,
@@ -61,9 +61,9 @@ impl Default for AssetServerSettings {
6161
///
6262
/// This is useful when providing a custom `AssetIo` instance that needs to
6363
/// delegate to the default `AssetIo` for the platform.
64-
pub fn create_platform_default_asset_io(app: &mut AppBuilder) -> Box<dyn AssetIo> {
64+
pub fn create_platform_default_asset_io(app: &mut App) -> Box<dyn AssetIo> {
6565
let settings = app
66-
.world_mut()
66+
.world
6767
.get_resource_or_insert_with(AssetServerSettings::default);
6868

6969
#[cfg(all(not(target_arch = "wasm32"), not(target_os = "android")))]
@@ -77,10 +77,10 @@ pub fn create_platform_default_asset_io(app: &mut AppBuilder) -> Box<dyn AssetIo
7777
}
7878

7979
impl Plugin for AssetPlugin {
80-
fn build(&self, app: &mut AppBuilder) {
81-
if app.world().get_resource::<AssetServer>().is_none() {
80+
fn build(&self, app: &mut App) {
81+
if app.world.get_resource::<AssetServer>().is_none() {
8282
let task_pool = app
83-
.world()
83+
.world
8484
.get_resource::<IoTaskPool>()
8585
.expect("`IoTaskPool` resource not found.")
8686
.0

crates/bevy_audio/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use bevy_ecs::system::IntoExclusiveSystem;
2020
pub struct AudioPlugin;
2121

2222
impl Plugin for AudioPlugin {
23-
fn build(&self, app: &mut AppBuilder) {
23+
fn build(&self, app: &mut App) {
2424
app.init_non_send_resource::<AudioOutput<AudioSource>>()
2525
.add_asset::<AudioSource>()
2626
.init_resource::<Audio<AudioSource>>()

crates/bevy_core/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ pub enum CoreSystem {
3838
}
3939

4040
impl Plugin for CorePlugin {
41-
fn build(&self, app: &mut AppBuilder) {
41+
fn build(&self, app: &mut App) {
4242
// Setup the default bevy task pools
43-
app.world_mut()
43+
app.world
4444
.get_resource::<DefaultTaskPoolOptions>()
4545
.cloned()
4646
.unwrap_or_else(DefaultTaskPoolOptions::default)
47-
.create_default_pools(app.world_mut());
47+
.create_default_pools(&mut app.world);
4848

4949
app.init_resource::<Time>()
5050
.init_resource::<EntityLabels>()
@@ -70,7 +70,7 @@ impl Plugin for CorePlugin {
7070
}
7171
}
7272

73-
fn register_rust_types(app: &mut AppBuilder) {
73+
fn register_rust_types(app: &mut App) {
7474
app.register_type::<bool>()
7575
.register_type::<u8>()
7676
.register_type::<u16>()
@@ -90,7 +90,7 @@ fn register_rust_types(app: &mut AppBuilder) {
9090
.register_type::<Option<String>>();
9191
}
9292

93-
fn register_math_types(app: &mut AppBuilder) {
93+
fn register_math_types(app: &mut App) {
9494
app.register_type::<bevy_math::IVec2>()
9595
.register_type::<bevy_math::IVec3>()
9696
.register_type::<bevy_math::IVec4>()

crates/bevy_diagnostic/src/entity_count_diagnostics_plugin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bevy_app::{AppBuilder, Plugin};
1+
use bevy_app::{App, Plugin};
22
use bevy_ecs::{
33
system::{IntoExclusiveSystem, IntoSystem, ResMut},
44
world::World,
@@ -11,7 +11,7 @@ use crate::{Diagnostic, DiagnosticId, Diagnostics};
1111
pub struct EntityCountDiagnosticsPlugin;
1212

1313
impl Plugin for EntityCountDiagnosticsPlugin {
14-
fn build(&self, app: &mut AppBuilder) {
14+
fn build(&self, app: &mut App) {
1515
app.add_startup_system(Self::setup_system.system())
1616
.add_system(Self::diagnostic_system.exclusive_system());
1717
}

crates/bevy_diagnostic/src/frame_time_diagnostics_plugin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct FrameTimeDiagnosticsState {
1212
}
1313

1414
impl Plugin for FrameTimeDiagnosticsPlugin {
15-
fn build(&self, app: &mut bevy_app::AppBuilder) {
15+
fn build(&self, app: &mut bevy_app::App) {
1616
app.add_startup_system(Self::setup_system.system())
1717
.insert_resource(FrameTimeDiagnosticsState { frame_count: 0.0 })
1818
.add_system(Self::diagnostic_system.system());

crates/bevy_diagnostic/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use bevy_app::prelude::*;
1414
pub struct DiagnosticsPlugin;
1515

1616
impl Plugin for DiagnosticsPlugin {
17-
fn build(&self, app: &mut AppBuilder) {
17+
fn build(&self, app: &mut App) {
1818
app.init_resource::<Diagnostics>();
1919
}
2020
}

crates/bevy_diagnostic/src/log_diagnostics_plugin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Default for LogDiagnosticsPlugin {
2929
}
3030

3131
impl Plugin for LogDiagnosticsPlugin {
32-
fn build(&self, app: &mut bevy_app::AppBuilder) {
32+
fn build(&self, app: &mut App) {
3333
app.insert_resource(LogDiagnosticsState {
3434
timer: Timer::new(self.wait_duration, true),
3535
filter: self.filter.clone(),

crates/bevy_dynamic_plugin/src/loader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use libloading::{Library, Symbol};
22

3-
use bevy_app::{AppBuilder, CreatePlugin, Plugin};
3+
use bevy_app::{App, CreatePlugin, Plugin};
44

55
/// Dynamically links a plugin a the given path. The plugin must export a function with the
66
/// [`CreatePlugin`] signature named `_bevy_create_plugin`.
@@ -24,7 +24,7 @@ pub trait DynamicPluginExt {
2424
unsafe fn load_plugin(&mut self, path: &str) -> &mut Self;
2525
}
2626

27-
impl DynamicPluginExt for AppBuilder {
27+
impl DynamicPluginExt for App {
2828
unsafe fn load_plugin(&mut self, path: &str) -> &mut Self {
2929
let (lib, plugin) = dynamically_load_plugin(path);
3030
std::mem::forget(lib); // Ensure that the library is not automatically unloaded

crates/bevy_ecs/src/event.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ enum State {
6868
/// [`Events::update`] exactly once per update/frame.
6969
///
7070
/// [`Events::update_system`] is a system that does this, typically intialized automatically using
71-
/// [`AppBuilder::add_event`]. [EventReader]s are expected to read events from this collection at
71+
/// [`App::add_event`]. [EventReader]s are expected to read events from this collection at
7272
/// least once per loop/frame.
7373
/// Events will persist across a single frame boundary and so ordering of event producers and
7474
/// consumers is not critical (although poorly-planned ordering may cause accumulating lag).
@@ -115,9 +115,9 @@ enum State {
115115
/// An alternative call pattern would be to call [Events::update] manually across frames to control
116116
/// when events are cleared.
117117
/// This complicates consumption and risks ever-expanding memory usage if not cleaned up,
118-
/// but can be done by adding your event as a resource instead of using [`AppBuilder::add_event`].
118+
/// but can be done by adding your event as a resource instead of using [`App::add_event`].
119119
///
120-
/// [`AppBuilder::add_event`]: https://docs.rs/bevy/*/bevy/app/struct.AppBuilder.html#method.add_event
120+
/// [`App::add_event`]: https://docs.rs/bevy/*/bevy/app/struct.App.html#method.add_event
121121
#[derive(Debug)]
122122
pub struct Events<T> {
123123
events_a: Vec<EventInstance<T>>,

crates/bevy_ecs/src/schedule/stage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub trait Stage: Downcast + Send + Sync {
2626

2727
impl_downcast!(Stage);
2828

29-
/// When this resource is present in the `AppBuilder`'s `Resources`,
29+
/// When this resource is present in the `App`'s `Resources`,
3030
/// each `SystemStage` will log a report containing
3131
/// pairs of systems with ambiguous execution order.
3232
///

crates/bevy_ecs/src/system/system.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl SystemId {
2424
///
2525
/// Systems are functions with all arguments implementing [SystemParam](crate::system::SystemParam).
2626
///
27-
/// Systems are added to an application using `AppBuilder::add_system(my_system.system())`
27+
/// Systems are added to an application using `App::add_system(my_system.system())`
2828
/// or similar methods, and will generally run once per pass of the main loop.
2929
///
3030
/// Systems are executed in parallel, in opportunistic order; data access is managed automatically.

crates/bevy_gilrs/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod converter;
22
mod gilrs_system;
33

4-
use bevy_app::{AppBuilder, CoreStage, Plugin, StartupStage};
4+
use bevy_app::{App, CoreStage, Plugin, StartupStage};
55
use bevy_ecs::system::IntoExclusiveSystem;
66
use bevy_utils::tracing::error;
77
use gilrs::GilrsBuilder;
@@ -11,7 +11,7 @@ use gilrs_system::{gilrs_event_startup_system, gilrs_event_system};
1111
pub struct GilrsPlugin;
1212

1313
impl Plugin for GilrsPlugin {
14-
fn build(&self, app: &mut AppBuilder) {
14+
fn build(&self, app: &mut App) {
1515
match GilrsBuilder::new()
1616
.with_default_filters(false)
1717
.set_update_state(false)

crates/bevy_gltf/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use bevy_scene::Scene;
1515
pub struct GltfPlugin;
1616

1717
impl Plugin for GltfPlugin {
18-
fn build(&self, app: &mut AppBuilder) {
18+
fn build(&self, app: &mut App) {
1919
app.init_asset_loader::<GltfLoader>()
2020
.add_asset::<Gltf>()
2121
.add_asset::<GltfNode>()

crates/bevy_input/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct InputPlugin;
4545
pub struct InputSystem;
4646

4747
impl Plugin for InputPlugin {
48-
fn build(&self, app: &mut AppBuilder) {
48+
fn build(&self, app: &mut App) {
4949
app
5050
// keyboard
5151
.add_event::<KeyboardInput>()

0 commit comments

Comments
 (0)