@@ -850,3 +850,95 @@ impl<Trait: ?Sized + TraitQuery> QueryFilter for WithOne<Trait> {
850
850
true
851
851
}
852
852
}
853
+
854
+ /// [`WorldQuery`] filter for entities without any [one](crate::One) component
855
+ /// implementing a trait.
856
+ pub struct WithoutOne < Trait : ?Sized + TraitQuery > ( PhantomData < & ' static Trait > ) ;
857
+
858
+ // this takes inspiration from `With` in bevy's main repo
859
+ unsafe impl < Trait : ?Sized + TraitQuery > WorldQuery for WithoutOne < Trait > {
860
+ type Item < ' w > = ( ) ;
861
+ type Fetch < ' w > = ( ) ;
862
+ type State = TraitQueryState < Trait > ;
863
+
864
+ #[ inline]
865
+ fn shrink < ' wlong : ' wshort , ' wshort > ( item : QueryItem < ' wlong , Self > ) -> QueryItem < ' wshort , Self > {
866
+ item
867
+ }
868
+
869
+ #[ inline]
870
+ unsafe fn init_fetch (
871
+ _world : UnsafeWorldCell < ' _ > ,
872
+ _state : & Self :: State ,
873
+ _last_run : Tick ,
874
+ _this_run : Tick ,
875
+ ) {
876
+ }
877
+
878
+ const IS_DENSE : bool = false ;
879
+
880
+ #[ inline]
881
+ unsafe fn set_archetype < ' w > (
882
+ _fetch : & mut ( ) ,
883
+ _state : & Self :: State ,
884
+ _archetype : & ' w bevy_ecs:: archetype:: Archetype ,
885
+ _table : & ' w bevy_ecs:: storage:: Table ,
886
+ ) {
887
+ }
888
+
889
+ #[ inline]
890
+ unsafe fn set_table ( _fetch : & mut ( ) , _state : & Self :: State , _table : & bevy_ecs:: storage:: Table ) { }
891
+
892
+ #[ inline]
893
+ unsafe fn fetch < ' w > (
894
+ _fetch : & mut Self :: Fetch < ' w > ,
895
+ _entity : Entity ,
896
+ _table_row : TableRow ,
897
+ ) -> Self :: Item < ' w > {
898
+ }
899
+
900
+ #[ inline]
901
+ fn update_component_access (
902
+ state : & Self :: State ,
903
+ access : & mut bevy_ecs:: query:: FilteredAccess < ComponentId > ,
904
+ ) {
905
+ for & component in & * state. components {
906
+ assert ! (
907
+ !access. access( ) . has_write( component) ,
908
+ "&{} conflicts with a previous access in this query. Shared access cannot coincide with exclusive access." ,
909
+ std:: any:: type_name:: <Trait >( ) ,
910
+ ) ;
911
+ access. and_without ( component) ;
912
+ }
913
+ }
914
+
915
+ #[ inline]
916
+ fn init_state ( world : & mut World ) -> Self :: State {
917
+ TraitQueryState :: init ( world)
918
+ }
919
+
920
+ #[ inline]
921
+ fn get_state ( world : & World ) -> Option < Self :: State > {
922
+ TraitQueryState :: get ( world)
923
+ }
924
+
925
+ #[ inline]
926
+ fn matches_component_set (
927
+ state : & Self :: State ,
928
+ set_contains_id : & impl Fn ( ComponentId ) -> bool ,
929
+ ) -> bool {
930
+ !state. components . iter ( ) . any ( |& id| set_contains_id ( id) )
931
+ }
932
+ }
933
+
934
+ /// SAFETY: read-only access
935
+ impl < Trait : ?Sized + TraitQuery > QueryFilter for WithoutOne < Trait > {
936
+ const IS_ARCHETYPAL : bool = false ;
937
+ unsafe fn filter_fetch (
938
+ _fetch : & mut Self :: Fetch < ' _ > ,
939
+ _entity : Entity ,
940
+ _table_row : TableRow ,
941
+ ) -> bool {
942
+ true
943
+ }
944
+ }
0 commit comments