Skip to content

[Merged by Bors] - make sub_app return an &App and add sub_app_mut() -> &mut App #3309

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
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
23 changes: 20 additions & 3 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,21 +854,38 @@ impl App {
}

/// Retrieves a "sub app" stored inside this [App]. This will panic if the sub app does not exist.
pub fn sub_app(&mut self, label: impl AppLabel) -> &mut App {
match self.get_sub_app(label) {
pub fn sub_app_mut(&mut self, label: impl AppLabel) -> &mut App {
match self.get_sub_app_mut(label) {
Ok(app) => app,
Err(label) => panic!("Sub-App with label '{:?}' does not exist", label),
}
}

/// Retrieves a "sub app" inside this [App] with the given label, if it exists. Otherwise returns
/// an [Err] containing the given label.
pub fn get_sub_app(&mut self, label: impl AppLabel) -> Result<&mut App, impl AppLabel> {
pub fn get_sub_app_mut(&mut self, label: impl AppLabel) -> Result<&mut App, impl AppLabel> {
self.sub_apps
.get_mut((&label) as &dyn AppLabel)
.map(|sub_app| &mut sub_app.app)
.ok_or(label)
}

/// Retrieves a "sub app" stored inside this [App]. This will panic if the sub app does not exist.
pub fn sub_app(&self, label: impl AppLabel) -> &App {
match self.get_sub_app(label) {
Ok(app) => app,
Err(label) => panic!("Sub-App with label '{:?}' does not exist", label),
}
}

/// Retrieves a "sub app" inside this [App] with the given label, if it exists. Otherwise returns
/// an [Err] containing the given label.
pub fn get_sub_app(&self, label: impl AppLabel) -> Result<&App, impl AppLabel> {
self.sub_apps
.get((&label) as &dyn AppLabel)
.map(|sub_app| &sub_app.app)
.ok_or(label)
}
}

fn run_once(mut app: App) {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_core_pipeline/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Plugin for CorePipelinePlugin {
fn build(&self, app: &mut App) {
app.init_resource::<ClearColor>();

let render_app = app.sub_app(RenderApp);
let render_app = app.sub_app_mut(RenderApp);
render_app
.init_resource::<DrawFunctions<Transparent2d>>()
.init_resource::<DrawFunctions<Opaque3d>>()
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Plugin for PbrPlugin {
},
);

let render_app = app.sub_app(RenderApp);
let render_app = app.sub_app_mut(RenderApp);
render_app
.add_system_to_stage(
RenderStage::Extract,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Plugin for MeshRenderPlugin {

app.add_plugin(UniformComponentPlugin::<MeshUniform>::default());

app.sub_app(RenderApp)
app.sub_app_mut(RenderApp)
.init_resource::<MeshPipeline>()
.add_system_to_stage(RenderStage::Extract, extract_meshes)
.add_system_to_stage(RenderStage::Queue, queue_mesh_bind_group)
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/wireframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Plugin for WireframePlugin {

app.init_resource::<WireframeConfig>();

app.sub_app(RenderApp)
app.sub_app_mut(RenderApp)
.add_render_command::<Opaque3d, DrawWireframes>()
.init_resource::<WireframePipeline>()
.init_resource::<SpecializedPipelines<WireframePipeline>>()
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/camera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Plugin for CameraPlugin {
CoreStage::PostUpdate,
crate::camera::camera_system::<PerspectiveProjection>,
);
app.sub_app(RenderApp)
app.sub_app_mut(RenderApp)
.init_resource::<ExtractedCameraNames>()
.add_system_to_stage(RenderStage::Extract, extract_cameras);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/render_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<A: RenderAsset> Default for RenderAssetPlugin<A> {

impl<A: RenderAsset> Plugin for RenderAssetPlugin<A> {
fn build(&self, app: &mut App) {
let render_app = app.sub_app(RenderApp);
let render_app = app.sub_app_mut(RenderApp);
let prepare_asset_system = PrepareAssetSystem::<A>::system(&mut render_app.world);
render_app
.init_resource::<ExtractedAssets<A>>()
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/render_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<C> Default for UniformComponentPlugin<C> {

impl<C: Component + AsStd140 + Clone> Plugin for UniformComponentPlugin<C> {
fn build(&self, app: &mut App) {
app.sub_app(RenderApp)
app.sub_app_mut(RenderApp)
.insert_resource(ComponentUniforms::<C>::default())
.add_system_to_stage(
RenderStage::Prepare,
Expand Down Expand Up @@ -145,7 +145,7 @@ where
{
fn build(&self, app: &mut App) {
let system = ExtractComponentSystem::<C>::system(&mut app.world);
let render_app = app.sub_app(RenderApp);
let render_app = app.sub_app_mut(RenderApp);
render_app.add_system_to_stage(RenderStage::Extract, system);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Plugin for ImagePlugin {
.unwrap()
.set_untracked(DEFAULT_IMAGE_HANDLE, Image::default());

app.sub_app(RenderApp)
app.sub_app_mut(RenderApp)
.init_resource::<TextureCache>()
.add_system_to_stage(RenderStage::Cleanup, update_texture_cache_system);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Plugin for ViewPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<Msaa>().add_plugin(VisibilityPlugin);

app.sub_app(RenderApp)
app.sub_app_mut(RenderApp)
.init_resource::<ViewUniforms>()
.add_system_to_stage(RenderStage::Extract, extract_msaa)
.add_system_to_stage(RenderStage::Prepare, prepare_view_uniforms)
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/view/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum WindowSystem {

impl Plugin for WindowRenderPlugin {
fn build(&self, app: &mut App) {
app.sub_app(RenderApp)
app.sub_app_mut(RenderApp)
.init_resource::<ExtractedWindows>()
.init_resource::<WindowSurfaces>()
.init_resource::<NonSendMarker>()
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_sprite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Plugin for SpritePlugin {
let sprite_shader = Shader::from_wgsl(include_str!("render/sprite.wgsl"));
shaders.set_untracked(SPRITE_SHADER_HANDLE, sprite_shader);
app.add_asset::<TextureAtlas>().register_type::<Sprite>();
let render_app = app.sub_app(RenderApp);
let render_app = app.sub_app_mut(RenderApp);
render_app
.init_resource::<ImageBindGroups>()
.init_resource::<SpritePipeline>()
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Plugin for TextPlugin {
.insert_resource(DefaultTextPipeline::default())
.add_system_to_stage(CoreStage::PostUpdate, text2d_system);

let render_app = app.sub_app(RenderApp);
let render_app = app.sub_app_mut(RenderApp);
render_app.add_system_to_stage(
RenderStage::Extract,
extract_text2d_sprite.after(SpriteSystem::ExtractSprite),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn build_ui_render(app: &mut App) {
let mut active_cameras = app.world.get_resource_mut::<ActiveCameras>().unwrap();
active_cameras.add(CAMERA_UI);

let render_app = app.sub_app(RenderApp);
let render_app = app.sub_app_mut(RenderApp);
render_app
.init_resource::<UiPipeline>()
.init_resource::<SpecializedPipelines<UiPipeline>>()
Expand Down
2 changes: 1 addition & 1 deletion examples/shader/shader_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct IsRedPlugin;
impl Plugin for IsRedPlugin {
fn build(&self, app: &mut App) {
app.add_plugin(ExtractComponentPlugin::<IsRed>::default());
app.sub_app(RenderApp)
app.sub_app_mut(RenderApp)
.add_render_command::<Transparent3d, DrawIsRed>()
.init_resource::<IsRedPipeline>()
.init_resource::<SpecializedPipelines<IsRedPipeline>>()
Expand Down
2 changes: 1 addition & 1 deletion examples/shader/shader_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Plugin for CustomMaterialPlugin {
app.add_asset::<CustomMaterial>()
.add_plugin(ExtractComponentPlugin::<Handle<CustomMaterial>>::default())
.add_plugin(RenderAssetPlugin::<CustomMaterial>::default());
app.sub_app(RenderApp)
app.sub_app_mut(RenderApp)
.add_render_command::<Transparent3d, DrawCustom>()
.init_resource::<CustomPipeline>()
.init_resource::<SpecializedPipelines<CustomPipeline>>()
Expand Down
2 changes: 1 addition & 1 deletion examples/window/multiple_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
.add_startup_system(setup)
.add_startup_system(create_new_window);

let render_app = app.sub_app(RenderApp);
let render_app = app.sub_app_mut(RenderApp);
render_app.add_system_to_stage(RenderStage::Extract, extract_secondary_camera_phases);
let mut graph = render_app.world.get_resource_mut::<RenderGraph>().unwrap();
graph.add_node(SECONDARY_PASS_DRIVER, SecondaryCameraDriver);
Expand Down