@@ -467,23 +467,6 @@ pub trait WorldQueryBatch<const N: usize, const ALIGN: usize>:
467
467
) -> <Self as WorldQueryBatchGats < ' w , N , ALIGN > >:: FullBatch ;
468
468
}
469
469
470
- impl < const N : usize , const ALIGN : usize > WorldQueryBatch < N , ALIGN > for Entity
471
- where
472
- Entity : AlignedBatchGat < N , ALIGN > ,
473
- {
474
- #[ inline]
475
- unsafe fn table_fetch_batched_aligned < ' w > (
476
- fetch : & mut <Self as WorldQueryGats < ' w > >:: Fetch ,
477
- table_row_start : usize ,
478
- len : usize ,
479
- ) -> <Self as WorldQueryBatchGats < ' w , N , ALIGN > >:: FullBatch {
480
- let entities = fetch
481
- . entities
482
- . unwrap_or_else ( || debug_checked_unreachable ( ) ) ;
483
- entities. get_batch_aligned :: < N , ALIGN > ( table_row_start, len)
484
- }
485
- }
486
-
487
470
/// A helper trait for [`WorldQueryBatch`] that works around Rust's lack of Generic Associated Types.
488
471
///
489
472
/// **Note**: Consider using the type alias [`QueryBatch`] for conenvience instead of referring to `FullBatch` directly.
@@ -597,6 +580,23 @@ unsafe impl WorldQuery for Entity {
597
580
}
598
581
}
599
582
583
+ impl < const N : usize , const ALIGN : usize > WorldQueryBatch < N , ALIGN > for Entity
584
+ where
585
+ Entity : AlignedBatchGat < N , ALIGN > ,
586
+ {
587
+ #[ inline]
588
+ unsafe fn table_fetch_batched_aligned < ' w > (
589
+ fetch : & mut <Self as WorldQueryGats < ' w > >:: Fetch ,
590
+ table_row_start : usize ,
591
+ len : usize ,
592
+ ) -> <Self as WorldQueryBatchGats < ' w , N , ALIGN > >:: FullBatch {
593
+ let entities = fetch
594
+ . entities
595
+ . unwrap_or_else ( || debug_checked_unreachable ( ) ) ;
596
+ entities. get_batch_aligned :: < N , ALIGN > ( table_row_start, len)
597
+ }
598
+ }
599
+
600
600
impl < ' w > WorldQueryGats < ' w > for Entity {
601
601
type Fetch = EntityFetch < ' w > ;
602
602
type Item = Entity ;
@@ -622,29 +622,6 @@ pub struct ReadFetch<'w, T> {
622
622
sparse_set : Option < & ' w ComponentSparseSet > ,
623
623
}
624
624
625
- impl < T : Component , const N : usize , const ALIGN : usize > WorldQueryBatch < N , ALIGN > for & T
626
- where
627
- T : AlignedBatchGat < N , ALIGN > ,
628
- {
629
- #[ inline]
630
- unsafe fn table_fetch_batched_aligned < ' w > (
631
- fetch : & mut <Self as WorldQueryGats < ' w > >:: Fetch ,
632
- table_row_start : usize ,
633
- len : usize ,
634
- ) -> <Self as WorldQueryBatchGats < ' w , N , ALIGN > >:: FullBatch
635
- where
636
- T : AlignedBatchGat < N , ALIGN > ,
637
- {
638
- //TODO: when generalized const expresions are stable, want the following:
639
- //gcd::euclid_usize(ptr::MAX_SIMD_ALIGNMENT, N * core::mem::size_of::<T>());
640
-
641
- let components = fetch
642
- . table_components
643
- . unwrap_or_else ( || debug_checked_unreachable ( ) ) ;
644
- components. get_batch_aligned_deref :: < N , ALIGN > ( table_row_start, len)
645
- }
646
- }
647
-
648
625
/// SAFETY: `ROQueryFetch<Self>` is the same as `QueryFetch<Self>`
649
626
unsafe impl < T : Component > WorldQuery for & T {
650
627
type ReadOnly = Self ;
@@ -775,6 +752,29 @@ unsafe impl<T: Component> WorldQuery for &T {
775
752
}
776
753
}
777
754
755
+ impl < T : Component , const N : usize , const ALIGN : usize > WorldQueryBatch < N , ALIGN > for & T
756
+ where
757
+ T : AlignedBatchGat < N , ALIGN > ,
758
+ {
759
+ #[ inline]
760
+ unsafe fn table_fetch_batched_aligned < ' w > (
761
+ fetch : & mut <Self as WorldQueryGats < ' w > >:: Fetch ,
762
+ table_row_start : usize ,
763
+ len : usize ,
764
+ ) -> <Self as WorldQueryBatchGats < ' w , N , ALIGN > >:: FullBatch
765
+ where
766
+ T : AlignedBatchGat < N , ALIGN > ,
767
+ {
768
+ //TODO: when generalized const expresions are stable, want the following:
769
+ //gcd::euclid_usize(ptr::MAX_SIMD_ALIGNMENT, N * core::mem::size_of::<T>());
770
+
771
+ let components = fetch
772
+ . table_components
773
+ . unwrap_or_else ( || debug_checked_unreachable ( ) ) ;
774
+ components. get_batch_aligned_deref :: < N , ALIGN > ( table_row_start, len)
775
+ }
776
+ }
777
+
778
778
impl < T > Clone for ReadFetch < ' _ , T > {
779
779
fn clone ( & self ) -> Self {
780
780
Self {
@@ -815,39 +815,6 @@ pub struct WriteFetch<'w, T> {
815
815
change_tick : u32 ,
816
816
}
817
817
818
- //TODO: inlines
819
-
820
- impl < ' __w , T : Component , const N : usize , const ALIGN : usize > WorldQueryBatch < N , ALIGN >
821
- for & ' __w mut T
822
- where
823
- T : AlignedBatchGat < N , ALIGN > ,
824
- ComponentTicks : AlignedBatchGat < N , ALIGN > ,
825
- {
826
- #[ inline]
827
- unsafe fn table_fetch_batched_aligned < ' w > (
828
- fetch : & mut <Self as WorldQueryGats < ' w > >:: Fetch ,
829
- table_row_start : usize ,
830
- len : usize ,
831
- ) -> <Self as WorldQueryBatchGats < ' w , N , ALIGN > >:: FullBatch {
832
- let ( table_components, table_ticks) = fetch
833
- . table_components
834
- . zip ( fetch. table_ticks )
835
- . unwrap_or_else ( || debug_checked_unreachable ( ) ) ;
836
-
837
- MutBatch :: < T , N , ALIGN > {
838
- value : table_components. get_batch_aligned_deref_mut :: < N , ALIGN > ( table_row_start, len) ,
839
- ticks : TicksBatch {
840
- // SAFETY: [table_row_start..+batch.len()] is in range
841
- component_ticks : table_ticks
842
- . get_batch_aligned_deref_mut :: < N , ALIGN > ( table_row_start, len) ,
843
- change_tick : fetch. change_tick ,
844
- last_change_tick : fetch. last_change_tick ,
845
- } ,
846
- _marker : PhantomData ,
847
- }
848
- }
849
- }
850
-
851
818
/// SAFETY: access of `&T` is a subset of `&mut T`
852
819
unsafe impl < ' __w , T : Component > WorldQuery for & ' __w mut T {
853
820
type ReadOnly = & ' __w T ;
@@ -1010,6 +977,37 @@ unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T {
1010
977
}
1011
978
}
1012
979
980
+ impl < ' __w , T : Component , const N : usize , const ALIGN : usize > WorldQueryBatch < N , ALIGN >
981
+ for & ' __w mut T
982
+ where
983
+ T : AlignedBatchGat < N , ALIGN > ,
984
+ ComponentTicks : AlignedBatchGat < N , ALIGN > ,
985
+ {
986
+ #[ inline]
987
+ unsafe fn table_fetch_batched_aligned < ' w > (
988
+ fetch : & mut <Self as WorldQueryGats < ' w > >:: Fetch ,
989
+ table_row_start : usize ,
990
+ len : usize ,
991
+ ) -> <Self as WorldQueryBatchGats < ' w , N , ALIGN > >:: FullBatch {
992
+ let ( table_components, table_ticks) = fetch
993
+ . table_components
994
+ . zip ( fetch. table_ticks )
995
+ . unwrap_or_else ( || debug_checked_unreachable ( ) ) ;
996
+
997
+ MutBatch :: < T , N , ALIGN > {
998
+ value : table_components. get_batch_aligned_deref_mut :: < N , ALIGN > ( table_row_start, len) ,
999
+ ticks : TicksBatch {
1000
+ // SAFETY: [table_row_start..+batch.len()] is in range
1001
+ component_ticks : table_ticks
1002
+ . get_batch_aligned_deref_mut :: < N , ALIGN > ( table_row_start, len) ,
1003
+ change_tick : fetch. change_tick ,
1004
+ last_change_tick : fetch. last_change_tick ,
1005
+ } ,
1006
+ _marker : PhantomData ,
1007
+ }
1008
+ }
1009
+ }
1010
+
1013
1011
impl < T > Clone for WriteFetch < ' _ , T > {
1014
1012
fn clone ( & self ) -> Self {
1015
1013
Self {
@@ -1055,28 +1053,6 @@ where
1055
1053
}
1056
1054
}
1057
1055
1058
- impl < T : WorldQuery , const N : usize , const ALIGN : usize > WorldQueryBatch < N , ALIGN > for Option < T >
1059
- where
1060
- T : WorldQueryBatch < N , ALIGN > ,
1061
- {
1062
- #[ inline]
1063
- unsafe fn table_fetch_batched_aligned < ' w > (
1064
- fetch : & mut <Self as WorldQueryGats < ' w > >:: Fetch ,
1065
- table_row_start : usize ,
1066
- len : usize ,
1067
- ) -> <Self as WorldQueryBatchGats < ' w , N , ALIGN > >:: FullBatch {
1068
- if fetch. matches {
1069
- Some ( T :: table_fetch_batched_aligned (
1070
- & mut fetch. fetch ,
1071
- table_row_start,
1072
- len,
1073
- ) )
1074
- } else {
1075
- None
1076
- }
1077
- }
1078
- }
1079
-
1080
1056
// SAFETY: defers to soundness of `T: WorldQuery` impl
1081
1057
unsafe impl < T : WorldQuery > WorldQuery for Option < T > {
1082
1058
type ReadOnly = Option < T :: ReadOnly > ;
@@ -1179,6 +1155,28 @@ unsafe impl<T: WorldQuery> WorldQuery for Option<T> {
1179
1155
}
1180
1156
}
1181
1157
1158
+ impl < T : WorldQuery , const N : usize , const ALIGN : usize > WorldQueryBatch < N , ALIGN > for Option < T >
1159
+ where
1160
+ T : WorldQueryBatch < N , ALIGN > ,
1161
+ {
1162
+ #[ inline]
1163
+ unsafe fn table_fetch_batched_aligned < ' w > (
1164
+ fetch : & mut <Self as WorldQueryGats < ' w > >:: Fetch ,
1165
+ table_row_start : usize ,
1166
+ len : usize ,
1167
+ ) -> <Self as WorldQueryBatchGats < ' w , N , ALIGN > >:: FullBatch {
1168
+ if fetch. matches {
1169
+ Some ( T :: table_fetch_batched_aligned (
1170
+ & mut fetch. fetch ,
1171
+ table_row_start,
1172
+ len,
1173
+ ) )
1174
+ } else {
1175
+ None
1176
+ }
1177
+ }
1178
+ }
1179
+
1182
1180
/// SAFETY: [`OptionFetch`] is read only because `T` is read only
1183
1181
unsafe impl < T : ReadOnlyWorldQuery > ReadOnlyWorldQuery for Option < T > { }
1184
1182
@@ -1259,6 +1257,8 @@ impl<T: Component> ChangeTrackers<T> {
1259
1257
}
1260
1258
}
1261
1259
1260
+ /// A batch of [`ChangeTrackers`]. This is used when performing queries with Change Trackers using the
1261
+ /// [`Query::for_each_mut_batched`](crate::system::Query::for_each_mut_batched) and [`Query::for_each_batched`](crate::system::Query::for_each_batched) functions.
1262
1262
#[ derive( Clone ) ]
1263
1263
pub struct ChangeTrackersBatch < ' a , T , const N : usize , const ALIGN : usize >
1264
1264
where
@@ -1275,6 +1275,7 @@ where
1275
1275
ComponentTicks : AlignedBatchGat < N , ALIGN > ,
1276
1276
{
1277
1277
/// Returns true if this component has been added since the last execution of this system.
1278
+ #[ inline]
1278
1279
pub fn is_added ( & self ) -> bool {
1279
1280
self . component_ticks
1280
1281
. as_array ( )
@@ -1283,6 +1284,7 @@ where
1283
1284
}
1284
1285
1285
1286
/// Returns true if this component has been changed since the last execution of this system.
1287
+ #[ inline]
1286
1288
pub fn is_changed ( & self ) -> bool {
1287
1289
self . component_ticks
1288
1290
. as_array ( )
@@ -1615,15 +1617,6 @@ macro_rules! impl_tuple_fetch {
1615
1617
}
1616
1618
}
1617
1619
1618
- /// SAFETY: each item in the tuple is read only
1619
- unsafe impl <$( $name: ReadOnlyWorldQuery ) ,* > ReadOnlyWorldQuery for ( $( $name, ) * ) { }
1620
-
1621
- #[ allow( unused_variables) ]
1622
- #[ allow( non_snake_case) ]
1623
- impl <' w, const N : usize , const ALIGN : usize , $( $name: WorldQueryBatchGats <' w, N , ALIGN >) ,* > WorldQueryBatchGats <' w, N , ALIGN > for ( $( $name, ) * ) {
1624
- type FullBatch = ( $( $name:: FullBatch , ) * ) ;
1625
- }
1626
-
1627
1620
#[ allow( unused_variables) ]
1628
1621
#[ allow( non_snake_case) ]
1629
1622
#[ allow( clippy:: unused_unit) ]
@@ -1641,6 +1634,16 @@ macro_rules! impl_tuple_fetch {
1641
1634
( $( $name:: table_fetch_batched_aligned( $name, _table_row_start, _len) , ) * )
1642
1635
}
1643
1636
}
1637
+
1638
+ /// SAFETY: each item in the tuple is read only
1639
+ unsafe impl <$( $name: ReadOnlyWorldQuery ) ,* > ReadOnlyWorldQuery for ( $( $name, ) * ) { }
1640
+
1641
+ #[ allow( unused_variables) ]
1642
+ #[ allow( non_snake_case) ]
1643
+ impl <' w, const N : usize , const ALIGN : usize , $( $name: WorldQueryBatchGats <' w, N , ALIGN >) ,* > WorldQueryBatchGats <' w, N , ALIGN > for ( $( $name, ) * ) {
1644
+ type FullBatch = ( $( $name:: FullBatch , ) * ) ;
1645
+ }
1646
+
1644
1647
} ;
1645
1648
}
1646
1649
0 commit comments