From e290a7e29c345d555db27cca4cba82fd57ab2162 Mon Sep 17 00:00:00 2001 From: Zicklag Date: Tue, 24 Aug 2021 00:31:21 +0000 Subject: [PATCH] Implement Sub-App Labels (#2695) This is a rather simple but wide change, and it involves adding a new `bevy_app_macros` crate. Let me know if there is a better way to do any of this! --- # Objective - Allow adding and accessing sub-apps by using a label instead of an index ## Solution - Migrate the bevy label implementation and derive code to the `bevy_utils` and `bevy_macro_utils` crates and then add a new `SubAppLabel` trait to the `bevy_app` crate that is used when adding or getting a sub-app from an app. --- crates/bevy_app/Cargo.toml | 1 + crates/bevy_app/macros/Cargo.toml | 16 +++ crates/bevy_app/macros/src/lib.rs | 19 ++++ crates/bevy_app/src/app.rs | 33 ++++--- crates/bevy_ecs/macros/Cargo.toml | 4 - crates/bevy_ecs/macros/src/lib.rs | 53 +++++----- crates/bevy_ecs/src/schedule/label.rs | 110 +-------------------- crates/bevy_macro_utils/Cargo.toml | 1 + crates/bevy_macro_utils/src/lib.rs | 27 +++++ crates/bevy_utils/src/label.rs | 100 +++++++++++++++++++ crates/bevy_utils/src/lib.rs | 1 + pipelined/bevy_core_pipeline/src/lib.rs | 4 +- pipelined/bevy_pbr2/src/lib.rs | 4 +- pipelined/bevy_render2/src/camera/mod.rs | 4 +- pipelined/bevy_render2/src/lib.rs | 8 +- pipelined/bevy_render2/src/render_asset.rs | 4 +- pipelined/bevy_render2/src/texture/mod.rs | 4 +- pipelined/bevy_render2/src/view/mod.rs | 4 +- pipelined/bevy_render2/src/view/window.rs | 4 +- pipelined/bevy_sprite2/src/lib.rs | 8 +- tools/publish.sh | 3 +- 21 files changed, 244 insertions(+), 168 deletions(-) create mode 100644 crates/bevy_app/macros/Cargo.toml create mode 100644 crates/bevy_app/macros/src/lib.rs create mode 100644 crates/bevy_utils/src/label.rs diff --git a/crates/bevy_app/Cargo.toml b/crates/bevy_app/Cargo.toml index 58e8ac243e..f73f333392 100644 --- a/crates/bevy_app/Cargo.toml +++ b/crates/bevy_app/Cargo.toml @@ -23,6 +23,7 @@ bevy_derive = { path = "../bevy_derive", version = "0.5.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } bevy_reflect = { path = "../bevy_reflect", version = "0.5.0", optional = true } bevy_utils = { path = "../bevy_utils", version = "0.5.0" } +bevy_app_macros = { path = "./macros", version = "0.5.0" } # other serde = { version = "1.0", features = ["derive"], optional = true } diff --git a/crates/bevy_app/macros/Cargo.toml b/crates/bevy_app/macros/Cargo.toml new file mode 100644 index 0000000000..505c27068b --- /dev/null +++ b/crates/bevy_app/macros/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "bevy_app_macros" +version = "0.5.0" +description = "Bevy App Macros" +edition = "2018" +license = "MIT OR Apache-2.0" + +[lib] +proc-macro = true + +[dependencies] +bevy_macro_utils = { path = "../../bevy_macro_utils", version = "0.5.0" } + +syn = "1.0" +quote = "1.0" +proc-macro2 = "1.0" diff --git a/crates/bevy_app/macros/src/lib.rs b/crates/bevy_app/macros/src/lib.rs new file mode 100644 index 0000000000..eafa3dde55 --- /dev/null +++ b/crates/bevy_app/macros/src/lib.rs @@ -0,0 +1,19 @@ +extern crate proc_macro; + +use bevy_macro_utils::{derive_label, BevyManifest}; +use proc_macro::TokenStream; +use quote::format_ident; + +#[proc_macro_derive(SubAppLabel)] +pub fn derive_sub_app_label(input: TokenStream) -> TokenStream { + let input = syn::parse_macro_input!(input as syn::DeriveInput); + let mut trait_path = bevy_app_path(); + trait_path + .segments + .push(format_ident!("SubAppLabel").into()); + derive_label(input, trait_path) +} + +fn bevy_app_path() -> syn::Path { + BevyManifest::default().get_path("bevy_app") +} diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 65ecd7217b..faf7a4cc15 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -7,12 +7,17 @@ use bevy_ecs::{ }, world::World, }; -use bevy_utils::tracing::debug; +use bevy_utils::{tracing::debug, HashMap}; use std::{fmt::Debug, hash::Hash}; +pub use bevy_app_macros::SubAppLabel; + #[cfg(feature = "trace")] use bevy_utils::tracing::info_span; +bevy_utils::define_label!(SubAppLabel); +type BoxedSubAppLabel = Box; + #[allow(clippy::needless_doctest_main)] /// Containers of app logic and data /// @@ -40,7 +45,7 @@ pub struct App { pub world: World, pub runner: Box, pub schedule: Schedule, - sub_apps: Vec, + sub_apps: HashMap, } struct SubApp { @@ -77,7 +82,7 @@ impl App { world: Default::default(), schedule: Default::default(), runner: Box::new(run_once), - sub_apps: Vec::new(), + sub_apps: HashMap::default(), } } @@ -87,7 +92,7 @@ impl App { #[cfg(feature = "trace")] let _bevy_frame_update_guard = bevy_frame_update_span.enter(); self.schedule.run(&mut self.world); - for sub_app in self.sub_apps.iter_mut() { + for sub_app in self.sub_apps.values_mut() { (sub_app.runner)(&mut self.world, &mut sub_app.app); } } @@ -589,19 +594,25 @@ impl App { pub fn add_sub_app( &mut self, + label: impl SubAppLabel, app: App, f: impl Fn(&mut World, &mut App) + 'static, ) -> &mut Self { - self.sub_apps.push(SubApp { - app, - runner: Box::new(f), - }); + self.sub_apps.insert( + Box::new(label), + SubApp { + app, + runner: Box::new(f), + }, + ); self } - // TODO: use labels instead of indices - pub fn sub_app_mut(&mut self, index: usize) -> &mut App { - &mut self.sub_apps[index].app + pub fn sub_app_mut(&mut self, label: impl SubAppLabel) -> Option<&mut App> { + let label = Box::new(label) as BoxedSubAppLabel; + self.sub_apps + .get_mut(&label) + .map(|sub_app| &mut sub_app.app) } } diff --git a/crates/bevy_ecs/macros/Cargo.toml b/crates/bevy_ecs/macros/Cargo.toml index b6617e54ee..78f882dead 100644 --- a/crates/bevy_ecs/macros/Cargo.toml +++ b/crates/bevy_ecs/macros/Cargo.toml @@ -2,10 +2,6 @@ name = "bevy_ecs_macros" version = "0.5.0" description = "Bevy ECS Macros" -authors = [ - "Bevy Contributors ", - "Carter Anderson ", -] edition = "2018" license = "MIT OR Apache-2.0" diff --git a/crates/bevy_ecs/macros/src/lib.rs b/crates/bevy_ecs/macros/src/lib.rs index 21c2feabaa..cc88f89ddc 100644 --- a/crates/bevy_ecs/macros/src/lib.rs +++ b/crates/bevy_ecs/macros/src/lib.rs @@ -1,8 +1,8 @@ extern crate proc_macro; -use bevy_macro_utils::BevyManifest; +use bevy_macro_utils::{derive_label, BevyManifest}; use proc_macro::TokenStream; -use proc_macro2::{Span, TokenStream as TokenStream2}; +use proc_macro2::Span; use quote::{format_ident, quote}; use syn::{ parse::{Parse, ParseStream}, @@ -10,7 +10,7 @@ use syn::{ punctuated::Punctuated, token::Comma, Data, DataStruct, DeriveInput, Field, Fields, GenericParam, Ident, Index, Lifetime, LitInt, - Path, Result, Token, + Result, Token, }; struct AllTuples { @@ -436,46 +436,43 @@ pub fn derive_system_param(input: TokenStream) -> TokenStream { #[proc_macro_derive(SystemLabel)] pub fn derive_system_label(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); - - derive_label(input, Ident::new("SystemLabel", Span::call_site())).into() + let mut trait_path = bevy_ecs_path(); + trait_path.segments.push(format_ident!("schedule").into()); + trait_path + .segments + .push(format_ident!("SystemLabel").into()); + derive_label(input, trait_path) } #[proc_macro_derive(StageLabel)] pub fn derive_stage_label(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); - derive_label(input, Ident::new("StageLabel", Span::call_site())).into() + let mut trait_path = bevy_ecs_path(); + trait_path.segments.push(format_ident!("schedule").into()); + trait_path.segments.push(format_ident!("StageLabel").into()); + derive_label(input, trait_path) } #[proc_macro_derive(AmbiguitySetLabel)] pub fn derive_ambiguity_set_label(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); - derive_label(input, Ident::new("AmbiguitySetLabel", Span::call_site())).into() + let mut trait_path = bevy_ecs_path(); + trait_path.segments.push(format_ident!("schedule").into()); + trait_path + .segments + .push(format_ident!("AmbiguitySetLabel").into()); + derive_label(input, trait_path) } #[proc_macro_derive(RunCriteriaLabel)] pub fn derive_run_criteria_label(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); - derive_label(input, Ident::new("RunCriteriaLabel", Span::call_site())).into() -} - -fn derive_label(input: DeriveInput, label_type: Ident) -> TokenStream2 { - let ident = input.ident; - let ecs_path: Path = bevy_ecs_path(); - - let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - let mut where_clause = where_clause.cloned().unwrap_or_else(|| syn::WhereClause { - where_token: Default::default(), - predicates: Default::default(), - }); - where_clause.predicates.push(syn::parse2(quote! { Self: Eq + ::std::fmt::Debug + ::std::hash::Hash + Clone + Send + Sync + 'static }).unwrap()); - - quote! { - impl #impl_generics #ecs_path::schedule::#label_type for #ident #ty_generics #where_clause { - fn dyn_clone(&self) -> Box { - Box::new(Clone::clone(self)) - } - } - } + let mut trait_path = bevy_ecs_path(); + trait_path.segments.push(format_ident!("schedule").into()); + trait_path + .segments + .push(format_ident!("RunCriteriaLabel").into()); + derive_label(input, trait_path) } fn bevy_ecs_path() -> syn::Path { diff --git a/crates/bevy_ecs/src/schedule/label.rs b/crates/bevy_ecs/src/schedule/label.rs index a7f3538741..ed9398426e 100644 --- a/crates/bevy_ecs/src/schedule/label.rs +++ b/crates/bevy_ecs/src/schedule/label.rs @@ -1,115 +1,15 @@ pub use bevy_ecs_macros::{AmbiguitySetLabel, RunCriteriaLabel, StageLabel, SystemLabel}; -use std::{ - any::Any, - borrow::Cow, - fmt::Debug, - hash::{Hash, Hasher}, -}; +use bevy_utils::define_label; -pub trait DynEq: Any { - fn as_any(&self) -> &dyn Any; - - fn dyn_eq(&self, other: &dyn DynEq) -> bool; -} - -impl DynEq for T -where - T: Any + Eq, -{ - fn as_any(&self) -> &dyn Any { - self - } - - fn dyn_eq(&self, other: &dyn DynEq) -> bool { - if let Some(other) = other.as_any().downcast_ref::() { - return self == other; - } - false - } -} - -pub trait DynHash: DynEq { - fn as_dyn_eq(&self) -> &dyn DynEq; - - fn dyn_hash(&self, state: &mut dyn Hasher); -} - -impl DynHash for T -where - T: DynEq + Hash, -{ - fn as_dyn_eq(&self) -> &dyn DynEq { - self - } - - fn dyn_hash(&self, mut state: &mut dyn Hasher) { - T::hash(self, &mut state); - self.type_id().hash(&mut state); - } -} - -pub trait StageLabel: DynHash + Debug + Send + Sync + 'static { - #[doc(hidden)] - fn dyn_clone(&self) -> Box; -} +define_label!(StageLabel); pub(crate) type BoxedStageLabel = Box; -pub trait SystemLabel: DynHash + Debug + Send + Sync + 'static { - #[doc(hidden)] - fn dyn_clone(&self) -> Box; -} +define_label!(SystemLabel); pub(crate) type BoxedSystemLabel = Box; -pub trait AmbiguitySetLabel: DynHash + Debug + Send + Sync + 'static { - #[doc(hidden)] - fn dyn_clone(&self) -> Box; -} +define_label!(AmbiguitySetLabel); pub(crate) type BoxedAmbiguitySetLabel = Box; -pub trait RunCriteriaLabel: DynHash + Debug + Send + Sync + 'static { - #[doc(hidden)] - fn dyn_clone(&self) -> Box; -} +define_label!(RunCriteriaLabel); pub(crate) type BoxedRunCriteriaLabel = Box; - -macro_rules! impl_label { - ($trait_name:ident) => { - impl PartialEq for dyn $trait_name { - fn eq(&self, other: &Self) -> bool { - self.dyn_eq(other.as_dyn_eq()) - } - } - - impl Eq for dyn $trait_name {} - - impl Hash for dyn $trait_name { - fn hash(&self, state: &mut H) { - self.dyn_hash(state); - } - } - - impl Clone for Box { - fn clone(&self) -> Self { - self.dyn_clone() - } - } - - impl $trait_name for Cow<'static, str> { - fn dyn_clone(&self) -> Box { - Box::new(self.clone()) - } - } - - impl $trait_name for &'static str { - fn dyn_clone(&self) -> Box { - Box::new(<&str>::clone(self)) - } - } - }; -} - -impl_label!(StageLabel); -impl_label!(SystemLabel); -impl_label!(AmbiguitySetLabel); -impl_label!(RunCriteriaLabel); diff --git a/crates/bevy_macro_utils/Cargo.toml b/crates/bevy_macro_utils/Cargo.toml index 46c8fac2ba..b92056f642 100644 --- a/crates/bevy_macro_utils/Cargo.toml +++ b/crates/bevy_macro_utils/Cargo.toml @@ -15,3 +15,4 @@ keywords = ["bevy"] [dependencies] cargo-manifest = "0.2.3" syn = "1.0" +quote = "1.0" diff --git a/crates/bevy_macro_utils/src/lib.rs b/crates/bevy_macro_utils/src/lib.rs index 2933d9d800..2c23461bf8 100644 --- a/crates/bevy_macro_utils/src/lib.rs +++ b/crates/bevy_macro_utils/src/lib.rs @@ -2,6 +2,7 @@ extern crate proc_macro; use cargo_manifest::{DepsSet, Manifest}; use proc_macro::TokenStream; +use quote::quote; use std::{env, path::PathBuf}; pub struct BevyManifest { @@ -59,3 +60,29 @@ fn get_path(path: &str) -> syn::Path { fn parse_str(path: &str) -> T { syn::parse(path.parse::().unwrap()).unwrap() } + +/// Derive a label trait +/// +/// # Args +/// +/// - `input`: The [`syn::DeriveInput`] for struct that is deriving the label trait +/// - `trait_path`: The path [`syn::Path`] to the label trait +pub fn derive_label(input: syn::DeriveInput, trait_path: syn::Path) -> TokenStream { + let ident = input.ident; + + let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); + let mut where_clause = where_clause.cloned().unwrap_or_else(|| syn::WhereClause { + where_token: Default::default(), + predicates: Default::default(), + }); + where_clause.predicates.push(syn::parse2(quote! { Self: Eq + ::std::fmt::Debug + ::std::hash::Hash + Clone + Send + Sync + 'static }).unwrap()); + + (quote! { + impl #impl_generics #trait_path for #ident #ty_generics #where_clause { + fn dyn_clone(&self) -> Box { + Box::new(Clone::clone(self)) + } + } + }) + .into() +} diff --git a/crates/bevy_utils/src/label.rs b/crates/bevy_utils/src/label.rs new file mode 100644 index 0000000000..ed759f6a59 --- /dev/null +++ b/crates/bevy_utils/src/label.rs @@ -0,0 +1,100 @@ +//! Traits used by label implementations + +use std::{ + any::Any, + hash::{Hash, Hasher}, +}; + +pub trait DynEq: Any { + fn as_any(&self) -> &dyn Any; + + fn dyn_eq(&self, other: &dyn DynEq) -> bool; +} + +impl DynEq for T +where + T: Any + Eq, +{ + fn as_any(&self) -> &dyn Any { + self + } + + fn dyn_eq(&self, other: &dyn DynEq) -> bool { + if let Some(other) = other.as_any().downcast_ref::() { + return self == other; + } + false + } +} + +pub trait DynHash: DynEq { + fn as_dyn_eq(&self) -> &dyn DynEq; + + fn dyn_hash(&self, state: &mut dyn Hasher); +} + +impl DynHash for T +where + T: DynEq + Hash, +{ + fn as_dyn_eq(&self) -> &dyn DynEq { + self + } + + fn dyn_hash(&self, mut state: &mut dyn Hasher) { + T::hash(self, &mut state); + self.type_id().hash(&mut state); + } +} + +/// Macro to define a new label trait +/// +/// # Example +/// +/// ``` +/// # use bevy_utils::define_label; +/// define_label!(MyNewLabelTrait); +/// ``` +#[macro_export] +macro_rules! define_label { + ($label_trait_name:ident) => { + pub trait $label_trait_name: + ::bevy_utils::label::DynHash + ::std::fmt::Debug + Send + Sync + 'static + { + #[doc(hidden)] + fn dyn_clone(&self) -> Box; + } + + impl PartialEq for dyn $label_trait_name { + fn eq(&self, other: &Self) -> bool { + self.dyn_eq(other.as_dyn_eq()) + } + } + + impl Eq for dyn $label_trait_name {} + + impl ::std::hash::Hash for dyn $label_trait_name { + fn hash(&self, state: &mut H) { + self.dyn_hash(state); + } + } + + impl Clone for Box { + fn clone(&self) -> Self { + self.dyn_clone() + } + } + + impl $label_trait_name for ::std::borrow::Cow<'static, str> { + fn dyn_clone(&self) -> Box { + Box::new(self.clone()) + } + } + + impl $label_trait_name for &'static str { + fn dyn_clone(&self) -> Box { + Box::new(<&str>::clone(self)) + } + } + }; +} diff --git a/crates/bevy_utils/src/lib.rs b/crates/bevy_utils/src/lib.rs index 57202de29b..c6b5f25359 100644 --- a/crates/bevy_utils/src/lib.rs +++ b/crates/bevy_utils/src/lib.rs @@ -1,4 +1,5 @@ mod enum_variant_meta; +pub mod label; pub mod slab; pub use ahash::AHasher; diff --git a/pipelined/bevy_core_pipeline/src/lib.rs b/pipelined/bevy_core_pipeline/src/lib.rs index 554ac46fc9..6f7d447ac5 100644 --- a/pipelined/bevy_core_pipeline/src/lib.rs +++ b/pipelined/bevy_core_pipeline/src/lib.rs @@ -20,7 +20,7 @@ use bevy_render2::{ renderer::RenderDevice, texture::TextureCache, view::{ExtractedView, ViewPlugin}, - RenderStage, RenderWorld, + RenderStage, RenderSubApp, RenderWorld, }; /// Resource that configures the clear color @@ -74,7 +74,7 @@ impl Plugin for CorePipelinePlugin { fn build(&self, app: &mut App) { app.init_resource::(); - let render_app = app.sub_app_mut(0); + let render_app = app.sub_app_mut(RenderSubApp).unwrap(); render_app .add_system_to_stage(RenderStage::Extract, extract_clear_color) .add_system_to_stage(RenderStage::Extract, extract_core_pipeline_camera_phases) diff --git a/pipelined/bevy_pbr2/src/lib.rs b/pipelined/bevy_pbr2/src/lib.rs index 75561835d9..4490e660b6 100644 --- a/pipelined/bevy_pbr2/src/lib.rs +++ b/pipelined/bevy_pbr2/src/lib.rs @@ -13,7 +13,7 @@ use bevy_ecs::prelude::*; use bevy_render2::{ render_graph::RenderGraph, render_phase::{sort_phase_system, DrawFunctions}, - RenderStage, + RenderStage, RenderSubApp, }; pub mod draw_3d_graph { @@ -30,7 +30,7 @@ impl Plugin for PbrPlugin { app.add_plugin(StandardMaterialPlugin) .init_resource::(); - let render_app = app.sub_app_mut(0); + let render_app = app.sub_app_mut(RenderSubApp).unwrap(); render_app .add_system_to_stage(RenderStage::Extract, render::extract_meshes) .add_system_to_stage(RenderStage::Extract, render::extract_lights) diff --git a/pipelined/bevy_render2/src/camera/mod.rs b/pipelined/bevy_render2/src/camera/mod.rs index 63ea8f6672..cade9c5149 100644 --- a/pipelined/bevy_render2/src/camera/mod.rs +++ b/pipelined/bevy_render2/src/camera/mod.rs @@ -12,7 +12,7 @@ pub use bundle::*; pub use camera::*; pub use projection::*; -use crate::{view::ExtractedView, RenderStage}; +use crate::{view::ExtractedView, RenderStage, RenderSubApp}; use bevy_app::{App, CoreStage, Plugin}; use bevy_ecs::prelude::*; @@ -40,7 +40,7 @@ impl Plugin for CameraPlugin { CoreStage::PostUpdate, crate::camera::camera_system::, ); - let render_app = app.sub_app_mut(0); + let render_app = app.sub_app_mut(RenderSubApp).unwrap(); render_app .init_resource::() .add_system_to_stage(RenderStage::Extract, extract_cameras); diff --git a/pipelined/bevy_render2/src/lib.rs b/pipelined/bevy_render2/src/lib.rs index 580e0d0a6c..49d73e97e4 100644 --- a/pipelined/bevy_render2/src/lib.rs +++ b/pipelined/bevy_render2/src/lib.rs @@ -24,7 +24,7 @@ use crate::{ texture::ImagePlugin, view::{ViewPlugin, WindowRenderPlugin}, }; -use bevy_app::{App, Plugin}; +use bevy_app::{App, Plugin, SubAppLabel}; use bevy_ecs::prelude::*; #[derive(Default)] @@ -73,6 +73,10 @@ impl DerefMut for RenderWorld { } } +/// Label for the rendering sub-app +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, SubAppLabel)] +pub struct RenderSubApp; + /// A "scratch" world used to avoid allocating new worlds every frame when // swapping out the Render World. #[derive(Default)] @@ -114,7 +118,7 @@ impl Plugin for RenderPlugin { .init_resource::() .init_resource::(); - app.add_sub_app(render_app, move |app_world, render_app| { + app.add_sub_app(RenderSubApp, render_app, move |app_world, render_app| { // reserve all existing app entities for use in render_app // they can only be spawned using `get_or_spawn()` let meta_len = app_world.entities().meta.len(); diff --git a/pipelined/bevy_render2/src/render_asset.rs b/pipelined/bevy_render2/src/render_asset.rs index 90533d2e59..66fd9f2dab 100644 --- a/pipelined/bevy_render2/src/render_asset.rs +++ b/pipelined/bevy_render2/src/render_asset.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use crate::{ renderer::{RenderDevice, RenderQueue}, - RenderStage, + RenderStage, RenderSubApp, }; use bevy_app::{App, Plugin}; use bevy_asset::{Asset, AssetEvent, Assets, Handle}; @@ -31,7 +31,7 @@ impl Default for RenderAssetPlugin { impl Plugin for RenderAssetPlugin { fn build(&self, app: &mut App) { - let render_app = app.sub_app_mut(0); + let render_app = app.sub_app_mut(RenderSubApp).unwrap(); render_app .init_resource::>() .init_resource::>() diff --git a/pipelined/bevy_render2/src/texture/mod.rs b/pipelined/bevy_render2/src/texture/mod.rs index 976b7c1059..efe05dc561 100644 --- a/pipelined/bevy_render2/src/texture/mod.rs +++ b/pipelined/bevy_render2/src/texture/mod.rs @@ -13,7 +13,7 @@ pub use hdr_texture_loader::*; pub use image_texture_loader::*; pub use texture_cache::*; -use crate::{render_asset::RenderAssetPlugin, RenderStage}; +use crate::{render_asset::RenderAssetPlugin, RenderStage, RenderSubApp}; use bevy_app::{App, Plugin}; use bevy_asset::AddAsset; @@ -30,7 +30,7 @@ impl Plugin for ImagePlugin { app.add_plugin(RenderAssetPlugin::::default()) .add_asset::(); - let render_app = app.sub_app_mut(0); + let render_app = app.sub_app_mut(RenderSubApp).unwrap(); render_app .init_resource::() .add_system_to_stage(RenderStage::Cleanup, update_texture_cache_system); diff --git a/pipelined/bevy_render2/src/view/mod.rs b/pipelined/bevy_render2/src/view/mod.rs index d95ae8834a..911148116b 100644 --- a/pipelined/bevy_render2/src/view/mod.rs +++ b/pipelined/bevy_render2/src/view/mod.rs @@ -7,7 +7,7 @@ use crate::{ render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext}, render_resource::DynamicUniformVec, renderer::{RenderContext, RenderDevice}, - RenderStage, + RenderStage, RenderSubApp, }; use bevy_app::{App, Plugin}; use bevy_ecs::prelude::*; @@ -22,7 +22,7 @@ impl ViewPlugin { impl Plugin for ViewPlugin { fn build(&self, app: &mut App) { - let render_app = app.sub_app_mut(0); + let render_app = app.sub_app_mut(RenderSubApp).unwrap(); render_app .init_resource::() .add_system_to_stage(RenderStage::Prepare, prepare_views); diff --git a/pipelined/bevy_render2/src/view/window.rs b/pipelined/bevy_render2/src/view/window.rs index 5ec52bec0d..dbcf46f4c3 100644 --- a/pipelined/bevy_render2/src/view/window.rs +++ b/pipelined/bevy_render2/src/view/window.rs @@ -2,7 +2,7 @@ use crate::{ render_resource::TextureView, renderer::{RenderDevice, RenderInstance}, texture::BevyDefault, - RenderStage, + RenderStage, RenderSubApp, }; use bevy_app::{App, Plugin}; use bevy_ecs::prelude::*; @@ -19,7 +19,7 @@ pub struct WindowRenderPlugin; impl Plugin for WindowRenderPlugin { fn build(&self, app: &mut App) { - let render_app = app.sub_app_mut(0); + let render_app = app.sub_app_mut(RenderSubApp).unwrap(); render_app .init_resource::() .init_resource::() diff --git a/pipelined/bevy_sprite2/src/lib.rs b/pipelined/bevy_sprite2/src/lib.rs index 484252a098..a1a7643ea6 100644 --- a/pipelined/bevy_sprite2/src/lib.rs +++ b/pipelined/bevy_sprite2/src/lib.rs @@ -16,7 +16,9 @@ pub use texture_atlas::*; pub use texture_atlas_builder::*; use bevy_app::prelude::*; -use bevy_render2::{render_graph::RenderGraph, render_phase::DrawFunctions, RenderStage}; +use bevy_render2::{ + render_graph::RenderGraph, render_phase::DrawFunctions, RenderStage, RenderSubApp, +}; #[derive(Default)] pub struct SpritePlugin; @@ -26,7 +28,7 @@ impl Plugin for SpritePlugin { app.add_asset::() .register_type::() .add_system_to_stage(CoreStage::PostUpdate, sprite_auto_resize_system); - let render_app = app.sub_app_mut(0); + let render_app = app.sub_app_mut(RenderSubApp).unwrap(); render_app .init_resource::() .add_system_to_stage(RenderStage::Extract, render::extract_atlases) @@ -42,7 +44,7 @@ impl Plugin for SpritePlugin { .unwrap() .write() .add(draw_sprite); - let render_world = app.sub_app_mut(0).world.cell(); + let render_world = app.sub_app_mut(RenderSubApp).unwrap().world.cell(); let mut graph = render_world.get_resource_mut::().unwrap(); graph.add_node("sprite", SpriteNode); graph diff --git a/tools/publish.sh b/tools/publish.sh index 85008c6247..62b7181c90 100644 --- a/tools/publish.sh +++ b/tools/publish.sh @@ -7,6 +7,7 @@ crates=( bevy_tasks bevy_ecs/macros bevy_ecs + bevy_app/macros bevy_app bevy_log bevy_dynamic_plugin @@ -42,4 +43,4 @@ do done cd .. -cargo publish \ No newline at end of file +cargo publish