@@ -12,7 +12,7 @@ use crate::{
12
12
} ,
13
13
entity:: { Entities , Entity , EntityLocation } ,
14
14
prelude:: Component ,
15
- storage:: { Column , ComponentSparseSet } ,
15
+ storage:: { Column , ComponentSparseSet , Storages } ,
16
16
system:: Resource ,
17
17
} ;
18
18
use bevy_ptr:: Ptr ;
@@ -271,6 +271,20 @@ impl<'w> UnsafeWorldCell<'w> {
271
271
unsafe { self . world_metadata ( ) } . increment_change_tick ( )
272
272
}
273
273
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
+
274
288
/// Shorthand helper function for getting the [`ArchetypeComponentId`] for a resource.
275
289
#[ inline]
276
290
pub ( crate ) fn get_resource_archetype_component_id (
@@ -342,8 +356,7 @@ impl<'w> UnsafeWorldCell<'w> {
342
356
pub unsafe fn get_resource_by_id ( self , component_id : ComponentId ) -> Option < Ptr < ' w > > {
343
357
// SAFETY: caller ensures that `self` has permission to access `R`
344
358
// caller ensures that no mutable reference exists to `R`
345
- unsafe { self . unsafe_world ( ) }
346
- . storages
359
+ unsafe { self . storages ( ) }
347
360
. resources
348
361
. get ( component_id) ?
349
362
. get_data ( )
@@ -385,8 +398,7 @@ impl<'w> UnsafeWorldCell<'w> {
385
398
pub unsafe fn get_non_send_resource_by_id ( self , component_id : ComponentId ) -> Option < Ptr < ' w > > {
386
399
// SAFETY: we only access data on world that the caller has ensured is unaliased and we have
387
400
// permission to access.
388
- unsafe { self . unsafe_world ( ) }
389
- . storages
401
+ unsafe { self . storages ( ) }
390
402
. non_send_resources
391
403
. get ( component_id) ?
392
404
. get_data ( )
@@ -429,8 +441,7 @@ impl<'w> UnsafeWorldCell<'w> {
429
441
) -> Option < MutUntyped < ' w > > {
430
442
// SAFETY: we only access data that the caller has ensured is unaliased and `self`
431
443
// has permission to access.
432
- let ( ptr, ticks) = unsafe { self . unsafe_world ( ) }
433
- . storages
444
+ let ( ptr, ticks) = unsafe { self . storages ( ) }
434
445
. resources
435
446
. get ( component_id) ?
436
447
. get_with_ticks ( ) ?;
@@ -492,8 +503,7 @@ impl<'w> UnsafeWorldCell<'w> {
492
503
let change_tick = self . change_tick ( ) ;
493
504
// SAFETY: we only access data that the caller has ensured is unaliased and `self`
494
505
// has permission to access.
495
- let ( ptr, ticks) = unsafe { self . unsafe_world ( ) }
496
- . storages
506
+ let ( ptr, ticks) = unsafe { self . storages ( ) }
497
507
. non_send_resources
498
508
. get ( component_id) ?
499
509
. get_with_ticks ( ) ?;
@@ -526,8 +536,7 @@ impl<'w> UnsafeWorldCell<'w> {
526
536
// - caller ensures there is no `&mut World`
527
537
// - caller ensures there are no mutable borrows of this resource
528
538
// - caller ensures that we have permission to access this resource
529
- unsafe { self . unsafe_world ( ) }
530
- . storages
539
+ unsafe { self . storages ( ) }
531
540
. resources
532
541
. get ( component_id) ?
533
542
. get_with_ticks ( )
@@ -551,8 +560,7 @@ impl<'w> UnsafeWorldCell<'w> {
551
560
// - caller ensures there is no `&mut World`
552
561
// - caller ensures there are no mutable borrows of this resource
553
562
// - caller ensures that we have permission to access this resource
554
- unsafe { self . unsafe_world ( ) }
555
- . storages
563
+ unsafe { self . storages ( ) }
556
564
. non_send_resources
557
565
. get ( component_id) ?
558
566
. get_with_ticks ( )
@@ -878,7 +886,7 @@ impl<'w> UnsafeWorldCell<'w> {
878
886
) -> Option < & ' w Column > {
879
887
// SAFETY: caller ensures returned data is not misused and we have not created any borrows
880
888
// 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)
882
890
}
883
891
884
892
#[ inline]
@@ -889,10 +897,7 @@ impl<'w> UnsafeWorldCell<'w> {
889
897
unsafe fn fetch_sparse_set ( self , component_id : ComponentId ) -> Option < & ' w ComponentSparseSet > {
890
898
// SAFETY: caller ensures returned data is not misused and we have not created any borrows
891
899
// 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)
896
901
}
897
902
}
898
903
0 commit comments