Skip to content

[Merged by Bors] - Remove App::add_sub_app #7290

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 19 additions & 28 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct App {
/// The main ECS [`World`] of the [`App`].
/// This stores and provides access to all the main data of the application.
/// The systems of the [`App`] will run using this [`World`].
/// If additional separate [`World`]-[`Schedule`] pairs are needed, you can use [`sub_app`](App::add_sub_app)s.
/// If additional separate [`World`]-[`Schedule`] pairs are needed, you can use [`sub_app`](App::insert_sub_app)s.
pub world: World,
/// The [runner function](Self::set_runner) is primarily responsible for managing
/// the application's event loop and advancing the [`Schedule`].
Expand Down Expand Up @@ -94,7 +94,7 @@ impl Debug for App {
/// # Example
///
/// ```rust
/// # use bevy_app::{App, AppLabel};
/// # use bevy_app::{App, AppLabel, SubApp};
/// # use bevy_ecs::prelude::*;
///
/// #[derive(Resource, Default)]
Expand Down Expand Up @@ -122,9 +122,9 @@ impl Debug for App {
/// sub_app.add_stage(ExampleStage, example_stage);
///
/// // add the sub_app to the app
/// app.add_sub_app(ExampleApp, sub_app, |main_world, sub_app| {
/// app.insert_sub_app(ExampleApp, SubApp::new(sub_app, |main_world, sub_app| {
/// sub_app.world.resource_mut::<Val>().0 = main_world.resource::<Val>().0;
/// });
/// }));
///
/// // This will run the schedules once, since we're using the default runner
/// app.run();
Expand All @@ -135,10 +135,23 @@ pub struct SubApp {

/// A function that allows access to both the [`SubApp`] [`World`] and the main [`App`]. This is
/// useful for moving data between the sub app and the main app.
pub extract: Box<dyn Fn(&mut World, &mut App) + Send>,
extract: Box<dyn Fn(&mut World, &mut App) + Send>,
}

impl SubApp {
/// Creates a new [`SubApp`].
///
/// The provided function `extract` is normally called by the [`update`](App::update) method.
/// After extract is called, the [`Schedule`] of the sub app is run. The [`World`]
/// parameter represents the main app world, while the [`App`] parameter is just a mutable
/// reference to the `SubApp` itself.
pub fn new(app: App, extract: impl Fn(&mut World, &mut App) + Send + 'static) -> Self {
Self {
app,
extract: Box::new(extract),
}
}

/// Runs the `SubApp`'s schedule.
pub fn run(&mut self) {
self.app.schedule.run(&mut self.app.world);
Expand Down Expand Up @@ -204,7 +217,7 @@ impl App {
///
/// This method also updates sub apps.
///
/// See [`add_sub_app`](Self::add_sub_app) and [`run_once`](Schedule::run_once) for more details.
/// See [`insert_sub_app`](Self::insert_sub_app) and [`run_once`](Schedule::run_once) for more details.
pub fn update(&mut self) {
{
#[cfg(feature = "trace")]
Expand Down Expand Up @@ -1081,28 +1094,6 @@ impl App {
self
}

/// Adds an [`App`] as a child of the current one.
///
/// The provided function `extract` is normally called by the [`update`](Self::update) method.
/// After extract is called, the [`Schedule`] of the sub app is run. The [`World`]
/// parameter represents the main app world, while the [`App`] parameter is just a mutable
/// reference to the `SubApp` itself.
pub fn add_sub_app(
&mut self,
label: impl AppLabel,
app: App,
extract: impl Fn(&mut World, &mut App) + 'static + Send,
) -> &mut Self {
self.sub_apps.insert(
label.as_label(),
SubApp {
app,
extract: Box::new(extract),
},
);
self
}

/// Retrieves a `SubApp` stored inside this [`App`].
///
/// # Panics
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use crate::{
settings::WgpuSettings,
view::{ViewPlugin, WindowRenderPlugin},
};
use bevy_app::{App, AppLabel, Plugin};
use bevy_app::{App, AppLabel, Plugin, SubApp};
use bevy_asset::{AddAsset, AssetServer};
use bevy_ecs::{prelude::*, system::SystemState};
use bevy_utils::tracing::debug;
Expand Down Expand Up @@ -231,7 +231,7 @@ impl Plugin for RenderPlugin {
app.insert_resource(receiver);
render_app.insert_resource(sender);

app.add_sub_app(RenderApp, render_app, move |app_world, render_app| {
app.insert_sub_app(RenderApp, SubApp::new(render_app, move |app_world, render_app| {
#[cfg(feature = "trace")]
let _render_span = bevy_utils::tracing::info_span!("extract main app to render subapp").entered();
{
Expand Down Expand Up @@ -267,7 +267,7 @@ impl Plugin for RenderPlugin {
// extract
extract(app_world, render_app);
}
});
}));
}

app.add_plugin(ValidParentCheckPlugin::<view::ComputedVisibility>::default())
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/pipelined_rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Plugin for PipelinedRenderingPlugin {
RenderExtractStage::BeforeIoAfterRenderStart,
SystemStage::parallel(),
);
app.add_sub_app(RenderExtractApp, sub_app, update_rendering);
app.insert_sub_app(RenderExtractApp, SubApp::new(sub_app, update_rendering));
}

// Sets up the render thread and inserts resources into the main app used for controlling the render thread.
Expand Down