@@ -2,14 +2,13 @@ use alloc::{boxed::Box, vec::Vec};
2
2
use bevy_platform:: sync:: PoisonError ;
3
3
use bevy_utils:: TypeIdMap ;
4
4
use core:: any:: Any ;
5
- use core:: ops:: DerefMut ;
6
5
use core:: { any:: TypeId , fmt:: Debug , ops:: Deref } ;
7
6
8
- use crate :: query:: DebugCheckedUnwrap as _;
9
7
use crate :: {
10
8
component:: {
11
9
Component , ComponentDescriptor , ComponentId , Components , RequiredComponents , StorageType ,
12
10
} ,
11
+ query:: DebugCheckedUnwrap as _,
13
12
resource:: Resource ,
14
13
} ;
15
14
@@ -62,8 +61,8 @@ impl ComponentIds {
62
61
63
62
/// A [`Components`] wrapper that enables additional features, like registration.
64
63
pub struct ComponentsRegistrator < ' w > {
65
- components : & ' w mut Components ,
66
- ids : & ' w mut ComponentIds ,
64
+ pub ( super ) components : & ' w mut Components ,
65
+ pub ( super ) ids : & ' w mut ComponentIds ,
67
66
}
68
67
69
68
impl Deref for ComponentsRegistrator < ' _ > {
@@ -74,12 +73,6 @@ impl Deref for ComponentsRegistrator<'_> {
74
73
}
75
74
}
76
75
77
- impl DerefMut for ComponentsRegistrator < ' _ > {
78
- fn deref_mut ( & mut self ) -> & mut Self :: Target {
79
- self . components
80
- }
81
- }
82
-
83
76
impl < ' w > ComponentsRegistrator < ' w > {
84
77
/// Constructs a new [`ComponentsRegistrator`].
85
78
///
@@ -223,10 +216,11 @@ impl<'w> ComponentsRegistrator<'w> {
223
216
) {
224
217
// SAFETY: ensured by caller.
225
218
unsafe {
226
- self . register_component_inner ( id, ComponentDescriptor :: new :: < T > ( ) ) ;
219
+ self . components
220
+ . register_component_inner ( id, ComponentDescriptor :: new :: < T > ( ) ) ;
227
221
}
228
222
let type_id = TypeId :: of :: < T > ( ) ;
229
- let prev = self . indices . insert ( type_id, id) ;
223
+ let prev = self . components . indices . insert ( type_id, id) ;
230
224
debug_assert ! ( prev. is_none( ) ) ;
231
225
232
226
let mut required_components = RequiredComponents :: default ( ) ;
@@ -272,7 +266,7 @@ impl<'w> ComponentsRegistrator<'w> {
272
266
let id = self . ids . next_mut ( ) ;
273
267
// SAFETY: The id is fresh.
274
268
unsafe {
275
- self . register_component_inner ( id, descriptor) ;
269
+ self . components . register_component_inner ( id, descriptor) ;
276
270
}
277
271
id
278
272
}
@@ -339,7 +333,8 @@ impl<'w> ComponentsRegistrator<'w> {
339
333
let id = self . ids . next_mut ( ) ;
340
334
// SAFETY: The resource is not currently registered, the id is fresh, and the [`ComponentDescriptor`] matches the [`TypeId`]
341
335
unsafe {
342
- self . register_resource_unchecked ( type_id, id, descriptor ( ) ) ;
336
+ self . components
337
+ . register_resource_unchecked ( type_id, id, descriptor ( ) ) ;
343
338
}
344
339
id
345
340
}
@@ -363,10 +358,20 @@ impl<'w> ComponentsRegistrator<'w> {
363
358
let id = self . ids . next_mut ( ) ;
364
359
// SAFETY: The id is fresh.
365
360
unsafe {
366
- self . register_component_inner ( id, descriptor) ;
361
+ self . components . register_component_inner ( id, descriptor) ;
367
362
}
368
363
id
369
364
}
365
+
366
+ /// Equivalent of `Components::any_queued_mut`
367
+ pub fn any_queued_mut ( & mut self ) -> bool {
368
+ self . components . any_queued_mut ( )
369
+ }
370
+
371
+ /// Equivalent of `Components::any_queued_mut`
372
+ pub fn num_queued_mut ( & mut self ) -> usize {
373
+ self . components . num_queued_mut ( )
374
+ }
370
375
}
371
376
372
377
/// A queued component registration.
@@ -587,7 +592,9 @@ impl<'w> ComponentsQueuedRegistrator<'w> {
587
592
self . register_arbitrary_dynamic ( descriptor, |registrator, id, descriptor| {
588
593
// SAFETY: Id uniqueness handled by caller.
589
594
unsafe {
590
- registrator. register_component_inner ( id, descriptor) ;
595
+ registrator
596
+ . components
597
+ . register_component_inner ( id, descriptor) ;
591
598
}
592
599
} )
593
600
}
@@ -616,7 +623,9 @@ impl<'w> ComponentsQueuedRegistrator<'w> {
616
623
// SAFETY: Id uniqueness handled by caller, and the type_id matches descriptor.
617
624
#[ expect( unused_unsafe, reason = "More precise to specify." ) ]
618
625
unsafe {
619
- registrator. register_resource_unchecked ( type_id, id, descriptor) ;
626
+ registrator
627
+ . components
628
+ . register_resource_unchecked ( type_id, id, descriptor) ;
620
629
}
621
630
} ,
622
631
)
@@ -648,7 +657,9 @@ impl<'w> ComponentsQueuedRegistrator<'w> {
648
657
// SAFETY: Id uniqueness handled by caller, and the type_id matches descriptor.
649
658
#[ expect( unused_unsafe, reason = "More precise to specify." ) ]
650
659
unsafe {
651
- registrator. register_resource_unchecked ( type_id, id, descriptor) ;
660
+ registrator
661
+ . components
662
+ . register_resource_unchecked ( type_id, id, descriptor) ;
652
663
}
653
664
} ,
654
665
)
@@ -672,7 +683,9 @@ impl<'w> ComponentsQueuedRegistrator<'w> {
672
683
self . register_arbitrary_dynamic ( descriptor, |registrator, id, descriptor| {
673
684
// SAFETY: Id uniqueness handled by caller.
674
685
unsafe {
675
- registrator. register_component_inner ( id, descriptor) ;
686
+ registrator
687
+ . components
688
+ . register_component_inner ( id, descriptor) ;
676
689
}
677
690
} )
678
691
}
0 commit comments