make sub_app
return an &App
and add sub_app_mut() -> &mut App
(#3309)
It's sometimes useful to have a reference to an app a sub app at the same time, which is only possible with an immutable reference.
This commit is contained in:
parent
5d5d7833f0
commit
adb3ad399c
@ -854,7 +854,24 @@ 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 {
|
||||
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(&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),
|
||||
@ -863,10 +880,10 @@ impl App {
|
||||
|
||||
/// 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(&self, label: impl AppLabel) -> Result<&App, impl AppLabel> {
|
||||
self.sub_apps
|
||||
.get_mut((&label) as &dyn AppLabel)
|
||||
.map(|sub_app| &mut sub_app.app)
|
||||
.get((&label) as &dyn AppLabel)
|
||||
.map(|sub_app| &sub_app.app)
|
||||
.ok_or(label)
|
||||
}
|
||||
}
|
||||
|
@ -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>>()
|
||||
|
@ -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,
|
||||
|
@ -57,7 +57,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)
|
||||
|
@ -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>>()
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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>>()
|
||||
|
@ -62,7 +62,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,
|
||||
@ -144,7 +144,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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -26,7 +26,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)
|
||||
|
@ -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>()
|
||||
|
@ -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>()
|
||||
|
@ -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),
|
||||
|
@ -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>>()
|
||||
|
@ -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>>()
|
||||
|
@ -110,7 +110,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>>()
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user