@@ -3,7 +3,7 @@ use bevy_ecs::{
3
3
component:: { ComponentId , Tick } ,
4
4
entity:: Entity ,
5
5
ptr:: UnsafeCellDeref ,
6
- query:: { QueryItem , ReadOnlyWorldQuery , WorldQuery } ,
6
+ query:: { QueryData , QueryItem , ReadOnlyQueryData , WorldQuery } ,
7
7
storage:: { SparseSets , Table , TableRow } ,
8
8
world:: { unsafe_world_cell:: UnsafeWorldCell , World } ,
9
9
} ;
@@ -58,7 +58,7 @@ impl<'a, Trait: ?Sized + TraitQuery> Iterator for ReadTableTraitsIter<'a, Trait>
58
58
let ptr = unsafe {
59
59
column
60
60
. get_data_ptr ( )
61
- . byte_add ( self . table_row . index ( ) * meta. size_bytes )
61
+ . byte_add ( self . table_row . as_usize ( ) * meta. size_bytes )
62
62
} ;
63
63
let trait_object = unsafe { meta. dyn_ctor . cast ( ptr) } ;
64
64
@@ -130,7 +130,7 @@ impl<'w, Trait: ?Sized + TraitQuery> IntoIterator for ReadTraits<'w, Trait> {
130
130
let sparse = ReadSparseTraitsIter {
131
131
components : self . registry . sparse_components . iter ( ) ,
132
132
meta : self . registry . sparse_meta . iter ( ) ,
133
- entity : self . table . entities ( ) [ self . table_row . index ( ) ] ,
133
+ entity : self . table . entities ( ) [ self . table_row . as_usize ( ) ] ,
134
134
sparse_sets : self . sparse_sets ,
135
135
last_run : self . last_run ,
136
136
this_run : self . this_run ,
@@ -155,7 +155,7 @@ impl<'w, Trait: ?Sized + TraitQuery> IntoIterator for &ReadTraits<'w, Trait> {
155
155
let sparse = ReadSparseTraitsIter {
156
156
components : self . registry . sparse_components . iter ( ) ,
157
157
meta : self . registry . sparse_meta . iter ( ) ,
158
- entity : self . table . entities ( ) [ self . table_row . index ( ) ] ,
158
+ entity : self . table . entities ( ) [ self . table_row . as_usize ( ) ] ,
159
159
sparse_sets : self . sparse_sets ,
160
160
last_run : self . last_run ,
161
161
this_run : self . this_run ,
@@ -246,7 +246,7 @@ impl<'a, Trait: ?Sized + TraitQuery> Iterator for WriteTableTraitsIter<'a, Trait
246
246
let ptr = unsafe {
247
247
column
248
248
. get_data_ptr ( )
249
- . byte_add ( self . table_row . index ( ) * meta. size_bytes )
249
+ . byte_add ( self . table_row . as_usize ( ) * meta. size_bytes )
250
250
} ;
251
251
// SAFETY: The instance of `WriteTraits` that created this iterator
252
252
// has exclusive access to all table components registered with the trait.
@@ -375,7 +375,7 @@ impl<'w, Trait: ?Sized + TraitQuery> IntoIterator for WriteTraits<'w, Trait> {
375
375
let sparse = WriteSparseTraitsIter {
376
376
components : self . registry . sparse_components . iter ( ) ,
377
377
meta : self . registry . sparse_meta . iter ( ) ,
378
- entity : self . table . entities ( ) [ self . table_row . index ( ) ] ,
378
+ entity : self . table . entities ( ) [ self . table_row . as_usize ( ) ] ,
379
379
sparse_sets : self . sparse_sets ,
380
380
last_run : self . last_run ,
381
381
this_run : self . this_run ,
@@ -402,7 +402,7 @@ impl<'world, 'local, Trait: ?Sized + TraitQuery> IntoIterator
402
402
let sparse = ReadSparseTraitsIter {
403
403
components : self . registry . sparse_components . iter ( ) ,
404
404
meta : self . registry . sparse_meta . iter ( ) ,
405
- entity : self . table . entities ( ) [ self . table_row . index ( ) ] ,
405
+ entity : self . table . entities ( ) [ self . table_row . as_usize ( ) ] ,
406
406
sparse_sets : self . sparse_sets ,
407
407
last_run : self . last_run ,
408
408
this_run : self . this_run ,
@@ -429,7 +429,7 @@ impl<'world, 'local, Trait: ?Sized + TraitQuery> IntoIterator
429
429
let sparse = WriteSparseTraitsIter {
430
430
components : self . registry . sparse_components . iter ( ) ,
431
431
meta : self . registry . sparse_meta . iter ( ) ,
432
- entity : self . table . entities ( ) [ self . table_row . index ( ) ] ,
432
+ entity : self . table . entities ( ) [ self . table_row . as_usize ( ) ] ,
433
433
sparse_sets : self . sparse_sets ,
434
434
last_run : self . last_run ,
435
435
this_run : self . this_run ,
@@ -443,15 +443,17 @@ impl<'world, 'local, Trait: ?Sized + TraitQuery> IntoIterator
443
443
/// You can usually just use `&dyn Trait` or `&mut dyn Trait` as a `WorldQuery` directly.
444
444
pub struct All < T : ?Sized > ( T ) ;
445
445
446
- unsafe impl < ' a , Trait : ?Sized + TraitQuery > ReadOnlyWorldQuery for All < & ' a Trait > { }
446
+ unsafe impl < ' a , Trait : ?Sized + TraitQuery > QueryData for All < & ' a Trait > {
447
+ type ReadOnly = Self ;
448
+ }
449
+ unsafe impl < ' a , Trait : ?Sized + TraitQuery > ReadOnlyQueryData for All < & ' a Trait > { }
447
450
448
451
// SAFETY: We only access the components registered in the trait registry.
449
452
// This is known to match the set of components in the TraitQueryState,
450
453
// which is used to match archetypes and register world access.
451
454
unsafe impl < ' a , Trait : ?Sized + TraitQuery > WorldQuery for All < & ' a Trait > {
452
455
type Item < ' w > = ReadTraits < ' w , Trait > ;
453
456
type Fetch < ' w > = AllTraitsFetch < ' w , Trait > ;
454
- type ReadOnly = Self ;
455
457
type State = TraitQueryState < Trait > ;
456
458
457
459
#[ inline]
@@ -478,7 +480,6 @@ unsafe impl<'a, Trait: ?Sized + TraitQuery> WorldQuery for All<&'a Trait> {
478
480
}
479
481
480
482
const IS_DENSE : bool = false ;
481
- const IS_ARCHETYPAL : bool = false ;
482
483
483
484
#[ inline]
484
485
unsafe fn set_archetype < ' w > (
@@ -521,33 +522,38 @@ unsafe impl<'a, Trait: ?Sized + TraitQuery> WorldQuery for All<&'a Trait> {
521
522
state : & Self :: State ,
522
523
access : & mut bevy_ecs:: query:: FilteredAccess < ComponentId > ,
523
524
) {
525
+ let mut not_first = false ;
526
+ let mut new_access = access. clone ( ) ;
524
527
for & component in & * state. components {
525
528
assert ! (
526
529
!access. access( ) . has_write( component) ,
527
530
"&{} conflicts with a previous access in this query. Shared access cannot coincide with exclusive access." ,
528
531
std:: any:: type_name:: <Trait >( ) ,
529
532
) ;
530
- access. add_read ( component) ;
531
- }
532
- }
533
-
534
- #[ inline]
535
- fn update_archetype_component_access (
536
- state : & Self :: State ,
537
- archetype : & bevy_ecs:: archetype:: Archetype ,
538
- access : & mut bevy_ecs:: query:: Access < bevy_ecs:: archetype:: ArchetypeComponentId > ,
539
- ) {
540
- for & component in & * state. components {
541
- if let Some ( archetype_component_id) = archetype. get_archetype_component_id ( component) {
542
- access. add_read ( archetype_component_id) ;
533
+ if not_first {
534
+ let mut intermediate = access. clone ( ) ;
535
+ intermediate. add_read ( component) ;
536
+ new_access. append_or ( & intermediate) ;
537
+ new_access. extend_access ( & intermediate) ;
538
+ } else {
539
+ new_access. and_with ( component) ;
540
+ new_access. access_mut ( ) . add_read ( component) ;
541
+ not_first = true ;
543
542
}
544
543
}
544
+ * access = new_access;
545
545
}
546
546
547
547
#[ inline]
548
548
fn init_state ( world : & mut World ) -> Self :: State {
549
549
TraitQueryState :: init ( world)
550
550
}
551
+
552
+ #[ inline]
553
+ fn get_state ( world : & World ) -> Option < Self :: State > {
554
+ TraitQueryState :: get ( world)
555
+ }
556
+
551
557
#[ inline]
552
558
fn matches_component_set (
553
559
state : & Self :: State ,
@@ -557,13 +563,16 @@ unsafe impl<'a, Trait: ?Sized + TraitQuery> WorldQuery for All<&'a Trait> {
557
563
}
558
564
}
559
565
566
+ unsafe impl < ' a , Trait : ?Sized + TraitQuery > QueryData for All < & ' a mut Trait > {
567
+ type ReadOnly = All < & ' a Trait > ;
568
+ }
569
+
560
570
// SAFETY: We only access the components registered in the trait registry.
561
571
// This is known to match the set of components in the TraitQueryState,
562
572
// which is used to match archetypes and register world access.
563
573
unsafe impl < ' a , Trait : ?Sized + TraitQuery > WorldQuery for All < & ' a mut Trait > {
564
574
type Item < ' w > = WriteTraits < ' w , Trait > ;
565
575
type Fetch < ' w > = AllTraitsFetch < ' w , Trait > ;
566
- type ReadOnly = All < & ' a Trait > ;
567
576
type State = TraitQueryState < Trait > ;
568
577
569
578
#[ inline]
@@ -590,7 +599,6 @@ unsafe impl<'a, Trait: ?Sized + TraitQuery> WorldQuery for All<&'a mut Trait> {
590
599
}
591
600
592
601
const IS_DENSE : bool = false ;
593
- const IS_ARCHETYPAL : bool = false ;
594
602
595
603
#[ inline]
596
604
unsafe fn set_archetype < ' w > (
@@ -634,33 +642,38 @@ unsafe impl<'a, Trait: ?Sized + TraitQuery> WorldQuery for All<&'a mut Trait> {
634
642
state : & Self :: State ,
635
643
access : & mut bevy_ecs:: query:: FilteredAccess < ComponentId > ,
636
644
) {
645
+ let mut not_first = false ;
646
+ let mut new_access = access. clone ( ) ;
637
647
for & component in & * state. components {
638
648
assert ! (
639
649
!access. access( ) . has_write( component) ,
640
650
"&mut {} conflicts with a previous access in this query. Mutable component access must be unique." ,
641
651
std:: any:: type_name:: <Trait >( ) ,
642
652
) ;
643
- access. add_write ( component) ;
644
- }
645
- }
646
-
647
- #[ inline]
648
- fn update_archetype_component_access (
649
- state : & Self :: State ,
650
- archetype : & bevy_ecs:: archetype:: Archetype ,
651
- access : & mut bevy_ecs:: query:: Access < bevy_ecs:: archetype:: ArchetypeComponentId > ,
652
- ) {
653
- for & component in & * state. components {
654
- if let Some ( archetype_component_id) = archetype. get_archetype_component_id ( component) {
655
- access. add_write ( archetype_component_id) ;
653
+ if not_first {
654
+ let mut intermediate = access. clone ( ) ;
655
+ intermediate. add_write ( component) ;
656
+ new_access. append_or ( & intermediate) ;
657
+ new_access. extend_access ( & intermediate) ;
658
+ } else {
659
+ new_access. and_with ( component) ;
660
+ new_access. access_mut ( ) . add_write ( component) ;
661
+ not_first = true ;
656
662
}
657
663
}
664
+ * access = new_access;
658
665
}
659
666
660
667
#[ inline]
661
668
fn init_state ( world : & mut World ) -> Self :: State {
662
669
TraitQueryState :: init ( world)
663
670
}
671
+
672
+ #[ inline]
673
+ fn get_state ( world : & World ) -> Option < Self :: State > {
674
+ TraitQueryState :: get ( world)
675
+ }
676
+
664
677
#[ inline]
665
678
fn matches_component_set (
666
679
state : & Self :: State ,
0 commit comments