@@ -555,6 +555,63 @@ all_tuples!(
555
555
S
556
556
) ;
557
557
558
+ /// Allows a query to contain entities with the component `T`, bypassing [`DefaultQueryFilters`].
559
+ ///
560
+ /// [`DefaultQueryFilters`]: crate::entity_disabling::DefaultQueryFilters
561
+ pub struct Allows < T > ( PhantomData < T > ) ;
562
+
563
+ /// SAFETY:
564
+ /// `update_component_access` does not add any accesses.
565
+ /// This is sound because [`QueryFilter::filter_fetch`] does not access any components.
566
+ /// `update_component_access` adds an archetypal filter for `T`.
567
+ /// This is sound because it doesn't affect the query
568
+ unsafe impl < T : Component > WorldQuery for Allows < T > {
569
+ type Fetch < ' w > = ( ) ;
570
+ type State = ComponentId ;
571
+
572
+ fn shrink_fetch < ' wlong : ' wshort , ' wshort > ( _: Self :: Fetch < ' wlong > ) -> Self :: Fetch < ' wshort > { }
573
+
574
+ #[ inline]
575
+ unsafe fn init_fetch ( _: UnsafeWorldCell , _: & ComponentId , _: Tick , _: Tick ) { }
576
+
577
+ // Even if the component is sparse, this implementation doesn't do anything with it
578
+ const IS_DENSE : bool = true ;
579
+
580
+ #[ inline]
581
+ unsafe fn set_archetype ( _: & mut ( ) , _: & ComponentId , _: & Archetype , _: & Table ) { }
582
+
583
+ #[ inline]
584
+ unsafe fn set_table ( _: & mut ( ) , _: & ComponentId , _: & Table ) { }
585
+
586
+ #[ inline]
587
+ fn update_component_access ( & id: & ComponentId , access : & mut FilteredAccess < ComponentId > ) {
588
+ access. access_mut ( ) . add_archetypal ( id) ;
589
+ }
590
+
591
+ fn init_state ( world : & mut World ) -> ComponentId {
592
+ world. register_component :: < T > ( )
593
+ }
594
+
595
+ fn get_state ( components : & Components ) -> Option < Self :: State > {
596
+ components. component_id :: < T > ( )
597
+ }
598
+
599
+ fn matches_component_set ( _: & ComponentId , _: & impl Fn ( ComponentId ) -> bool ) -> bool {
600
+ // Allows<T> always matches
601
+ true
602
+ }
603
+ }
604
+
605
+ // SAFETY: WorldQuery impl performs no access at all
606
+ unsafe impl < T : Component > QueryFilter for Allows < T > {
607
+ const IS_ARCHETYPAL : bool = true ;
608
+
609
+ #[ inline( always) ]
610
+ unsafe fn filter_fetch ( _: & mut Self :: Fetch < ' _ > , _: Entity , _: TableRow ) -> bool {
611
+ true
612
+ }
613
+ }
614
+
558
615
/// A filter on a component that only retains results the first time after they have been added.
559
616
///
560
617
/// A common use for this filter is one-time initialization.
0 commit comments