1use crate::{
2 archetype::{Archetype, Archetypes},
3 bundle::Bundle,
4 change_detection::{
5 ComponentTicksMut, ComponentTicksRef, ContiguousComponentTicksMut,
6 ContiguousComponentTicksRef, ContiguousMut, ContiguousRef, MaybeLocation, Tick,
7 },
8 component::{Component, ComponentId, Components, Mutable, StorageType},
9 entity::{Entities, Entity, EntityLocation},
10 query::{
11 access_iter::{EcsAccessLevel, EcsAccessType},
12 Access, DebugCheckedUnwrap, FilteredAccess, FilteredAccessSet, QueryFilter, QueryState,
13 WorldQuery,
14 },
15 storage::{ComponentSparseSet, Table, TableRow},
16 system::Query,
17 world::{
18 unsafe_world_cell::UnsafeWorldCell, EntityMut, EntityMutExcept, EntityRef, EntityRefExcept,
19 FilteredEntityMut, FilteredEntityRef, Mut, Ref, World,
20 },
21};
22use bevy_ptr::{ThinSlicePtr, UnsafeCellDeref};
23use bevy_utils::prelude::DebugName;
24use core::{cell::UnsafeCell, iter, marker::PhantomData, panic::Location};
25use variadics_please::all_tuples;
26
27#[diagnostic::on_unimplemented(
320 message = "`{Self}` is not valid to request as data in a `Query`",
321 label = "invalid `Query` data",
322 note = "if `{Self}` is a component type, try using `&{Self}` or `&mut {Self}`"
323)]
324pub unsafe trait QueryData: WorldQuery {
325 const IS_READ_ONLY: bool;
327
328 const IS_ARCHETYPAL: bool;
336
337 type ReadOnly: ReadOnlyQueryData<State = <Self as WorldQuery>::State>;
339
340 type Item<'w, 's>;
344
345 fn shrink<'wlong: 'wshort, 'wshort, 's>(
347 item: Self::Item<'wlong, 's>,
348 ) -> Self::Item<'wshort, 's>;
349
350 fn provide_extra_access(
360 _state: &mut Self::State,
361 _access: &mut Access,
362 _available_access: &Access,
363 ) {
364 }
365
366 unsafe fn fetch<'w, 's>(
383 state: &'s Self::State,
384 fetch: &mut Self::Fetch<'w>,
385 entity: Entity,
386 table_row: TableRow,
387 ) -> Option<Self::Item<'w, 's>>;
388
389 fn iter_access(state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>>;
393}
394
395#[diagnostic::on_unimplemented(
405 message = "`{Self}` cannot be iterated contiguously",
406 label = "invalid contiguous `Query` data",
407 note = "if `{Self}` is a custom query type, using `QueryData` derive macro, ensure that the `#[query_data(contiguous(target))]` attribute is added"
408)]
409pub trait ContiguousQueryData: ArchetypeQueryData + IterQueryData {
410 type Contiguous<'w, 's>;
413
414 unsafe fn fetch_contiguous<'w, 's>(
424 state: &'s Self::State,
425 fetch: &mut Self::Fetch<'w>,
426 entities: &'w [Entity],
427 ) -> Self::Contiguous<'w, 's>;
428}
429
430pub unsafe trait IterQueryData: QueryData {}
457
458pub unsafe trait ReadOnlyQueryData: IterQueryData<ReadOnly = Self> {}
464
465pub unsafe trait SingleEntityQueryData: IterQueryData {}
474
475pub type QueryItem<'w, 's, Q> = <Q as QueryData>::Item<'w, 's>;
477pub type ROQueryItem<'w, 's, D> = QueryItem<'w, 's, <D as QueryData>::ReadOnly>;
479
480pub trait ReleaseStateQueryData: QueryData {
487 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static>;
489}
490
491pub trait ArchetypeQueryData: QueryData {}
498
499unsafe impl WorldQuery for Entity {
503 type Fetch<'w> = ();
504 type State = ();
505
506 fn shrink_fetch<'wlong: 'wshort, 'wshort>(_: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {}
507
508 unsafe fn init_fetch<'w, 's>(
509 _world: UnsafeWorldCell<'w>,
510 _state: &'s Self::State,
511 _last_run: Tick,
512 _this_run: Tick,
513 ) -> Self::Fetch<'w> {
514 }
515
516 const IS_DENSE: bool = true;
517
518 #[inline]
519 unsafe fn set_archetype<'w, 's>(
520 _fetch: &mut Self::Fetch<'w>,
521 _state: &'s Self::State,
522 _archetype: &'w Archetype,
523 _table: &Table,
524 ) {
525 }
526
527 #[inline]
528 unsafe fn set_table<'w, 's>(
529 _fetch: &mut Self::Fetch<'w>,
530 _state: &'s Self::State,
531 _table: &'w Table,
532 ) {
533 }
534
535 fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) {}
536
537 fn init_state(_world: &mut World) {}
538
539 fn get_state(_components: &Components) -> Option<()> {
540 Some(())
541 }
542
543 fn matches_component_set(
544 _state: &Self::State,
545 _set_contains_id: &impl Fn(ComponentId) -> bool,
546 ) -> bool {
547 true
548 }
549}
550
551unsafe impl QueryData for Entity {
553 const IS_READ_ONLY: bool = true;
554 const IS_ARCHETYPAL: bool = true;
555 type ReadOnly = Self;
556
557 type Item<'w, 's> = Entity;
558
559 fn shrink<'wlong: 'wshort, 'wshort, 's>(
560 item: Self::Item<'wlong, 's>,
561 ) -> Self::Item<'wshort, 's> {
562 item
563 }
564
565 #[inline(always)]
566 unsafe fn fetch<'w, 's>(
567 _state: &'s Self::State,
568 _fetch: &mut Self::Fetch<'w>,
569 entity: Entity,
570 _table_row: TableRow,
571 ) -> Option<Self::Item<'w, 's>> {
572 Some(entity)
573 }
574
575 fn iter_access(_state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
576 iter::empty()
577 }
578}
579
580unsafe impl IterQueryData for Entity {}
582
583unsafe impl ReadOnlyQueryData for Entity {}
585
586unsafe impl SingleEntityQueryData for Entity {}
588
589impl ReleaseStateQueryData for Entity {
590 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
591 item
592 }
593}
594
595impl ArchetypeQueryData for Entity {}
596
597impl ContiguousQueryData for Entity {
598 type Contiguous<'w, 's> = &'w [Entity];
599
600 unsafe fn fetch_contiguous<'w, 's>(
601 _state: &'s Self::State,
602 _fetch: &mut Self::Fetch<'w>,
603 entities: &'w [Entity],
604 ) -> Self::Contiguous<'w, 's> {
605 entities
606 }
607}
608
609unsafe impl WorldQuery for EntityLocation {
613 type Fetch<'w> = &'w Entities;
614 type State = ();
615
616 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
617 fetch
618 }
619
620 unsafe fn init_fetch<'w, 's>(
621 world: UnsafeWorldCell<'w>,
622 _state: &'s Self::State,
623 _last_run: Tick,
624 _this_run: Tick,
625 ) -> Self::Fetch<'w> {
626 world.entities()
627 }
628
629 const IS_DENSE: bool = true;
632
633 #[inline]
634 unsafe fn set_archetype<'w, 's>(
635 _fetch: &mut Self::Fetch<'w>,
636 _state: &'s Self::State,
637 _archetype: &'w Archetype,
638 _table: &Table,
639 ) {
640 }
641
642 #[inline]
643 unsafe fn set_table<'w, 's>(
644 _fetch: &mut Self::Fetch<'w>,
645 _state: &'s Self::State,
646 _table: &'w Table,
647 ) {
648 }
649
650 fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) {}
651
652 fn init_state(_world: &mut World) {}
653
654 fn get_state(_components: &Components) -> Option<()> {
655 Some(())
656 }
657
658 fn matches_component_set(
659 _state: &Self::State,
660 _set_contains_id: &impl Fn(ComponentId) -> bool,
661 ) -> bool {
662 true
663 }
664}
665
666unsafe impl QueryData for EntityLocation {
668 const IS_READ_ONLY: bool = true;
669 const IS_ARCHETYPAL: bool = true;
670 type ReadOnly = Self;
671 type Item<'w, 's> = EntityLocation;
672
673 fn shrink<'wlong: 'wshort, 'wshort, 's>(
674 item: Self::Item<'wlong, 's>,
675 ) -> Self::Item<'wshort, 's> {
676 item
677 }
678
679 #[inline(always)]
680 unsafe fn fetch<'w, 's>(
681 _state: &'s Self::State,
682 fetch: &mut Self::Fetch<'w>,
683 entity: Entity,
684 _table_row: TableRow,
685 ) -> Option<Self::Item<'w, 's>> {
686 Some(unsafe { fetch.get_spawned(entity).debug_checked_unwrap() })
688 }
689
690 fn iter_access(_state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
691 iter::empty()
692 }
693}
694
695unsafe impl IterQueryData for EntityLocation {}
697
698unsafe impl ReadOnlyQueryData for EntityLocation {}
700
701unsafe impl SingleEntityQueryData for EntityLocation {}
703
704impl ReleaseStateQueryData for EntityLocation {
705 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
706 item
707 }
708}
709
710impl ArchetypeQueryData for EntityLocation {}
711
712#[derive(#[automatically_derived]
impl ::core::clone::Clone for SpawnDetails {
#[inline]
fn clone(&self) -> SpawnDetails {
let _: ::core::clone::AssertParamIsClone<MaybeLocation>;
let _: ::core::clone::AssertParamIsClone<Tick>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for SpawnDetails { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for SpawnDetails {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f, "SpawnDetails",
"spawned_by", &self.spawned_by, "spawn_tick", &self.spawn_tick,
"last_run", &self.last_run, "this_run", &&self.this_run)
}
}Debug)]
749pub struct SpawnDetails {
750 spawned_by: MaybeLocation,
751 spawn_tick: Tick,
752 last_run: Tick,
753 this_run: Tick,
754}
755
756impl SpawnDetails {
757 pub fn is_spawned(self) -> bool {
760 self.is_spawned_after(self.last_run)
761 }
762
763 #[inline]
766 pub fn is_spawned_after(self, other: Tick) -> bool {
767 self.spawn_tick.is_newer_than(other, self.this_run)
768 }
769
770 pub fn spawn_tick(self) -> Tick {
772 self.spawn_tick
773 }
774
775 pub fn spawned_by(self) -> MaybeLocation {
777 self.spawned_by
778 }
779}
780
781#[doc(hidden)]
782#[derive(#[automatically_derived]
impl<'w> ::core::clone::Clone for SpawnDetailsFetch<'w> {
#[inline]
fn clone(&self) -> SpawnDetailsFetch<'w> {
SpawnDetailsFetch {
entities: ::core::clone::Clone::clone(&self.entities),
last_run: ::core::clone::Clone::clone(&self.last_run),
this_run: ::core::clone::Clone::clone(&self.this_run),
}
}
}Clone)]
783pub struct SpawnDetailsFetch<'w> {
784 entities: &'w Entities,
785 last_run: Tick,
786 this_run: Tick,
787}
788
789unsafe impl WorldQuery for SpawnDetails {
792 type Fetch<'w> = SpawnDetailsFetch<'w>;
793 type State = ();
794
795 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
796 fetch
797 }
798
799 unsafe fn init_fetch<'w, 's>(
800 world: UnsafeWorldCell<'w>,
801 _state: &'s Self::State,
802 last_run: Tick,
803 this_run: Tick,
804 ) -> Self::Fetch<'w> {
805 SpawnDetailsFetch {
806 entities: world.entities(),
807 last_run,
808 this_run,
809 }
810 }
811
812 const IS_DENSE: bool = true;
813
814 #[inline]
815 unsafe fn set_archetype<'w, 's>(
816 _fetch: &mut Self::Fetch<'w>,
817 _state: &'s Self::State,
818 _archetype: &'w Archetype,
819 _table: &'w Table,
820 ) {
821 }
822
823 #[inline]
824 unsafe fn set_table<'w, 's>(
825 _fetch: &mut Self::Fetch<'w>,
826 _state: &'s Self::State,
827 _table: &'w Table,
828 ) {
829 }
830
831 fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) {}
832
833 fn init_state(_world: &mut World) {}
834
835 fn get_state(_components: &Components) -> Option<()> {
836 Some(())
837 }
838
839 fn matches_component_set(
840 _state: &Self::State,
841 _set_contains_id: &impl Fn(ComponentId) -> bool,
842 ) -> bool {
843 true
844 }
845}
846
847unsafe impl QueryData for SpawnDetails {
851 const IS_READ_ONLY: bool = true;
852 const IS_ARCHETYPAL: bool = true;
853 type ReadOnly = Self;
854 type Item<'w, 's> = Self;
855
856 fn shrink<'wlong: 'wshort, 'wshort, 's>(
857 item: Self::Item<'wlong, 's>,
858 ) -> Self::Item<'wshort, 's> {
859 item
860 }
861
862 #[inline(always)]
863 unsafe fn fetch<'w, 's>(
864 _state: &'s Self::State,
865 fetch: &mut Self::Fetch<'w>,
866 entity: Entity,
867 _table_row: TableRow,
868 ) -> Option<Self::Item<'w, 's>> {
869 let (spawned_by, spawn_tick) = unsafe {
871 fetch
872 .entities
873 .entity_get_spawned_or_despawned_unchecked(entity)
874 };
875 Some(Self {
876 spawned_by,
877 spawn_tick,
878 last_run: fetch.last_run,
879 this_run: fetch.this_run,
880 })
881 }
882
883 fn iter_access(_state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
884 iter::empty()
885 }
886}
887
888unsafe impl IterQueryData for SpawnDetails {}
890
891unsafe impl ReadOnlyQueryData for SpawnDetails {}
893
894unsafe impl SingleEntityQueryData for SpawnDetails {}
896
897impl ReleaseStateQueryData for SpawnDetails {
898 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
899 item
900 }
901}
902
903impl ArchetypeQueryData for SpawnDetails {}
904
905#[derive(#[automatically_derived]
impl<'w> ::core::marker::Copy for EntityFetch<'w> { }Copy, #[automatically_derived]
impl<'w> ::core::clone::Clone for EntityFetch<'w> {
#[inline]
fn clone(&self) -> EntityFetch<'w> {
let _: ::core::clone::AssertParamIsClone<UnsafeWorldCell<'w>>;
let _: ::core::clone::AssertParamIsClone<Tick>;
*self
}
}Clone)]
908#[doc(hidden)]
909pub struct EntityFetch<'w> {
910 world: UnsafeWorldCell<'w>,
911 last_run: Tick,
912 this_run: Tick,
913}
914
915unsafe impl<'a> WorldQuery for EntityRef<'a> {
920 type Fetch<'w> = EntityFetch<'w>;
921 type State = ();
922
923 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
924 fetch
925 }
926
927 unsafe fn init_fetch<'w, 's>(
928 world: UnsafeWorldCell<'w>,
929 _state: &'s Self::State,
930 last_run: Tick,
931 this_run: Tick,
932 ) -> Self::Fetch<'w> {
933 EntityFetch {
934 world,
935 last_run,
936 this_run,
937 }
938 }
939
940 const IS_DENSE: bool = true;
941
942 #[inline]
943 unsafe fn set_archetype<'w, 's>(
944 _fetch: &mut Self::Fetch<'w>,
945 _state: &'s Self::State,
946 _archetype: &'w Archetype,
947 _table: &Table,
948 ) {
949 }
950
951 #[inline]
952 unsafe fn set_table<'w, 's>(
953 _fetch: &mut Self::Fetch<'w>,
954 _state: &'s Self::State,
955 _table: &'w Table,
956 ) {
957 }
958
959 fn update_component_access(_state: &Self::State, access: &mut FilteredAccess) {
960 if !!access.access().has_any_write() {
{
::core::panicking::panic_fmt(format_args!("EntityRef conflicts with a previous access in this query. Shared access cannot coincide with exclusive access."));
}
};assert!(
961 !access.access().has_any_write(),
962 "EntityRef conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.",
963 );
964 access.read_all();
965 }
966
967 fn init_state(_world: &mut World) {}
968
969 fn get_state(_components: &Components) -> Option<()> {
970 Some(())
971 }
972
973 fn matches_component_set(
974 _state: &Self::State,
975 _set_contains_id: &impl Fn(ComponentId) -> bool,
976 ) -> bool {
977 true
978 }
979}
980
981unsafe impl<'a> QueryData for EntityRef<'a> {
983 const IS_READ_ONLY: bool = true;
984 const IS_ARCHETYPAL: bool = true;
985 type ReadOnly = Self;
986 type Item<'w, 's> = EntityRef<'w>;
987
988 fn shrink<'wlong: 'wshort, 'wshort, 's>(
989 item: Self::Item<'wlong, 's>,
990 ) -> Self::Item<'wshort, 's> {
991 item
992 }
993
994 #[inline(always)]
995 unsafe fn fetch<'w, 's>(
996 _state: &'s Self::State,
997 fetch: &mut Self::Fetch<'w>,
998 entity: Entity,
999 _table_row: TableRow,
1000 ) -> Option<Self::Item<'w, 's>> {
1001 let cell = unsafe {
1003 fetch
1004 .world
1005 .get_entity_with_ticks(entity, fetch.last_run, fetch.this_run)
1006 .debug_checked_unwrap()
1007 };
1008 Some(unsafe { EntityRef::new(cell) })
1010 }
1011
1012 fn iter_access(_state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
1013 iter::once(EcsAccessType::Component(EcsAccessLevel::ReadAll))
1014 }
1015}
1016
1017unsafe impl IterQueryData for EntityRef<'_> {}
1019
1020unsafe impl ReadOnlyQueryData for EntityRef<'_> {}
1022
1023unsafe impl SingleEntityQueryData for EntityRef<'_> {}
1025
1026impl ReleaseStateQueryData for EntityRef<'_> {
1027 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
1028 item
1029 }
1030}
1031
1032impl ArchetypeQueryData for EntityRef<'_> {}
1033
1034unsafe impl<'a> WorldQuery for EntityMut<'a> {
1036 type Fetch<'w> = EntityFetch<'w>;
1037 type State = ();
1038
1039 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
1040 fetch
1041 }
1042
1043 unsafe fn init_fetch<'w, 's>(
1044 world: UnsafeWorldCell<'w>,
1045 _state: &'s Self::State,
1046 last_run: Tick,
1047 this_run: Tick,
1048 ) -> Self::Fetch<'w> {
1049 EntityFetch {
1050 world,
1051 last_run,
1052 this_run,
1053 }
1054 }
1055
1056 const IS_DENSE: bool = true;
1057
1058 #[inline]
1059 unsafe fn set_archetype<'w, 's>(
1060 _fetch: &mut Self::Fetch<'w>,
1061 _state: &'s Self::State,
1062 _archetype: &'w Archetype,
1063 _table: &Table,
1064 ) {
1065 }
1066
1067 #[inline]
1068 unsafe fn set_table<'w, 's>(
1069 _fetch: &mut Self::Fetch<'w>,
1070 _state: &'s Self::State,
1071 _table: &'w Table,
1072 ) {
1073 }
1074
1075 fn update_component_access(_state: &Self::State, access: &mut FilteredAccess) {
1076 if !!access.access().has_any_read() {
{
::core::panicking::panic_fmt(format_args!("EntityMut conflicts with a previous access in this query. Exclusive access cannot coincide with any other accesses."));
}
};assert!(
1077 !access.access().has_any_read(),
1078 "EntityMut conflicts with a previous access in this query. Exclusive access cannot coincide with any other accesses.",
1079 );
1080 access.write_all();
1081 }
1082
1083 fn init_state(_world: &mut World) {}
1084
1085 fn get_state(_components: &Components) -> Option<()> {
1086 Some(())
1087 }
1088
1089 fn matches_component_set(
1090 _state: &Self::State,
1091 _set_contains_id: &impl Fn(ComponentId) -> bool,
1092 ) -> bool {
1093 true
1094 }
1095}
1096
1097unsafe impl<'a> QueryData for EntityMut<'a> {
1099 const IS_READ_ONLY: bool = false;
1100 const IS_ARCHETYPAL: bool = true;
1101 type ReadOnly = EntityRef<'a>;
1102 type Item<'w, 's> = EntityMut<'w>;
1103
1104 fn shrink<'wlong: 'wshort, 'wshort, 's>(
1105 item: Self::Item<'wlong, 's>,
1106 ) -> Self::Item<'wshort, 's> {
1107 item
1108 }
1109
1110 #[inline(always)]
1111 unsafe fn fetch<'w, 's>(
1112 _state: &'s Self::State,
1113 fetch: &mut Self::Fetch<'w>,
1114 entity: Entity,
1115 _table_row: TableRow,
1116 ) -> Option<Self::Item<'w, 's>> {
1117 let cell = unsafe {
1119 fetch
1120 .world
1121 .get_entity_with_ticks(entity, fetch.last_run, fetch.this_run)
1122 .debug_checked_unwrap()
1123 };
1124 Some(unsafe { EntityMut::new(cell) })
1126 }
1127
1128 fn iter_access(_state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
1129 iter::once(EcsAccessType::Component(EcsAccessLevel::WriteAll))
1130 }
1131}
1132
1133unsafe impl IterQueryData for EntityMut<'_> {}
1135
1136unsafe impl SingleEntityQueryData for EntityMut<'_> {}
1138
1139impl ReleaseStateQueryData for EntityMut<'_> {
1140 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
1141 item
1142 }
1143}
1144
1145impl ArchetypeQueryData for EntityMut<'_> {}
1146
1147unsafe impl WorldQuery for FilteredEntityRef<'_, '_> {
1149 type Fetch<'w> = EntityFetch<'w>;
1150 type State = Access;
1151
1152 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
1153 fetch
1154 }
1155
1156 const IS_DENSE: bool = true;
1157
1158 unsafe fn init_fetch<'w, 's>(
1159 world: UnsafeWorldCell<'w>,
1160 _state: &'s Self::State,
1161 last_run: Tick,
1162 this_run: Tick,
1163 ) -> Self::Fetch<'w> {
1164 EntityFetch {
1165 world,
1166 last_run,
1167 this_run,
1168 }
1169 }
1170
1171 #[inline]
1172 unsafe fn set_archetype<'w, 's>(
1173 _fetch: &mut Self::Fetch<'w>,
1174 _state: &'s Self::State,
1175 _: &'w Archetype,
1176 _table: &Table,
1177 ) {
1178 }
1179
1180 #[inline]
1181 unsafe fn set_table<'w, 's>(
1182 _fetch: &mut Self::Fetch<'w>,
1183 _state: &'s Self::State,
1184 _: &'w Table,
1185 ) {
1186 }
1187
1188 fn update_component_access(state: &Self::State, filtered_access: &mut FilteredAccess) {
1189 if !filtered_access.access().is_compatible(state) {
{
::core::panicking::panic_fmt(format_args!("FilteredEntityRef conflicts with a previous access in this query. Exclusive access cannot coincide with any other accesses."));
}
};assert!(
1190 filtered_access.access().is_compatible(state),
1191 "FilteredEntityRef conflicts with a previous access in this query. Exclusive access cannot coincide with any other accesses.",
1192 );
1193 filtered_access.access.extend(state);
1194 }
1195
1196 fn init_state(_world: &mut World) -> Self::State {
1197 Access::default()
1198 }
1199
1200 fn get_state(_components: &Components) -> Option<Self::State> {
1201 Some(Access::default())
1202 }
1203
1204 fn matches_component_set(
1205 _state: &Self::State,
1206 _set_contains_id: &impl Fn(ComponentId) -> bool,
1207 ) -> bool {
1208 true
1209 }
1210}
1211
1212unsafe impl<'a, 'b> QueryData for FilteredEntityRef<'a, 'b> {
1214 const IS_READ_ONLY: bool = true;
1215 const IS_ARCHETYPAL: bool = true;
1216 type ReadOnly = Self;
1217 type Item<'w, 's> = FilteredEntityRef<'w, 's>;
1218
1219 fn shrink<'wlong: 'wshort, 'wshort, 's>(
1220 item: Self::Item<'wlong, 's>,
1221 ) -> Self::Item<'wshort, 's> {
1222 item
1223 }
1224
1225 #[inline]
1226 fn provide_extra_access(
1227 state: &mut Self::State,
1228 access: &mut Access,
1229 available_access: &Access,
1230 ) {
1231 state.clone_from(available_access);
1235 state.clear_writes();
1237 state.remove_conflicting_access(access);
1239 access.extend(state);
1242 }
1243
1244 #[inline(always)]
1245 unsafe fn fetch<'w, 's>(
1246 access: &'s Self::State,
1247 fetch: &mut Self::Fetch<'w>,
1248 entity: Entity,
1249 _table_row: TableRow,
1250 ) -> Option<Self::Item<'w, 's>> {
1251 let cell = unsafe {
1253 fetch
1254 .world
1255 .get_entity_with_ticks(entity, fetch.last_run, fetch.this_run)
1256 .debug_checked_unwrap()
1257 };
1258 Some(unsafe { FilteredEntityRef::new(cell, access) })
1260 }
1261
1262 fn iter_access(state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
1263 iter::once(EcsAccessType::Access(state))
1264 }
1265}
1266
1267unsafe impl IterQueryData for FilteredEntityRef<'_, '_> {}
1269
1270unsafe impl ReadOnlyQueryData for FilteredEntityRef<'_, '_> {}
1272
1273unsafe impl SingleEntityQueryData for FilteredEntityRef<'_, '_> {}
1275
1276impl ArchetypeQueryData for FilteredEntityRef<'_, '_> {}
1277
1278unsafe impl WorldQuery for FilteredEntityMut<'_, '_> {
1280 type Fetch<'w> = EntityFetch<'w>;
1281 type State = Access;
1282
1283 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
1284 fetch
1285 }
1286
1287 const IS_DENSE: bool = true;
1288
1289 unsafe fn init_fetch<'w, 's>(
1290 world: UnsafeWorldCell<'w>,
1291 _state: &'s Self::State,
1292 last_run: Tick,
1293 this_run: Tick,
1294 ) -> Self::Fetch<'w> {
1295 EntityFetch {
1296 world,
1297 last_run,
1298 this_run,
1299 }
1300 }
1301
1302 #[inline]
1303 unsafe fn set_archetype<'w, 's>(
1304 _fetch: &mut Self::Fetch<'w>,
1305 _state: &'s Self::State,
1306 _: &'w Archetype,
1307 _table: &Table,
1308 ) {
1309 }
1310
1311 #[inline]
1312 unsafe fn set_table<'w, 's>(
1313 _fetch: &mut Self::Fetch<'w>,
1314 _state: &'s Self::State,
1315 _: &'w Table,
1316 ) {
1317 }
1318
1319 fn update_component_access(state: &Self::State, filtered_access: &mut FilteredAccess) {
1320 if !filtered_access.access().is_compatible(state) {
{
::core::panicking::panic_fmt(format_args!("FilteredEntityMut conflicts with a previous access in this query. Exclusive access cannot coincide with any other accesses."));
}
};assert!(
1321 filtered_access.access().is_compatible(state),
1322 "FilteredEntityMut conflicts with a previous access in this query. Exclusive access cannot coincide with any other accesses.",
1323 );
1324 filtered_access.access.extend(state);
1325 }
1326
1327 fn init_state(_world: &mut World) -> Self::State {
1328 Access::default()
1329 }
1330
1331 fn get_state(_components: &Components) -> Option<Self::State> {
1332 Some(Access::default())
1333 }
1334
1335 fn matches_component_set(
1336 _state: &Self::State,
1337 _set_contains_id: &impl Fn(ComponentId) -> bool,
1338 ) -> bool {
1339 true
1340 }
1341}
1342
1343unsafe impl<'a, 'b> QueryData for FilteredEntityMut<'a, 'b> {
1345 const IS_READ_ONLY: bool = false;
1346 const IS_ARCHETYPAL: bool = true;
1347 type ReadOnly = FilteredEntityRef<'a, 'b>;
1348 type Item<'w, 's> = FilteredEntityMut<'w, 's>;
1349
1350 fn shrink<'wlong: 'wshort, 'wshort, 's>(
1351 item: Self::Item<'wlong, 's>,
1352 ) -> Self::Item<'wshort, 's> {
1353 item
1354 }
1355
1356 #[inline]
1357 fn provide_extra_access(
1358 state: &mut Self::State,
1359 access: &mut Access,
1360 available_access: &Access,
1361 ) {
1362 state.clone_from(available_access);
1366 state.remove_conflicting_access(access);
1368 access.extend(state);
1371 }
1372
1373 #[inline(always)]
1374 unsafe fn fetch<'w, 's>(
1375 access: &'s Self::State,
1376 fetch: &mut Self::Fetch<'w>,
1377 entity: Entity,
1378 _table_row: TableRow,
1379 ) -> Option<Self::Item<'w, 's>> {
1380 let cell = unsafe {
1382 fetch
1383 .world
1384 .get_entity_with_ticks(entity, fetch.last_run, fetch.this_run)
1385 .debug_checked_unwrap()
1386 };
1387 Some(unsafe { FilteredEntityMut::new(cell, access) })
1389 }
1390
1391 fn iter_access(state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
1392 iter::once(EcsAccessType::Access(state))
1393 }
1394}
1395
1396unsafe impl IterQueryData for FilteredEntityMut<'_, '_> {}
1398
1399unsafe impl SingleEntityQueryData for FilteredEntityMut<'_, '_> {}
1401
1402impl ArchetypeQueryData for FilteredEntityMut<'_, '_> {}
1403
1404unsafe impl<'a, 'b, B> WorldQuery for EntityRefExcept<'a, 'b, B>
1408where
1409 B: Bundle,
1410{
1411 type Fetch<'w> = EntityFetch<'w>;
1412 type State = Access;
1413
1414 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
1415 fetch
1416 }
1417
1418 unsafe fn init_fetch<'w, 's>(
1419 world: UnsafeWorldCell<'w>,
1420 _: &'s Self::State,
1421 last_run: Tick,
1422 this_run: Tick,
1423 ) -> Self::Fetch<'w> {
1424 EntityFetch {
1425 world,
1426 last_run,
1427 this_run,
1428 }
1429 }
1430
1431 const IS_DENSE: bool = true;
1432
1433 unsafe fn set_archetype<'w, 's>(
1434 _: &mut Self::Fetch<'w>,
1435 _: &'s Self::State,
1436 _: &'w Archetype,
1437 _: &'w Table,
1438 ) {
1439 }
1440
1441 unsafe fn set_table<'w, 's>(_: &mut Self::Fetch<'w>, _: &'s Self::State, _: &'w Table) {}
1442
1443 fn update_component_access(state: &Self::State, filtered_access: &mut FilteredAccess) {
1444 let access = filtered_access.access_mut();
1445 if !access.is_compatible(state) {
{
::core::panicking::panic_fmt(format_args!("`EntityRefExcept<{0}>` conflicts with a previous access in this query.",
DebugName::type_name::<B>()));
}
};assert!(
1446 access.is_compatible(state),
1447 "`EntityRefExcept<{}>` conflicts with a previous access in this query.",
1448 DebugName::type_name::<B>(),
1449 );
1450 access.extend(state);
1451 }
1452
1453 fn init_state(world: &mut World) -> Self::State {
1454 let mut access = Access::new();
1455 access.read_all();
1456 for id in B::component_ids(&mut world.components_registrator()) {
1457 access.remove_read(id);
1458 }
1459 access
1460 }
1461
1462 fn get_state(components: &Components) -> Option<Self::State> {
1463 let mut access = Access::new();
1464 access.read_all();
1465 for id in B::get_component_ids(components).flatten() {
1472 access.remove_read(id);
1473 }
1474 Some(access)
1475 }
1476
1477 fn matches_component_set(_: &Self::State, _: &impl Fn(ComponentId) -> bool) -> bool {
1478 true
1479 }
1480}
1481
1482unsafe impl<'a, 'b, B> QueryData for EntityRefExcept<'a, 'b, B>
1484where
1485 B: Bundle,
1486{
1487 const IS_READ_ONLY: bool = true;
1488 const IS_ARCHETYPAL: bool = true;
1489 type ReadOnly = Self;
1490 type Item<'w, 's> = EntityRefExcept<'w, 's, B>;
1491
1492 fn shrink<'wlong: 'wshort, 'wshort, 's>(
1493 item: Self::Item<'wlong, 's>,
1494 ) -> Self::Item<'wshort, 's> {
1495 item
1496 }
1497
1498 unsafe fn fetch<'w, 's>(
1499 access: &'s Self::State,
1500 fetch: &mut Self::Fetch<'w>,
1501 entity: Entity,
1502 _: TableRow,
1503 ) -> Option<Self::Item<'w, 's>> {
1504 let cell = fetch
1505 .world
1506 .get_entity_with_ticks(entity, fetch.last_run, fetch.this_run)
1507 .unwrap();
1508 Some(EntityRefExcept::new(cell, access))
1509 }
1510
1511 fn iter_access(state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
1512 iter::once(EcsAccessType::Access(state))
1513 }
1514}
1515
1516unsafe impl<B> IterQueryData for EntityRefExcept<'_, '_, B> where B: Bundle {}
1518
1519unsafe impl<B> ReadOnlyQueryData for EntityRefExcept<'_, '_, B> where B: Bundle {}
1521
1522unsafe impl<B> SingleEntityQueryData for EntityRefExcept<'_, '_, B> where B: Bundle {}
1524
1525impl<B: Bundle> ArchetypeQueryData for EntityRefExcept<'_, '_, B> {}
1526
1527unsafe impl<'a, 'b, B> WorldQuery for EntityMutExcept<'a, 'b, B>
1531where
1532 B: Bundle,
1533{
1534 type Fetch<'w> = EntityFetch<'w>;
1535 type State = Access;
1536
1537 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
1538 fetch
1539 }
1540
1541 unsafe fn init_fetch<'w, 's>(
1542 world: UnsafeWorldCell<'w>,
1543 _: &'s Self::State,
1544 last_run: Tick,
1545 this_run: Tick,
1546 ) -> Self::Fetch<'w> {
1547 EntityFetch {
1548 world,
1549 last_run,
1550 this_run,
1551 }
1552 }
1553
1554 const IS_DENSE: bool = true;
1555
1556 unsafe fn set_archetype<'w, 's>(
1557 _: &mut Self::Fetch<'w>,
1558 _: &'s Self::State,
1559 _: &'w Archetype,
1560 _: &'w Table,
1561 ) {
1562 }
1563
1564 unsafe fn set_table<'w, 's>(_: &mut Self::Fetch<'w>, _: &'s Self::State, _: &'w Table) {}
1565
1566 fn update_component_access(state: &Self::State, filtered_access: &mut FilteredAccess) {
1567 let access = filtered_access.access_mut();
1568 if !access.is_compatible(state) {
{
::core::panicking::panic_fmt(format_args!("`EntityMutExcept<{0}>` conflicts with a previous access in this query.",
DebugName::type_name::<B>()));
}
};assert!(
1569 access.is_compatible(state),
1570 "`EntityMutExcept<{}>` conflicts with a previous access in this query.",
1571 DebugName::type_name::<B>()
1572 );
1573 access.extend(state);
1574 }
1575
1576 fn init_state(world: &mut World) -> Self::State {
1577 let mut access = Access::new();
1578 access.write_all();
1579 for id in B::component_ids(&mut world.components_registrator()) {
1580 access.remove_read(id);
1581 }
1582 access
1583 }
1584
1585 fn get_state(components: &Components) -> Option<Self::State> {
1586 let mut access = Access::new();
1587 access.write_all();
1588 for id in B::get_component_ids(components).flatten() {
1595 access.remove_read(id);
1596 }
1597 Some(access)
1598 }
1599
1600 fn matches_component_set(_: &Self::State, _: &impl Fn(ComponentId) -> bool) -> bool {
1601 true
1602 }
1603}
1604
1605unsafe impl<'a, 'b, B> QueryData for EntityMutExcept<'a, 'b, B>
1608where
1609 B: Bundle,
1610{
1611 const IS_READ_ONLY: bool = false;
1612 const IS_ARCHETYPAL: bool = true;
1613 type ReadOnly = EntityRefExcept<'a, 'b, B>;
1614 type Item<'w, 's> = EntityMutExcept<'w, 's, B>;
1615
1616 fn shrink<'wlong: 'wshort, 'wshort, 's>(
1617 item: Self::Item<'wlong, 's>,
1618 ) -> Self::Item<'wshort, 's> {
1619 item
1620 }
1621
1622 unsafe fn fetch<'w, 's>(
1623 access: &'s Self::State,
1624 fetch: &mut Self::Fetch<'w>,
1625 entity: Entity,
1626 _: TableRow,
1627 ) -> Option<Self::Item<'w, 's>> {
1628 let cell = fetch
1629 .world
1630 .get_entity_with_ticks(entity, fetch.last_run, fetch.this_run)
1631 .unwrap();
1632 Some(EntityMutExcept::new(cell, access))
1633 }
1634
1635 fn iter_access(state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
1636 iter::once(EcsAccessType::Access(state))
1637 }
1638}
1639
1640unsafe impl<B> IterQueryData for EntityMutExcept<'_, '_, B> where B: Bundle {}
1642
1643unsafe impl<B> SingleEntityQueryData for EntityMutExcept<'_, '_, B> where B: Bundle {}
1645
1646impl<B: Bundle> ArchetypeQueryData for EntityMutExcept<'_, '_, B> {}
1647
1648unsafe impl WorldQuery for &Archetype {
1652 type Fetch<'w> = (&'w Entities, &'w Archetypes);
1653 type State = ();
1654
1655 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
1656 fetch
1657 }
1658
1659 unsafe fn init_fetch<'w, 's>(
1660 world: UnsafeWorldCell<'w>,
1661 _state: &'s Self::State,
1662 _last_run: Tick,
1663 _this_run: Tick,
1664 ) -> Self::Fetch<'w> {
1665 (world.entities(), world.archetypes())
1666 }
1667
1668 const IS_DENSE: bool = true;
1671
1672 #[inline]
1673 unsafe fn set_archetype<'w, 's>(
1674 _fetch: &mut Self::Fetch<'w>,
1675 _state: &'s Self::State,
1676 _archetype: &'w Archetype,
1677 _table: &Table,
1678 ) {
1679 }
1680
1681 #[inline]
1682 unsafe fn set_table<'w, 's>(
1683 _fetch: &mut Self::Fetch<'w>,
1684 _state: &'s Self::State,
1685 _table: &'w Table,
1686 ) {
1687 }
1688
1689 fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) {}
1690
1691 fn init_state(_world: &mut World) {}
1692
1693 fn get_state(_components: &Components) -> Option<()> {
1694 Some(())
1695 }
1696
1697 fn matches_component_set(
1698 _state: &Self::State,
1699 _set_contains_id: &impl Fn(ComponentId) -> bool,
1700 ) -> bool {
1701 true
1702 }
1703}
1704
1705unsafe impl QueryData for &Archetype {
1707 const IS_READ_ONLY: bool = true;
1708 const IS_ARCHETYPAL: bool = true;
1709 type ReadOnly = Self;
1710 type Item<'w, 's> = &'w Archetype;
1711
1712 fn shrink<'wlong: 'wshort, 'wshort, 's>(
1713 item: Self::Item<'wlong, 's>,
1714 ) -> Self::Item<'wshort, 's> {
1715 item
1716 }
1717
1718 #[inline(always)]
1719 unsafe fn fetch<'w, 's>(
1720 _state: &'s Self::State,
1721 fetch: &mut Self::Fetch<'w>,
1722 entity: Entity,
1723 _table_row: TableRow,
1724 ) -> Option<Self::Item<'w, 's>> {
1725 let (entities, archetypes) = *fetch;
1726 let location = unsafe { entities.get_spawned(entity).debug_checked_unwrap() };
1728 Some(unsafe { archetypes.get(location.archetype_id).debug_checked_unwrap() })
1730 }
1731
1732 fn iter_access(_state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
1733 iter::empty()
1734 }
1735}
1736
1737unsafe impl IterQueryData for &Archetype {}
1739
1740unsafe impl ReadOnlyQueryData for &Archetype {}
1742
1743unsafe impl SingleEntityQueryData for &Archetype {}
1745
1746impl ReleaseStateQueryData for &Archetype {
1747 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
1748 item
1749 }
1750}
1751
1752impl ArchetypeQueryData for &Archetype {}
1753
1754pub struct ReadFetch<'w, T: Component> {
1756 components: StorageSwitch<
1757 T,
1758 Option<ThinSlicePtr<'w, UnsafeCell<T>>>,
1760 Option<&'w ComponentSparseSet>,
1762 >,
1763}
1764
1765impl<T: Component> Clone for ReadFetch<'_, T> {
1766 fn clone(&self) -> Self {
1767 *self
1768 }
1769}
1770
1771impl<T: Component> Copy for ReadFetch<'_, T> {}
1772
1773unsafe impl<T: Component> WorldQuery for &T {
1779 type Fetch<'w> = ReadFetch<'w, T>;
1780 type State = ComponentId;
1781
1782 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
1783 fetch
1784 }
1785
1786 #[inline]
1787 unsafe fn init_fetch<'w, 's>(
1788 world: UnsafeWorldCell<'w>,
1789 &component_id: &ComponentId,
1790 _last_run: Tick,
1791 _this_run: Tick,
1792 ) -> ReadFetch<'w, T> {
1793 ReadFetch {
1794 components: StorageSwitch::new(
1795 || None,
1796 || {
1797 unsafe { world.storages().sparse_sets.get(component_id) }
1802 },
1803 ),
1804 }
1805 }
1806
1807 const IS_DENSE: bool = {
1808 match T::STORAGE_TYPE {
1809 StorageType::Table => true,
1810 StorageType::SparseSet => false,
1811 }
1812 };
1813
1814 #[inline]
1815 unsafe fn set_archetype<'w>(
1816 fetch: &mut ReadFetch<'w, T>,
1817 component_id: &ComponentId,
1818 _archetype: &'w Archetype,
1819 table: &'w Table,
1820 ) {
1821 if Self::IS_DENSE {
1822 unsafe {
1824 Self::set_table(fetch, component_id, table);
1825 }
1826 }
1827 }
1828
1829 #[inline]
1830 unsafe fn set_table<'w>(
1831 fetch: &mut ReadFetch<'w, T>,
1832 &component_id: &ComponentId,
1833 table: &'w Table,
1834 ) {
1835 let table_data = Some(
1836 table
1837 .get_data_slice_for(component_id)
1838 .debug_checked_unwrap()
1839 .into(),
1840 );
1841 unsafe { fetch.components.set_table(table_data) };
1843 }
1844
1845 fn update_component_access(&component_id: &ComponentId, access: &mut FilteredAccess) {
1846 if !!access.access().has_write(component_id) {
{
::core::panicking::panic_fmt(format_args!("&{0} conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.",
DebugName::type_name::<T>()));
}
};assert!(
1847 !access.access().has_write(component_id),
1848 "&{} conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.",
1849 DebugName::type_name::<T>(),
1850 );
1851 access.add_read(component_id);
1852 }
1853
1854 fn init_state(world: &mut World) -> ComponentId {
1855 world.register_component::<T>()
1856 }
1857
1858 fn get_state(components: &Components) -> Option<Self::State> {
1859 components.component_id::<T>()
1860 }
1861
1862 fn matches_component_set(
1863 &state: &ComponentId,
1864 set_contains_id: &impl Fn(ComponentId) -> bool,
1865 ) -> bool {
1866 set_contains_id(state)
1867 }
1868}
1869
1870unsafe impl<T: Component> QueryData for &T {
1872 const IS_READ_ONLY: bool = true;
1873 const IS_ARCHETYPAL: bool = true;
1874 type ReadOnly = Self;
1875 type Item<'w, 's> = &'w T;
1876
1877 fn shrink<'wlong: 'wshort, 'wshort, 's>(
1878 item: Self::Item<'wlong, 's>,
1879 ) -> Self::Item<'wshort, 's> {
1880 item
1881 }
1882
1883 #[inline(always)]
1884 unsafe fn fetch<'w, 's>(
1885 _state: &'s Self::State,
1886 fetch: &mut Self::Fetch<'w>,
1887 entity: Entity,
1888 table_row: TableRow,
1889 ) -> Option<Self::Item<'w, 's>> {
1890 Some(fetch.components.extract(
1891 |table| {
1892 let table = unsafe { table.debug_checked_unwrap() };
1894 let item = unsafe { table.get_unchecked(table_row.index()) };
1896 item.deref()
1897 },
1898 |sparse_set| {
1899 let item = unsafe {
1901 sparse_set
1902 .debug_checked_unwrap()
1903 .get(entity)
1904 .debug_checked_unwrap()
1905 };
1906 item.deref()
1907 },
1908 ))
1909 }
1910
1911 fn iter_access(state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
1912 iter::once(EcsAccessType::Component(EcsAccessLevel::Read(*state)))
1913 }
1914}
1915
1916impl<T: Component> ContiguousQueryData for &T {
1917 type Contiguous<'w, 's> = &'w [T];
1918
1919 unsafe fn fetch_contiguous<'w, 's>(
1920 _state: &'s Self::State,
1921 fetch: &mut Self::Fetch<'w>,
1922 entities: &'w [Entity],
1923 ) -> Self::Contiguous<'w, 's> {
1924 fetch.components.extract(
1925 |table| {
1926 let table = unsafe { table.debug_checked_unwrap() };
1928 unsafe { table.cast().as_slice_unchecked(entities.len()) }
1932 },
1933 |_| {
1934 #[cfg(debug_assertions)]
1935 ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
1936 #[cfg(not(debug_assertions))]
1938 core::hint::unreachable_unchecked();
1939 },
1940 )
1941 }
1942}
1943
1944unsafe impl<T: Component> IterQueryData for &T {}
1946
1947unsafe impl<T: Component> ReadOnlyQueryData for &T {}
1949
1950unsafe impl<T: Component> SingleEntityQueryData for &T {}
1952
1953impl<T: Component> ReleaseStateQueryData for &T {
1954 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
1955 item
1956 }
1957}
1958
1959impl<T: Component> ArchetypeQueryData for &T {}
1960
1961#[doc(hidden)]
1962pub struct RefFetch<'w, T: Component> {
1963 components: StorageSwitch<
1964 T,
1965 Option<(
1967 ThinSlicePtr<'w, UnsafeCell<T>>,
1968 ThinSlicePtr<'w, UnsafeCell<Tick>>,
1969 ThinSlicePtr<'w, UnsafeCell<Tick>>,
1970 MaybeLocation<ThinSlicePtr<'w, UnsafeCell<&'static Location<'static>>>>,
1971 )>,
1972 Option<&'w ComponentSparseSet>,
1975 >,
1976 last_run: Tick,
1977 this_run: Tick,
1978}
1979
1980impl<T: Component> Clone for RefFetch<'_, T> {
1981 fn clone(&self) -> Self {
1982 *self
1983 }
1984}
1985
1986impl<T: Component> Copy for RefFetch<'_, T> {}
1987
1988unsafe impl<'__w, T: Component> WorldQuery for Ref<'__w, T> {
1994 type Fetch<'w> = RefFetch<'w, T>;
1995 type State = ComponentId;
1996
1997 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
1998 fetch
1999 }
2000
2001 #[inline]
2002 unsafe fn init_fetch<'w, 's>(
2003 world: UnsafeWorldCell<'w>,
2004 &component_id: &ComponentId,
2005 last_run: Tick,
2006 this_run: Tick,
2007 ) -> RefFetch<'w, T> {
2008 RefFetch {
2009 components: StorageSwitch::new(
2010 || None,
2011 || {
2012 unsafe { world.storages().sparse_sets.get(component_id) }
2017 },
2018 ),
2019 last_run,
2020 this_run,
2021 }
2022 }
2023
2024 const IS_DENSE: bool = {
2025 match T::STORAGE_TYPE {
2026 StorageType::Table => true,
2027 StorageType::SparseSet => false,
2028 }
2029 };
2030
2031 #[inline]
2032 unsafe fn set_archetype<'w>(
2033 fetch: &mut RefFetch<'w, T>,
2034 component_id: &ComponentId,
2035 _archetype: &'w Archetype,
2036 table: &'w Table,
2037 ) {
2038 if Self::IS_DENSE {
2039 unsafe {
2041 Self::set_table(fetch, component_id, table);
2042 }
2043 }
2044 }
2045
2046 #[inline]
2047 unsafe fn set_table<'w>(
2048 fetch: &mut RefFetch<'w, T>,
2049 &component_id: &ComponentId,
2050 table: &'w Table,
2051 ) {
2052 let column = table.get_column(component_id).debug_checked_unwrap();
2053 let table_data = Some((
2054 column.get_data_slice(table.entity_count() as usize).into(),
2055 column
2056 .get_added_ticks_slice(table.entity_count() as usize)
2057 .into(),
2058 column
2059 .get_changed_ticks_slice(table.entity_count() as usize)
2060 .into(),
2061 column
2062 .get_changed_by_slice(table.entity_count() as usize)
2063 .map(Into::into),
2064 ));
2065 unsafe { fetch.components.set_table(table_data) };
2067 }
2068
2069 fn update_component_access(&component_id: &ComponentId, access: &mut FilteredAccess) {
2070 if !!access.access().has_write(component_id) {
{
::core::panicking::panic_fmt(format_args!("&{0} conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.",
DebugName::type_name::<T>()));
}
};assert!(
2071 !access.access().has_write(component_id),
2072 "&{} conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.",
2073 DebugName::type_name::<T>(),
2074 );
2075 access.add_read(component_id);
2076 }
2077
2078 fn init_state(world: &mut World) -> ComponentId {
2079 world.register_component::<T>()
2080 }
2081
2082 fn get_state(components: &Components) -> Option<Self::State> {
2083 components.component_id::<T>()
2084 }
2085
2086 fn matches_component_set(
2087 &state: &ComponentId,
2088 set_contains_id: &impl Fn(ComponentId) -> bool,
2089 ) -> bool {
2090 set_contains_id(state)
2091 }
2092}
2093
2094unsafe impl<'__w, T: Component> QueryData for Ref<'__w, T> {
2096 const IS_READ_ONLY: bool = true;
2097 const IS_ARCHETYPAL: bool = true;
2098 type ReadOnly = Self;
2099 type Item<'w, 's> = Ref<'w, T>;
2100
2101 fn shrink<'wlong: 'wshort, 'wshort, 's>(
2102 item: Self::Item<'wlong, 's>,
2103 ) -> Self::Item<'wshort, 's> {
2104 item
2105 }
2106
2107 #[inline(always)]
2108 unsafe fn fetch<'w, 's>(
2109 _state: &'s Self::State,
2110 fetch: &mut Self::Fetch<'w>,
2111 entity: Entity,
2112 table_row: TableRow,
2113 ) -> Option<Self::Item<'w, 's>> {
2114 Some(fetch.components.extract(
2115 |table| {
2116 let (table_components, added_ticks, changed_ticks, callers) =
2118 unsafe { table.debug_checked_unwrap() };
2119
2120 let component = unsafe { table_components.get_unchecked(table_row.index()) };
2122 let added = unsafe { added_ticks.get_unchecked(table_row.index()) };
2124 let changed = unsafe { changed_ticks.get_unchecked(table_row.index()) };
2126 let caller =
2128 callers.map(|callers| unsafe { callers.get_unchecked(table_row.index()) });
2129
2130 Ref {
2131 value: component.deref(),
2132 ticks: ComponentTicksRef {
2133 added: added.deref(),
2134 changed: changed.deref(),
2135 changed_by: caller.map(|caller| caller.deref()),
2136 this_run: fetch.this_run,
2137 last_run: fetch.last_run,
2138 },
2139 }
2140 },
2141 |sparse_set| {
2142 let (component, ticks) = unsafe {
2144 sparse_set
2145 .debug_checked_unwrap()
2146 .get_with_ticks(entity)
2147 .debug_checked_unwrap()
2148 };
2149
2150 Ref {
2151 value: component.deref(),
2152 ticks: ComponentTicksRef::from_tick_cells(
2153 ticks,
2154 fetch.last_run,
2155 fetch.this_run,
2156 ),
2157 }
2158 },
2159 ))
2160 }
2161
2162 fn iter_access(state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
2163 iter::once(EcsAccessType::Component(EcsAccessLevel::Read(*state)))
2164 }
2165}
2166
2167unsafe impl<'__w, T: Component> IterQueryData for Ref<'__w, T> {}
2169
2170unsafe impl<'__w, T: Component> ReadOnlyQueryData for Ref<'__w, T> {}
2172
2173unsafe impl<'__w, T: Component> SingleEntityQueryData for Ref<'__w, T> {}
2175
2176impl<T: Component> ReleaseStateQueryData for Ref<'_, T> {
2177 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
2178 item
2179 }
2180}
2181
2182impl<T: Component> ArchetypeQueryData for Ref<'_, T> {}
2183
2184impl<T: Component> ContiguousQueryData for Ref<'_, T> {
2185 type Contiguous<'w, 's> = ContiguousRef<'w, T>;
2186
2187 unsafe fn fetch_contiguous<'w, 's>(
2188 _state: &'s Self::State,
2189 fetch: &mut Self::Fetch<'w>,
2190 entities: &'w [Entity],
2191 ) -> Self::Contiguous<'w, 's> {
2192 fetch.components.extract(
2193 |table| {
2194 let (table_components, added_ticks, changed_ticks, callers) =
2196 unsafe { table.debug_checked_unwrap() };
2197
2198 ContiguousRef {
2199 value: unsafe { table_components.cast().as_slice_unchecked(entities.len()) },
2201 ticks: unsafe {
2206 ContiguousComponentTicksRef::from_slice_ptrs(
2207 added_ticks,
2208 changed_ticks,
2209 callers,
2210 entities.len(),
2211 fetch.this_run,
2212 fetch.last_run,
2213 )
2214 },
2215 }
2216 },
2217 |_| {
2218 #[cfg(debug_assertions)]
2219 ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
2220 #[cfg(not(debug_assertions))]
2222 core::hint::unreachable_unchecked();
2223 },
2224 )
2225 }
2226}
2227
2228pub struct WriteFetch<'w, T: Component> {
2230 components: StorageSwitch<
2231 T,
2232 Option<(
2234 ThinSlicePtr<'w, UnsafeCell<T>>,
2235 ThinSlicePtr<'w, UnsafeCell<Tick>>,
2236 ThinSlicePtr<'w, UnsafeCell<Tick>>,
2237 MaybeLocation<ThinSlicePtr<'w, UnsafeCell<&'static Location<'static>>>>,
2238 )>,
2239 Option<&'w ComponentSparseSet>,
2242 >,
2243 last_run: Tick,
2244 this_run: Tick,
2245}
2246
2247impl<T: Component> Clone for WriteFetch<'_, T> {
2248 fn clone(&self) -> Self {
2249 *self
2250 }
2251}
2252
2253impl<T: Component> Copy for WriteFetch<'_, T> {}
2254
2255unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T {
2261 type Fetch<'w> = WriteFetch<'w, T>;
2262 type State = ComponentId;
2263
2264 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
2265 fetch
2266 }
2267
2268 #[inline]
2269 unsafe fn init_fetch<'w, 's>(
2270 world: UnsafeWorldCell<'w>,
2271 &component_id: &ComponentId,
2272 last_run: Tick,
2273 this_run: Tick,
2274 ) -> WriteFetch<'w, T> {
2275 WriteFetch {
2276 components: StorageSwitch::new(
2277 || None,
2278 || {
2279 unsafe { world.storages().sparse_sets.get(component_id) }
2284 },
2285 ),
2286 last_run,
2287 this_run,
2288 }
2289 }
2290
2291 const IS_DENSE: bool = {
2292 match T::STORAGE_TYPE {
2293 StorageType::Table => true,
2294 StorageType::SparseSet => false,
2295 }
2296 };
2297
2298 #[inline]
2299 unsafe fn set_archetype<'w>(
2300 fetch: &mut WriteFetch<'w, T>,
2301 component_id: &ComponentId,
2302 _archetype: &'w Archetype,
2303 table: &'w Table,
2304 ) {
2305 if Self::IS_DENSE {
2306 unsafe {
2308 Self::set_table(fetch, component_id, table);
2309 }
2310 }
2311 }
2312
2313 #[inline]
2314 unsafe fn set_table<'w>(
2315 fetch: &mut WriteFetch<'w, T>,
2316 &component_id: &ComponentId,
2317 table: &'w Table,
2318 ) {
2319 let column = table.get_column(component_id).debug_checked_unwrap();
2320 let table_data = Some((
2321 column.get_data_slice(table.entity_count() as usize).into(),
2322 column
2323 .get_added_ticks_slice(table.entity_count() as usize)
2324 .into(),
2325 column
2326 .get_changed_ticks_slice(table.entity_count() as usize)
2327 .into(),
2328 column
2329 .get_changed_by_slice(table.entity_count() as usize)
2330 .map(Into::into),
2331 ));
2332 unsafe { fetch.components.set_table(table_data) };
2334 }
2335
2336 fn update_component_access(&component_id: &ComponentId, access: &mut FilteredAccess) {
2337 if !!access.access().has_read(component_id) {
{
::core::panicking::panic_fmt(format_args!("&mut {0} conflicts with a previous access in this query. Mutable component access must be unique.",
DebugName::type_name::<T>()));
}
};assert!(
2338 !access.access().has_read(component_id),
2339 "&mut {} conflicts with a previous access in this query. Mutable component access must be unique.",
2340 DebugName::type_name::<T>(),
2341 );
2342 access.add_write(component_id);
2343 }
2344
2345 fn init_state(world: &mut World) -> ComponentId {
2346 world.register_component::<T>()
2347 }
2348
2349 fn get_state(components: &Components) -> Option<Self::State> {
2350 components.component_id::<T>()
2351 }
2352
2353 fn matches_component_set(
2354 &state: &ComponentId,
2355 set_contains_id: &impl Fn(ComponentId) -> bool,
2356 ) -> bool {
2357 set_contains_id(state)
2358 }
2359}
2360
2361unsafe impl<'__w, T: Component<Mutability = Mutable>> QueryData for &'__w mut T {
2363 const IS_READ_ONLY: bool = false;
2364 const IS_ARCHETYPAL: bool = true;
2365 type ReadOnly = &'__w T;
2366 type Item<'w, 's> = Mut<'w, T>;
2367
2368 fn shrink<'wlong: 'wshort, 'wshort, 's>(
2369 item: Self::Item<'wlong, 's>,
2370 ) -> Self::Item<'wshort, 's> {
2371 item
2372 }
2373
2374 #[inline(always)]
2375 unsafe fn fetch<'w, 's>(
2376 _state: &'s Self::State,
2377 fetch: &mut Self::Fetch<'w>,
2378 entity: Entity,
2379 table_row: TableRow,
2380 ) -> Option<Self::Item<'w, 's>> {
2381 Some(fetch.components.extract(
2382 |table| {
2383 let (table_components, added_ticks, changed_ticks, callers) =
2385 unsafe { table.debug_checked_unwrap() };
2386
2387 let component = unsafe { table_components.get_unchecked(table_row.index()) };
2389 let added = unsafe { added_ticks.get_unchecked(table_row.index()) };
2391 let changed = unsafe { changed_ticks.get_unchecked(table_row.index()) };
2393 let caller =
2395 callers.map(|callers| unsafe { callers.get_unchecked(table_row.index()) });
2396
2397 Mut {
2398 value: component.deref_mut(),
2399 ticks: ComponentTicksMut {
2400 added: added.deref_mut(),
2401 changed: changed.deref_mut(),
2402 changed_by: caller.map(|caller| caller.deref_mut()),
2403 this_run: fetch.this_run,
2404 last_run: fetch.last_run,
2405 },
2406 }
2407 },
2408 |sparse_set| {
2409 let (component, ticks) = unsafe {
2411 sparse_set
2412 .debug_checked_unwrap()
2413 .get_with_ticks(entity)
2414 .debug_checked_unwrap()
2415 };
2416
2417 Mut {
2418 value: component.assert_unique().deref_mut(),
2419 ticks: ComponentTicksMut::from_tick_cells(
2420 ticks,
2421 fetch.last_run,
2422 fetch.this_run,
2423 ),
2424 }
2425 },
2426 ))
2427 }
2428
2429 fn iter_access(state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
2430 iter::once(EcsAccessType::Component(EcsAccessLevel::Write(*state)))
2431 }
2432}
2433
2434unsafe impl<T: Component<Mutability = Mutable>> IterQueryData for &mut T {}
2436
2437unsafe impl<T: Component<Mutability = Mutable>> SingleEntityQueryData for &mut T {}
2439
2440impl<T: Component<Mutability = Mutable>> ReleaseStateQueryData for &mut T {
2441 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
2442 item
2443 }
2444}
2445
2446impl<T: Component<Mutability = Mutable>> ArchetypeQueryData for &mut T {}
2447
2448impl<T: Component<Mutability = Mutable>> ContiguousQueryData for &mut T {
2449 type Contiguous<'w, 's> = ContiguousMut<'w, T>;
2450
2451 unsafe fn fetch_contiguous<'w, 's>(
2452 _state: &'s Self::State,
2453 fetch: &mut Self::Fetch<'w>,
2454 entities: &'w [Entity],
2455 ) -> Self::Contiguous<'w, 's> {
2456 fetch.components.extract(
2457 |table| {
2458 let (table_components, added_ticks, changed_ticks, callers) =
2460 unsafe { table.debug_checked_unwrap() };
2461
2462 ContiguousMut {
2463 value: unsafe { table_components.as_mut_slice_unchecked(entities.len()) },
2465 ticks: unsafe {
2470 ContiguousComponentTicksMut::from_slice_ptrs(
2471 added_ticks,
2472 changed_ticks,
2473 callers,
2474 entities.len(),
2475 fetch.this_run,
2476 fetch.last_run,
2477 )
2478 },
2479 }
2480 },
2481 |_| {
2482 #[cfg(debug_assertions)]
2483 ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
2484 #[cfg(not(debug_assertions))]
2486 core::hint::unreachable_unchecked();
2487 },
2488 )
2489 }
2490}
2491
2492unsafe impl<'__w, T: Component> WorldQuery for Mut<'__w, T> {
2502 type Fetch<'w> = WriteFetch<'w, T>;
2503 type State = ComponentId;
2504
2505 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
2506 fetch
2507 }
2508
2509 #[inline]
2510 unsafe fn init_fetch<'w, 's>(
2512 world: UnsafeWorldCell<'w>,
2513 state: &ComponentId,
2514 last_run: Tick,
2515 this_run: Tick,
2516 ) -> WriteFetch<'w, T> {
2517 <&mut T as WorldQuery>::init_fetch(world, state, last_run, this_run)
2518 }
2519
2520 const IS_DENSE: bool = <&mut T as WorldQuery>::IS_DENSE;
2522
2523 #[inline]
2524 unsafe fn set_archetype<'w>(
2526 fetch: &mut WriteFetch<'w, T>,
2527 state: &ComponentId,
2528 archetype: &'w Archetype,
2529 table: &'w Table,
2530 ) {
2531 <&mut T as WorldQuery>::set_archetype(fetch, state, archetype, table);
2532 }
2533
2534 #[inline]
2535 unsafe fn set_table<'w>(fetch: &mut WriteFetch<'w, T>, state: &ComponentId, table: &'w Table) {
2537 <&mut T as WorldQuery>::set_table(fetch, state, table);
2538 }
2539
2540 fn update_component_access(&component_id: &ComponentId, access: &mut FilteredAccess) {
2542 if !!access.access().has_read(component_id) {
{
::core::panicking::panic_fmt(format_args!("Mut<{0}> conflicts with a previous access in this query. Mutable component access mut be unique.",
DebugName::type_name::<T>()));
}
};assert!(
2545 !access.access().has_read(component_id),
2546 "Mut<{}> conflicts with a previous access in this query. Mutable component access mut be unique.",
2547 DebugName::type_name::<T>(),
2548 );
2549 access.add_write(component_id);
2550 }
2551
2552 fn init_state(world: &mut World) -> ComponentId {
2554 <&mut T as WorldQuery>::init_state(world)
2555 }
2556
2557 fn get_state(components: &Components) -> Option<ComponentId> {
2559 <&mut T as WorldQuery>::get_state(components)
2560 }
2561
2562 fn matches_component_set(
2564 state: &ComponentId,
2565 set_contains_id: &impl Fn(ComponentId) -> bool,
2566 ) -> bool {
2567 <&mut T as WorldQuery>::matches_component_set(state, set_contains_id)
2568 }
2569}
2570
2571unsafe impl<'__w, T: Component<Mutability = Mutable>> QueryData for Mut<'__w, T> {
2573 const IS_READ_ONLY: bool = false;
2574 const IS_ARCHETYPAL: bool = true;
2575 type ReadOnly = Ref<'__w, T>;
2576 type Item<'w, 's> = Mut<'w, T>;
2577
2578 fn shrink<'wlong: 'wshort, 'wshort, 's>(
2580 item: Self::Item<'wlong, 's>,
2581 ) -> Self::Item<'wshort, 's> {
2582 <&mut T as QueryData>::shrink(item)
2583 }
2584
2585 #[inline(always)]
2586 unsafe fn fetch<'w, 's>(
2588 state: &'s Self::State,
2589 fetch: &mut Self::Fetch<'w>,
2592 entity: Entity,
2593 table_row: TableRow,
2594 ) -> Option<Self::Item<'w, 's>> {
2595 <&mut T as QueryData>::fetch(state, fetch, entity, table_row)
2596 }
2597
2598 fn iter_access(state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
2599 iter::once(EcsAccessType::Component(EcsAccessLevel::Write(*state)))
2600 }
2601}
2602
2603unsafe impl<T: Component<Mutability = Mutable>> IterQueryData for Mut<'_, T> {}
2605
2606unsafe impl<T: Component<Mutability = Mutable>> SingleEntityQueryData for Mut<'_, T> {}
2608
2609impl<T: Component<Mutability = Mutable>> ReleaseStateQueryData for Mut<'_, T> {
2610 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
2611 item
2612 }
2613}
2614
2615impl<T: Component<Mutability = Mutable>> ArchetypeQueryData for Mut<'_, T> {}
2616
2617impl<'__w, T: Component<Mutability = Mutable>> ContiguousQueryData for Mut<'__w, T> {
2618 type Contiguous<'w, 's> = ContiguousMut<'w, T>;
2619
2620 unsafe fn fetch_contiguous<'w, 's>(
2621 state: &'s Self::State,
2622 fetch: &mut Self::Fetch<'w>,
2623 entities: &'w [Entity],
2624 ) -> Self::Contiguous<'w, 's> {
2625 <&mut T as ContiguousQueryData>::fetch_contiguous(state, fetch, entities)
2626 }
2627}
2628
2629pub struct NestedQuery<D: QueryData + 'static, F: QueryFilter + 'static = ()>(
2851 PhantomData<Query<'static, 'static, D, F>>,
2852);
2853
2854#[doc(hidden)]
2855#[derive(#[automatically_derived]
impl<'w> ::core::clone::Clone for NestedQueryFetch<'w> {
#[inline]
fn clone(&self) -> NestedQueryFetch<'w> {
NestedQueryFetch {
world: ::core::clone::Clone::clone(&self.world),
last_run: ::core::clone::Clone::clone(&self.last_run),
this_run: ::core::clone::Clone::clone(&self.this_run),
}
}
}Clone)]
2856pub struct NestedQueryFetch<'w> {
2857 world: UnsafeWorldCell<'w>,
2858 last_run: Tick,
2859 this_run: Tick,
2860}
2861
2862unsafe impl<D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> WorldQuery
2866 for NestedQuery<D, F>
2867{
2868 type Fetch<'w> = NestedQueryFetch<'w>;
2869 type State = QueryState<D, F>;
2870
2871 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
2872 fetch
2873 }
2874
2875 #[inline]
2876 unsafe fn init_fetch<'w, 's>(
2877 world: UnsafeWorldCell<'w>,
2878 _state: &'s Self::State,
2879 last_run: Tick,
2880 this_run: Tick,
2881 ) -> Self::Fetch<'w> {
2882 NestedQueryFetch {
2883 world,
2884 last_run,
2885 this_run,
2886 }
2887 }
2888
2889 const IS_DENSE: bool = true;
2890
2891 #[inline]
2892 unsafe fn set_archetype<'w>(
2893 _fetch: &mut Self::Fetch<'w>,
2894 _state: &Self::State,
2895 _archetype: &'w Archetype,
2896 _table: &'w Table,
2897 ) {
2898 }
2899
2900 #[inline]
2901 unsafe fn set_table<'w>(_fetch: &mut Self::Fetch<'w>, _state: &Self::State, _table: &'w Table) {
2902 }
2903
2904 fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) {
2905 }
2908
2909 fn init_nested_access(
2910 state: &Self::State,
2911 system_name: Option<&str>,
2912 component_access_set: &mut FilteredAccessSet,
2913 world: UnsafeWorldCell,
2914 ) {
2915 state.init_access(system_name, component_access_set, world);
2916 }
2917
2918 fn init_state(world: &mut World) -> Self::State {
2919 unsafe { QueryState::<D, F>::new_unchecked(world) }
2924 }
2925
2926 fn get_state(_components: &Components) -> Option<Self::State> {
2927 None
2932 }
2933
2934 fn matches_component_set(
2935 _state: &Self::State,
2936 _set_contains_id: &impl Fn(ComponentId) -> bool,
2937 ) -> bool {
2938 true
2939 }
2940
2941 fn update_archetypes(state: &mut Self::State, world: UnsafeWorldCell) {
2942 state.update_archetypes_unsafe_world_cell(world);
2943 }
2944}
2945
2946unsafe impl<D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> QueryData
2950 for NestedQuery<D, F>
2951{
2952 const IS_READ_ONLY: bool = D::IS_READ_ONLY;
2953 const IS_ARCHETYPAL: bool = true;
2958 type ReadOnly = NestedQuery<D, F>;
2959 type Item<'w, 's> = Query<'w, 's, D, F>;
2960
2961 fn shrink<'wlong: 'wshort, 'wshort, 's>(
2962 item: Self::Item<'wlong, 's>,
2963 ) -> Self::Item<'wshort, 's> {
2964 item
2965 }
2966
2967 #[inline(always)]
2968 unsafe fn fetch<'w, 's>(
2969 state: &'s Self::State,
2970 fetch: &mut Self::Fetch<'w>,
2971 _entity: Entity,
2972 _table_row: TableRow,
2973 ) -> Option<Self::Item<'w, 's>> {
2974 unsafe {
2980 Some(state.query_unchecked_manual_with_ticks(
2981 fetch.world,
2982 fetch.last_run,
2983 fetch.this_run,
2984 ))
2985 }
2986 }
2987
2988 fn iter_access(_state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
2989 iter::empty()
2992 }
2993}
2994
2995unsafe impl<D: ReadOnlyQueryData, F: QueryFilter> ReadOnlyQueryData for NestedQuery<D, F> {}
2997
2998unsafe impl<D: ReadOnlyQueryData, F: QueryFilter> IterQueryData for NestedQuery<D, F> {}
3002
3003impl<D: ReadOnlyQueryData, F: QueryFilter> ArchetypeQueryData for NestedQuery<D, F> {}
3008
3009#[doc(hidden)]
3010pub struct OptionFetch<'w, T: WorldQuery> {
3011 fetch: T::Fetch<'w>,
3012 matches: bool,
3013}
3014
3015impl<T: WorldQuery> Clone for OptionFetch<'_, T> {
3016 fn clone(&self) -> Self {
3017 Self {
3018 fetch: self.fetch.clone(),
3019 matches: self.matches,
3020 }
3021 }
3022}
3023
3024unsafe impl<T: WorldQuery> WorldQuery for Option<T> {
3029 type Fetch<'w> = OptionFetch<'w, T>;
3030 type State = T::State;
3031
3032 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
3033 OptionFetch {
3034 fetch: T::shrink_fetch(fetch.fetch),
3035 matches: fetch.matches,
3036 }
3037 }
3038
3039 #[inline]
3040 unsafe fn init_fetch<'w, 's>(
3041 world: UnsafeWorldCell<'w>,
3042 state: &'s T::State,
3043 last_run: Tick,
3044 this_run: Tick,
3045 ) -> OptionFetch<'w, T> {
3046 OptionFetch {
3047 fetch: unsafe { T::init_fetch(world, state, last_run, this_run) },
3049 matches: false,
3050 }
3051 }
3052
3053 const IS_DENSE: bool = T::IS_DENSE;
3054
3055 #[inline]
3056 unsafe fn set_archetype<'w, 's>(
3057 fetch: &mut OptionFetch<'w, T>,
3058 state: &'s T::State,
3059 archetype: &'w Archetype,
3060 table: &'w Table,
3061 ) {
3062 fetch.matches = T::matches_component_set(state, &|id| archetype.contains(id));
3063 if fetch.matches {
3064 unsafe {
3066 T::set_archetype(&mut fetch.fetch, state, archetype, table);
3067 }
3068 }
3069 }
3070
3071 #[inline]
3072 unsafe fn set_table<'w, 's>(
3073 fetch: &mut OptionFetch<'w, T>,
3074 state: &'s T::State,
3075 table: &'w Table,
3076 ) {
3077 fetch.matches = T::matches_component_set(state, &|id| table.has_column(id));
3078 if fetch.matches {
3079 unsafe {
3081 T::set_table(&mut fetch.fetch, state, table);
3082 }
3083 }
3084 }
3085
3086 fn update_component_access(state: &T::State, access: &mut FilteredAccess) {
3087 let mut intermediate = access.clone();
3097 T::update_component_access(state, &mut intermediate);
3098 access.extend_access(&intermediate);
3099 }
3100
3101 fn init_nested_access(
3102 state: &Self::State,
3103 system_name: Option<&str>,
3104 component_access_set: &mut FilteredAccessSet,
3105 world: UnsafeWorldCell,
3106 ) {
3107 T::init_nested_access(state, system_name, component_access_set, world);
3108 }
3109
3110 fn init_state(world: &mut World) -> T::State {
3111 T::init_state(world)
3112 }
3113
3114 fn get_state(components: &Components) -> Option<Self::State> {
3115 T::get_state(components)
3116 }
3117
3118 fn matches_component_set(
3119 _state: &T::State,
3120 _set_contains_id: &impl Fn(ComponentId) -> bool,
3121 ) -> bool {
3122 true
3123 }
3124
3125 fn update_archetypes(state: &mut Self::State, world: UnsafeWorldCell) {
3126 T::update_archetypes(state, world);
3127 }
3128}
3129
3130unsafe impl<T: QueryData> QueryData for Option<T> {
3132 const IS_READ_ONLY: bool = T::IS_READ_ONLY;
3133 const IS_ARCHETYPAL: bool = true;
3136 type ReadOnly = Option<T::ReadOnly>;
3137 type Item<'w, 's> = Option<T::Item<'w, 's>>;
3138
3139 fn shrink<'wlong: 'wshort, 'wshort, 's>(
3140 item: Self::Item<'wlong, 's>,
3141 ) -> Self::Item<'wshort, 's> {
3142 item.map(T::shrink)
3143 }
3144
3145 #[inline(always)]
3146 unsafe fn fetch<'w, 's>(
3147 state: &'s Self::State,
3148 fetch: &mut Self::Fetch<'w>,
3149 entity: Entity,
3150 table_row: TableRow,
3151 ) -> Option<Self::Item<'w, 's>> {
3152 Some(
3153 fetch
3154 .matches
3155 .then(|| unsafe { T::fetch(state, &mut fetch.fetch, entity, table_row) })
3157 .flatten(),
3158 )
3159 }
3160
3161 fn iter_access(state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
3162 T::iter_access(state)
3163 }
3164}
3165
3166unsafe impl<T: IterQueryData> IterQueryData for Option<T> {}
3168
3169unsafe impl<T: ReadOnlyQueryData> ReadOnlyQueryData for Option<T> {}
3171
3172unsafe impl<T: SingleEntityQueryData> SingleEntityQueryData for Option<T> {}
3174
3175impl<T: ReleaseStateQueryData> ReleaseStateQueryData for Option<T> {
3176 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
3177 item.map(T::release_state)
3178 }
3179}
3180
3181impl<T: QueryData> ArchetypeQueryData for Option<T> {}
3184
3185impl<T: ContiguousQueryData> ContiguousQueryData for Option<T> {
3186 type Contiguous<'w, 's> = Option<T::Contiguous<'w, 's>>;
3187
3188 unsafe fn fetch_contiguous<'w, 's>(
3189 state: &'s Self::State,
3190 fetch: &mut Self::Fetch<'w>,
3191 entities: &'w [Entity],
3192 ) -> Self::Contiguous<'w, 's> {
3193 fetch
3194 .matches
3195 .then(|| unsafe { T::fetch_contiguous(state, &mut fetch.fetch, entities) })
3197 }
3198}
3199
3200pub struct Has<T>(PhantomData<T>);
3264
3265impl<T> core::fmt::Debug for Has<T> {
3266 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
3267 f.write_fmt(format_args!("Has<{0}>", DebugName::type_name::<T>()))write!(f, "Has<{}>", DebugName::type_name::<T>())
3268 }
3269}
3270
3271unsafe impl<T: Component> WorldQuery for Has<T> {
3275 type Fetch<'w> = bool;
3276 type State = ComponentId;
3277
3278 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
3279 fetch
3280 }
3281
3282 #[inline]
3283 unsafe fn init_fetch<'w, 's>(
3284 _world: UnsafeWorldCell<'w>,
3285 _state: &'s Self::State,
3286 _last_run: Tick,
3287 _this_run: Tick,
3288 ) -> Self::Fetch<'w> {
3289 false
3290 }
3291
3292 const IS_DENSE: bool = {
3293 match T::STORAGE_TYPE {
3294 StorageType::Table => true,
3295 StorageType::SparseSet => false,
3296 }
3297 };
3298
3299 #[inline]
3300 unsafe fn set_archetype<'w, 's>(
3301 fetch: &mut Self::Fetch<'w>,
3302 state: &'s Self::State,
3303 archetype: &'w Archetype,
3304 _table: &Table,
3305 ) {
3306 *fetch = archetype.contains(*state);
3307 }
3308
3309 #[inline]
3310 unsafe fn set_table<'w, 's>(
3311 fetch: &mut Self::Fetch<'w>,
3312 state: &'s Self::State,
3313 table: &'w Table,
3314 ) {
3315 *fetch = table.has_column(*state);
3316 }
3317
3318 fn update_component_access(&component_id: &Self::State, access: &mut FilteredAccess) {
3319 access.access_mut().add_archetypal(component_id);
3320 }
3321
3322 fn init_state(world: &mut World) -> ComponentId {
3323 world.register_component::<T>()
3324 }
3325
3326 fn get_state(components: &Components) -> Option<Self::State> {
3327 components.component_id::<T>()
3328 }
3329
3330 fn matches_component_set(
3331 _state: &Self::State,
3332 _set_contains_id: &impl Fn(ComponentId) -> bool,
3333 ) -> bool {
3334 true
3336 }
3337}
3338
3339unsafe impl<T: Component> QueryData for Has<T> {
3341 const IS_READ_ONLY: bool = true;
3342 const IS_ARCHETYPAL: bool = true;
3343 type ReadOnly = Self;
3344 type Item<'w, 's> = bool;
3345
3346 fn shrink<'wlong: 'wshort, 'wshort, 's>(
3347 item: Self::Item<'wlong, 's>,
3348 ) -> Self::Item<'wshort, 's> {
3349 item
3350 }
3351
3352 #[inline(always)]
3353 unsafe fn fetch<'w, 's>(
3354 _state: &'s Self::State,
3355 fetch: &mut Self::Fetch<'w>,
3356 _entity: Entity,
3357 _table_row: TableRow,
3358 ) -> Option<Self::Item<'w, 's>> {
3359 Some(*fetch)
3360 }
3361
3362 fn iter_access(_state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
3363 iter::empty()
3364 }
3365}
3366
3367unsafe impl<T: Component> IterQueryData for Has<T> {}
3369
3370unsafe impl<T: Component> ReadOnlyQueryData for Has<T> {}
3372
3373unsafe impl<T: Component> SingleEntityQueryData for Has<T> {}
3375
3376impl<T: Component> ReleaseStateQueryData for Has<T> {
3377 fn release_state<'w>(item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
3378 item
3379 }
3380}
3381
3382impl<T: Component> ArchetypeQueryData for Has<T> {}
3383
3384impl<T: Component> ContiguousQueryData for Has<T> {
3385 type Contiguous<'w, 's> = bool;
3386
3387 unsafe fn fetch_contiguous<'w, 's>(
3388 _state: &'s Self::State,
3389 fetch: &mut Self::Fetch<'w>,
3390 _entities: &'w [Entity],
3391 ) -> Self::Contiguous<'w, 's> {
3392 *fetch
3393 }
3394}
3395
3396pub struct AnyOf<T>(PhantomData<T>);
3402
3403macro_rules! impl_tuple_query_data {
3404 ($(#[$meta:meta])* $(($name: ident, $item: ident, $state: ident)),*) => {
3405 #[expect(
3406 clippy::allow_attributes,
3407 reason = "This is a tuple-related macro; as such the lints below may not always apply."
3408 )]
3409 #[allow(
3410 non_snake_case,
3411 reason = "The names of some variables are provided by the macro's caller, not by us."
3412 )]
3413 #[allow(
3414 unused_variables,
3415 reason = "Zero-length tuples won't use any of the parameters."
3416 )]
3417 #[allow(
3418 clippy::unused_unit,
3419 reason = "Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case."
3420 )]
3421 $(#[$meta])*
3422 unsafe impl<$($name: QueryData),*> QueryData for ($($name,)*) {
3424 const IS_READ_ONLY: bool = true $(&& $name::IS_READ_ONLY)*;
3425 const IS_ARCHETYPAL: bool = true $(&& $name::IS_ARCHETYPAL)*;
3426 type ReadOnly = ($($name::ReadOnly,)*);
3427 type Item<'w, 's> = ($($name::Item<'w, 's>,)*);
3428
3429 fn shrink<'wlong: 'wshort, 'wshort, 's>(item: Self::Item<'wlong, 's>) -> Self::Item<'wshort, 's> {
3430 let ($($name,)*) = item;
3431 ($(
3432 $name::shrink($name),
3433 )*)
3434 }
3435
3436 #[inline]
3437 fn provide_extra_access(
3438 state: &mut Self::State,
3439 access: &mut Access,
3440 available_access: &Access,
3441 ) {
3442 let ($($name,)*) = state;
3443 $($name::provide_extra_access($name, access, available_access);)*
3444 }
3445
3446 #[inline(always)]
3447 unsafe fn fetch<'w, 's>(
3448 state: &'s Self::State,
3449 fetch: &mut Self::Fetch<'w>,
3450 entity: Entity,
3451 table_row: TableRow
3452 ) -> Option<Self::Item<'w, 's>> {
3453 let ($($state,)*) = state;
3454 let ($($name,)*) = fetch;
3455 Some(($(unsafe { $name::fetch($state, $name, entity, table_row) }?,)*))
3457 }
3458
3459 fn iter_access(state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
3460 let ($($name,)*) = state;
3461 iter::empty()$(.chain($name::iter_access($name)))*
3462 }
3463 }
3464
3465 $(#[$meta])*
3466 unsafe impl<$($name: IterQueryData),*> IterQueryData for ($($name,)*) {}
3468
3469 $(#[$meta])*
3470 unsafe impl<$($name: ReadOnlyQueryData),*> ReadOnlyQueryData for ($($name,)*) {}
3472
3473 $(#[$meta])*
3474 unsafe impl<$($name: SingleEntityQueryData),*> SingleEntityQueryData for ($($name,)*) {}
3476
3477 #[expect(
3478 clippy::allow_attributes,
3479 reason = "This is a tuple-related macro; as such the lints below may not always apply."
3480 )]
3481 #[allow(
3482 clippy::unused_unit,
3483 reason = "Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case."
3484 )]
3485 $(#[$meta])*
3486 impl<$($name: ReleaseStateQueryData),*> ReleaseStateQueryData for ($($name,)*) {
3487 fn release_state<'w>(($($item,)*): Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
3488 ($($name::release_state($item),)*)
3489 }
3490 }
3491
3492 $(#[$meta])*
3493 impl<$($name: ArchetypeQueryData),*> ArchetypeQueryData for ($($name,)*) {}
3494
3495 #[expect(
3496 clippy::allow_attributes,
3497 reason = "This is a tuple-related macro; as such the lints below may not always apply."
3498 )]
3499 #[allow(
3500 non_snake_case,
3501 reason = "The names of some variables are provided by the macro's caller, not by us."
3502 )]
3503 #[allow(
3504 unused_variables,
3505 reason = "Zero-length tuples won't use any of the parameters."
3506 )]
3507 #[allow(
3508 clippy::unused_unit,
3509 reason = "Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case."
3510 )]
3511 $(#[$meta])*
3512 impl<$($name: ContiguousQueryData),*> ContiguousQueryData for ($($name,)*) {
3513 type Contiguous<'w, 's> = ($($name::Contiguous::<'w, 's>,)*);
3514
3515 unsafe fn fetch_contiguous<'w, 's>(
3516 state: &'s Self::State,
3517 fetch: &mut Self::Fetch<'w>,
3518 entities: &'w [Entity],
3519 ) -> Self::Contiguous<'w, 's> {
3520 let ($($state,)*) = state;
3521 let ($($name,)*) = fetch;
3522 ($(unsafe {$name::fetch_contiguous($state, $name, entities)},)*)
3524 }
3525 }
3526 };
3527}
3528
3529macro_rules! impl_anytuple_fetch {
3530 ($(#[$meta:meta])* $(($name: ident, $state: ident, $item: ident)),*) => {
3531 $(#[$meta])*
3532 #[expect(
3533 clippy::allow_attributes,
3534 reason = "This is a tuple-related macro; as such the lints below may not always apply."
3535 )]
3536 #[allow(
3537 non_snake_case,
3538 reason = "The names of some variables are provided by the macro's caller, not by us."
3539 )]
3540 #[allow(
3541 unused_variables,
3542 reason = "Zero-length tuples won't use any of the parameters."
3543 )]
3544 #[allow(
3545 clippy::unused_unit,
3546 reason = "Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case."
3547 )]
3548 unsafe impl<$($name: WorldQuery),*> WorldQuery for AnyOf<($($name,)*)> {
3554 type Fetch<'w> = ($(($name::Fetch<'w>, bool),)*);
3555 type State = ($($name::State,)*);
3556
3557 fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
3558 let ($($name,)*) = fetch;
3559 ($(
3560 ($name::shrink_fetch($name.0), $name.1),
3561 )*)
3562 }
3563
3564 #[inline]
3565 unsafe fn init_fetch<'w, 's>(_world: UnsafeWorldCell<'w>, state: &'s Self::State, _last_run: Tick, _this_run: Tick) -> Self::Fetch<'w> {
3566 let ($($name,)*) = state;
3567 ($(( unsafe { $name::init_fetch(_world, $name, _last_run, _this_run) }, false),)*)
3569 }
3570
3571 const IS_DENSE: bool = true $(&& $name::IS_DENSE)*;
3572
3573 #[inline]
3574 unsafe fn set_archetype<'w, 's>(
3575 _fetch: &mut Self::Fetch<'w>,
3576 _state: &'s Self::State,
3577 _archetype: &'w Archetype,
3578 _table: &'w Table
3579 ) {
3580 let ($($name,)*) = _fetch;
3581 let ($($state,)*) = _state;
3582 $(
3583 $name.1 = $name::matches_component_set($state, &|id| _archetype.contains(id));
3584 if $name.1 {
3585 unsafe { $name::set_archetype(&mut $name.0, $state, _archetype, _table); }
3587 }
3588 )*
3589 }
3590
3591 #[inline]
3592 unsafe fn set_table<'w, 's>(_fetch: &mut Self::Fetch<'w>, _state: &'s Self::State, _table: &'w Table) {
3593 let ($($name,)*) = _fetch;
3594 let ($($state,)*) = _state;
3595 $(
3596 $name.1 = $name::matches_component_set($state, &|id| _table.has_column(id));
3597 if $name.1 {
3598 unsafe { $name::set_table(&mut $name.0, $state, _table); }
3600 }
3601 )*
3602 }
3603
3604 fn update_component_access(state: &Self::State, access: &mut FilteredAccess) {
3605 let ($($name,)*) = state;
3607
3608 let mut _new_access = FilteredAccess::matches_nothing();
3609
3610 $(
3611 let mut intermediate = access.clone();
3615 $name::update_component_access($name, &mut intermediate);
3616 _new_access.append_or(&intermediate);
3617 )*
3618
3619 access.filter_sets = _new_access.filter_sets;
3621
3622 <($(Option<$name>,)*)>::update_component_access(state, access);
3628
3629 }
3630
3631 fn init_nested_access(
3632 state: &Self::State,
3633 system_name: Option<&str>,
3634 component_access_set: &mut FilteredAccessSet,
3635 world: UnsafeWorldCell,
3636 ) {
3637 <($(Option<$name>,)*)>::init_nested_access(state, system_name, component_access_set, world);
3638 }
3639
3640 fn init_state(world: &mut World) -> Self::State {
3641 ($($name::init_state(world),)*)
3642 }
3643 fn get_state(components: &Components) -> Option<Self::State> {
3644 Some(($($name::get_state(components)?,)*))
3645 }
3646
3647 fn matches_component_set(_state: &Self::State, _set_contains_id: &impl Fn(ComponentId) -> bool) -> bool {
3648 let ($($name,)*) = _state;
3649 false $(|| $name::matches_component_set($name, _set_contains_id))*
3650 }
3651
3652 fn update_archetypes(state: &mut Self::State, world: UnsafeWorldCell) {
3653 <($(Option<$name>,)*)>::update_archetypes(state, world);
3654 }
3655 }
3656
3657 #[expect(
3658 clippy::allow_attributes,
3659 reason = "This is a tuple-related macro; as such the lints below may not always apply."
3660 )]
3661 #[allow(
3662 non_snake_case,
3663 reason = "The names of some variables are provided by the macro's caller, not by us."
3664 )]
3665 #[allow(
3666 unused_variables,
3667 reason = "Zero-length tuples won't use any of the parameters."
3668 )]
3669 #[allow(
3670 clippy::unused_unit,
3671 reason = "Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case."
3672 )]
3673 $(#[$meta])*
3674 unsafe impl<$($name: QueryData),*> QueryData for AnyOf<($($name,)*)> {
3676 const IS_READ_ONLY: bool = true $(&& $name::IS_READ_ONLY)*;
3677 const IS_ARCHETYPAL: bool = true $(&& $name::IS_ARCHETYPAL)*;
3678 type ReadOnly = AnyOf<($($name::ReadOnly,)*)>;
3679 type Item<'w, 's> = ($(Option<$name::Item<'w, 's>>,)*);
3680
3681 fn shrink<'wlong: 'wshort, 'wshort, 's>(item: Self::Item<'wlong, 's>) -> Self::Item<'wshort, 's> {
3682 let ($($name,)*) = item;
3683 ($(
3684 $name.map($name::shrink),
3685 )*)
3686 }
3687
3688 #[inline(always)]
3689 unsafe fn fetch<'w, 's>(
3690 _state: &'s Self::State,
3691 _fetch: &mut Self::Fetch<'w>,
3692 _entity: Entity,
3693 _table_row: TableRow
3694 ) -> Option<Self::Item<'w, 's>> {
3695 let ($($name,)*) = _fetch;
3696 let ($($state,)*) = _state;
3697 let result = ($(
3698 $name.1.then(|| unsafe { $name::fetch($state, &mut $name.0, _entity, _table_row) }).flatten(),
3700 )*);
3701 (Self::IS_ARCHETYPAL
3704 || !matches!(result, ($(Option::<QueryItem<$name>>::None,)*))
3708 || !(false $(|| $name.1)*))
3712 .then_some(result)
3713 }
3714
3715 fn iter_access(state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
3716 let ($($name,)*) = state;
3717 iter::empty()$(.chain($name::iter_access($name)))*
3718 }
3719 }
3720
3721 $(#[$meta])*
3722 unsafe impl<$($name: IterQueryData),*> IterQueryData for AnyOf<($($name,)*)> {}
3724
3725 $(#[$meta])*
3726 unsafe impl<$($name: ReadOnlyQueryData),*> ReadOnlyQueryData for AnyOf<($($name,)*)> {}
3728
3729 $(#[$meta])*
3730 unsafe impl<$($name: SingleEntityQueryData),*> SingleEntityQueryData for AnyOf<($($name,)*)> {}
3732
3733 #[expect(
3734 clippy::allow_attributes,
3735 reason = "This is a tuple-related macro; as such the lints below may not always apply."
3736 )]
3737 #[allow(
3738 clippy::unused_unit,
3739 reason = "Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case."
3740 )]
3741 impl<$($name: ReleaseStateQueryData),*> ReleaseStateQueryData for AnyOf<($($name,)*)> {
3742 fn release_state<'w>(($($item,)*): Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
3743 ($($item.map(|$item| $name::release_state($item)),)*)
3744 }
3745 }
3746
3747 $(#[$meta])*
3748 impl<$($name: ArchetypeQueryData),*> ArchetypeQueryData for AnyOf<($($name,)*)> {}
3749
3750
3751 #[expect(
3752 clippy::allow_attributes,
3753 reason = "This is a tuple-related macro; as such the lints below may not always apply."
3754 )]
3755 #[allow(
3756 non_snake_case,
3757 reason = "The names of some variables are provided by the macro's caller, not by us."
3758 )]
3759 #[allow(
3760 unused_variables,
3761 reason = "Zero-length tuples won't use any of the parameters."
3762 )]
3763 #[allow(
3764 clippy::unused_unit,
3765 reason = "Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case."
3766 )]
3767 $(#[$meta])*
3768 impl<$($name: ContiguousQueryData),*> ContiguousQueryData for AnyOf<($($name,)*)> {
3769 type Contiguous<'w, 's> = ($(Option<$name::Contiguous<'w,'s>>,)*);
3770
3771 unsafe fn fetch_contiguous<'w, 's>(
3772 state: &'s Self::State,
3773 fetch: &mut Self::Fetch<'w>,
3774 entities: &'w [Entity],
3775 ) -> Self::Contiguous<'w, 's> {
3776 let ($($name,)*) = fetch;
3777 let ($($state,)*) = state;
3778 ($(
3780 $name.1.then(|| unsafe { $name::fetch_contiguous($state, &mut $name.0, entities) }),
3782 )*)
3783 }
3784 }
3785 };
3786}
3787
3788#[expect(clippy :: allow_attributes, reason =
"This is a tuple-related macro; as such the lints below may not always apply.")]
#[allow(non_snake_case, reason =
"The names of some variables are provided by the macro's caller, not by us.")]
#[allow(unused_variables, reason =
"Zero-length tuples won't use any of the parameters.")]
#[allow(clippy :: unused_unit, reason =
"Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case.")]
#[doc(hidden)]
unsafe impl<F0: QueryData, F1: QueryData, F2: QueryData, F3: QueryData,
F4: QueryData, F5: QueryData, F6: QueryData, F7: QueryData, F8: QueryData,
F9: QueryData, F10: QueryData, F11: QueryData, F12: QueryData,
F13: QueryData, F14: QueryData> QueryData for
(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14) {
const IS_READ_ONLY: bool =
true && F0::IS_READ_ONLY && F1::IS_READ_ONLY && F2::IS_READ_ONLY &&
F3::IS_READ_ONLY && F4::IS_READ_ONLY && F5::IS_READ_ONLY &&
F6::IS_READ_ONLY && F7::IS_READ_ONLY && F8::IS_READ_ONLY &&
F9::IS_READ_ONLY && F10::IS_READ_ONLY && F11::IS_READ_ONLY
&& F12::IS_READ_ONLY && F13::IS_READ_ONLY &&
F14::IS_READ_ONLY;
const IS_ARCHETYPAL: bool =
true && F0::IS_ARCHETYPAL && F1::IS_ARCHETYPAL && F2::IS_ARCHETYPAL &&
F3::IS_ARCHETYPAL && F4::IS_ARCHETYPAL && F5::IS_ARCHETYPAL
&& F6::IS_ARCHETYPAL && F7::IS_ARCHETYPAL &&
F8::IS_ARCHETYPAL && F9::IS_ARCHETYPAL && F10::IS_ARCHETYPAL
&& F11::IS_ARCHETYPAL && F12::IS_ARCHETYPAL &&
F13::IS_ARCHETYPAL && F14::IS_ARCHETYPAL;
type ReadOnly =
(F0::ReadOnly, F1::ReadOnly, F2::ReadOnly, F3::ReadOnly, F4::ReadOnly,
F5::ReadOnly, F6::ReadOnly, F7::ReadOnly, F8::ReadOnly, F9::ReadOnly,
F10::ReadOnly, F11::ReadOnly, F12::ReadOnly, F13::ReadOnly,
F14::ReadOnly);
type Item<'w, 's> =
(F0::Item<'w, 's>, F1::Item<'w, 's>, F2::Item<'w, 's>,
F3::Item<'w, 's>, F4::Item<'w, 's>, F5::Item<'w, 's>,
F6::Item<'w, 's>, F7::Item<'w, 's>, F8::Item<'w, 's>,
F9::Item<'w, 's>, F10::Item<'w, 's>, F11::Item<'w, 's>,
F12::Item<'w, 's>, F13::Item<'w, 's>, F14::Item<'w, 's>);
fn shrink<'wlong: 'wshort, 'wshort, 's>(item: Self::Item<'wlong, 's>)
-> Self::Item<'wshort, 's> {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = item;
(F0::shrink(F0), F1::shrink(F1), F2::shrink(F2), F3::shrink(F3),
F4::shrink(F4), F5::shrink(F5), F6::shrink(F6), F7::shrink(F7),
F8::shrink(F8), F9::shrink(F9), F10::shrink(F10),
F11::shrink(F11), F12::shrink(F12), F13::shrink(F13),
F14::shrink(F14))
}
#[inline]
fn provide_extra_access(state: &mut Self::State, access: &mut Access,
available_access: &Access) {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = state;
F0::provide_extra_access(F0, access, available_access);
F1::provide_extra_access(F1, access, available_access);
F2::provide_extra_access(F2, access, available_access);
F3::provide_extra_access(F3, access, available_access);
F4::provide_extra_access(F4, access, available_access);
F5::provide_extra_access(F5, access, available_access);
F6::provide_extra_access(F6, access, available_access);
F7::provide_extra_access(F7, access, available_access);
F8::provide_extra_access(F8, access, available_access);
F9::provide_extra_access(F9, access, available_access);
F10::provide_extra_access(F10, access, available_access);
F11::provide_extra_access(F11, access, available_access);
F12::provide_extra_access(F12, access, available_access);
F13::provide_extra_access(F13, access, available_access);
F14::provide_extra_access(F14, access, available_access);
}
#[inline(always)]
unsafe fn fetch<'w,
's>(state: &'s Self::State, fetch: &mut Self::Fetch<'w>,
entity: Entity, table_row: TableRow) -> Option<Self::Item<'w, 's>> {
let (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13,
s14) = state;
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = fetch;
Some((unsafe { F0::fetch(s0, F0, entity, table_row) }?,
unsafe { F1::fetch(s1, F1, entity, table_row) }?,
unsafe { F2::fetch(s2, F2, entity, table_row) }?,
unsafe { F3::fetch(s3, F3, entity, table_row) }?,
unsafe { F4::fetch(s4, F4, entity, table_row) }?,
unsafe { F5::fetch(s5, F5, entity, table_row) }?,
unsafe { F6::fetch(s6, F6, entity, table_row) }?,
unsafe { F7::fetch(s7, F7, entity, table_row) }?,
unsafe { F8::fetch(s8, F8, entity, table_row) }?,
unsafe { F9::fetch(s9, F9, entity, table_row) }?,
unsafe { F10::fetch(s10, F10, entity, table_row) }?,
unsafe { F11::fetch(s11, F11, entity, table_row) }?,
unsafe { F12::fetch(s12, F12, entity, table_row) }?,
unsafe { F13::fetch(s13, F13, entity, table_row) }?,
unsafe { F14::fetch(s14, F14, entity, table_row) }?))
}
fn iter_access(state: &Self::State)
-> impl Iterator<Item = EcsAccessType<'_>> {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = state;
iter::empty().chain(F0::iter_access(F0)).chain(F1::iter_access(F1)).chain(F2::iter_access(F2)).chain(F3::iter_access(F3)).chain(F4::iter_access(F4)).chain(F5::iter_access(F5)).chain(F6::iter_access(F6)).chain(F7::iter_access(F7)).chain(F8::iter_access(F8)).chain(F9::iter_access(F9)).chain(F10::iter_access(F10)).chain(F11::iter_access(F11)).chain(F12::iter_access(F12)).chain(F13::iter_access(F13)).chain(F14::iter_access(F14))
}
}
#[doc(hidden)]
unsafe impl<F0: IterQueryData, F1: IterQueryData, F2: IterQueryData,
F3: IterQueryData, F4: IterQueryData, F5: IterQueryData,
F6: IterQueryData, F7: IterQueryData, F8: IterQueryData,
F9: IterQueryData, F10: IterQueryData, F11: IterQueryData,
F12: IterQueryData, F13: IterQueryData, F14: IterQueryData> IterQueryData
for (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14) {
}
#[doc(hidden)]
unsafe impl<F0: ReadOnlyQueryData, F1: ReadOnlyQueryData,
F2: ReadOnlyQueryData, F3: ReadOnlyQueryData, F4: ReadOnlyQueryData,
F5: ReadOnlyQueryData, F6: ReadOnlyQueryData, F7: ReadOnlyQueryData,
F8: ReadOnlyQueryData, F9: ReadOnlyQueryData, F10: ReadOnlyQueryData,
F11: ReadOnlyQueryData, F12: ReadOnlyQueryData, F13: ReadOnlyQueryData,
F14: ReadOnlyQueryData> ReadOnlyQueryData for
(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14) {
}
#[doc(hidden)]
unsafe impl<F0: SingleEntityQueryData, F1: SingleEntityQueryData,
F2: SingleEntityQueryData, F3: SingleEntityQueryData,
F4: SingleEntityQueryData, F5: SingleEntityQueryData,
F6: SingleEntityQueryData, F7: SingleEntityQueryData,
F8: SingleEntityQueryData, F9: SingleEntityQueryData,
F10: SingleEntityQueryData, F11: SingleEntityQueryData,
F12: SingleEntityQueryData, F13: SingleEntityQueryData,
F14: SingleEntityQueryData> SingleEntityQueryData for
(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14) {
}
#[expect(clippy :: allow_attributes, reason =
"This is a tuple-related macro; as such the lints below may not always apply.")]
#[allow(clippy :: unused_unit, reason =
"Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case.")]
#[doc(hidden)]
impl<F0: ReleaseStateQueryData, F1: ReleaseStateQueryData,
F2: ReleaseStateQueryData, F3: ReleaseStateQueryData,
F4: ReleaseStateQueryData, F5: ReleaseStateQueryData,
F6: ReleaseStateQueryData, F7: ReleaseStateQueryData,
F8: ReleaseStateQueryData, F9: ReleaseStateQueryData,
F10: ReleaseStateQueryData, F11: ReleaseStateQueryData,
F12: ReleaseStateQueryData, F13: ReleaseStateQueryData,
F14: ReleaseStateQueryData> ReleaseStateQueryData for
(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14) {
fn release_state<'w>((i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11,
i12, i13, i14): Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
(F0::release_state(i0), F1::release_state(i1), F2::release_state(i2),
F3::release_state(i3), F4::release_state(i4),
F5::release_state(i5), F6::release_state(i6),
F7::release_state(i7), F8::release_state(i8),
F9::release_state(i9), F10::release_state(i10),
F11::release_state(i11), F12::release_state(i12),
F13::release_state(i13), F14::release_state(i14))
}
}
#[doc(hidden)]
impl<F0: ArchetypeQueryData, F1: ArchetypeQueryData, F2: ArchetypeQueryData,
F3: ArchetypeQueryData, F4: ArchetypeQueryData, F5: ArchetypeQueryData,
F6: ArchetypeQueryData, F7: ArchetypeQueryData, F8: ArchetypeQueryData,
F9: ArchetypeQueryData, F10: ArchetypeQueryData, F11: ArchetypeQueryData,
F12: ArchetypeQueryData, F13: ArchetypeQueryData, F14: ArchetypeQueryData>
ArchetypeQueryData for
(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14) {
}
#[expect(clippy :: allow_attributes, reason =
"This is a tuple-related macro; as such the lints below may not always apply.")]
#[allow(non_snake_case, reason =
"The names of some variables are provided by the macro's caller, not by us.")]
#[allow(unused_variables, reason =
"Zero-length tuples won't use any of the parameters.")]
#[allow(clippy :: unused_unit, reason =
"Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case.")]
#[doc(hidden)]
impl<F0: ContiguousQueryData, F1: ContiguousQueryData,
F2: ContiguousQueryData, F3: ContiguousQueryData, F4: ContiguousQueryData,
F5: ContiguousQueryData, F6: ContiguousQueryData, F7: ContiguousQueryData,
F8: ContiguousQueryData, F9: ContiguousQueryData,
F10: ContiguousQueryData, F11: ContiguousQueryData,
F12: ContiguousQueryData, F13: ContiguousQueryData,
F14: ContiguousQueryData> ContiguousQueryData for
(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14) {
type Contiguous<'w, 's> =
(F0::Contiguous<'w, 's>, F1::Contiguous<'w, 's>,
F2::Contiguous<'w, 's>, F3::Contiguous<'w, 's>,
F4::Contiguous<'w, 's>, F5::Contiguous<'w, 's>,
F6::Contiguous<'w, 's>, F7::Contiguous<'w, 's>,
F8::Contiguous<'w, 's>, F9::Contiguous<'w, 's>,
F10::Contiguous<'w, 's>, F11::Contiguous<'w, 's>,
F12::Contiguous<'w, 's>, F13::Contiguous<'w, 's>,
F14::Contiguous<'w, 's>);
unsafe fn fetch_contiguous<'w,
's>(state: &'s Self::State, fetch: &mut Self::Fetch<'w>,
entities: &'w [Entity]) -> Self::Contiguous<'w, 's> {
let (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13,
s14) = state;
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = fetch;
(unsafe { F0::fetch_contiguous(s0, F0, entities) },
unsafe { F1::fetch_contiguous(s1, F1, entities) },
unsafe { F2::fetch_contiguous(s2, F2, entities) },
unsafe { F3::fetch_contiguous(s3, F3, entities) },
unsafe { F4::fetch_contiguous(s4, F4, entities) },
unsafe { F5::fetch_contiguous(s5, F5, entities) },
unsafe { F6::fetch_contiguous(s6, F6, entities) },
unsafe { F7::fetch_contiguous(s7, F7, entities) },
unsafe { F8::fetch_contiguous(s8, F8, entities) },
unsafe { F9::fetch_contiguous(s9, F9, entities) },
unsafe { F10::fetch_contiguous(s10, F10, entities) },
unsafe { F11::fetch_contiguous(s11, F11, entities) },
unsafe { F12::fetch_contiguous(s12, F12, entities) },
unsafe { F13::fetch_contiguous(s13, F13, entities) },
unsafe { F14::fetch_contiguous(s14, F14, entities) })
}
}all_tuples!(
3789 #[doc(fake_variadic)]
3790 impl_tuple_query_data,
3791 0,
3792 15,
3793 F,
3794 i,
3795 s
3796);
3797#[doc(hidden)]
#[expect(clippy :: allow_attributes, reason =
"This is a tuple-related macro; as such the lints below may not always apply.")]
#[allow(non_snake_case, reason =
"The names of some variables are provided by the macro's caller, not by us.")]
#[allow(unused_variables, reason =
"Zero-length tuples won't use any of the parameters.")]
#[allow(clippy :: unused_unit, reason =
"Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case.")]
unsafe impl<F0: WorldQuery, F1: WorldQuery, F2: WorldQuery, F3: WorldQuery,
F4: WorldQuery, F5: WorldQuery, F6: WorldQuery, F7: WorldQuery,
F8: WorldQuery, F9: WorldQuery, F10: WorldQuery, F11: WorldQuery,
F12: WorldQuery, F13: WorldQuery, F14: WorldQuery> WorldQuery for
AnyOf<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14)> {
type Fetch<'w> =
((F0::Fetch<'w>, bool), (F1::Fetch<'w>, bool), (F2::Fetch<'w>, bool),
(F3::Fetch<'w>, bool), (F4::Fetch<'w>, bool), (F5::Fetch<'w>, bool),
(F6::Fetch<'w>, bool), (F7::Fetch<'w>, bool), (F8::Fetch<'w>, bool),
(F9::Fetch<'w>, bool), (F10::Fetch<'w>, bool), (F11::Fetch<'w>, bool),
(F12::Fetch<'w>, bool), (F13::Fetch<'w>, bool),
(F14::Fetch<'w>, bool));
type State =
(F0::State, F1::State, F2::State, F3::State, F4::State, F5::State,
F6::State, F7::State, F8::State, F9::State, F10::State, F11::State,
F12::State, F13::State, F14::State);
fn shrink_fetch<'wlong: 'wshort, 'wshort>(fetch: Self::Fetch<'wlong>)
-> Self::Fetch<'wshort> {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = fetch;
((F0::shrink_fetch(F0.0), F0.1), (F1::shrink_fetch(F1.0), F1.1),
(F2::shrink_fetch(F2.0), F2.1), (F3::shrink_fetch(F3.0), F3.1),
(F4::shrink_fetch(F4.0), F4.1), (F5::shrink_fetch(F5.0), F5.1),
(F6::shrink_fetch(F6.0), F6.1), (F7::shrink_fetch(F7.0), F7.1),
(F8::shrink_fetch(F8.0), F8.1), (F9::shrink_fetch(F9.0), F9.1),
(F10::shrink_fetch(F10.0), F10.1),
(F11::shrink_fetch(F11.0), F11.1),
(F12::shrink_fetch(F12.0), F12.1),
(F13::shrink_fetch(F13.0), F13.1),
(F14::shrink_fetch(F14.0), F14.1))
}
#[inline]
unsafe fn init_fetch<'w,
's>(_world: UnsafeWorldCell<'w>, state: &'s Self::State,
_last_run: Tick, _this_run: Tick) -> Self::Fetch<'w> {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = state;
((unsafe { F0::init_fetch(_world, F0, _last_run, _this_run) }, false),
(unsafe { F1::init_fetch(_world, F1, _last_run, _this_run) },
false),
(unsafe { F2::init_fetch(_world, F2, _last_run, _this_run) },
false),
(unsafe { F3::init_fetch(_world, F3, _last_run, _this_run) },
false),
(unsafe { F4::init_fetch(_world, F4, _last_run, _this_run) },
false),
(unsafe { F5::init_fetch(_world, F5, _last_run, _this_run) },
false),
(unsafe { F6::init_fetch(_world, F6, _last_run, _this_run) },
false),
(unsafe { F7::init_fetch(_world, F7, _last_run, _this_run) },
false),
(unsafe { F8::init_fetch(_world, F8, _last_run, _this_run) },
false),
(unsafe { F9::init_fetch(_world, F9, _last_run, _this_run) },
false),
(unsafe { F10::init_fetch(_world, F10, _last_run, _this_run) },
false),
(unsafe { F11::init_fetch(_world, F11, _last_run, _this_run) },
false),
(unsafe { F12::init_fetch(_world, F12, _last_run, _this_run) },
false),
(unsafe { F13::init_fetch(_world, F13, _last_run, _this_run) },
false),
(unsafe { F14::init_fetch(_world, F14, _last_run, _this_run) },
false))
}
const IS_DENSE: bool =
true && F0::IS_DENSE && F1::IS_DENSE && F2::IS_DENSE && F3::IS_DENSE
&& F4::IS_DENSE && F5::IS_DENSE && F6::IS_DENSE &&
F7::IS_DENSE && F8::IS_DENSE && F9::IS_DENSE &&
F10::IS_DENSE && F11::IS_DENSE && F12::IS_DENSE &&
F13::IS_DENSE && F14::IS_DENSE;
#[inline]
unsafe fn set_archetype<'w,
's>(_fetch: &mut Self::Fetch<'w>, _state: &'s Self::State,
_archetype: &'w Archetype, _table: &'w Table) {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = _fetch;
let (S0, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13,
S14) = _state;
F0.1 = F0::matches_component_set(S0, &|id| _archetype.contains(id));
if F0.1 {
unsafe { F0::set_archetype(&mut F0.0, S0, _archetype, _table); }
}
F1.1 = F1::matches_component_set(S1, &|id| _archetype.contains(id));
if F1.1 {
unsafe { F1::set_archetype(&mut F1.0, S1, _archetype, _table); }
}
F2.1 = F2::matches_component_set(S2, &|id| _archetype.contains(id));
if F2.1 {
unsafe { F2::set_archetype(&mut F2.0, S2, _archetype, _table); }
}
F3.1 = F3::matches_component_set(S3, &|id| _archetype.contains(id));
if F3.1 {
unsafe { F3::set_archetype(&mut F3.0, S3, _archetype, _table); }
}
F4.1 = F4::matches_component_set(S4, &|id| _archetype.contains(id));
if F4.1 {
unsafe { F4::set_archetype(&mut F4.0, S4, _archetype, _table); }
}
F5.1 = F5::matches_component_set(S5, &|id| _archetype.contains(id));
if F5.1 {
unsafe { F5::set_archetype(&mut F5.0, S5, _archetype, _table); }
}
F6.1 = F6::matches_component_set(S6, &|id| _archetype.contains(id));
if F6.1 {
unsafe { F6::set_archetype(&mut F6.0, S6, _archetype, _table); }
}
F7.1 = F7::matches_component_set(S7, &|id| _archetype.contains(id));
if F7.1 {
unsafe { F7::set_archetype(&mut F7.0, S7, _archetype, _table); }
}
F8.1 = F8::matches_component_set(S8, &|id| _archetype.contains(id));
if F8.1 {
unsafe { F8::set_archetype(&mut F8.0, S8, _archetype, _table); }
}
F9.1 = F9::matches_component_set(S9, &|id| _archetype.contains(id));
if F9.1 {
unsafe { F9::set_archetype(&mut F9.0, S9, _archetype, _table); }
}
F10.1 =
F10::matches_component_set(S10, &|id| _archetype.contains(id));
if F10.1 {
unsafe {
F10::set_archetype(&mut F10.0, S10, _archetype, _table);
}
}
F11.1 =
F11::matches_component_set(S11, &|id| _archetype.contains(id));
if F11.1 {
unsafe {
F11::set_archetype(&mut F11.0, S11, _archetype, _table);
}
}
F12.1 =
F12::matches_component_set(S12, &|id| _archetype.contains(id));
if F12.1 {
unsafe {
F12::set_archetype(&mut F12.0, S12, _archetype, _table);
}
}
F13.1 =
F13::matches_component_set(S13, &|id| _archetype.contains(id));
if F13.1 {
unsafe {
F13::set_archetype(&mut F13.0, S13, _archetype, _table);
}
}
F14.1 =
F14::matches_component_set(S14, &|id| _archetype.contains(id));
if F14.1 {
unsafe {
F14::set_archetype(&mut F14.0, S14, _archetype, _table);
}
}
}
#[inline]
unsafe fn set_table<'w,
's>(_fetch: &mut Self::Fetch<'w>, _state: &'s Self::State,
_table: &'w Table) {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = _fetch;
let (S0, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13,
S14) = _state;
F0.1 = F0::matches_component_set(S0, &|id| _table.has_column(id));
if F0.1 { unsafe { F0::set_table(&mut F0.0, S0, _table); } }
F1.1 = F1::matches_component_set(S1, &|id| _table.has_column(id));
if F1.1 { unsafe { F1::set_table(&mut F1.0, S1, _table); } }
F2.1 = F2::matches_component_set(S2, &|id| _table.has_column(id));
if F2.1 { unsafe { F2::set_table(&mut F2.0, S2, _table); } }
F3.1 = F3::matches_component_set(S3, &|id| _table.has_column(id));
if F3.1 { unsafe { F3::set_table(&mut F3.0, S3, _table); } }
F4.1 = F4::matches_component_set(S4, &|id| _table.has_column(id));
if F4.1 { unsafe { F4::set_table(&mut F4.0, S4, _table); } }
F5.1 = F5::matches_component_set(S5, &|id| _table.has_column(id));
if F5.1 { unsafe { F5::set_table(&mut F5.0, S5, _table); } }
F6.1 = F6::matches_component_set(S6, &|id| _table.has_column(id));
if F6.1 { unsafe { F6::set_table(&mut F6.0, S6, _table); } }
F7.1 = F7::matches_component_set(S7, &|id| _table.has_column(id));
if F7.1 { unsafe { F7::set_table(&mut F7.0, S7, _table); } }
F8.1 = F8::matches_component_set(S8, &|id| _table.has_column(id));
if F8.1 { unsafe { F8::set_table(&mut F8.0, S8, _table); } }
F9.1 = F9::matches_component_set(S9, &|id| _table.has_column(id));
if F9.1 { unsafe { F9::set_table(&mut F9.0, S9, _table); } }
F10.1 = F10::matches_component_set(S10, &|id| _table.has_column(id));
if F10.1 { unsafe { F10::set_table(&mut F10.0, S10, _table); } }
F11.1 = F11::matches_component_set(S11, &|id| _table.has_column(id));
if F11.1 { unsafe { F11::set_table(&mut F11.0, S11, _table); } }
F12.1 = F12::matches_component_set(S12, &|id| _table.has_column(id));
if F12.1 { unsafe { F12::set_table(&mut F12.0, S12, _table); } }
F13.1 = F13::matches_component_set(S13, &|id| _table.has_column(id));
if F13.1 { unsafe { F13::set_table(&mut F13.0, S13, _table); } }
F14.1 = F14::matches_component_set(S14, &|id| _table.has_column(id));
if F14.1 { unsafe { F14::set_table(&mut F14.0, S14, _table); } }
}
fn update_component_access(state: &Self::State,
access: &mut FilteredAccess) {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = state;
let mut _new_access = FilteredAccess::matches_nothing();
let mut intermediate = access.clone();
F0::update_component_access(F0, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F1::update_component_access(F1, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F2::update_component_access(F2, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F3::update_component_access(F3, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F4::update_component_access(F4, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F5::update_component_access(F5, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F6::update_component_access(F6, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F7::update_component_access(F7, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F8::update_component_access(F8, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F9::update_component_access(F9, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F10::update_component_access(F10, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F11::update_component_access(F11, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F12::update_component_access(F12, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F13::update_component_access(F13, &mut intermediate);
_new_access.append_or(&intermediate);
let mut intermediate = access.clone();
F14::update_component_access(F14, &mut intermediate);
_new_access.append_or(&intermediate);
access.filter_sets = _new_access.filter_sets;
<(Option<F0>, Option<F1>, Option<F2>, Option<F3>, Option<F4>,
Option<F5>, Option<F6>, Option<F7>, Option<F8>, Option<F9>,
Option<F10>, Option<F11>, Option<F12>, Option<F13>,
Option<F14>)>::update_component_access(state, access);
}
fn init_nested_access(state: &Self::State, system_name: Option<&str>,
component_access_set: &mut FilteredAccessSet,
world: UnsafeWorldCell) {
<(Option<F0>, Option<F1>, Option<F2>, Option<F3>, Option<F4>,
Option<F5>, Option<F6>, Option<F7>, Option<F8>, Option<F9>,
Option<F10>, Option<F11>, Option<F12>, Option<F13>,
Option<F14>)>::init_nested_access(state, system_name,
component_access_set, world);
}
fn init_state(world: &mut World) -> Self::State {
(F0::init_state(world), F1::init_state(world), F2::init_state(world),
F3::init_state(world), F4::init_state(world),
F5::init_state(world), F6::init_state(world),
F7::init_state(world), F8::init_state(world),
F9::init_state(world), F10::init_state(world),
F11::init_state(world), F12::init_state(world),
F13::init_state(world), F14::init_state(world))
}
fn get_state(components: &Components) -> Option<Self::State> {
Some((F0::get_state(components)?, F1::get_state(components)?,
F2::get_state(components)?, F3::get_state(components)?,
F4::get_state(components)?, F5::get_state(components)?,
F6::get_state(components)?, F7::get_state(components)?,
F8::get_state(components)?, F9::get_state(components)?,
F10::get_state(components)?, F11::get_state(components)?,
F12::get_state(components)?, F13::get_state(components)?,
F14::get_state(components)?))
}
fn matches_component_set(_state: &Self::State,
_set_contains_id: &impl Fn(ComponentId) -> bool) -> bool {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = _state;
false || F0::matches_component_set(F0, _set_contains_id) ||
F1::matches_component_set(F1, _set_contains_id) ||
F2::matches_component_set(F2, _set_contains_id) ||
F3::matches_component_set(F3, _set_contains_id) ||
F4::matches_component_set(F4, _set_contains_id) ||
F5::matches_component_set(F5, _set_contains_id) ||
F6::matches_component_set(F6, _set_contains_id) ||
F7::matches_component_set(F7, _set_contains_id) ||
F8::matches_component_set(F8, _set_contains_id) ||
F9::matches_component_set(F9, _set_contains_id) ||
F10::matches_component_set(F10, _set_contains_id) ||
F11::matches_component_set(F11, _set_contains_id) ||
F12::matches_component_set(F12, _set_contains_id) ||
F13::matches_component_set(F13, _set_contains_id) ||
F14::matches_component_set(F14, _set_contains_id)
}
fn update_archetypes(state: &mut Self::State, world: UnsafeWorldCell) {
<(Option<F0>, Option<F1>, Option<F2>, Option<F3>, Option<F4>,
Option<F5>, Option<F6>, Option<F7>, Option<F8>, Option<F9>,
Option<F10>, Option<F11>, Option<F12>, Option<F13>,
Option<F14>)>::update_archetypes(state, world);
}
}
#[expect(clippy :: allow_attributes, reason =
"This is a tuple-related macro; as such the lints below may not always apply.")]
#[allow(non_snake_case, reason =
"The names of some variables are provided by the macro's caller, not by us.")]
#[allow(unused_variables, reason =
"Zero-length tuples won't use any of the parameters.")]
#[allow(clippy :: unused_unit, reason =
"Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case.")]
#[doc(hidden)]
unsafe impl<F0: QueryData, F1: QueryData, F2: QueryData, F3: QueryData,
F4: QueryData, F5: QueryData, F6: QueryData, F7: QueryData, F8: QueryData,
F9: QueryData, F10: QueryData, F11: QueryData, F12: QueryData,
F13: QueryData, F14: QueryData> QueryData for
AnyOf<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14)> {
const IS_READ_ONLY: bool =
true && F0::IS_READ_ONLY && F1::IS_READ_ONLY && F2::IS_READ_ONLY &&
F3::IS_READ_ONLY && F4::IS_READ_ONLY && F5::IS_READ_ONLY &&
F6::IS_READ_ONLY && F7::IS_READ_ONLY && F8::IS_READ_ONLY &&
F9::IS_READ_ONLY && F10::IS_READ_ONLY && F11::IS_READ_ONLY
&& F12::IS_READ_ONLY && F13::IS_READ_ONLY &&
F14::IS_READ_ONLY;
const IS_ARCHETYPAL: bool =
true && F0::IS_ARCHETYPAL && F1::IS_ARCHETYPAL && F2::IS_ARCHETYPAL &&
F3::IS_ARCHETYPAL && F4::IS_ARCHETYPAL && F5::IS_ARCHETYPAL
&& F6::IS_ARCHETYPAL && F7::IS_ARCHETYPAL &&
F8::IS_ARCHETYPAL && F9::IS_ARCHETYPAL && F10::IS_ARCHETYPAL
&& F11::IS_ARCHETYPAL && F12::IS_ARCHETYPAL &&
F13::IS_ARCHETYPAL && F14::IS_ARCHETYPAL;
type ReadOnly =
AnyOf<(F0::ReadOnly, F1::ReadOnly, F2::ReadOnly, F3::ReadOnly,
F4::ReadOnly, F5::ReadOnly, F6::ReadOnly, F7::ReadOnly, F8::ReadOnly,
F9::ReadOnly, F10::ReadOnly, F11::ReadOnly, F12::ReadOnly,
F13::ReadOnly, F14::ReadOnly)>;
type Item<'w, 's> =
(Option<F0::Item<'w, 's>>, Option<F1::Item<'w, 's>>,
Option<F2::Item<'w, 's>>, Option<F3::Item<'w, 's>>,
Option<F4::Item<'w, 's>>, Option<F5::Item<'w, 's>>,
Option<F6::Item<'w, 's>>, Option<F7::Item<'w, 's>>,
Option<F8::Item<'w, 's>>, Option<F9::Item<'w, 's>>,
Option<F10::Item<'w, 's>>, Option<F11::Item<'w, 's>>,
Option<F12::Item<'w, 's>>, Option<F13::Item<'w, 's>>,
Option<F14::Item<'w, 's>>);
fn shrink<'wlong: 'wshort, 'wshort, 's>(item: Self::Item<'wlong, 's>)
-> Self::Item<'wshort, 's> {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = item;
(F0.map(F0::shrink), F1.map(F1::shrink), F2.map(F2::shrink),
F3.map(F3::shrink), F4.map(F4::shrink), F5.map(F5::shrink),
F6.map(F6::shrink), F7.map(F7::shrink), F8.map(F8::shrink),
F9.map(F9::shrink), F10.map(F10::shrink), F11.map(F11::shrink),
F12.map(F12::shrink), F13.map(F13::shrink), F14.map(F14::shrink))
}
#[inline(always)]
unsafe fn fetch<'w,
's>(_state: &'s Self::State, _fetch: &mut Self::Fetch<'w>,
_entity: Entity, _table_row: TableRow) -> Option<Self::Item<'w, 's>> {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = _fetch;
let (S0, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13,
S14) = _state;
let result =
(F0.1.then(||
unsafe {
F0::fetch(S0, &mut F0.0, _entity, _table_row)
}).flatten(),
F1.1.then(||
unsafe {
F1::fetch(S1, &mut F1.0, _entity, _table_row)
}).flatten(),
F2.1.then(||
unsafe {
F2::fetch(S2, &mut F2.0, _entity, _table_row)
}).flatten(),
F3.1.then(||
unsafe {
F3::fetch(S3, &mut F3.0, _entity, _table_row)
}).flatten(),
F4.1.then(||
unsafe {
F4::fetch(S4, &mut F4.0, _entity, _table_row)
}).flatten(),
F5.1.then(||
unsafe {
F5::fetch(S5, &mut F5.0, _entity, _table_row)
}).flatten(),
F6.1.then(||
unsafe {
F6::fetch(S6, &mut F6.0, _entity, _table_row)
}).flatten(),
F7.1.then(||
unsafe {
F7::fetch(S7, &mut F7.0, _entity, _table_row)
}).flatten(),
F8.1.then(||
unsafe {
F8::fetch(S8, &mut F8.0, _entity, _table_row)
}).flatten(),
F9.1.then(||
unsafe {
F9::fetch(S9, &mut F9.0, _entity, _table_row)
}).flatten(),
F10.1.then(||
unsafe {
F10::fetch(S10, &mut F10.0, _entity, _table_row)
}).flatten(),
F11.1.then(||
unsafe {
F11::fetch(S11, &mut F11.0, _entity, _table_row)
}).flatten(),
F12.1.then(||
unsafe {
F12::fetch(S12, &mut F12.0, _entity, _table_row)
}).flatten(),
F13.1.then(||
unsafe {
F13::fetch(S13, &mut F13.0, _entity, _table_row)
}).flatten(),
F14.1.then(||
unsafe {
F14::fetch(S14, &mut F14.0, _entity, _table_row)
}).flatten());
(Self::IS_ARCHETYPAL ||
!#[allow(non_exhaustive_omitted_patterns)] match result {
(Option::<QueryItem<F0>>::None,
Option::<QueryItem<F1>>::None,
Option::<QueryItem<F2>>::None,
Option::<QueryItem<F3>>::None,
Option::<QueryItem<F4>>::None,
Option::<QueryItem<F5>>::None,
Option::<QueryItem<F6>>::None,
Option::<QueryItem<F7>>::None,
Option::<QueryItem<F8>>::None,
Option::<QueryItem<F9>>::None,
Option::<QueryItem<F10>>::None,
Option::<QueryItem<F11>>::None,
Option::<QueryItem<F12>>::None,
Option::<QueryItem<F13>>::None,
Option::<QueryItem<F14>>::None) => true,
_ => false,
} ||
!(false || F0.1 || F1.1 || F2.1 || F3.1 || F4.1 || F5.1 ||
F6.1 || F7.1 || F8.1 || F9.1 || F10.1 || F11.1 || F12.1 ||
F13.1 || F14.1)).then_some(result)
}
fn iter_access(state: &Self::State)
-> impl Iterator<Item = EcsAccessType<'_>> {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = state;
iter::empty().chain(F0::iter_access(F0)).chain(F1::iter_access(F1)).chain(F2::iter_access(F2)).chain(F3::iter_access(F3)).chain(F4::iter_access(F4)).chain(F5::iter_access(F5)).chain(F6::iter_access(F6)).chain(F7::iter_access(F7)).chain(F8::iter_access(F8)).chain(F9::iter_access(F9)).chain(F10::iter_access(F10)).chain(F11::iter_access(F11)).chain(F12::iter_access(F12)).chain(F13::iter_access(F13)).chain(F14::iter_access(F14))
}
}
#[doc(hidden)]
unsafe impl<F0: IterQueryData, F1: IterQueryData, F2: IterQueryData,
F3: IterQueryData, F4: IterQueryData, F5: IterQueryData,
F6: IterQueryData, F7: IterQueryData, F8: IterQueryData,
F9: IterQueryData, F10: IterQueryData, F11: IterQueryData,
F12: IterQueryData, F13: IterQueryData, F14: IterQueryData> IterQueryData
for
AnyOf<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14)> {
}
#[doc(hidden)]
unsafe impl<F0: ReadOnlyQueryData, F1: ReadOnlyQueryData,
F2: ReadOnlyQueryData, F3: ReadOnlyQueryData, F4: ReadOnlyQueryData,
F5: ReadOnlyQueryData, F6: ReadOnlyQueryData, F7: ReadOnlyQueryData,
F8: ReadOnlyQueryData, F9: ReadOnlyQueryData, F10: ReadOnlyQueryData,
F11: ReadOnlyQueryData, F12: ReadOnlyQueryData, F13: ReadOnlyQueryData,
F14: ReadOnlyQueryData> ReadOnlyQueryData for
AnyOf<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14)> {
}
#[doc(hidden)]
unsafe impl<F0: SingleEntityQueryData, F1: SingleEntityQueryData,
F2: SingleEntityQueryData, F3: SingleEntityQueryData,
F4: SingleEntityQueryData, F5: SingleEntityQueryData,
F6: SingleEntityQueryData, F7: SingleEntityQueryData,
F8: SingleEntityQueryData, F9: SingleEntityQueryData,
F10: SingleEntityQueryData, F11: SingleEntityQueryData,
F12: SingleEntityQueryData, F13: SingleEntityQueryData,
F14: SingleEntityQueryData> SingleEntityQueryData for
AnyOf<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14)> {
}
#[expect(clippy :: allow_attributes, reason =
"This is a tuple-related macro; as such the lints below may not always apply.")]
#[allow(clippy :: unused_unit, reason =
"Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case.")]
impl<F0: ReleaseStateQueryData, F1: ReleaseStateQueryData,
F2: ReleaseStateQueryData, F3: ReleaseStateQueryData,
F4: ReleaseStateQueryData, F5: ReleaseStateQueryData,
F6: ReleaseStateQueryData, F7: ReleaseStateQueryData,
F8: ReleaseStateQueryData, F9: ReleaseStateQueryData,
F10: ReleaseStateQueryData, F11: ReleaseStateQueryData,
F12: ReleaseStateQueryData, F13: ReleaseStateQueryData,
F14: ReleaseStateQueryData> ReleaseStateQueryData for
AnyOf<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14)> {
fn release_state<'w>((i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11,
i12, i13, i14): Self::Item<'w, '_>) -> Self::Item<'w, 'static> {
(i0.map(|i0| F0::release_state(i0)),
i1.map(|i1| F1::release_state(i1)),
i2.map(|i2| F2::release_state(i2)),
i3.map(|i3| F3::release_state(i3)),
i4.map(|i4| F4::release_state(i4)),
i5.map(|i5| F5::release_state(i5)),
i6.map(|i6| F6::release_state(i6)),
i7.map(|i7| F7::release_state(i7)),
i8.map(|i8| F8::release_state(i8)),
i9.map(|i9| F9::release_state(i9)),
i10.map(|i10| F10::release_state(i10)),
i11.map(|i11| F11::release_state(i11)),
i12.map(|i12| F12::release_state(i12)),
i13.map(|i13| F13::release_state(i13)),
i14.map(|i14| F14::release_state(i14)))
}
}
#[doc(hidden)]
impl<F0: ArchetypeQueryData, F1: ArchetypeQueryData, F2: ArchetypeQueryData,
F3: ArchetypeQueryData, F4: ArchetypeQueryData, F5: ArchetypeQueryData,
F6: ArchetypeQueryData, F7: ArchetypeQueryData, F8: ArchetypeQueryData,
F9: ArchetypeQueryData, F10: ArchetypeQueryData, F11: ArchetypeQueryData,
F12: ArchetypeQueryData, F13: ArchetypeQueryData, F14: ArchetypeQueryData>
ArchetypeQueryData for
AnyOf<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14)> {
}
#[expect(clippy :: allow_attributes, reason =
"This is a tuple-related macro; as such the lints below may not always apply.")]
#[allow(non_snake_case, reason =
"The names of some variables are provided by the macro's caller, not by us.")]
#[allow(unused_variables, reason =
"Zero-length tuples won't use any of the parameters.")]
#[allow(clippy :: unused_unit, reason =
"Zero-length tuples will generate some function bodies equivalent to `()`; however, this macro is meant for all applicable tuples, and as such it makes no sense to rewrite it just for that case.")]
#[doc(hidden)]
impl<F0: ContiguousQueryData, F1: ContiguousQueryData,
F2: ContiguousQueryData, F3: ContiguousQueryData, F4: ContiguousQueryData,
F5: ContiguousQueryData, F6: ContiguousQueryData, F7: ContiguousQueryData,
F8: ContiguousQueryData, F9: ContiguousQueryData,
F10: ContiguousQueryData, F11: ContiguousQueryData,
F12: ContiguousQueryData, F13: ContiguousQueryData,
F14: ContiguousQueryData> ContiguousQueryData for
AnyOf<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14)> {
type Contiguous<'w, 's> =
(Option<F0::Contiguous<'w, 's>>, Option<F1::Contiguous<'w, 's>>,
Option<F2::Contiguous<'w, 's>>, Option<F3::Contiguous<'w, 's>>,
Option<F4::Contiguous<'w, 's>>, Option<F5::Contiguous<'w, 's>>,
Option<F6::Contiguous<'w, 's>>, Option<F7::Contiguous<'w, 's>>,
Option<F8::Contiguous<'w, 's>>, Option<F9::Contiguous<'w, 's>>,
Option<F10::Contiguous<'w, 's>>, Option<F11::Contiguous<'w, 's>>,
Option<F12::Contiguous<'w, 's>>, Option<F13::Contiguous<'w, 's>>,
Option<F14::Contiguous<'w, 's>>);
unsafe fn fetch_contiguous<'w,
's>(state: &'s Self::State, fetch: &mut Self::Fetch<'w>,
entities: &'w [Entity]) -> Self::Contiguous<'w, 's> {
let (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
F14) = fetch;
let (S0, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13,
S14) = state;
(F0.1.then(||
unsafe { F0::fetch_contiguous(S0, &mut F0.0, entities) }),
F1.1.then(||
unsafe { F1::fetch_contiguous(S1, &mut F1.0, entities) }),
F2.1.then(||
unsafe { F2::fetch_contiguous(S2, &mut F2.0, entities) }),
F3.1.then(||
unsafe { F3::fetch_contiguous(S3, &mut F3.0, entities) }),
F4.1.then(||
unsafe { F4::fetch_contiguous(S4, &mut F4.0, entities) }),
F5.1.then(||
unsafe { F5::fetch_contiguous(S5, &mut F5.0, entities) }),
F6.1.then(||
unsafe { F6::fetch_contiguous(S6, &mut F6.0, entities) }),
F7.1.then(||
unsafe { F7::fetch_contiguous(S7, &mut F7.0, entities) }),
F8.1.then(||
unsafe { F8::fetch_contiguous(S8, &mut F8.0, entities) }),
F9.1.then(||
unsafe { F9::fetch_contiguous(S9, &mut F9.0, entities) }),
F10.1.then(||
unsafe {
F10::fetch_contiguous(S10, &mut F10.0, entities)
}),
F11.1.then(||
unsafe {
F11::fetch_contiguous(S11, &mut F11.0, entities)
}),
F12.1.then(||
unsafe {
F12::fetch_contiguous(S12, &mut F12.0, entities)
}),
F13.1.then(||
unsafe {
F13::fetch_contiguous(S13, &mut F13.0, entities)
}),
F14.1.then(||
unsafe {
F14::fetch_contiguous(S14, &mut F14.0, entities)
}))
}
}all_tuples!(
3798 #[doc(fake_variadic)]
3799 impl_anytuple_fetch,
3800 0,
3801 15,
3802 F,
3803 S,
3804 i
3805);
3806
3807pub(crate) struct NopWorldQuery<D: QueryData>(PhantomData<D>);
3811
3812unsafe impl<D: QueryData> WorldQuery for NopWorldQuery<D> {
3816 type Fetch<'w> = ();
3817 type State = D::State;
3818
3819 fn shrink_fetch<'wlong: 'wshort, 'wshort>(_fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
3820 }
3821
3822 #[inline(always)]
3823 unsafe fn init_fetch(
3824 _world: UnsafeWorldCell,
3825 _state: &D::State,
3826 _last_run: Tick,
3827 _this_run: Tick,
3828 ) {
3829 }
3830
3831 const IS_DENSE: bool = D::IS_DENSE;
3832
3833 #[inline(always)]
3834 unsafe fn set_archetype(
3835 _fetch: &mut (),
3836 _state: &D::State,
3837 _archetype: &Archetype,
3838 _tables: &Table,
3839 ) {
3840 }
3841
3842 #[inline(always)]
3843 unsafe fn set_table<'w>(_fetch: &mut (), _state: &D::State, _table: &Table) {}
3844
3845 fn update_component_access(_state: &D::State, _access: &mut FilteredAccess) {}
3846
3847 fn init_state(world: &mut World) -> Self::State {
3848 D::init_state(world)
3849 }
3850
3851 fn get_state(components: &Components) -> Option<Self::State> {
3852 D::get_state(components)
3853 }
3854
3855 fn matches_component_set(
3856 state: &Self::State,
3857 set_contains_id: &impl Fn(ComponentId) -> bool,
3858 ) -> bool {
3859 D::matches_component_set(state, set_contains_id)
3860 }
3861
3862 fn update_archetypes(state: &mut Self::State, world: UnsafeWorldCell) {
3863 D::update_archetypes(state, world);
3864 }
3865}
3866
3867unsafe impl<D: QueryData> QueryData for NopWorldQuery<D> {
3869 const IS_READ_ONLY: bool = true;
3870 const IS_ARCHETYPAL: bool = true;
3871 type ReadOnly = Self;
3872 type Item<'w, 's> = ();
3873
3874 fn shrink<'wlong: 'wshort, 'wshort, 's>(
3875 _item: Self::Item<'wlong, 's>,
3876 ) -> Self::Item<'wshort, 's> {
3877 }
3878
3879 #[inline(always)]
3880 unsafe fn fetch<'w, 's>(
3881 _state: &'s Self::State,
3882 _fetch: &mut Self::Fetch<'w>,
3883 _entity: Entity,
3884 _table_row: TableRow,
3885 ) -> Option<Self::Item<'w, 's>> {
3886 Some(())
3887 }
3888
3889 fn iter_access(_state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
3890 iter::empty()
3891 }
3892}
3893
3894unsafe impl<D: QueryData> IterQueryData for NopWorldQuery<D> {}
3896
3897unsafe impl<D: QueryData> ReadOnlyQueryData for NopWorldQuery<D> {}
3899
3900unsafe impl<D: QueryData> SingleEntityQueryData for NopWorldQuery<D> {}
3902
3903impl<D: QueryData> ReleaseStateQueryData for NopWorldQuery<D> {
3904 fn release_state<'w>(_item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {}
3905}
3906
3907impl<D: QueryData> ArchetypeQueryData for NopWorldQuery<D> {}
3908
3909unsafe impl<T: ?Sized> WorldQuery for PhantomData<T> {
3913 type Fetch<'w> = ();
3914
3915 type State = ();
3916
3917 fn shrink_fetch<'wlong: 'wshort, 'wshort>(_fetch: Self::Fetch<'wlong>) -> Self::Fetch<'wshort> {
3918 }
3919
3920 unsafe fn init_fetch<'w, 's>(
3921 _world: UnsafeWorldCell<'w>,
3922 _state: &'s Self::State,
3923 _last_run: Tick,
3924 _this_run: Tick,
3925 ) -> Self::Fetch<'w> {
3926 }
3927
3928 const IS_DENSE: bool = true;
3931
3932 unsafe fn set_archetype<'w, 's>(
3933 _fetch: &mut Self::Fetch<'w>,
3934 _state: &'s Self::State,
3935 _archetype: &'w Archetype,
3936 _table: &'w Table,
3937 ) {
3938 }
3939
3940 unsafe fn set_table<'w, 's>(
3941 _fetch: &mut Self::Fetch<'w>,
3942 _state: &'s Self::State,
3943 _table: &'w Table,
3944 ) {
3945 }
3946
3947 fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) {}
3948
3949 fn init_state(_world: &mut World) -> Self::State {}
3950
3951 fn get_state(_components: &Components) -> Option<Self::State> {
3952 Some(())
3953 }
3954
3955 fn matches_component_set(
3956 _state: &Self::State,
3957 _set_contains_id: &impl Fn(ComponentId) -> bool,
3958 ) -> bool {
3959 true
3960 }
3961}
3962
3963unsafe impl<T: ?Sized> QueryData for PhantomData<T> {
3965 const IS_READ_ONLY: bool = true;
3966 const IS_ARCHETYPAL: bool = true;
3967 type ReadOnly = Self;
3968 type Item<'w, 's> = ();
3969
3970 fn shrink<'wlong: 'wshort, 'wshort, 's>(
3971 _item: Self::Item<'wlong, 's>,
3972 ) -> Self::Item<'wshort, 's> {
3973 }
3974
3975 unsafe fn fetch<'w, 's>(
3976 _state: &'s Self::State,
3977 _fetch: &mut Self::Fetch<'w>,
3978 _entity: Entity,
3979 _table_row: TableRow,
3980 ) -> Option<Self::Item<'w, 's>> {
3981 Some(())
3982 }
3983
3984 fn iter_access(_state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
3985 iter::empty()
3986 }
3987}
3988
3989unsafe impl<T: ?Sized> IterQueryData for PhantomData<T> {}
3991
3992unsafe impl<T: ?Sized> ReadOnlyQueryData for PhantomData<T> {}
3994
3995unsafe impl<T: ?Sized> SingleEntityQueryData for PhantomData<T> {}
3997
3998impl<T: ?Sized> ReleaseStateQueryData for PhantomData<T> {
3999 fn release_state<'w>(_item: Self::Item<'w, '_>) -> Self::Item<'w, 'static> {}
4000}
4001
4002impl<T: ?Sized> ArchetypeQueryData for PhantomData<T> {}
4003
4004pub(super) union StorageSwitch<C: Component, T: Copy, S: Copy> {
4007 table: T,
4009 sparse_set: S,
4011 _marker: PhantomData<C>,
4012}
4013
4014impl<C: Component, T: Copy, S: Copy> StorageSwitch<C, T, S> {
4015 pub fn new(table: impl FnOnce() -> T, sparse_set: impl FnOnce() -> S) -> Self {
4018 match C::STORAGE_TYPE {
4019 StorageType::Table => Self { table: table() },
4020 StorageType::SparseSet => Self {
4021 sparse_set: sparse_set(),
4022 },
4023 }
4024 }
4025
4026 #[inline]
4036 pub unsafe fn set_table(&mut self, table: T) {
4037 match C::STORAGE_TYPE {
4038 StorageType::Table => self.table = table,
4039 _ => {
4040 #[cfg(debug_assertions)]
4041 ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
4042 #[cfg(not(debug_assertions))]
4043 core::hint::unreachable_unchecked()
4044 }
4045 }
4046 }
4047
4048 pub fn extract<R>(&self, table: impl FnOnce(T) -> R, sparse_set: impl FnOnce(S) -> R) -> R {
4051 match C::STORAGE_TYPE {
4052 StorageType::Table => table(
4053 unsafe { self.table },
4055 ),
4056 StorageType::SparseSet => sparse_set(
4057 unsafe { self.sparse_set },
4059 ),
4060 }
4061 }
4062}
4063
4064impl<C: Component, T: Copy, S: Copy> Clone for StorageSwitch<C, T, S> {
4065 fn clone(&self) -> Self {
4066 *self
4067 }
4068}
4069
4070impl<C: Component, T: Copy, S: Copy> Copy for StorageSwitch<C, T, S> {}
4071
4072#[cfg(test)]
4073mod tests {
4074 use super::*;
4075 use crate::change_detection::DetectChanges;
4076 use crate::query::Without;
4077 use crate::system::{assert_is_system, Query};
4078 use bevy_ecs::prelude::Schedule;
4079 use bevy_ecs_macros::QueryData;
4080
4081 #[derive(Component)]
4082 pub struct A;
4083
4084 #[derive(Component)]
4085 pub struct B;
4086
4087 #[test]
4089 fn world_query_struct_variants() {
4090 #[derive(QueryData)]
4091 pub struct NamedQuery {
4092 id: Entity,
4093 a: &'static A,
4094 }
4095
4096 #[derive(QueryData)]
4097 pub struct TupleQuery(&'static A, &'static B);
4098
4099 #[derive(QueryData)]
4100 pub struct UnitQuery;
4101
4102 fn my_system(_: Query<(NamedQuery, TupleQuery, UnitQuery)>) {}
4103
4104 assert_is_system(my_system);
4105 }
4106
4107 #[test]
4109 fn world_query_phantom_data() {
4110 #[derive(QueryData)]
4111 pub struct IgnoredQuery<Marker> {
4112 id: Entity,
4113 _marker: PhantomData<Marker>,
4114 }
4115
4116 fn ignored_system(_: Query<IgnoredQuery<()>>) {}
4117
4118 assert_is_system(ignored_system);
4119 }
4120
4121 #[test]
4122 fn derive_release_state() {
4123 struct NonReleaseQueryData;
4124
4125 unsafe impl WorldQuery for NonReleaseQueryData {
4129 type Fetch<'w> = ();
4130 type State = ();
4131
4132 fn shrink_fetch<'wlong: 'wshort, 'wshort>(
4133 _: Self::Fetch<'wlong>,
4134 ) -> Self::Fetch<'wshort> {
4135 }
4136
4137 unsafe fn init_fetch<'w, 's>(
4138 _world: UnsafeWorldCell<'w>,
4139 _state: &'s Self::State,
4140 _last_run: Tick,
4141 _this_run: Tick,
4142 ) -> Self::Fetch<'w> {
4143 }
4144
4145 const IS_DENSE: bool = true;
4146
4147 #[inline]
4148 unsafe fn set_archetype<'w, 's>(
4149 _fetch: &mut Self::Fetch<'w>,
4150 _state: &'s Self::State,
4151 _archetype: &'w Archetype,
4152 _table: &Table,
4153 ) {
4154 }
4155
4156 #[inline]
4157 unsafe fn set_table<'w, 's>(
4158 _fetch: &mut Self::Fetch<'w>,
4159 _state: &'s Self::State,
4160 _table: &'w Table,
4161 ) {
4162 }
4163
4164 fn update_component_access(_state: &Self::State, _access: &mut FilteredAccess) {}
4165
4166 fn init_state(_world: &mut World) {}
4167
4168 fn get_state(_components: &Components) -> Option<()> {
4169 Some(())
4170 }
4171
4172 fn matches_component_set(
4173 _state: &Self::State,
4174 _set_contains_id: &impl Fn(ComponentId) -> bool,
4175 ) -> bool {
4176 true
4177 }
4178 }
4179
4180 unsafe impl QueryData for NonReleaseQueryData {
4182 type ReadOnly = Self;
4183 const IS_READ_ONLY: bool = true;
4184 const IS_ARCHETYPAL: bool = true;
4185
4186 type Item<'w, 's> = ();
4187
4188 fn shrink<'wlong: 'wshort, 'wshort, 's>(
4189 _item: Self::Item<'wlong, 's>,
4190 ) -> Self::Item<'wshort, 's> {
4191 }
4192
4193 #[inline(always)]
4194 unsafe fn fetch<'w, 's>(
4195 _state: &'s Self::State,
4196 _fetch: &mut Self::Fetch<'w>,
4197 _entity: Entity,
4198 _table_row: TableRow,
4199 ) -> Option<Self::Item<'w, 's>> {
4200 Some(())
4201 }
4202
4203 fn iter_access(_state: &Self::State) -> impl Iterator<Item = EcsAccessType<'_>> {
4204 iter::empty()
4205 }
4206 }
4207
4208 unsafe impl ReadOnlyQueryData for NonReleaseQueryData {}
4210
4211 unsafe impl IterQueryData for NonReleaseQueryData {}
4213
4214 impl ArchetypeQueryData for NonReleaseQueryData {}
4215
4216 #[derive(QueryData)]
4217 pub struct DerivedNonReleaseRead {
4218 non_release: NonReleaseQueryData,
4219 a: &'static A,
4220 }
4221
4222 #[derive(QueryData)]
4223 #[query_data(mutable)]
4224 pub struct DerivedNonReleaseMutable {
4225 non_release: NonReleaseQueryData,
4226 a: &'static mut A,
4227 }
4228
4229 #[derive(QueryData)]
4230 pub struct DerivedReleaseRead {
4231 a: &'static A,
4232 }
4233
4234 #[derive(QueryData)]
4235 #[query_data(mutable)]
4236 pub struct DerivedReleaseMutable {
4237 a: &'static mut A,
4238 }
4239
4240 fn assert_is_release_state<Q: ReleaseStateQueryData>() {}
4241
4242 assert_is_release_state::<DerivedReleaseRead>();
4243 assert_is_release_state::<DerivedReleaseMutable>();
4244 }
4245
4246 #[test]
4249 fn read_only_field_visibility() {
4250 mod private {
4251 use super::*;
4252
4253 #[derive(QueryData)]
4254 #[query_data(mutable)]
4255 pub struct D {
4256 pub a: &'static mut A,
4257 }
4258 }
4259
4260 let _ = private::DReadOnly { a: &A };
4261
4262 fn my_system(query: Query<private::D>) {
4263 for q in &query {
4264 let _ = &q.a;
4265 }
4266 }
4267
4268 assert_is_system(my_system);
4269 }
4270
4271 #[test]
4275 fn world_query_metadata_collision() {
4276 #[derive(QueryData)]
4279 pub struct Client<S: ClientState> {
4280 pub state: &'static S,
4281 pub fetch: &'static ClientFetch,
4282 }
4283
4284 pub trait ClientState: Component {}
4285
4286 #[derive(Component)]
4287 pub struct ClientFetch;
4288
4289 #[derive(Component)]
4290 pub struct C;
4291
4292 impl ClientState for C {}
4293
4294 fn client_system(_: Query<Client<C>>) {}
4295
4296 assert_is_system(client_system);
4297 }
4298
4299 #[test]
4303 fn test_entity_ref_query_with_ticks() {
4304 #[derive(Component)]
4305 pub struct C;
4306
4307 fn system(query: Query<EntityRef>) {
4308 for entity_ref in &query {
4309 if let Some(c) = entity_ref.get_ref::<C>()
4310 && !c.is_added()
4311 {
4312 panic!("Expected C to be added");
4313 }
4314 }
4315 }
4316
4317 let mut world = World::new();
4318 let mut schedule = Schedule::default();
4319 schedule.add_systems(system);
4320 world.spawn(C);
4321
4322 world.clear_trackers();
4324
4325 schedule.run(&mut world);
4327 }
4328
4329 #[test]
4330 fn test_contiguous_query_data() {
4331 #[derive(Component, PartialEq, Eq, Debug)]
4332 pub struct C(i32);
4333
4334 #[derive(Component, PartialEq, Eq, Debug)]
4335 pub struct D(bool);
4336
4337 let mut world = World::new();
4338 world.spawn((C(0), D(true)));
4339 world.spawn((C(1), D(false)));
4340 world.spawn(C(2));
4341
4342 let mut query = world.query::<(&C, &D)>();
4343 let mut iter = query.contiguous_iter(&world).unwrap();
4344 let c = iter.next().unwrap();
4345 assert_eq!(c.0, [C(0), C(1)].as_slice());
4346 assert_eq!(c.1, [D(true), D(false)].as_slice());
4347 assert!(iter.next().is_none());
4348
4349 let mut query = world.query::<&C>();
4350 let mut iter = query.contiguous_iter(&world).unwrap();
4351 let mut present = [false; 3];
4352 let mut len = 0;
4353 for _ in 0..2 {
4354 let c = iter.next().unwrap();
4355 for c in c {
4356 present[c.0 as usize] = true;
4357 len += 1;
4358 }
4359 }
4360 assert!(iter.next().is_none());
4361 assert_eq!(len, 3);
4362 assert_eq!(present, [true; 3]);
4363
4364 let mut query = world.query::<&mut C>();
4365 let mut iter = query.contiguous_iter_mut(&mut world).unwrap();
4366 for _ in 0..2 {
4367 let c = iter.next().unwrap();
4368 for c in c {
4369 c.0 *= 2;
4370 }
4371 }
4372 assert!(iter.next().is_none());
4373 let mut iter = query.contiguous_iter(&world).unwrap();
4374 let mut present = [false; 6];
4375 let mut len = 0;
4376 for _ in 0..2 {
4377 let c = iter.next().unwrap();
4378 for c in c {
4379 present[c.0 as usize] = true;
4380 len += 1;
4381 }
4382 }
4383 assert_eq!(present, [true, false, true, false, true, false]);
4384 assert_eq!(len, 3);
4385
4386 let mut query = world.query_filtered::<&C, Without<D>>();
4387 let mut iter = query.contiguous_iter(&world).unwrap();
4388 assert_eq!(iter.next().unwrap(), &[C(4)]);
4389 assert!(iter.next().is_none());
4390 }
4391
4392 #[test]
4393 fn sparse_set_contiguous_query() {
4394 #[derive(Component, Debug, PartialEq, Eq)]
4395 #[component(storage = "SparseSet")]
4396 pub struct S(i32);
4397
4398 let mut world = World::new();
4399 world.spawn(S(0));
4400
4401 let mut query = world.query::<&mut S>();
4402 let iter = query.contiguous_iter_mut(&mut world);
4403 assert!(iter.is_err());
4404 }
4405
4406 #[test]
4407 fn any_of_contiguous_test() {
4408 #[derive(Component, Debug, Clone, Copy)]
4409 pub struct C(i32);
4410
4411 #[derive(Component, Debug, Clone, Copy)]
4412 pub struct D(i32);
4413
4414 let mut world = World::new();
4415 world.spawn((C(0), D(1)));
4416 world.spawn(C(2));
4417 world.spawn(D(3));
4418 world.spawn(());
4419
4420 let mut query = world.query::<AnyOf<(&C, &D)>>();
4421 let iter = query.contiguous_iter(&world).unwrap();
4422 let mut present = [false; 4];
4423
4424 for (c, d) in iter {
4425 assert!(c.is_some() || d.is_some());
4426 let c = c.unwrap_or_default();
4427 let d = d.unwrap_or_default();
4428 for i in 0..c.len().max(d.len()) {
4429 let c = c.get(i).cloned();
4430 let d = d.get(i).cloned();
4431 if let Some(C(c)) = c {
4432 assert!(!present[c as usize]);
4433 present[c as usize] = true;
4434 }
4435 if let Some(D(d)) = d {
4436 assert!(!present[d as usize]);
4437 present[d as usize] = true;
4438 }
4439 }
4440 }
4441
4442 assert_eq!(present, [true; 4]);
4443 }
4444
4445 #[test]
4446 fn option_contiguous_test() {
4447 #[derive(Component, Clone, Copy)]
4448 struct C(i32);
4449
4450 #[derive(Component, Clone, Copy)]
4451 struct D(i32);
4452
4453 let mut world = World::new();
4454 world.spawn((C(0), D(1)));
4455 world.spawn(D(2));
4456 world.spawn(C(3));
4457
4458 let mut query = world.query::<(Option<&C>, &D)>();
4459 let iter = query.contiguous_iter(&world).unwrap();
4460 let mut present = [false; 3];
4461
4462 for (c, d) in iter {
4463 let c = c.unwrap_or_default();
4464 for i in 0..d.len() {
4465 let c = c.get(i).cloned();
4466 let D(d) = d[i];
4467 if let Some(C(c)) = c {
4468 assert!(!present[c as usize]);
4469 present[c as usize] = true;
4470 }
4471 assert!(!present[d as usize]);
4472 present[d as usize] = true;
4473 }
4474 }
4475
4476 assert_eq!(present, [true; 3]);
4477 }
4478}