1
1
use core:: { any:: TypeId , hash:: Hash } ;
2
2
use std:: { boxed:: Box , vec:: Vec } ;
3
3
4
- use crate :: { Archetype , World } ;
4
+ use crate :: { Archetype , ComponentId , World } ;
5
5
use bevy_utils:: HashSet ;
6
6
7
7
#[ derive( Debug , Copy , Clone , Ord , PartialOrd , Eq , PartialEq ) ]
@@ -14,52 +14,53 @@ pub enum Access {
14
14
#[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash ) ]
15
15
pub struct ArchetypeComponent {
16
16
pub archetype_index : u32 ,
17
- pub component : TypeId ,
17
+ pub component : ComponentId ,
18
18
}
19
19
20
20
impl ArchetypeComponent {
21
21
#[ inline]
22
22
pub fn new < T : ' static > ( archetype_index : u32 ) -> Self {
23
23
ArchetypeComponent {
24
24
archetype_index,
25
- component : TypeId :: of :: < T > ( ) ,
25
+ component : TypeId :: of :: < T > ( ) . into ( ) ,
26
26
}
27
27
}
28
28
29
29
#[ inline]
30
- pub fn new_ty ( archetype_index : u32 , component : TypeId ) -> Self {
30
+ pub fn new_component ( archetype_index : u32 , component : ComponentId ) -> Self {
31
31
ArchetypeComponent {
32
32
archetype_index,
33
33
component,
34
34
}
35
35
}
36
36
}
37
37
38
+ #[ derive( Clone , Debug ) ]
38
39
pub enum QueryAccess {
39
40
None ,
40
- Read ( TypeId , & ' static str ) ,
41
- Write ( TypeId , & ' static str ) ,
41
+ Read ( ComponentId , & ' static str ) ,
42
+ Write ( ComponentId , & ' static str ) ,
42
43
Optional ( Box < QueryAccess > ) ,
43
- With ( TypeId , Box < QueryAccess > ) ,
44
- Without ( TypeId , Box < QueryAccess > ) ,
44
+ With ( ComponentId , Box < QueryAccess > ) ,
45
+ Without ( ComponentId , Box < QueryAccess > ) ,
45
46
Union ( Vec < QueryAccess > ) ,
46
47
}
47
48
48
49
impl QueryAccess {
49
50
pub fn read < T : ' static > ( ) -> QueryAccess {
50
- QueryAccess :: Read ( TypeId :: of :: < T > ( ) , std:: any:: type_name :: < T > ( ) )
51
+ QueryAccess :: Read ( TypeId :: of :: < T > ( ) . into ( ) , std:: any:: type_name :: < T > ( ) )
51
52
}
52
53
53
54
pub fn write < T : ' static > ( ) -> QueryAccess {
54
- QueryAccess :: Write ( TypeId :: of :: < T > ( ) , std:: any:: type_name :: < T > ( ) )
55
+ QueryAccess :: Write ( TypeId :: of :: < T > ( ) . into ( ) , std:: any:: type_name :: < T > ( ) )
55
56
}
56
57
57
58
pub fn with < T : ' static > ( access : QueryAccess ) -> QueryAccess {
58
- QueryAccess :: With ( TypeId :: of :: < T > ( ) , Box :: new ( access) )
59
+ QueryAccess :: With ( TypeId :: of :: < T > ( ) . into ( ) , Box :: new ( access) )
59
60
}
60
61
61
62
pub fn without < T : ' static > ( access : QueryAccess ) -> QueryAccess {
62
- QueryAccess :: Without ( TypeId :: of :: < T > ( ) , Box :: new ( access) )
63
+ QueryAccess :: Without ( TypeId :: of :: < T > ( ) . into ( ) , Box :: new ( access) )
63
64
}
64
65
65
66
pub fn optional ( access : QueryAccess ) -> QueryAccess {
@@ -82,29 +83,29 @@ impl QueryAccess {
82
83
}
83
84
}
84
85
85
- pub fn get_type_name ( & self , type_id : TypeId ) -> Option < & ' static str > {
86
+ pub fn get_type_name ( & self , component_id : ComponentId ) -> Option < & ' static str > {
86
87
match self {
87
88
QueryAccess :: None => None ,
88
- QueryAccess :: Read ( current_type_id , name) => {
89
- if type_id == * current_type_id {
89
+ QueryAccess :: Read ( current_component_id , name) => {
90
+ if component_id == * current_component_id {
90
91
Some ( * name)
91
92
} else {
92
93
None
93
94
}
94
95
}
95
- QueryAccess :: Write ( current_type_id , name) => {
96
- if type_id == * current_type_id {
96
+ QueryAccess :: Write ( current_component_id , name) => {
97
+ if component_id == * current_component_id {
97
98
Some ( * name)
98
99
} else {
99
100
None
100
101
}
101
102
}
102
- QueryAccess :: Optional ( query_access) => query_access. get_type_name ( type_id ) ,
103
- QueryAccess :: With ( _, query_access) => query_access. get_type_name ( type_id ) ,
104
- QueryAccess :: Without ( _, query_access) => query_access. get_type_name ( type_id ) ,
103
+ QueryAccess :: Optional ( query_access) => query_access. get_type_name ( component_id ) ,
104
+ QueryAccess :: With ( _, query_access) => query_access. get_type_name ( component_id ) ,
105
+ QueryAccess :: Without ( _, query_access) => query_access. get_type_name ( component_id ) ,
105
106
QueryAccess :: Union ( query_accesses) => {
106
107
for query_access in query_accesses. iter ( ) {
107
- if let Some ( name) = query_access. get_type_name ( type_id ) {
108
+ if let Some ( name) = query_access. get_type_name ( component_id ) {
108
109
return Some ( name) ;
109
110
}
110
111
}
@@ -125,19 +126,21 @@ impl QueryAccess {
125
126
match self {
126
127
QueryAccess :: None => Some ( Access :: None ) ,
127
128
QueryAccess :: Read ( ty, _) => {
128
- if archetype. has_type ( * ty) {
129
+ if archetype. has_component ( * ty) {
129
130
if let Some ( type_access) = type_access {
130
- type_access. add_read ( ArchetypeComponent :: new_ty ( archetype_index, * ty) ) ;
131
+ type_access
132
+ . add_read ( ArchetypeComponent :: new_component ( archetype_index, * ty) ) ;
131
133
}
132
134
Some ( Access :: Read )
133
135
} else {
134
136
None
135
137
}
136
138
}
137
139
QueryAccess :: Write ( ty, _) => {
138
- if archetype. has_type ( * ty) {
140
+ if archetype. has_component ( * ty) {
139
141
if let Some ( type_access) = type_access {
140
- type_access. add_write ( ArchetypeComponent :: new_ty ( archetype_index, * ty) ) ;
142
+ type_access
143
+ . add_write ( ArchetypeComponent :: new_component ( archetype_index, * ty) ) ;
141
144
}
142
145
Some ( Access :: Write )
143
146
} else {
@@ -157,14 +160,14 @@ impl QueryAccess {
157
160
}
158
161
}
159
162
QueryAccess :: With ( ty, query_access) => {
160
- if archetype. has_type ( * ty) {
163
+ if archetype. has_component ( * ty) {
161
164
query_access. get_access ( archetype, archetype_index, type_access)
162
165
} else {
163
166
None
164
167
}
165
168
}
166
169
QueryAccess :: Without ( ty, query_access) => {
167
- if !archetype. has_type ( * ty) {
170
+ if !archetype. has_component ( * ty) {
168
171
query_access. get_access ( archetype, archetype_index, type_access)
169
172
} else {
170
173
None
@@ -308,7 +311,7 @@ mod tests {
308
311
let e3_c = ArchetypeComponent :: new :: < C > ( e3_archetype) ;
309
312
310
313
let mut a_type_access = TypeAccess :: default ( ) ;
311
- <( & A , ) as Query >:: Fetch :: access ( )
314
+ <( & A , ) as Query >:: Fetch :: access ( & ( ) )
312
315
. get_world_archetype_access ( & world, Some ( & mut a_type_access) ) ;
313
316
314
317
assert_eq ! (
@@ -317,7 +320,7 @@ mod tests {
317
320
) ;
318
321
319
322
let mut a_b_type_access = TypeAccess :: default ( ) ;
320
- <( & A , & B ) as Query >:: Fetch :: access ( )
323
+ <( & A , & B ) as Query >:: Fetch :: access ( & ( ) )
321
324
. get_world_archetype_access ( & world, Some ( & mut a_b_type_access) ) ;
322
325
323
326
assert_eq ! (
@@ -326,7 +329,7 @@ mod tests {
326
329
) ;
327
330
328
331
let mut a_bmut_type_access = TypeAccess :: default ( ) ;
329
- <( & A , & mut B ) as Query >:: Fetch :: access ( )
332
+ <( & A , & mut B ) as Query >:: Fetch :: access ( & ( ) )
330
333
. get_world_archetype_access ( & world, Some ( & mut a_bmut_type_access) ) ;
331
334
332
335
assert_eq ! (
@@ -335,7 +338,7 @@ mod tests {
335
338
) ;
336
339
337
340
let mut a_option_bmut_type_access = TypeAccess :: default ( ) ;
338
- <( Entity , & A , Option < & mut B > ) as Query >:: Fetch :: access ( )
341
+ <( Entity , & A , Option < & mut B > ) as Query >:: Fetch :: access ( & ( ) )
339
342
. get_world_archetype_access ( & world, Some ( & mut a_option_bmut_type_access) ) ;
340
343
341
344
assert_eq ! (
@@ -344,7 +347,7 @@ mod tests {
344
347
) ;
345
348
346
349
let mut a_with_b_type_access = TypeAccess :: default ( ) ;
347
- <With < B , & A > as Query >:: Fetch :: access ( )
350
+ <With < B , & A > as Query >:: Fetch :: access ( & ( ) )
348
351
. get_world_archetype_access ( & world, Some ( & mut a_with_b_type_access) ) ;
349
352
350
353
assert_eq ! (
@@ -353,7 +356,7 @@ mod tests {
353
356
) ;
354
357
355
358
let mut a_with_b_option_c_type_access = TypeAccess :: default ( ) ;
356
- <With < B , ( & A , Option < & mut C > ) > as Query >:: Fetch :: access ( )
359
+ <With < B , ( & A , Option < & mut C > ) > as Query >:: Fetch :: access ( & ( ) )
357
360
. get_world_archetype_access ( & world, Some ( & mut a_with_b_option_c_type_access) ) ;
358
361
359
362
assert_eq ! (
0 commit comments