@@ -20,7 +20,7 @@ use crate::{
20
20
storage:: { ResourceData , SparseSet , Storages } ,
21
21
system:: Resource ,
22
22
} ;
23
- use bevy_ptr:: { OwningPtr , Ptr , UnsafeCellDeref } ;
23
+ use bevy_ptr:: { OwningPtr , Ptr } ;
24
24
use bevy_utils:: tracing:: warn;
25
25
use std:: {
26
26
any:: TypeId ,
@@ -907,7 +907,7 @@ impl World {
907
907
#[ inline]
908
908
pub fn get_resource_mut < R : Resource > ( & mut self ) -> Option < Mut < ' _ , R > > {
909
909
// SAFETY: unique world access
910
- unsafe { self . get_resource_unchecked_mut ( ) }
910
+ unsafe { self . as_interior_mutable ( ) . get_resource_mut ( ) }
911
911
}
912
912
913
913
// PERF: optimize this to avoid redundant lookups
@@ -924,18 +924,6 @@ impl World {
924
924
self . resource_mut ( )
925
925
}
926
926
927
- /// Gets a mutable reference to the resource of the given type, if it exists
928
- /// Otherwise returns [None]
929
- ///
930
- /// # Safety
931
- /// This will allow aliased mutable access to the given resource type. The caller must ensure
932
- /// that there is either only one mutable access or multiple immutable accesses at a time.
933
- #[ inline]
934
- pub unsafe fn get_resource_unchecked_mut < R : Resource > ( & self ) -> Option < Mut < ' _ , R > > {
935
- let component_id = self . components . get_resource_id ( TypeId :: of :: < R > ( ) ) ?;
936
- self . get_resource_unchecked_mut_with_id ( component_id)
937
- }
938
-
939
927
/// Gets an immutable reference to the non-send resource of the given type, if it exists.
940
928
///
941
929
/// # Panics
@@ -990,19 +978,7 @@ impl World {
990
978
#[ inline]
991
979
pub fn get_non_send_resource_mut < R : ' static > ( & mut self ) -> Option < Mut < ' _ , R > > {
992
980
// SAFETY: unique world access
993
- unsafe { self . get_non_send_resource_unchecked_mut ( ) }
994
- }
995
-
996
- /// Gets a mutable reference to the non-send resource of the given type, if it exists.
997
- /// Otherwise returns [None]
998
- ///
999
- /// # Safety
1000
- /// This will allow aliased mutable access to the given non-send resource type. The caller must
1001
- /// ensure that there is either only one mutable access or multiple immutable accesses at a time.
1002
- #[ inline]
1003
- pub unsafe fn get_non_send_resource_unchecked_mut < R : ' static > ( & self ) -> Option < Mut < ' _ , R > > {
1004
- let component_id = self . components . get_resource_id ( TypeId :: of :: < R > ( ) ) ?;
1005
- self . get_non_send_unchecked_mut_with_id ( component_id)
981
+ unsafe { self . as_interior_mutable ( ) . get_non_send_resource_mut ( ) }
1006
982
}
1007
983
1008
984
// Shorthand helper function for getting the data and change ticks for a resource.
@@ -1271,25 +1247,6 @@ impl World {
1271
1247
. map ( |ptr| ptr. deref ( ) )
1272
1248
}
1273
1249
1274
- /// # Safety
1275
- /// `component_id` must be assigned to a component of type `R`
1276
- /// Caller must ensure this doesn't violate Rust mutability rules for the given resource.
1277
- #[ inline]
1278
- pub ( crate ) unsafe fn get_resource_unchecked_mut_with_id < R > (
1279
- & self ,
1280
- component_id : ComponentId ,
1281
- ) -> Option < Mut < ' _ , R > > {
1282
- let ( ptr, ticks) = self . get_resource_with_ticks ( component_id) ?;
1283
- Some ( Mut {
1284
- value : ptr. assert_unique ( ) . deref_mut ( ) ,
1285
- ticks : Ticks {
1286
- component_ticks : ticks. deref_mut ( ) ,
1287
- last_change_tick : self . last_change_tick ( ) ,
1288
- change_tick : self . read_change_tick ( ) ,
1289
- } ,
1290
- } )
1291
- }
1292
-
1293
1250
/// # Safety
1294
1251
/// `component_id` must be assigned to a component of type `R`
1295
1252
#[ inline]
@@ -1301,18 +1258,6 @@ impl World {
1301
1258
self . get_resource_with_id ( component_id)
1302
1259
}
1303
1260
1304
- /// # Safety
1305
- /// `component_id` must be assigned to a component of type `R`.
1306
- /// Caller must ensure this doesn't violate Rust mutability rules for the given resource.
1307
- #[ inline]
1308
- pub ( crate ) unsafe fn get_non_send_unchecked_mut_with_id < R : ' static > (
1309
- & self ,
1310
- component_id : ComponentId ,
1311
- ) -> Option < Mut < ' _ , R > > {
1312
- self . validate_non_send_access :: < R > ( ) ;
1313
- self . get_resource_unchecked_mut_with_id ( component_id)
1314
- }
1315
-
1316
1261
/// Inserts a new resource with the given `value`. Will replace the value if it already existed.
1317
1262
///
1318
1263
/// **You should prefer to use the typed API [`World::insert_resource`] where possible and only
@@ -1459,28 +1404,11 @@ impl World {
1459
1404
/// use this in cases where the actual types are not known at compile time.**
1460
1405
#[ inline]
1461
1406
pub fn get_resource_mut_by_id ( & mut self , component_id : ComponentId ) -> Option < MutUntyped < ' _ > > {
1462
- let info = self . components . get_info ( component_id) ?;
1463
- if !info. is_send_and_sync ( ) {
1464
- self . validate_non_send_access_untyped ( info. name ( ) ) ;
1407
+ // SAFETY: unique world access
1408
+ unsafe {
1409
+ self . as_interior_mutable ( )
1410
+ . get_resource_mut_by_id ( component_id)
1465
1411
}
1466
-
1467
- let ( ptr, ticks) = self . get_resource_with_ticks ( component_id) ?;
1468
-
1469
- // SAFE: This function has exclusive access to the world so nothing aliases `ticks`.
1470
- let ticks = Ticks {
1471
- // SAFETY:
1472
- // - index is in-bounds because the column is initialized and non-empty
1473
- // - no other reference to the ticks of the same row can exist at the same time
1474
- component_ticks : unsafe { ticks. deref_mut ( ) } ,
1475
- last_change_tick : self . last_change_tick ( ) ,
1476
- change_tick : self . read_change_tick ( ) ,
1477
- } ;
1478
-
1479
- Some ( MutUntyped {
1480
- // SAFETY: This function has exclusive access to the world so nothing aliases `ptr`.
1481
- value : unsafe { ptr. assert_unique ( ) } ,
1482
- ticks,
1483
- } )
1484
1412
}
1485
1413
1486
1414
/// Removes the resource of a given type, if it exists. Otherwise returns [None].
0 commit comments