Skip to content

Commit

Permalink
update plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
maniwani committed Jul 18, 2023
1 parent a65e347 commit a0f986a
Show file tree
Hide file tree
Showing 63 changed files with 334 additions and 346 deletions.
26 changes: 13 additions & 13 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,41 +886,41 @@ mod test {
let path: AssetPath = "fake.png".into();
assert_eq!(
LoadState::NotLoaded,
get_load_state(path.get_id(), &app.world)
get_load_state(path.get_id(), app.world())
);

// load the asset
let handle = load_asset(path.clone(), &app.world).typed();
let handle = load_asset(path.clone(), app.world()).typed();
let weak_handle = handle.clone_weak();

// asset is loading
assert_eq!(LoadState::Loading, get_load_state(&handle, &app.world));
assert_eq!(LoadState::Loading, get_load_state(&handle, app.world()));

app.update();
// asset should exist and be loaded at this point
assert_eq!(LoadState::Loaded, get_load_state(&handle, &app.world));
assert!(get_asset(&handle, &app.world).is_some());
assert_eq!(LoadState::Loaded, get_load_state(&handle, app.world()));
assert!(get_asset(&handle, app.world()).is_some());

// after dropping the handle, next call to `tick` will prepare the assets for removal.
drop(handle);
app.update();
assert_eq!(LoadState::Loaded, get_load_state(&weak_handle, &app.world));
assert!(get_asset(&weak_handle, &app.world).is_some());
assert_eq!(LoadState::Loaded, get_load_state(&weak_handle, app.world()));
assert!(get_asset(&weak_handle, app.world()).is_some());

// second call to tick will actually remove the asset.
app.update();
assert_eq!(
LoadState::Unloaded,
get_load_state(&weak_handle, &app.world)
get_load_state(&weak_handle, app.world())
);
assert!(get_asset(&weak_handle, &app.world).is_none());
assert!(get_asset(&weak_handle, app.world()).is_none());

// finally, reload the asset
let handle = load_asset(path.clone(), &app.world).typed();
assert_eq!(LoadState::Loading, get_load_state(&handle, &app.world));
let handle = load_asset(path.clone(), app.world()).typed();
assert_eq!(LoadState::Loading, get_load_state(&handle, app.world()));
app.update();
assert_eq!(LoadState::Loaded, get_load_state(&handle, &app.world));
assert!(get_asset(&handle, &app.world).is_some());
assert_eq!(LoadState::Loaded, get_load_state(&handle, app.world()));
assert!(get_asset(&handle, app.world()).is_some());
}

#[test]
Expand Down
34 changes: 18 additions & 16 deletions crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ impl AddAsset for App {
where
T: Asset,
{
if self.world.contains_resource::<Assets<T>>() {
if self.world().contains_resource::<Assets<T>>() {
return self;
}
let assets = {
let asset_server = self.world.resource::<AssetServer>();
let asset_server = self.world().resource::<AssetServer>();
asset_server.register_asset_type::<T>()
};

Expand All @@ -343,7 +343,7 @@ impl AddAsset for App {
where
T: Asset + Reflect + FromReflect + GetTypeRegistration,
{
let type_registry = self.world.resource::<AppTypeRegistry>();
let type_registry = self.world().resource::<AppTypeRegistry>();
{
let mut type_registry = type_registry.write();

Expand All @@ -367,7 +367,7 @@ impl AddAsset for App {
crate::debug_asset_server::sync_debug_assets::<T>,
);
let mut app = self
.world
.world_mut()
.non_send_resource_mut::<crate::debug_asset_server::DebugAssetApp>();
app.add_asset::<T>()
.init_resource::<crate::debug_asset_server::HandleMap<T>>();
Expand All @@ -379,7 +379,7 @@ impl AddAsset for App {
where
T: AssetLoader + FromWorld,
{
let result = T::from_world(&mut self.world);
let result = T::from_world(self.world_mut());
self.add_asset_loader(result)
}

Expand All @@ -390,7 +390,7 @@ impl AddAsset for App {
#[cfg(feature = "debug_asset_server")]
{
let mut app = self
.world
.world_mut()
.non_send_resource_mut::<crate::debug_asset_server::DebugAssetApp>();
app.init_asset_loader::<T>();
}
Expand All @@ -401,7 +401,9 @@ impl AddAsset for App {
where
T: AssetLoader,
{
self.world.resource_mut::<AssetServer>().add_loader(loader);
self.world_mut()
.resource_mut::<AssetServer>()
.add_loader(loader);
self
}
}
Expand All @@ -418,7 +420,7 @@ macro_rules! load_internal_asset {
($app: ident, $handle: ident, $path_str: expr, $loader: expr) => {{
{
let mut debug_app = $app
.world
.world_mut()
.non_send_resource_mut::<$crate::debug_asset_server::DebugAssetApp>();
$crate::debug_asset_server::register_handle_with_loader::<_, &'static str>(
$loader,
Expand All @@ -428,7 +430,7 @@ macro_rules! load_internal_asset {
$path_str,
);
}
let mut assets = $app.world.resource_mut::<$crate::Assets<_>>();
let mut assets = $app.world_mut().resource_mut::<$crate::Assets<_>>();
assets.set_untracked(
$handle,
($loader)(
Expand All @@ -443,7 +445,7 @@ macro_rules! load_internal_asset {
}};
// we can't support params without variadic arguments, so internal assets with additional params can't be hot-reloaded
($app: ident, $handle: ident, $path_str: expr, $loader: expr $(, $param:expr)+) => {{
let mut assets = $app.world.resource_mut::<$crate::Assets<_>>();
let mut assets = $app.world_mut().resource_mut::<$crate::Assets<_>>();
assets.set_untracked(
$handle,
($loader)(
Expand All @@ -469,7 +471,7 @@ macro_rules! load_internal_asset {
#[macro_export]
macro_rules! load_internal_asset {
($app: ident, $handle: ident, $path_str: expr, $loader: expr $(, $param:expr)*) => {{
let mut assets = $app.world.resource_mut::<$crate::Assets<_>>();
let mut assets = $app.world_mut().resource_mut::<$crate::Assets<_>>();
assets.set_untracked(
$handle,
($loader)(
Expand All @@ -495,7 +497,7 @@ macro_rules! load_internal_binary_asset {
($app: ident, $handle: ident, $path_str: expr, $loader: expr) => {{
{
let mut debug_app = $app
.world
.world_mut()
.non_send_resource_mut::<$crate::debug_asset_server::DebugAssetApp>();
$crate::debug_asset_server::register_handle_with_loader::<_, &'static [u8]>(
$loader,
Expand All @@ -505,7 +507,7 @@ macro_rules! load_internal_binary_asset {
$path_str,
);
}
let mut assets = $app.world.resource_mut::<$crate::Assets<_>>();
let mut assets = $app.world_mut().resource_mut::<$crate::Assets<_>>();
assets.set_untracked(
$handle,
($loader)(
Expand All @@ -529,7 +531,7 @@ macro_rules! load_internal_binary_asset {
#[macro_export]
macro_rules! load_internal_binary_asset {
($app: ident, $handle: ident, $path_str: expr, $loader: expr) => {{
let mut assets = $app.world.resource_mut::<$crate::Assets<_>>();
let mut assets = $app.world_mut().resource_mut::<$crate::Assets<_>>();
assets.set_untracked(
$handle,
($loader)(
Expand Down Expand Up @@ -563,10 +565,10 @@ mod tests {
crate::AssetPlugin::default(),
));
app.add_asset::<MyAsset>();
let mut assets_before = app.world.resource_mut::<Assets<MyAsset>>();
let mut assets_before = app.world_mut().resource_mut::<Assets<MyAsset>>();
let handle = assets_before.add(MyAsset);
app.add_asset::<MyAsset>(); // Ensure this doesn't overwrite the Asset
let assets_after = app.world.resource_mut::<Assets<MyAsset>>();
let assets_after = app.world_mut().resource_mut::<Assets<MyAsset>>();
assert!(assets_after.get(&handle).is_some());
}
}
6 changes: 3 additions & 3 deletions crates/bevy_asset/src/debug_asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub(crate) fn sync_debug_assets<T: Asset + Clone>(
mut debug_asset_app: NonSendMut<DebugAssetApp>,
mut assets: ResMut<Assets<T>>,
) {
let world = &mut debug_asset_app.0.world;
let world = debug_asset_app.0.world_mut();
let mut state = SystemState::<(
Res<Events<AssetEvent<T>>>,
Res<HandleMap<T>>,
Expand Down Expand Up @@ -120,10 +120,10 @@ pub fn register_handle_with_loader<A: Asset, T>(
file_path: &str,
path: &'static str,
) {
let mut state = SystemState::<(ResMut<HandleMap<A>>, Res<AssetServer>)>::new(&mut app.world);
let mut state = SystemState::<(ResMut<HandleMap<A>>, Res<AssetServer>)>::new(app.world_mut());
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let manifest_dir_path = Path::new(&manifest_dir);
let (mut handle_map, asset_server) = state.get_mut(&mut app.world);
let (mut handle_map, asset_server) = state.get_mut(app.world_mut());
let asset_io = asset_server
.asset_io()
.downcast_ref::<FileAssetIo>()
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl AssetPlugin {

impl Plugin for AssetPlugin {
fn build(&self, app: &mut App) {
if !app.world.contains_resource::<AssetServer>() {
if !app.world().contains_resource::<AssetServer>() {
let source = self.create_platform_default_asset_io();
let asset_server = AssetServer::with_boxed_io(source);
app.insert_resource(asset_server);
Expand All @@ -142,7 +142,7 @@ impl Plugin for AssetPlugin {
))]
app.add_systems(LoadAssets, io::filesystem_watcher_system);

let mut order = app.world.resource_mut::<MainScheduleOrder>();
let mut order = app.world_mut().resource_mut::<MainScheduleOrder>();
order.insert_after(First, LoadAssets);
order.insert_after(PostUpdate, AssetEvents);
}
Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_asset/src/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ mod tests {
.register_asset_reflect::<AssetType>();

let reflect_asset = {
let type_registry = app.world.resource::<AppTypeRegistry>();
let type_registry = app.world().resource::<AppTypeRegistry>();
let type_registry = type_registry.read();

type_registry
Expand All @@ -286,9 +286,9 @@ mod tests {
field: "test".into(),
};

let handle = reflect_asset.add(&mut app.world, &value);
let handle = reflect_asset.add(app.world_mut(), &value);
let strukt = match reflect_asset
.get_mut(&mut app.world, handle)
.get_mut(app.world_mut(), handle)
.unwrap()
.reflect_mut()
{
Expand All @@ -300,19 +300,19 @@ mod tests {
.unwrap()
.apply(&String::from("edited"));

assert_eq!(reflect_asset.len(&app.world), 1);
let ids: Vec<_> = reflect_asset.ids(&app.world).collect();
assert_eq!(reflect_asset.len(app.world()), 1);
let ids: Vec<_> = reflect_asset.ids(app.world()).collect();
assert_eq!(ids.len(), 1);

let fetched_handle = HandleUntyped::weak(ids[0]);
let asset = reflect_asset
.get(&app.world, fetched_handle.clone_weak())
.get(app.world(), fetched_handle.clone_weak())
.unwrap();
assert_eq!(asset.downcast_ref::<AssetType>().unwrap().field, "edited");

reflect_asset
.remove(&mut app.world, fetched_handle)
.remove(app.world_mut(), fetched_handle)
.unwrap();
assert_eq!(reflect_asset.len(&app.world), 0);
assert_eq!(reflect_asset.len(app.world()), 0);
}
}
3 changes: 1 addition & 2 deletions crates/bevy_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use std::marker::PhantomData;
use std::ops::Range;
use std::path::{Path, PathBuf};

#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_arch = "wasm32"))]
use bevy_tasks::tick_global_task_pools_on_main_thread;

Expand Down Expand Up @@ -205,7 +204,7 @@ mod tests {
));
app.update();

let frame_count = app.world.resource::<FrameCount>();
let frame_count = app.world().resource::<FrameCount>();
assert_eq!(1, frame_count.0);
}
}
5 changes: 1 addition & 4 deletions crates/bevy_core_pipeline/src/blit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ impl Plugin for BlitPlugin {
}

fn finish(&self, app: &mut App) {
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
return
};

let Some(render_app) = app.get_sub_app_mut(&RenderApp) else { return };
render_app
.init_resource::<BlitPipeline>()
.init_resource::<SpecializedRenderPipelines<BlitPipeline>>();
Expand Down
12 changes: 2 additions & 10 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ impl Plugin for BloomPlugin {
UniformComponentPlugin::<BloomUniforms>::default(),
));

let render_app = match app.get_sub_app_mut(RenderApp) {
Ok(render_app) => render_app,
Err(_) => return,
};

let Some(render_app) = app.get_sub_app_mut(&RenderApp) else { return };
render_app
.init_resource::<SpecializedRenderPipelines<BloomDownsamplingPipeline>>()
.init_resource::<SpecializedRenderPipelines<BloomUpsamplingPipeline>>()
Expand Down Expand Up @@ -103,11 +99,7 @@ impl Plugin for BloomPlugin {
}

fn finish(&self, app: &mut App) {
let render_app = match app.get_sub_app_mut(RenderApp) {
Ok(render_app) => render_app,
Err(_) => return,
};

let Some(render_app) = app.get_sub_app_mut(&RenderApp) else { return };
render_app
.init_resource::<BloomDownsamplingPipeline>()
.init_resource::<BloomUpsamplingPipeline>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ impl Plugin for CASPlugin {
UniformComponentPlugin::<CASUniform>::default(),
));

let render_app = match app.get_sub_app_mut(RenderApp) {
Ok(render_app) => render_app,
Err(_) => return,
};
let Some(render_app) = app.get_sub_app_mut(&RenderApp) else { return };
render_app
.init_resource::<SpecializedRenderPipelines<CASPipeline>>()
.add_systems(Render, prepare_cas_pipelines.in_set(RenderSet::Prepare));
Expand Down Expand Up @@ -152,10 +149,7 @@ impl Plugin for CASPlugin {
}

fn finish(&self, app: &mut App) {
let render_app = match app.get_sub_app_mut(RenderApp) {
Ok(render_app) => render_app,
Err(_) => return,
};
let Some(render_app) = app.get_sub_app_mut(&RenderApp) else { return };
render_app.init_resource::<CASPipeline>();
}
}
Expand Down
6 changes: 1 addition & 5 deletions crates/bevy_core_pipeline/src/core_2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ impl Plugin for Core2dPlugin {
app.register_type::<Camera2d>()
.add_plugins(ExtractComponentPlugin::<Camera2d>::default());

let render_app = match app.get_sub_app_mut(RenderApp) {
Ok(render_app) => render_app,
Err(_) => return,
};

let Some(render_app) = app.get_sub_app_mut(&RenderApp) else { return };
render_app
.init_resource::<DrawFunctions<Transparent2d>>()
.add_systems(ExtractSchedule, extract_core_2d_camera_phases)
Expand Down
6 changes: 1 addition & 5 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ impl Plugin for Core3dPlugin {
.register_type::<Camera3dDepthLoadOp>()
.add_plugins((SkyboxPlugin, ExtractComponentPlugin::<Camera3d>::default()));

let render_app = match app.get_sub_app_mut(RenderApp) {
Ok(render_app) => render_app,
Err(_) => return,
};

let Some(render_app) = app.get_sub_app_mut(&RenderApp) else { return };
render_app
.init_resource::<DrawFunctions<Opaque3d>>()
.init_resource::<DrawFunctions<AlphaMask3d>>()
Expand Down
Loading

0 comments on commit a0f986a

Please sign in to comment.