@@ -13,7 +13,6 @@ use crate::{
13
13
} ;
14
14
use bevy_ptr:: { ThinSlicePtr , UnsafeCellDeref } ;
15
15
use bevy_utils:: all_tuples;
16
- use smallvec:: SmallVec ;
17
16
use std:: { cell:: UnsafeCell , marker:: PhantomData } ;
18
17
19
18
/// Types that can be fetched from a [`World`] using a [`Query`].
@@ -857,13 +856,13 @@ unsafe impl<'w, 's> QueryData for FilteredEntityMut<'w, 's> {
857
856
/// SAFETY: `EntityRefExcept` guards access to all components in the bundle `B`
858
857
/// and populates `Access` values so that queries that conflict with this access
859
858
/// are rejected.
860
- unsafe impl < ' a , B > WorldQuery for EntityRefExcept < ' a , B >
859
+ unsafe impl < B > WorldQuery for EntityRefExcept < ' _ , ' _ , B >
861
860
where
862
861
B : Bundle ,
863
862
{
864
- type Fetch < ' w , ' s > = UnsafeWorldCell < ' w > ;
865
- type Item < ' w , ' s > = EntityRefExcept < ' w , B > ;
866
- type State = SmallVec < [ ComponentId ; 4 ] > ;
863
+ type Fetch < ' w , ' s > = ( UnsafeWorldCell < ' w > , & ' s Access < ComponentId > ) ;
864
+ type Item < ' w , ' s > = EntityRefExcept < ' w , ' s , B > ;
865
+ type State = Access < ComponentId > ;
867
866
868
867
fn shrink < ' wlong : ' wshort , ' wshort , ' s > (
869
868
item : Self :: Item < ' wlong , ' s > ,
@@ -879,11 +878,11 @@ where
879
878
880
879
unsafe fn init_fetch < ' w , ' s > (
881
880
world : UnsafeWorldCell < ' w > ,
882
- _ : & ' s Self :: State ,
881
+ state : & ' s Self :: State ,
883
882
_: Tick ,
884
883
_: Tick ,
885
884
) -> Self :: Fetch < ' w , ' s > {
886
- world
885
+ ( world, state )
887
886
}
888
887
889
888
const IS_DENSE : bool = true ;
@@ -899,45 +898,47 @@ where
899
898
unsafe fn set_table < ' w , ' s > ( _: & mut Self :: Fetch < ' w , ' s > , _: & ' s Self :: State , _: & ' w Table ) { }
900
899
901
900
unsafe fn fetch < ' w , ' s > (
902
- world : & mut Self :: Fetch < ' w , ' s > ,
901
+ ( world, access ) : & mut Self :: Fetch < ' w , ' s > ,
903
902
entity : Entity ,
904
903
_: TableRow ,
905
904
) -> Self :: Item < ' w , ' s > {
906
905
let cell = world. get_entity ( entity) . unwrap ( ) ;
907
- EntityRefExcept :: new ( cell)
906
+ EntityRefExcept :: new ( cell, access )
908
907
}
909
908
910
909
fn update_component_access (
911
910
state : & Self :: State ,
912
911
filtered_access : & mut FilteredAccess < ComponentId > ,
913
912
) {
914
- let mut my_access = Access :: new ( ) ;
915
- my_access. read_all_components ( ) ;
916
- for id in state {
917
- my_access. remove_component_read ( * id) ;
918
- }
919
-
920
- let access = filtered_access. access_mut ( ) ;
921
913
assert ! (
922
- access. is_compatible( & my_access ) ,
914
+ filtered_access . access( ) . is_compatible( state ) ,
923
915
"`EntityRefExcept<{}>` conflicts with a previous access in this query." ,
924
916
std:: any:: type_name:: <B >( ) ,
925
917
) ;
926
- access. extend ( & my_access ) ;
918
+ filtered_access . access . extend ( state ) ;
927
919
}
928
920
929
921
fn init_state ( world : & mut World ) -> Self :: State {
930
- Self :: get_state ( world. components ( ) ) . unwrap ( )
922
+ let mut access = Access :: new ( ) ;
923
+ access. read_all_components ( ) ;
924
+ B :: component_ids ( & mut world. components , & mut world. storages , & mut |id| {
925
+ access. remove_component_read ( id) ;
926
+ } ) ;
927
+ access
931
928
}
932
929
933
930
fn get_state ( components : & Components ) -> Option < Self :: State > {
934
- let mut ids = SmallVec :: new ( ) ;
931
+ let mut access = Access :: new ( ) ;
932
+ access. read_all_components ( ) ;
933
+ let mut all_initialized = true ;
935
934
B :: get_component_ids ( components, & mut |maybe_id| {
936
935
if let Some ( id) = maybe_id {
937
- ids. push ( id) ;
936
+ access. remove_component_read ( id) ;
937
+ } else {
938
+ all_initialized = false ;
938
939
}
939
940
} ) ;
940
- Some ( ids )
941
+ all_initialized . then_some ( access )
941
942
}
942
943
943
944
fn matches_component_set ( _: & Self :: State , _: & impl Fn ( ComponentId ) -> bool ) -> bool {
@@ -946,7 +947,7 @@ where
946
947
}
947
948
948
949
/// SAFETY: `Self` is the same as `Self::ReadOnly`.
949
- unsafe impl < ' a , B > QueryData for EntityRefExcept < ' a , B >
950
+ unsafe impl < B > QueryData for EntityRefExcept < ' _ , ' _ , B >
950
951
where
951
952
B : Bundle ,
952
953
{
@@ -955,18 +956,18 @@ where
955
956
956
957
/// SAFETY: `EntityRefExcept` enforces read-only access to its contained
957
958
/// components.
958
- unsafe impl < ' a , B > ReadOnlyQueryData for EntityRefExcept < ' a , B > where B : Bundle { }
959
+ unsafe impl < B > ReadOnlyQueryData for EntityRefExcept < ' _ , ' _ , B > where B : Bundle { }
959
960
960
961
/// SAFETY: `EntityMutExcept` guards access to all components in the bundle `B`
961
962
/// and populates `Access` values so that queries that conflict with this access
962
963
/// are rejected.
963
- unsafe impl < ' a , B > WorldQuery for EntityMutExcept < ' a , B >
964
+ unsafe impl < B > WorldQuery for EntityMutExcept < ' _ , ' _ , B >
964
965
where
965
966
B : Bundle ,
966
967
{
967
- type Fetch < ' w , ' s > = UnsafeWorldCell < ' w > ;
968
- type Item < ' w , ' s > = EntityMutExcept < ' w , B > ;
969
- type State = SmallVec < [ ComponentId ; 4 ] > ;
968
+ type Fetch < ' w , ' s > = ( UnsafeWorldCell < ' w > , & ' s Access < ComponentId > ) ;
969
+ type Item < ' w , ' s > = EntityMutExcept < ' w , ' s , B > ;
970
+ type State = Access < ComponentId > ;
970
971
971
972
fn shrink < ' wlong : ' wshort , ' wshort , ' s > (
972
973
item : Self :: Item < ' wlong , ' s > ,
@@ -982,11 +983,11 @@ where
982
983
983
984
unsafe fn init_fetch < ' w , ' s > (
984
985
world : UnsafeWorldCell < ' w > ,
985
- _ : & ' s Self :: State ,
986
+ state : & ' s Self :: State ,
986
987
_: Tick ,
987
988
_: Tick ,
988
989
) -> Self :: Fetch < ' w , ' s > {
989
- world
990
+ ( world, state )
990
991
}
991
992
992
993
const IS_DENSE : bool = true ;
@@ -1002,45 +1003,47 @@ where
1002
1003
unsafe fn set_table < ' w , ' s > ( _: & mut Self :: Fetch < ' w , ' s > , _: & ' s Self :: State , _: & ' w Table ) { }
1003
1004
1004
1005
unsafe fn fetch < ' w , ' s > (
1005
- world : & mut Self :: Fetch < ' w , ' s > ,
1006
+ ( world, access ) : & mut Self :: Fetch < ' w , ' s > ,
1006
1007
entity : Entity ,
1007
1008
_: TableRow ,
1008
1009
) -> Self :: Item < ' w , ' s > {
1009
1010
let cell = world. get_entity ( entity) . unwrap ( ) ;
1010
- EntityMutExcept :: new ( cell)
1011
+ EntityMutExcept :: new ( cell, access )
1011
1012
}
1012
1013
1013
1014
fn update_component_access (
1014
1015
state : & Self :: State ,
1015
1016
filtered_access : & mut FilteredAccess < ComponentId > ,
1016
1017
) {
1017
- let mut my_access = Access :: new ( ) ;
1018
- my_access. write_all_components ( ) ;
1019
- for id in state {
1020
- my_access. remove_component_read ( * id) ;
1021
- }
1022
-
1023
- let access = filtered_access. access_mut ( ) ;
1024
1018
assert ! (
1025
- access. is_compatible( & my_access ) ,
1019
+ filtered_access . access( ) . is_compatible( state ) ,
1026
1020
"`EntityMutExcept<{}>` conflicts with a previous access in this query." ,
1027
1021
std:: any:: type_name:: <B >( )
1028
1022
) ;
1029
- access. extend ( & my_access ) ;
1023
+ filtered_access . access . extend ( state ) ;
1030
1024
}
1031
1025
1032
1026
fn init_state ( world : & mut World ) -> Self :: State {
1033
- Self :: get_state ( world. components ( ) ) . unwrap ( )
1027
+ let mut access = Access :: new ( ) ;
1028
+ access. write_all_components ( ) ;
1029
+ B :: component_ids ( & mut world. components , & mut world. storages , & mut |id| {
1030
+ access. remove_component_read ( id) ;
1031
+ } ) ;
1032
+ access
1034
1033
}
1035
1034
1036
1035
fn get_state ( components : & Components ) -> Option < Self :: State > {
1037
- let mut ids = SmallVec :: new ( ) ;
1036
+ let mut access = Access :: new ( ) ;
1037
+ access. write_all_components ( ) ;
1038
+ let mut all_initialized = true ;
1038
1039
B :: get_component_ids ( components, & mut |maybe_id| {
1039
1040
if let Some ( id) = maybe_id {
1040
- ids. push ( id) ;
1041
+ access. remove_component_read ( id) ;
1042
+ } else {
1043
+ all_initialized = false ;
1041
1044
}
1042
1045
} ) ;
1043
- Some ( ids )
1046
+ all_initialized . then_some ( access )
1044
1047
}
1045
1048
1046
1049
fn matches_component_set ( _: & Self :: State , _: & impl Fn ( ComponentId ) -> bool ) -> bool {
@@ -1050,11 +1053,11 @@ where
1050
1053
1051
1054
/// SAFETY: All accesses that `EntityRefExcept` provides are also accesses that
1052
1055
/// `EntityMutExcept` provides.
1053
- unsafe impl < ' a , B > QueryData for EntityMutExcept < ' a , B >
1056
+ unsafe impl < ' w , ' s , B > QueryData for EntityMutExcept < ' w , ' s , B >
1054
1057
where
1055
1058
B : Bundle ,
1056
1059
{
1057
- type ReadOnly = EntityRefExcept < ' a , B > ;
1060
+ type ReadOnly = EntityRefExcept < ' w , ' s , B > ;
1058
1061
}
1059
1062
1060
1063
/// SAFETY:
0 commit comments