Skip to content

Commit

Permalink
Merge AppBuilder into App
Browse files Browse the repository at this point in the history
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 <mcanders1@gmail.com>
  • Loading branch information
bjorn3 and cart committed Jul 24, 2021
1 parent e167a1d commit b256c0e
Show file tree
Hide file tree
Showing 130 changed files with 712 additions and 764 deletions.
541 changes: 525 additions & 16 deletions crates/bevy_app/src/app.rs

Large diffs are not rendered by default.

559 changes: 0 additions & 559 deletions crates/bevy_app/src/app_builder.rs

This file was deleted.

4 changes: 2 additions & 2 deletions crates/bevy_app/src/ci_testing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::Deserialize;

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

/// Configuration for automated testing on CI
Expand All @@ -23,7 +23,7 @@ fn ci_testing_exit_after(
*current_frame += 1;
}

pub(crate) fn setup_app(app_builder: &mut AppBuilder) -> &mut AppBuilder {
pub(crate) fn setup_app(app_builder: &mut App) -> &mut App {
let filename =
std::env::var("CI_TESTING_CONFIG").unwrap_or_else(|_| "ci_testing_config.ron".to_string());
let config: CiTestingConfig = ron::from_str(
Expand Down
7 changes: 1 addition & 6 deletions crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod app;
mod app_builder;
mod plugin;
mod plugin_group;
mod schedule_runner;
Expand All @@ -8,7 +7,6 @@ mod schedule_runner;
mod ci_testing;

pub use app::*;
pub use app_builder::*;
pub use bevy_derive::DynamicPlugin;
pub use bevy_ecs::event::*;
pub use plugin::*;
Expand All @@ -17,10 +15,7 @@ pub use schedule_runner::*;

pub mod prelude {
#[doc(hidden)]
pub use crate::{
app::App, app_builder::AppBuilder, CoreStage, DynamicPlugin, Plugin, PluginGroup,
StartupStage,
};
pub use crate::{app::App, CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupStage};
}

use bevy_ecs::schedule::StageLabel;
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_app/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::AppBuilder;
use crate::App;
use std::any::Any;

/// A collection of Bevy App logic and configuration
///
/// Plugins use [AppBuilder] to configure an [App](crate::App). When an [App](crate::App) registers
/// Plugins configure an [App](crate::App). When an [App](crate::App) registers
/// a plugin, the plugin's [Plugin::build] function is run.
pub trait Plugin: Any + Send + Sync {
fn build(&self, app: &mut AppBuilder);
fn build(&self, app: &mut App);
fn name(&self) -> &str {
std::any::type_name::<Self>()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_app/src/plugin_group.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{AppBuilder, Plugin};
use crate::{App, Plugin};
use bevy_utils::{tracing::debug, HashMap};
use std::any::TypeId;

Expand Down Expand Up @@ -96,7 +96,7 @@ impl PluginGroupBuilder {
self
}

pub fn finish(self, app: &mut AppBuilder) {
pub fn finish(self, app: &mut App) {
for ty in self.order.iter() {
if let Some(entry) = self.plugins.get(ty) {
if entry.enabled {
Expand Down
11 changes: 7 additions & 4 deletions crates/bevy_app/src/schedule_runner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::{App, AppBuilder};
use crate::{app::AppExit, plugin::Plugin, ManualEventReader};
use crate::{
app::{App, AppExit},
plugin::Plugin,
ManualEventReader,
};
use bevy_ecs::event::Events;
use bevy_utils::{Duration, Instant};

Expand Down Expand Up @@ -48,9 +51,9 @@ impl ScheduleRunnerSettings {
pub struct ScheduleRunnerPlugin {}

impl Plugin for ScheduleRunnerPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
let settings = app
.world_mut()
.world
.get_resource_or_insert_with(ScheduleRunnerSettings::default)
.to_owned();
app.set_runner(move |mut app: App| {
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
update_asset_storage_system, Asset, AssetLoader, AssetServer, AssetStage, Handle, HandleId,
RefChange,
};
use bevy_app::{AppBuilder, EventWriter, Events};
use bevy_app::{App, EventWriter, Events};
use bevy_ecs::{
system::{IntoSystem, ResMut},
world::FromWorld,
Expand Down Expand Up @@ -193,7 +193,7 @@ impl<T: Asset> Assets<T> {
}
}

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

impl AddAsset for AppBuilder {
impl AddAsset for App {
fn add_asset<T>(&mut self) -> &mut Self
where
T: Asset,
{
let assets = {
let asset_server = self.world().get_resource::<AssetServer>().unwrap();
let asset_server = self.world.get_resource::<AssetServer>().unwrap();
asset_server.register_asset_type::<T>()
};

Expand All @@ -233,15 +233,15 @@ impl AddAsset for AppBuilder {
where
T: AssetLoader + FromWorld,
{
let result = T::from_world(self.world_mut());
let result = T::from_world(&mut self.world);
self.add_asset_loader(result)
}

fn add_asset_loader<T>(&mut self, loader: T) -> &mut Self
where
T: AssetLoader,
{
self.world_mut()
self.world
.get_resource_mut::<AssetServer>()
.expect("AssetServer does not exist. Consider adding it as a resource.")
.add_loader(loader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<T: Asset> Default for AssetCountDiagnosticsPlugin<T> {
}

impl<T: Asset> Plugin for AssetCountDiagnosticsPlugin<T> {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.add_startup_system(Self::setup_system.system())
.add_system(Self::diagnostic_system.system());
}
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use io::*;
pub use loader::*;
pub use path::*;

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

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

impl Plugin for AssetPlugin {
fn build(&self, app: &mut AppBuilder) {
if app.world().get_resource::<AssetServer>().is_none() {
fn build(&self, app: &mut App) {
if app.world.get_resource::<AssetServer>().is_none() {
let task_pool = app
.world()
.world
.get_resource::<IoTaskPool>()
.expect("`IoTaskPool` resource not found.")
.0
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_audio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use bevy_ecs::system::IntoExclusiveSystem;
pub struct AudioPlugin;

impl Plugin for AudioPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.init_non_send_resource::<AudioOutput<AudioSource>>()
.add_asset::<AudioSource>()
.init_resource::<Audio<AudioSource>>()
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ pub enum CoreSystem {
}

impl Plugin for CorePlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
// Setup the default bevy task pools
app.world_mut()
app.world
.get_resource::<DefaultTaskPoolOptions>()
.cloned()
.unwrap_or_else(DefaultTaskPoolOptions::default)
.create_default_pools(app.world_mut());
.create_default_pools(&mut app.world);

app.init_resource::<Time>()
.init_resource::<EntityLabels>()
Expand All @@ -70,7 +70,7 @@ impl Plugin for CorePlugin {
}
}

fn register_rust_types(app: &mut AppBuilder) {
fn register_rust_types(app: &mut App) {
app.register_type::<bool>()
.register_type::<u8>()
.register_type::<u16>()
Expand All @@ -90,7 +90,7 @@ fn register_rust_types(app: &mut AppBuilder) {
.register_type::<Option<String>>();
}

fn register_math_types(app: &mut AppBuilder) {
fn register_math_types(app: &mut App) {
app.register_type::<bevy_math::IVec2>()
.register_type::<bevy_math::IVec3>()
.register_type::<bevy_math::IVec4>()
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,4 +1,4 @@
use bevy_app::{AppBuilder, Plugin};
use bevy_app::{App, Plugin};
use bevy_ecs::{
system::{IntoExclusiveSystem, IntoSystem, ResMut},
world::World,
Expand All @@ -11,7 +11,7 @@ use crate::{Diagnostic, DiagnosticId, Diagnostics};
pub struct EntityCountDiagnosticsPlugin;

impl Plugin for EntityCountDiagnosticsPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.add_startup_system(Self::setup_system.system())
.add_system(Self::diagnostic_system.exclusive_system());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct FrameTimeDiagnosticsState {
}

impl Plugin for FrameTimeDiagnosticsPlugin {
fn build(&self, app: &mut bevy_app::AppBuilder) {
fn build(&self, app: &mut bevy_app::App) {
app.add_startup_system(Self::setup_system.system())
.insert_resource(FrameTimeDiagnosticsState { frame_count: 0.0 })
.add_system(Self::diagnostic_system.system());
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_diagnostic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bevy_app::prelude::*;
pub struct DiagnosticsPlugin;

impl Plugin for DiagnosticsPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.init_resource::<Diagnostics>();
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_diagnostic/src/log_diagnostics_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Default for LogDiagnosticsPlugin {
}

impl Plugin for LogDiagnosticsPlugin {
fn build(&self, app: &mut bevy_app::AppBuilder) {
fn build(&self, app: &mut App) {
app.insert_resource(LogDiagnosticsState {
timer: Timer::new(self.wait_duration, true),
filter: self.filter.clone(),
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_dynamic_plugin/src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use libloading::{Library, Symbol};

use bevy_app::{AppBuilder, CreatePlugin, Plugin};
use bevy_app::{App, CreatePlugin, Plugin};

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

impl DynamicPluginExt for AppBuilder {
impl DynamicPluginExt for App {
unsafe fn load_plugin(&mut self, path: &str) -> &mut Self {
let (lib, plugin) = dynamically_load_plugin(path);
std::mem::forget(lib); // Ensure that the library is not automatically unloaded
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ enum State {
/// [`Events::update`] exactly once per update/frame.
///
/// [`Events::update_system`] is a system that does this, typically intialized automatically using
/// [`AppBuilder::add_event`]. [EventReader]s are expected to read events from this collection at
/// [`App::add_event`]. [EventReader]s are expected to read events from this collection at
/// least once per loop/frame.
/// Events will persist across a single frame boundary and so ordering of event producers and
/// consumers is not critical (although poorly-planned ordering may cause accumulating lag).
Expand Down Expand Up @@ -115,9 +115,9 @@ enum State {
/// An alternative call pattern would be to call [Events::update] manually across frames to control
/// when events are cleared.
/// This complicates consumption and risks ever-expanding memory usage if not cleaned up,
/// but can be done by adding your event as a resource instead of using [`AppBuilder::add_event`].
/// but can be done by adding your event as a resource instead of using [`App::add_event`].
///
/// [`AppBuilder::add_event`]: https://docs.rs/bevy/*/bevy/app/struct.AppBuilder.html#method.add_event
/// [`App::add_event`]: https://docs.rs/bevy/*/bevy/app/struct.App.html#method.add_event
#[derive(Debug)]
pub struct Events<T> {
events_a: Vec<EventInstance<T>>,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/schedule/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub trait Stage: Downcast + Send + Sync {

impl_downcast!(Stage);

/// When this resource is present in the `AppBuilder`'s `Resources`,
/// When this resource is present in the `App`'s `Resources`,
/// each `SystemStage` will log a report containing
/// pairs of systems with ambiguous execution order.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/system/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl SystemId {
///
/// Systems are functions with all arguments implementing [SystemParam](crate::system::SystemParam).
///
/// Systems are added to an application using `AppBuilder::add_system(my_system.system())`
/// Systems are added to an application using `App::add_system(my_system.system())`
/// or similar methods, and will generally run once per pass of the main loop.
///
/// Systems are executed in parallel, in opportunistic order; data access is managed automatically.
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_gilrs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod converter;
mod gilrs_system;

use bevy_app::{AppBuilder, CoreStage, Plugin, StartupStage};
use bevy_app::{App, CoreStage, Plugin, StartupStage};
use bevy_ecs::system::IntoExclusiveSystem;
use bevy_utils::tracing::error;
use gilrs::GilrsBuilder;
Expand All @@ -11,7 +11,7 @@ use gilrs_system::{gilrs_event_startup_system, gilrs_event_system};
pub struct GilrsPlugin;

impl Plugin for GilrsPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
match GilrsBuilder::new()
.with_default_filters(false)
.set_update_state(false)
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gltf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bevy_scene::Scene;
pub struct GltfPlugin;

impl Plugin for GltfPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.init_asset_loader::<GltfLoader>()
.add_asset::<Gltf>()
.add_asset::<GltfNode>()
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_input/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct InputPlugin;
pub struct InputSystem;

impl Plugin for InputPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app
// keyboard
.add_event::<KeyboardInput>()
Expand Down
Loading

0 comments on commit b256c0e

Please sign in to comment.