@@ -145,7 +145,7 @@ impl Plugin for AssetPlugin {
145145 watch_for_changes,
146146 } => {
147147 let source_reader = app
148- . world
148+ . world_mut ( )
149149 . resource_mut :: < AssetProviders > ( )
150150 . get_source_reader ( source) ;
151151 app. insert_resource ( AssetServer :: new ( source_reader, * watch_for_changes) ) ;
@@ -155,7 +155,7 @@ impl Plugin for AssetPlugin {
155155 watch_for_changes,
156156 } => {
157157 let destination_reader = app
158- . world
158+ . world_mut ( )
159159 . resource_mut :: < AssetProviders > ( )
160160 . get_destination_reader ( destination) ;
161161 app. insert_resource ( AssetServer :: new ( destination_reader, * watch_for_changes) ) ;
@@ -165,7 +165,7 @@ impl Plugin for AssetPlugin {
165165 destination,
166166 watch_for_changes,
167167 } => {
168- let mut asset_providers = app. world . resource_mut :: < AssetProviders > ( ) ;
168+ let mut asset_providers = app. world_mut ( ) . resource_mut :: < AssetProviders > ( ) ;
169169 let processor = AssetProcessor :: new ( & mut asset_providers, source, destination) ;
170170 let destination_reader = asset_providers. get_destination_reader ( source) ;
171171 // the main asset server gates loads based on asset state
@@ -190,7 +190,7 @@ impl Plugin for AssetPlugin {
190190 )
191191 . add_systems ( UpdateAssets , server:: handle_internal_asset_events) ;
192192
193- let mut order = app. world . resource_mut :: < MainScheduleOrder > ( ) ;
193+ let mut order = app. world_mut ( ) . resource_mut :: < MainScheduleOrder > ( ) ;
194194 order. insert_after ( First , UpdateAssets ) ;
195195 order. insert_after ( PostUpdate , AssetEvents ) ;
196196 }
@@ -275,20 +275,24 @@ pub trait AssetApp {
275275
276276impl AssetApp for App {
277277 fn register_asset_loader < L : AssetLoader > ( & mut self , loader : L ) -> & mut Self {
278- self . world . resource :: < AssetServer > ( ) . register_loader ( loader) ;
278+ self . world ( )
279+ . resource :: < AssetServer > ( )
280+ . register_loader ( loader) ;
279281 self
280282 }
281283
282284 fn init_asset_loader < L : AssetLoader + FromWorld > ( & mut self ) -> & mut Self {
283- let loader = L :: from_world ( & mut self . world ) ;
285+ let loader = L :: from_world ( self . world_mut ( ) ) ;
284286 self . register_asset_loader ( loader)
285287 }
286288
287289 fn init_asset < A : Asset > ( & mut self ) -> & mut Self {
288290 let assets = Assets :: < A > :: default ( ) ;
289- self . world . resource :: < AssetServer > ( ) . register_asset ( & assets) ;
290- if self . world . contains_resource :: < AssetProcessor > ( ) {
291- let processor = self . world . resource :: < AssetProcessor > ( ) ;
291+ self . world ( )
292+ . resource :: < AssetServer > ( )
293+ . register_asset ( & assets) ;
294+ if self . world ( ) . contains_resource :: < AssetProcessor > ( ) {
295+ let processor = self . world ( ) . resource :: < AssetProcessor > ( ) ;
292296 // The processor should have its own handle provider separate from the Asset storage
293297 // to ensure the id spaces are entirely separate. Not _strictly_ necessary, but
294298 // desirable.
@@ -311,7 +315,7 @@ impl AssetApp for App {
311315 where
312316 A : Asset + Reflect + FromReflect + GetTypeRegistration ,
313317 {
314- let type_registry = self . world . resource :: < AppTypeRegistry > ( ) ;
318+ let type_registry = self . world ( ) . resource :: < AppTypeRegistry > ( ) ;
315319 {
316320 let mut type_registry = type_registry. write ( ) ;
317321
@@ -325,21 +329,21 @@ impl AssetApp for App {
325329 }
326330
327331 fn preregister_asset_loader < L : AssetLoader > ( & mut self , extensions : & [ & str ] ) -> & mut Self {
328- self . world
332+ self . world_mut ( )
329333 . resource_mut :: < AssetServer > ( )
330334 . preregister_loader :: < L > ( extensions) ;
331335 self
332336 }
333337
334338 fn register_asset_processor < P : Process > ( & mut self , processor : P ) -> & mut Self {
335- if let Some ( asset_processor) = self . world . get_resource :: < AssetProcessor > ( ) {
339+ if let Some ( asset_processor) = self . world ( ) . get_resource :: < AssetProcessor > ( ) {
336340 asset_processor. register_processor ( processor) ;
337341 }
338342 self
339343 }
340344
341345 fn set_default_asset_processor < P : Process > ( & mut self , extension : & str ) -> & mut Self {
342- if let Some ( asset_processor) = self . world . get_resource :: < AssetProcessor > ( ) {
346+ if let Some ( asset_processor) = self . world ( ) . get_resource :: < AssetProcessor > ( ) {
343347 asset_processor. set_default_processor :: < P > ( extension) ;
344348 }
345349 self
@@ -364,7 +368,7 @@ pub struct AssetEvents;
364368#[ macro_export]
365369macro_rules! load_internal_asset {
366370 ( $app: ident, $handle: expr, $path_str: expr, $loader: expr) => { {
367- let mut assets = $app. world . resource_mut:: <$crate:: Assets <_>>( ) ;
371+ let mut assets = $app. world_mut ( ) . resource_mut:: <$crate:: Assets <_>>( ) ;
368372 assets. insert( $handle, ( $loader) (
369373 include_str!( $path_str) ,
370374 std:: path:: Path :: new( file!( ) )
@@ -376,7 +380,7 @@ macro_rules! load_internal_asset {
376380 } } ;
377381 // we can't support params without variadic arguments, so internal assets with additional params can't be hot-reloaded
378382 ( $app: ident, $handle: ident, $path_str: expr, $loader: expr $( , $param: expr) +) => { {
379- let mut assets = $app. world . resource_mut:: <$crate:: Assets <_>>( ) ;
383+ let mut assets = $app. world_mut ( ) . resource_mut:: <$crate:: Assets <_>>( ) ;
380384 assets. insert( $handle, ( $loader) (
381385 include_str!( $path_str) ,
382386 std:: path:: Path :: new( file!( ) )
@@ -393,7 +397,7 @@ macro_rules! load_internal_asset {
393397#[ macro_export]
394398macro_rules! load_internal_binary_asset {
395399 ( $app: ident, $handle: expr, $path_str: expr, $loader: expr) => { {
396- let mut assets = $app. world . resource_mut:: <$crate:: Assets <_>>( ) ;
400+ let mut assets = $app. world_mut ( ) . resource_mut:: <$crate:: Assets <_>>( ) ;
397401 assets. insert(
398402 $handle,
399403 ( $loader) (
@@ -525,7 +529,7 @@ mod tests {
525529 fn run_app_until ( app : & mut App , mut predicate : impl FnMut ( & mut World ) -> Option < ( ) > ) {
526530 for _ in 0 ..LARGE_ITERATION_COUNT {
527531 app. update ( ) ;
528- if ( predicate) ( & mut app. world ) . is_some ( ) {
532+ if ( predicate) ( app. world_mut ( ) ) . is_some ( ) {
529533 return ;
530534 }
531535 }
@@ -611,13 +615,13 @@ mod tests {
611615 . init_resource :: < StoredEvents > ( )
612616 . register_asset_loader ( CoolTextLoader )
613617 . add_systems ( Update , store_asset_events) ;
614- let asset_server = app. world . resource :: < AssetServer > ( ) . clone ( ) ;
618+ let asset_server = app. world ( ) . resource :: < AssetServer > ( ) . clone ( ) ;
615619 let handle: Handle < CoolText > = asset_server. load ( a_path) ;
616620 let a_id = handle. id ( ) ;
617- let entity = app. world . spawn ( handle) . id ( ) ;
621+ let entity = app. world_mut ( ) . spawn ( handle) . id ( ) ;
618622 app. update ( ) ;
619623 {
620- let a_text = get :: < CoolText > ( & app. world , a_id) ;
624+ let a_text = get :: < CoolText > ( app. world ( ) , a_id) ;
621625 let ( a_load, a_deps, a_rec_deps) = asset_server. get_load_states ( a_id) . unwrap ( ) ;
622626 assert ! ( a_text. is_none( ) , "a's asset should not exist yet" ) ;
623627 assert_eq ! ( a_load, LoadState :: Loading , "a should still be loading" ) ;
@@ -799,27 +803,27 @@ mod tests {
799803 } ) ;
800804
801805 {
802- let mut texts = app. world . resource_mut :: < Assets < CoolText > > ( ) ;
806+ let mut texts = app. world_mut ( ) . resource_mut :: < Assets < CoolText > > ( ) ;
803807 let a = texts. get_mut ( a_id) . unwrap ( ) ;
804808 a. text = "Changed" . to_string ( ) ;
805809 }
806810
807- app. world . despawn ( entity) ;
811+ app. world_mut ( ) . despawn ( entity) ;
808812 app. update ( ) ;
809813 assert_eq ! (
810- app. world. resource:: <Assets <CoolText >>( ) . len( ) ,
814+ app. world( ) . resource:: <Assets <CoolText >>( ) . len( ) ,
811815 0 ,
812816 "CoolText asset entities should be despawned when no more handles exist"
813817 ) ;
814818 app. update ( ) ;
815819 // this requires a second update because the parent asset was freed in the previous app.update()
816820 assert_eq ! (
817- app. world. resource:: <Assets <SubText >>( ) . len( ) ,
821+ app. world( ) . resource:: <Assets <SubText >>( ) . len( ) ,
818822 0 ,
819823 "SubText asset entities should be despawned when no more handles exist"
820824 ) ;
821- let events = app. world . remove_resource :: < StoredEvents > ( ) . unwrap ( ) ;
822- let id_results = app. world . remove_resource :: < IdResults > ( ) . unwrap ( ) ;
825+ let events = app. world_mut ( ) . remove_resource :: < StoredEvents > ( ) . unwrap ( ) ;
826+ let id_results = app. world_mut ( ) . remove_resource :: < IdResults > ( ) . unwrap ( ) ;
823827 let expected_events = vec ! [
824828 AssetEvent :: Added { id: a_id } ,
825829 AssetEvent :: LoadedWithDependencies {
@@ -909,7 +913,7 @@ mod tests {
909913 let ( mut app, gate_opener) = test_app ( dir) ;
910914 app. init_asset :: < CoolText > ( )
911915 . register_asset_loader ( CoolTextLoader ) ;
912- let asset_server = app. world . resource :: < AssetServer > ( ) . clone ( ) ;
916+ let asset_server = app. world ( ) . resource :: < AssetServer > ( ) . clone ( ) ;
913917 let handle: Handle < CoolText > = asset_server. load ( a_path) ;
914918 let a_id = handle. id ( ) ;
915919 {
@@ -925,7 +929,7 @@ mod tests {
925929 ) ;
926930 }
927931
928- app. world . spawn ( handle) ;
932+ app. world_mut ( ) . spawn ( handle) ;
929933 gate_opener. open ( a_path) ;
930934 gate_opener. open ( b_path) ;
931935 gate_opener. open ( c_path) ;
@@ -1002,7 +1006,7 @@ mod tests {
10021006
10031007 let id = {
10041008 let handle = {
1005- let mut texts = app. world . resource_mut :: < Assets < CoolText > > ( ) ;
1009+ let mut texts = app. world_mut ( ) . resource_mut :: < Assets < CoolText > > ( ) ;
10061010 texts. add ( CoolText {
10071011 text : hello. clone ( ) ,
10081012 embedded : empty. clone ( ) ,
@@ -1015,7 +1019,7 @@ mod tests {
10151019
10161020 {
10171021 let text = app
1018- . world
1022+ . world ( )
10191023 . resource :: < Assets < CoolText > > ( )
10201024 . get ( & handle)
10211025 . unwrap ( ) ;
@@ -1026,36 +1030,36 @@ mod tests {
10261030 // handle is dropped
10271031 app. update ( ) ;
10281032 assert ! (
1029- app. world. resource:: <Assets <CoolText >>( ) . get( id) . is_none( ) ,
1033+ app. world( ) . resource:: <Assets <CoolText >>( ) . get( id) . is_none( ) ,
10301034 "asset has no handles, so it should have been dropped last update"
10311035 ) ;
10321036 // remove event is emitted
10331037 app. update ( ) ;
1034- let events = std:: mem:: take ( & mut app. world . resource_mut :: < StoredEvents > ( ) . 0 ) ;
1038+ let events = std:: mem:: take ( & mut app. world_mut ( ) . resource_mut :: < StoredEvents > ( ) . 0 ) ;
10351039 let expected_events = vec ! [ AssetEvent :: Added { id } , AssetEvent :: Removed { id } ] ;
10361040 assert_eq ! ( events, expected_events) ;
10371041
1038- let dep_handle = app. world . resource :: < AssetServer > ( ) . load ( dep_path) ;
1042+ let dep_handle = app. world ( ) . resource :: < AssetServer > ( ) . load ( dep_path) ;
10391043 let a = CoolText {
10401044 text : "a" . to_string ( ) ,
10411045 embedded : empty,
10421046 // this dependency is behind a manual load gate, which should prevent 'a' from emitting a LoadedWithDependencies event
10431047 dependencies : vec ! [ dep_handle. clone( ) ] ,
10441048 sub_texts : Vec :: new ( ) ,
10451049 } ;
1046- let a_handle = app. world . resource :: < AssetServer > ( ) . load_asset ( a) ;
1050+ let a_handle = app. world ( ) . resource :: < AssetServer > ( ) . load_asset ( a) ;
10471051 app. update ( ) ;
10481052 // TODO: ideally it doesn't take two updates for the added event to emit
10491053 app. update ( ) ;
10501054
1051- let events = std:: mem:: take ( & mut app. world . resource_mut :: < StoredEvents > ( ) . 0 ) ;
1055+ let events = std:: mem:: take ( & mut app. world_mut ( ) . resource_mut :: < StoredEvents > ( ) . 0 ) ;
10521056 let expected_events = vec ! [ AssetEvent :: Added { id: a_handle. id( ) } ] ;
10531057 assert_eq ! ( events, expected_events) ;
10541058
10551059 gate_opener. open ( dep_path) ;
10561060 loop {
10571061 app. update ( ) ;
1058- let events = std:: mem:: take ( & mut app. world . resource_mut :: < StoredEvents > ( ) . 0 ) ;
1062+ let events = std:: mem:: take ( & mut app. world_mut ( ) . resource_mut :: < StoredEvents > ( ) . 0 ) ;
10591063 if events. is_empty ( ) {
10601064 continue ;
10611065 }
@@ -1069,7 +1073,7 @@ mod tests {
10691073 break ;
10701074 }
10711075 app. update ( ) ;
1072- let events = std:: mem:: take ( & mut app. world . resource_mut :: < StoredEvents > ( ) . 0 ) ;
1076+ let events = std:: mem:: take ( & mut app. world_mut ( ) . resource_mut :: < StoredEvents > ( ) . 0 ) ;
10731077 let expected_events = vec ! [ AssetEvent :: Added {
10741078 id: dep_handle. id( ) ,
10751079 } ] ;
@@ -1116,7 +1120,7 @@ mod tests {
11161120 app. init_asset :: < CoolText > ( )
11171121 . init_asset :: < SubText > ( )
11181122 . register_asset_loader ( CoolTextLoader ) ;
1119- let asset_server = app. world . resource :: < AssetServer > ( ) . clone ( ) ;
1123+ let asset_server = app. world ( ) . resource :: < AssetServer > ( ) . clone ( ) ;
11201124 let handle: Handle < LoadedFolder > = asset_server. load_folder ( "text" ) ;
11211125 gate_opener. open ( a_path) ;
11221126 gate_opener. open ( b_path) ;
0 commit comments