@@ -12,7 +12,7 @@ use crate::{
1212 } ,
1313 entity:: { Entities , Entity , EntityLocation } ,
1414 prelude:: Component ,
15- storage:: { Column , ComponentSparseSet } ,
15+ storage:: { Column , ComponentSparseSet , Storages } ,
1616 system:: Resource ,
1717} ;
1818use bevy_ptr:: Ptr ;
@@ -271,6 +271,20 @@ impl<'w> UnsafeWorldCell<'w> {
271271 unsafe { self . world_metadata ( ) } . increment_change_tick ( )
272272 }
273273
274+ /// Provides unchecked access to the internal data stores of the [`World`].
275+ ///
276+ /// # Safety
277+ ///
278+ /// The caller must ensure that this is only used to access world data
279+ /// that this [`UnsafeWorldCell`] is allowed to.
280+ /// As always, any mutable access to a component must not exist at the same
281+ /// time as any other accesses to that same component.
282+ #[ inline]
283+ pub unsafe fn storages ( self ) -> & ' w Storages {
284+ // SAFETY: The caller promises to only access world data allowed by this instance.
285+ & unsafe { self . unsafe_world ( ) } . storages
286+ }
287+
274288 /// Shorthand helper function for getting the [`ArchetypeComponentId`] for a resource.
275289 #[ inline]
276290 pub ( crate ) fn get_resource_archetype_component_id (
@@ -342,8 +356,7 @@ impl<'w> UnsafeWorldCell<'w> {
342356 pub unsafe fn get_resource_by_id ( self , component_id : ComponentId ) -> Option < Ptr < ' w > > {
343357 // SAFETY: caller ensures that `self` has permission to access `R`
344358 // caller ensures that no mutable reference exists to `R`
345- unsafe { self . unsafe_world ( ) }
346- . storages
359+ unsafe { self . storages ( ) }
347360 . resources
348361 . get ( component_id) ?
349362 . get_data ( )
@@ -385,8 +398,7 @@ impl<'w> UnsafeWorldCell<'w> {
385398 pub unsafe fn get_non_send_resource_by_id ( self , component_id : ComponentId ) -> Option < Ptr < ' w > > {
386399 // SAFETY: we only access data on world that the caller has ensured is unaliased and we have
387400 // permission to access.
388- unsafe { self . unsafe_world ( ) }
389- . storages
401+ unsafe { self . storages ( ) }
390402 . non_send_resources
391403 . get ( component_id) ?
392404 . get_data ( )
@@ -429,8 +441,7 @@ impl<'w> UnsafeWorldCell<'w> {
429441 ) -> Option < MutUntyped < ' w > > {
430442 // SAFETY: we only access data that the caller has ensured is unaliased and `self`
431443 // has permission to access.
432- let ( ptr, ticks) = unsafe { self . unsafe_world ( ) }
433- . storages
444+ let ( ptr, ticks) = unsafe { self . storages ( ) }
434445 . resources
435446 . get ( component_id) ?
436447 . get_with_ticks ( ) ?;
@@ -492,8 +503,7 @@ impl<'w> UnsafeWorldCell<'w> {
492503 let change_tick = self . change_tick ( ) ;
493504 // SAFETY: we only access data that the caller has ensured is unaliased and `self`
494505 // has permission to access.
495- let ( ptr, ticks) = unsafe { self . unsafe_world ( ) }
496- . storages
506+ let ( ptr, ticks) = unsafe { self . storages ( ) }
497507 . non_send_resources
498508 . get ( component_id) ?
499509 . get_with_ticks ( ) ?;
@@ -526,8 +536,7 @@ impl<'w> UnsafeWorldCell<'w> {
526536 // - caller ensures there is no `&mut World`
527537 // - caller ensures there are no mutable borrows of this resource
528538 // - caller ensures that we have permission to access this resource
529- unsafe { self . unsafe_world ( ) }
530- . storages
539+ unsafe { self . storages ( ) }
531540 . resources
532541 . get ( component_id) ?
533542 . get_with_ticks ( )
@@ -551,8 +560,7 @@ impl<'w> UnsafeWorldCell<'w> {
551560 // - caller ensures there is no `&mut World`
552561 // - caller ensures there are no mutable borrows of this resource
553562 // - caller ensures that we have permission to access this resource
554- unsafe { self . unsafe_world ( ) }
555- . storages
563+ unsafe { self . storages ( ) }
556564 . non_send_resources
557565 . get ( component_id) ?
558566 . get_with_ticks ( )
@@ -878,7 +886,7 @@ impl<'w> UnsafeWorldCell<'w> {
878886 ) -> Option < & ' w Column > {
879887 // SAFETY: caller ensures returned data is not misused and we have not created any borrows
880888 // of component/resource data
881- unsafe { self . unsafe_world ( ) } . storages . tables [ location. table_id ] . get_column ( component_id)
889+ unsafe { self . storages ( ) } . tables [ location. table_id ] . get_column ( component_id)
882890 }
883891
884892 #[ inline]
@@ -889,10 +897,7 @@ impl<'w> UnsafeWorldCell<'w> {
889897 unsafe fn fetch_sparse_set ( self , component_id : ComponentId ) -> Option < & ' w ComponentSparseSet > {
890898 // SAFETY: caller ensures returned data is not misused and we have not created any borrows
891899 // of component/resource data
892- unsafe { self . unsafe_world ( ) }
893- . storages
894- . sparse_sets
895- . get ( component_id)
900+ unsafe { self . storages ( ) } . sparse_sets . get ( component_id)
896901 }
897902}
898903
0 commit comments