Skip to content

Commit

Permalink
Try #3309:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Dec 12, 2021
2 parents 172f4d6 + 6ce78df commit 8f0eeba
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 19 deletions.
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 examples/shader/custom_shader_pipelined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,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/shader/shader_defs_pipelined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 pipelined/bevy_core_pipeline/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,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 pipelined/bevy_pbr2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Plugin for PbrPlugin {
.after(VisibilitySystems::CheckVisibility),
);

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 pipelined/bevy_pbr2/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 pipelined/bevy_pbr2/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 pipelined/bevy_render2/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 pipelined/bevy_render2/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 pipelined/bevy_render2/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 pipelined/bevy_render2/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 pipelined/bevy_render2/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 pipelined/bevy_render2/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 pipelined/bevy_sprite2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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 pipelined/bevy_text2/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 pipelined/bevy_ui2/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

0 comments on commit 8f0eeba

Please sign in to comment.