@@ -421,7 +421,7 @@ pub trait Fetch<'world>: Sized {
421
421
///
422
422
/// Implementor must ensure that [`FetchState::update_component_access`] and
423
423
/// [`FetchState::update_archetype_component_access`] exactly reflects the results of
424
- /// [`FetchState::matches_archetype`], [`FetchState::matches_table `], [`Fetch::archetype_fetch`], and
424
+ /// [`FetchState::matches_component_set `], [`Fetch::archetype_fetch`], and
425
425
/// [`Fetch::table_fetch`].
426
426
pub unsafe trait FetchState : Send + Sync + Sized {
427
427
fn init ( world : & mut World ) -> Self ;
@@ -431,8 +431,7 @@ pub unsafe trait FetchState: Send + Sync + Sized {
431
431
archetype : & Archetype ,
432
432
access : & mut Access < ArchetypeComponentId > ,
433
433
) ;
434
- fn matches_archetype ( & self , archetype : & Archetype ) -> bool ;
435
- fn matches_table ( & self , table : & Table ) -> bool ;
434
+ fn matches_component_set ( & self , set_contains_id : & impl Fn ( ComponentId ) -> bool ) -> bool ;
436
435
}
437
436
438
437
/// A fetch that is read only.
@@ -480,12 +479,7 @@ unsafe impl FetchState for EntityState {
480
479
}
481
480
482
481
#[ inline]
483
- fn matches_archetype ( & self , _archetype : & Archetype ) -> bool {
484
- true
485
- }
486
-
487
- #[ inline]
488
- fn matches_table ( & self , _table : & Table ) -> bool {
482
+ fn matches_component_set ( & self , _set_contains_id : & impl Fn ( ComponentId ) -> bool ) -> bool {
489
483
true
490
484
}
491
485
}
@@ -588,12 +582,8 @@ unsafe impl<T: Component> FetchState for ReadState<T> {
588
582
}
589
583
}
590
584
591
- fn matches_archetype ( & self , archetype : & Archetype ) -> bool {
592
- archetype. contains ( self . component_id )
593
- }
594
-
595
- fn matches_table ( & self , table : & Table ) -> bool {
596
- table. has_column ( self . component_id )
585
+ fn matches_component_set ( & self , set_contains_id : & impl Fn ( ComponentId ) -> bool ) -> bool {
586
+ set_contains_id ( self . component_id )
597
587
}
598
588
}
599
589
@@ -825,12 +815,8 @@ unsafe impl<T: Component> FetchState for WriteState<T> {
825
815
}
826
816
}
827
817
828
- fn matches_archetype ( & self , archetype : & Archetype ) -> bool {
829
- archetype. contains ( self . component_id )
830
- }
831
-
832
- fn matches_table ( & self , table : & Table ) -> bool {
833
- table. has_column ( self . component_id )
818
+ fn matches_component_set ( & self , set_contains_id : & impl Fn ( ComponentId ) -> bool ) -> bool {
819
+ set_contains_id ( self . component_id )
834
820
}
835
821
}
836
822
@@ -1105,17 +1091,16 @@ unsafe impl<T: FetchState> FetchState for OptionState<T> {
1105
1091
archetype : & Archetype ,
1106
1092
access : & mut Access < ArchetypeComponentId > ,
1107
1093
) {
1108
- if self . state . matches_archetype ( archetype) {
1094
+ if self
1095
+ . state
1096
+ . matches_component_set ( & |id| archetype. contains ( id) )
1097
+ {
1109
1098
self . state
1110
1099
. update_archetype_component_access ( archetype, access) ;
1111
1100
}
1112
1101
}
1113
1102
1114
- fn matches_archetype ( & self , _archetype : & Archetype ) -> bool {
1115
- true
1116
- }
1117
-
1118
- fn matches_table ( & self , _table : & Table ) -> bool {
1103
+ fn matches_component_set ( & self , _set_contains_id : & impl Fn ( ComponentId ) -> bool ) -> bool {
1119
1104
true
1120
1105
}
1121
1106
}
@@ -1153,15 +1138,19 @@ impl<'w, T: Fetch<'w>> Fetch<'w> for OptionFetch<T> {
1153
1138
archetype : & ' w Archetype ,
1154
1139
tables : & ' w Tables ,
1155
1140
) {
1156
- self . matches = state. state . matches_archetype ( archetype) ;
1141
+ self . matches = state
1142
+ . state
1143
+ . matches_component_set ( & |id| archetype. contains ( id) ) ;
1157
1144
if self . matches {
1158
1145
self . fetch . set_archetype ( & state. state , archetype, tables) ;
1159
1146
}
1160
1147
}
1161
1148
1162
1149
#[ inline]
1163
1150
unsafe fn set_table ( & mut self , state : & Self :: State , table : & ' w Table ) {
1164
- self . matches = state. state . matches_table ( table) ;
1151
+ self . matches = state
1152
+ . state
1153
+ . matches_component_set ( & |id| table. has_column ( id) ) ;
1165
1154
if self . matches {
1166
1155
self . fetch . set_table ( & state. state , table) ;
1167
1156
}
@@ -1297,12 +1286,8 @@ unsafe impl<T: Component> FetchState for ChangeTrackersState<T> {
1297
1286
}
1298
1287
}
1299
1288
1300
- fn matches_archetype ( & self , archetype : & Archetype ) -> bool {
1301
- archetype. contains ( self . component_id )
1302
- }
1303
-
1304
- fn matches_table ( & self , table : & Table ) -> bool {
1305
- table. has_column ( self . component_id )
1289
+ fn matches_component_set ( & self , set_contains_id : & impl Fn ( ComponentId ) -> bool ) -> bool {
1290
+ set_contains_id ( self . component_id )
1306
1291
}
1307
1292
}
1308
1293
@@ -1551,14 +1536,9 @@ macro_rules! impl_tuple_fetch {
1551
1536
$( $name. update_archetype_component_access( _archetype, _access) ; ) *
1552
1537
}
1553
1538
1554
- fn matches_archetype( & self , _archetype: & Archetype ) -> bool {
1555
- let ( $( $name, ) * ) = self ;
1556
- true $( && $name. matches_archetype( _archetype) ) *
1557
- }
1558
-
1559
- fn matches_table( & self , _table: & Table ) -> bool {
1539
+ fn matches_component_set( & self , _set_contains_id: & impl Fn ( ComponentId ) -> bool ) -> bool {
1560
1540
let ( $( $name, ) * ) = self ;
1561
- true $( && $name. matches_table ( _table ) ) *
1541
+ true $( && $name. matches_component_set ( _set_contains_id ) ) *
1562
1542
}
1563
1543
}
1564
1544
@@ -1618,7 +1598,7 @@ macro_rules! impl_anytuple_fetch {
1618
1598
let ( $( $name, ) * ) = & mut self . 0 ;
1619
1599
let ( $( $state, ) * ) = & _state. 0 ;
1620
1600
$(
1621
- $name. 1 = $state. matches_archetype ( _archetype) ;
1601
+ $name. 1 = $state. matches_component_set ( & |id| _archetype. contains ( id ) ) ;
1622
1602
if $name. 1 {
1623
1603
$name. 0 . set_archetype( $state, _archetype, _tables) ;
1624
1604
}
@@ -1630,7 +1610,7 @@ macro_rules! impl_anytuple_fetch {
1630
1610
let ( $( $name, ) * ) = & mut self . 0 ;
1631
1611
let ( $( $state, ) * ) = & _state. 0 ;
1632
1612
$(
1633
- $name. 1 = $state. matches_table ( _table) ;
1613
+ $name. 1 = $state. matches_component_set ( & |id| _table. has_column ( id ) ) ;
1634
1614
if $name. 1 {
1635
1615
$name. 0 . set_table( $state, _table) ;
1636
1616
}
@@ -1699,20 +1679,14 @@ macro_rules! impl_anytuple_fetch {
1699
1679
fn update_archetype_component_access( & self , _archetype: & Archetype , _access: & mut Access <ArchetypeComponentId >) {
1700
1680
let ( $( $name, ) * ) = & self . 0 ;
1701
1681
$(
1702
- if $name. matches_archetype ( _archetype) {
1682
+ if $name. matches_component_set ( & |id| _archetype. contains ( id ) ) {
1703
1683
$name. update_archetype_component_access( _archetype, _access) ;
1704
1684
}
1705
1685
) *
1706
1686
}
1707
-
1708
- fn matches_archetype( & self , _archetype: & Archetype ) -> bool {
1709
- let ( $( $name, ) * ) = & self . 0 ;
1710
- false $( || $name. matches_archetype( _archetype) ) *
1711
- }
1712
-
1713
- fn matches_table( & self , _table: & Table ) -> bool {
1687
+ fn matches_component_set( & self , _set_contains_id: & impl Fn ( ComponentId ) -> bool ) -> bool {
1714
1688
let ( $( $name, ) * ) = & self . 0 ;
1715
- false $( || $name. matches_table ( _table ) ) *
1689
+ false $( || $name. matches_component_set ( _set_contains_id ) ) *
1716
1690
}
1717
1691
}
1718
1692
0 commit comments