@@ -13,16 +13,17 @@ pub mod unsafe_world_cell;
13
13
#[ cfg( feature = "bevy_reflect" ) ]
14
14
pub mod reflect;
15
15
16
- pub use crate :: {
17
- change_detection:: { Mut , Ref , CHECK_TICK_THRESHOLD } ,
18
- world:: command_queue:: CommandQueue ,
19
- } ;
20
16
use crate :: {
17
+ bundle:: BundleId ,
21
18
error:: { DefaultErrorHandler , ErrorHandler } ,
22
19
event:: BufferedEvent ,
23
20
lifecycle:: { ComponentHooks , ADD , DESPAWN , INSERT , REMOVE , REPLACE } ,
24
21
prelude:: { Add , Despawn , Insert , Remove , Replace } ,
25
22
} ;
23
+ pub use crate :: {
24
+ change_detection:: { Mut , Ref , CHECK_TICK_THRESHOLD } ,
25
+ world:: command_queue:: CommandQueue ,
26
+ } ;
26
27
pub use bevy_ecs_macros:: FromWorld ;
27
28
use bevy_utils:: prelude:: DebugName ;
28
29
pub use deferred_world:: DeferredWorld ;
@@ -2302,15 +2303,7 @@ impl World {
2302
2303
2303
2304
self . flush ( ) ;
2304
2305
let change_tick = self . change_tick ( ) ;
2305
- // SAFETY: These come from the same world. `Self.components_registrator` can't be used since we borrow other fields too.
2306
- let mut registrator =
2307
- unsafe { ComponentsRegistrator :: new ( & mut self . components , & mut self . component_ids ) } ;
2308
-
2309
- // SAFETY: `registrator`, `self.bundles`, and `self.storages` all come from this world.
2310
- let bundle_id = unsafe {
2311
- self . bundles
2312
- . register_info :: < B > ( & mut registrator, & mut self . storages )
2313
- } ;
2306
+ let bundle_id = self . register_bundle_info :: < B > ( ) ;
2314
2307
2315
2308
let mut batch_iter = batch. into_iter ( ) ;
2316
2309
@@ -2450,15 +2443,7 @@ impl World {
2450
2443
2451
2444
self . flush ( ) ;
2452
2445
let change_tick = self . change_tick ( ) ;
2453
- // SAFETY: These come from the same world. `Self.components_registrator` can't be used since we borrow other fields too.
2454
- let mut registrator =
2455
- unsafe { ComponentsRegistrator :: new ( & mut self . components , & mut self . component_ids ) } ;
2456
-
2457
- // SAFETY: `registrator`, `self.bundles`, and `self.storages` all come from this world.
2458
- let bundle_id = unsafe {
2459
- self . bundles
2460
- . register_info :: < B > ( & mut registrator, & mut self . storages )
2461
- } ;
2446
+ let bundle_id = self . register_bundle_info :: < B > ( ) ;
2462
2447
2463
2448
let mut invalid_entities = Vec :: < Entity > :: new ( ) ;
2464
2449
let mut batch_iter = batch. into_iter ( ) ;
@@ -2470,7 +2455,7 @@ impl World {
2470
2455
if let Some ( ( first_entity, first_bundle) ) = batch_iter. next ( ) {
2471
2456
if let Some ( first_location) = self . entities ( ) . get ( first_entity) {
2472
2457
let mut cache = InserterArchetypeCache {
2473
- // SAFETY: we initialized this bundle_id in `register_info `
2458
+ // SAFETY: we initialized this bundle_id in `register_bundle_info `
2474
2459
inserter : unsafe {
2475
2460
BundleInserter :: new_with_id (
2476
2461
self ,
@@ -3075,18 +3060,34 @@ impl World {
3075
3060
/// component in the bundle.
3076
3061
#[ inline]
3077
3062
pub fn register_bundle < B : Bundle > ( & mut self ) -> & BundleInfo {
3063
+ let id = self . register_bundle_info :: < B > ( ) ;
3064
+
3065
+ // SAFETY: We just initialized the bundle so its id should definitely be valid.
3066
+ unsafe { self . bundles . get ( id) . debug_checked_unwrap ( ) }
3067
+ }
3068
+
3069
+ pub ( crate ) fn register_bundle_info < B : Bundle > ( & mut self ) -> BundleId {
3078
3070
// SAFETY: These come from the same world. `Self.components_registrator` can't be used since we borrow other fields too.
3079
3071
let mut registrator =
3080
3072
unsafe { ComponentsRegistrator :: new ( & mut self . components , & mut self . component_ids ) } ;
3081
3073
3082
3074
// SAFETY: `registrator`, `self.storages` and `self.bundles` all come from this world.
3083
- let id = unsafe {
3075
+ unsafe {
3084
3076
self . bundles
3085
3077
. register_info :: < B > ( & mut registrator, & mut self . storages )
3086
- } ;
3078
+ }
3079
+ }
3087
3080
3088
- // SAFETY: We just initialized the bundle so its id should definitely be valid.
3089
- unsafe { self . bundles . get ( id) . debug_checked_unwrap ( ) }
3081
+ pub ( crate ) fn register_contributed_bundle_info < B : Bundle > ( & mut self ) -> BundleId {
3082
+ // SAFETY: These come from the same world. `Self.components_registrator` can't be used since we borrow other fields too.
3083
+ let mut registrator =
3084
+ unsafe { ComponentsRegistrator :: new ( & mut self . components , & mut self . component_ids ) } ;
3085
+
3086
+ // SAFETY: `registrator`, `self.bundles` and `self.storages` are all from this world.
3087
+ unsafe {
3088
+ self . bundles
3089
+ . register_contributed_bundle_info :: < B > ( & mut registrator, & mut self . storages )
3090
+ }
3090
3091
}
3091
3092
3092
3093
/// Registers the given [`ComponentId`]s as a dynamic bundle and returns both the required component ids and the bundle id.
0 commit comments