@@ -146,7 +146,7 @@ impl Plugin for AssetPlugin {
146146 watch_for_changes,
147147 } => {
148148 let source_reader = app
149- . world
149+ . world_mut ( )
150150 . resource_mut :: < AssetProviders > ( )
151151 . get_source_reader ( source) ;
152152 app. insert_resource ( AssetServer :: new ( source_reader, * watch_for_changes) ) ;
@@ -156,7 +156,7 @@ impl Plugin for AssetPlugin {
156156 watch_for_changes,
157157 } => {
158158 let destination_reader = app
159- . world
159+ . world_mut ( )
160160 . resource_mut :: < AssetProviders > ( )
161161 . get_destination_reader ( destination) ;
162162 app. insert_resource ( AssetServer :: new ( destination_reader, * watch_for_changes) ) ;
@@ -166,7 +166,7 @@ impl Plugin for AssetPlugin {
166166 destination,
167167 watch_for_changes,
168168 } => {
169- let mut asset_providers = app. world . resource_mut :: < AssetProviders > ( ) ;
169+ let mut asset_providers = app. world_mut ( ) . resource_mut :: < AssetProviders > ( ) ;
170170 let processor = AssetProcessor :: new ( & mut asset_providers, source, destination) ;
171171 let destination_reader = asset_providers. get_destination_reader ( source) ;
172172 // the main asset server gates loads based on asset state
@@ -191,7 +191,7 @@ impl Plugin for AssetPlugin {
191191 )
192192 . add_systems ( UpdateAssets , server:: handle_internal_asset_events) ;
193193
194- let mut order = app. world . resource_mut :: < MainScheduleOrder > ( ) ;
194+ let mut order = app. world_mut ( ) . resource_mut :: < MainScheduleOrder > ( ) ;
195195 order. insert_after ( First , UpdateAssets ) ;
196196 order. insert_after ( PostUpdate , AssetEvents ) ;
197197 }
@@ -276,20 +276,24 @@ pub trait AssetApp {
276276
277277impl AssetApp for App {
278278 fn register_asset_loader < L : AssetLoader > ( & mut self , loader : L ) -> & mut Self {
279- self . world . resource :: < AssetServer > ( ) . register_loader ( loader) ;
279+ self . world ( )
280+ . resource :: < AssetServer > ( )
281+ . register_loader ( loader) ;
280282 self
281283 }
282284
283285 fn init_asset_loader < L : AssetLoader + FromWorld > ( & mut self ) -> & mut Self {
284- let loader = L :: from_world ( & mut self . world ) ;
286+ let loader = L :: from_world ( self . world_mut ( ) ) ;
285287 self . register_asset_loader ( loader)
286288 }
287289
288290 fn init_asset < A : Asset > ( & mut self ) -> & mut Self {
289291 let assets = Assets :: < A > :: default ( ) ;
290- self . world . resource :: < AssetServer > ( ) . register_asset ( & assets) ;
291- if self . world . contains_resource :: < AssetProcessor > ( ) {
292- let processor = self . world . resource :: < AssetProcessor > ( ) ;
292+ self . world ( )
293+ . resource :: < AssetServer > ( )
294+ . register_asset ( & assets) ;
295+ if self . world ( ) . contains_resource :: < AssetProcessor > ( ) {
296+ let processor = self . world ( ) . resource :: < AssetProcessor > ( ) ;
293297 // The processor should have its own handle provider separate from the Asset storage
294298 // to ensure the id spaces are entirely separate. Not _strictly_ necessary, but
295299 // desirable.
@@ -312,7 +316,7 @@ impl AssetApp for App {
312316 where
313317 A : Asset + Reflect + FromReflect + GetTypeRegistration ,
314318 {
315- let type_registry = self . world . resource :: < AppTypeRegistry > ( ) ;
319+ let type_registry = self . world ( ) . resource :: < AppTypeRegistry > ( ) ;
316320 {
317321 let mut type_registry = type_registry. write ( ) ;
318322
@@ -326,21 +330,21 @@ impl AssetApp for App {
326330 }
327331
328332 fn preregister_asset_loader < L : AssetLoader > ( & mut self , extensions : & [ & str ] ) -> & mut Self {
329- self . world
333+ self . world_mut ( )
330334 . resource_mut :: < AssetServer > ( )
331335 . preregister_loader :: < L > ( extensions) ;
332336 self
333337 }
334338
335339 fn register_asset_processor < P : Process > ( & mut self , processor : P ) -> & mut Self {
336- if let Some ( asset_processor) = self . world . get_resource :: < AssetProcessor > ( ) {
340+ if let Some ( asset_processor) = self . world ( ) . get_resource :: < AssetProcessor > ( ) {
337341 asset_processor. register_processor ( processor) ;
338342 }
339343 self
340344 }
341345
342346 fn set_default_asset_processor < P : Process > ( & mut self , extension : & str ) -> & mut Self {
343- if let Some ( asset_processor) = self . world . get_resource :: < AssetProcessor > ( ) {
347+ if let Some ( asset_processor) = self . world ( ) . get_resource :: < AssetProcessor > ( ) {
344348 asset_processor. set_default_processor :: < P > ( extension) ;
345349 }
346350 self
@@ -365,7 +369,7 @@ pub struct AssetEvents;
365369#[ macro_export]
366370macro_rules! load_internal_asset {
367371 ( $app: ident, $handle: expr, $path_str: expr, $loader: expr) => { {
368- let mut assets = $app. world . resource_mut:: <$crate:: Assets <_>>( ) ;
372+ let mut assets = $app. world_mut ( ) . resource_mut:: <$crate:: Assets <_>>( ) ;
369373 assets. insert( $handle, ( $loader) (
370374 include_str!( $path_str) ,
371375 std:: path:: Path :: new( file!( ) )
@@ -377,7 +381,7 @@ macro_rules! load_internal_asset {
377381 } } ;
378382 // we can't support params without variadic arguments, so internal assets with additional params can't be hot-reloaded
379383 ( $app: ident, $handle: ident, $path_str: expr, $loader: expr $( , $param: expr) +) => { {
380- let mut assets = $app. world . resource_mut:: <$crate:: Assets <_>>( ) ;
384+ let mut assets = $app. world_mut ( ) . resource_mut:: <$crate:: Assets <_>>( ) ;
381385 assets. insert( $handle, ( $loader) (
382386 include_str!( $path_str) ,
383387 std:: path:: Path :: new( file!( ) )
@@ -394,7 +398,7 @@ macro_rules! load_internal_asset {
394398#[ macro_export]
395399macro_rules! load_internal_binary_asset {
396400 ( $app: ident, $handle: expr, $path_str: expr, $loader: expr) => { {
397- let mut assets = $app. world . resource_mut:: <$crate:: Assets <_>>( ) ;
401+ let mut assets = $app. world_mut ( ) . resource_mut:: <$crate:: Assets <_>>( ) ;
398402 assets. insert(
399403 $handle,
400404 ( $loader) (
@@ -526,7 +530,7 @@ mod tests {
526530 fn run_app_until ( app : & mut App , mut predicate : impl FnMut ( & mut World ) -> Option < ( ) > ) {
527531 for _ in 0 ..LARGE_ITERATION_COUNT {
528532 app. update ( ) ;
529- if ( predicate) ( & mut app. world ) . is_some ( ) {
533+ if ( predicate) ( app. world_mut ( ) ) . is_some ( ) {
530534 return ;
531535 }
532536 }
@@ -612,13 +616,13 @@ mod tests {
612616 . init_resource :: < StoredEvents > ( )
613617 . register_asset_loader ( CoolTextLoader )
614618 . add_systems ( Update , store_asset_events) ;
615- let asset_server = app. world . resource :: < AssetServer > ( ) . clone ( ) ;
619+ let asset_server = app. world ( ) . resource :: < AssetServer > ( ) . clone ( ) ;
616620 let handle: Handle < CoolText > = asset_server. load ( a_path) ;
617621 let a_id = handle. id ( ) ;
618- let entity = app. world . spawn ( handle) . id ( ) ;
622+ let entity = app. world_mut ( ) . spawn ( handle) . id ( ) ;
619623 app. update ( ) ;
620624 {
621- let a_text = get :: < CoolText > ( & app. world , a_id) ;
625+ let a_text = get :: < CoolText > ( app. world ( ) , a_id) ;
622626 let ( a_load, a_deps, a_rec_deps) = asset_server. get_load_states ( a_id) . unwrap ( ) ;
623627 assert ! ( a_text. is_none( ) , "a's asset should not exist yet" ) ;
624628 assert_eq ! ( a_load, LoadState :: Loading , "a should still be loading" ) ;
@@ -800,27 +804,27 @@ mod tests {
800804 } ) ;
801805
802806 {
803- let mut texts = app. world . resource_mut :: < Assets < CoolText > > ( ) ;
807+ let mut texts = app. world_mut ( ) . resource_mut :: < Assets < CoolText > > ( ) ;
804808 let a = texts. get_mut ( a_id) . unwrap ( ) ;
805809 a. text = "Changed" . to_string ( ) ;
806810 }
807811
808- app. world . despawn ( entity) ;
812+ app. world_mut ( ) . despawn ( entity) ;
809813 app. update ( ) ;
810814 assert_eq ! (
811- app. world. resource:: <Assets <CoolText >>( ) . len( ) ,
815+ app. world( ) . resource:: <Assets <CoolText >>( ) . len( ) ,
812816 0 ,
813817 "CoolText asset entities should be despawned when no more handles exist"
814818 ) ;
815819 app. update ( ) ;
816820 // this requires a second update because the parent asset was freed in the previous app.update()
817821 assert_eq ! (
818- app. world. resource:: <Assets <SubText >>( ) . len( ) ,
822+ app. world( ) . resource:: <Assets <SubText >>( ) . len( ) ,
819823 0 ,
820824 "SubText asset entities should be despawned when no more handles exist"
821825 ) ;
822- let events = app. world . remove_resource :: < StoredEvents > ( ) . unwrap ( ) ;
823- let id_results = app. world . remove_resource :: < IdResults > ( ) . unwrap ( ) ;
826+ let events = app. world_mut ( ) . remove_resource :: < StoredEvents > ( ) . unwrap ( ) ;
827+ let id_results = app. world_mut ( ) . remove_resource :: < IdResults > ( ) . unwrap ( ) ;
824828 let expected_events = vec ! [
825829 AssetEvent :: Added { id: a_id } ,
826830 AssetEvent :: LoadedWithDependencies {
@@ -910,7 +914,7 @@ mod tests {
910914 let ( mut app, gate_opener) = test_app ( dir) ;
911915 app. init_asset :: < CoolText > ( )
912916 . register_asset_loader ( CoolTextLoader ) ;
913- let asset_server = app. world . resource :: < AssetServer > ( ) . clone ( ) ;
917+ let asset_server = app. world ( ) . resource :: < AssetServer > ( ) . clone ( ) ;
914918 let handle: Handle < CoolText > = asset_server. load ( a_path) ;
915919 let a_id = handle. id ( ) ;
916920 {
@@ -926,7 +930,7 @@ mod tests {
926930 ) ;
927931 }
928932
929- app. world . spawn ( handle) ;
933+ app. world_mut ( ) . spawn ( handle) ;
930934 gate_opener. open ( a_path) ;
931935 gate_opener. open ( b_path) ;
932936 gate_opener. open ( c_path) ;
@@ -1003,7 +1007,7 @@ mod tests {
10031007
10041008 let id = {
10051009 let handle = {
1006- let mut texts = app. world . resource_mut :: < Assets < CoolText > > ( ) ;
1010+ let mut texts = app. world_mut ( ) . resource_mut :: < Assets < CoolText > > ( ) ;
10071011 texts. add ( CoolText {
10081012 text : hello. clone ( ) ,
10091013 embedded : empty. clone ( ) ,
@@ -1016,7 +1020,7 @@ mod tests {
10161020
10171021 {
10181022 let text = app
1019- . world
1023+ . world ( )
10201024 . resource :: < Assets < CoolText > > ( )
10211025 . get ( & handle)
10221026 . unwrap ( ) ;
@@ -1027,36 +1031,36 @@ mod tests {
10271031 // handle is dropped
10281032 app. update ( ) ;
10291033 assert ! (
1030- app. world. resource:: <Assets <CoolText >>( ) . get( id) . is_none( ) ,
1034+ app. world( ) . resource:: <Assets <CoolText >>( ) . get( id) . is_none( ) ,
10311035 "asset has no handles, so it should have been dropped last update"
10321036 ) ;
10331037 // remove event is emitted
10341038 app. update ( ) ;
1035- let events = std:: mem:: take ( & mut app. world . resource_mut :: < StoredEvents > ( ) . 0 ) ;
1039+ let events = std:: mem:: take ( & mut app. world_mut ( ) . resource_mut :: < StoredEvents > ( ) . 0 ) ;
10361040 let expected_events = vec ! [ AssetEvent :: Added { id } , AssetEvent :: Removed { id } ] ;
10371041 assert_eq ! ( events, expected_events) ;
10381042
1039- let dep_handle = app. world . resource :: < AssetServer > ( ) . load ( dep_path) ;
1043+ let dep_handle = app. world ( ) . resource :: < AssetServer > ( ) . load ( dep_path) ;
10401044 let a = CoolText {
10411045 text : "a" . to_string ( ) ,
10421046 embedded : empty,
10431047 // this dependency is behind a manual load gate, which should prevent 'a' from emitting a LoadedWithDependencies event
10441048 dependencies : vec ! [ dep_handle. clone( ) ] ,
10451049 sub_texts : Vec :: new ( ) ,
10461050 } ;
1047- let a_handle = app. world . resource :: < AssetServer > ( ) . load_asset ( a) ;
1051+ let a_handle = app. world ( ) . resource :: < AssetServer > ( ) . load_asset ( a) ;
10481052 app. update ( ) ;
10491053 // TODO: ideally it doesn't take two updates for the added event to emit
10501054 app. update ( ) ;
10511055
1052- let events = std:: mem:: take ( & mut app. world . resource_mut :: < StoredEvents > ( ) . 0 ) ;
1056+ let events = std:: mem:: take ( & mut app. world_mut ( ) . resource_mut :: < StoredEvents > ( ) . 0 ) ;
10531057 let expected_events = vec ! [ AssetEvent :: Added { id: a_handle. id( ) } ] ;
10541058 assert_eq ! ( events, expected_events) ;
10551059
10561060 gate_opener. open ( dep_path) ;
10571061 loop {
10581062 app. update ( ) ;
1059- let events = std:: mem:: take ( & mut app. world . resource_mut :: < StoredEvents > ( ) . 0 ) ;
1063+ let events = std:: mem:: take ( & mut app. world_mut ( ) . resource_mut :: < StoredEvents > ( ) . 0 ) ;
10601064 if events. is_empty ( ) {
10611065 continue ;
10621066 }
@@ -1070,7 +1074,7 @@ mod tests {
10701074 break ;
10711075 }
10721076 app. update ( ) ;
1073- let events = std:: mem:: take ( & mut app. world . resource_mut :: < StoredEvents > ( ) . 0 ) ;
1077+ let events = std:: mem:: take ( & mut app. world_mut ( ) . resource_mut :: < StoredEvents > ( ) . 0 ) ;
10741078 let expected_events = vec ! [ AssetEvent :: Added {
10751079 id: dep_handle. id( ) ,
10761080 } ] ;
@@ -1117,7 +1121,7 @@ mod tests {
11171121 app. init_asset :: < CoolText > ( )
11181122 . init_asset :: < SubText > ( )
11191123 . register_asset_loader ( CoolTextLoader ) ;
1120- let asset_server = app. world . resource :: < AssetServer > ( ) . clone ( ) ;
1124+ let asset_server = app. world ( ) . resource :: < AssetServer > ( ) . clone ( ) ;
11211125 let handle: Handle < LoadedFolder > = asset_server. load_folder ( "text" ) ;
11221126 gate_opener. open ( a_path) ;
11231127 gate_opener. open ( b_path) ;
0 commit comments