@@ -178,88 +178,83 @@ fn get_idents(fmt_string: fn(usize) -> String, count: usize) -> Vec<Ident> {
178
178
}
179
179
180
180
#[ proc_macro]
181
- pub fn impl_query_set ( _input : TokenStream ) -> TokenStream {
181
+ pub fn impl_param_set ( _input : TokenStream ) -> TokenStream {
182
182
let mut tokens = TokenStream :: new ( ) ;
183
- let max_queries = 4 ;
184
- let queries = get_idents ( |i| format ! ( "Q{}" , i) , max_queries) ;
185
- let filters = get_idents ( |i| format ! ( "F{}" , i) , max_queries) ;
186
- let mut query_fn_muts = Vec :: new ( ) ;
187
- for i in 0 ..max_queries {
188
- let query = & queries[ i] ;
189
- let filter = & filters[ i] ;
190
- let fn_name = Ident :: new ( & format ! ( "q{}" , i) , Span :: call_site ( ) ) ;
183
+ let max_params = 8 ;
184
+ let params = get_idents ( |i| format ! ( "P{}" , i) , max_params) ;
185
+ let params_fetch = get_idents ( |i| format ! ( "PF{}" , i) , max_params) ;
186
+ let metas = get_idents ( |i| format ! ( "m{}" , i) , max_params) ;
187
+ let mut param_fn_muts = Vec :: new ( ) ;
188
+ for ( i, param) in params. iter ( ) . enumerate ( ) {
189
+ let fn_name = Ident :: new ( & format ! ( "p{}" , i) , Span :: call_site ( ) ) ;
191
190
let index = Index :: from ( i) ;
192
- query_fn_muts . push ( quote ! {
193
- pub fn #fn_name( & mut self ) -> Query < ' _ , ' _ , #query , #filter> {
191
+ param_fn_muts . push ( quote ! {
192
+ pub fn #fn_name< ' a> ( & ' a mut self ) -> <#param :: Fetch as SystemParamFetch < ' a , ' a>> :: Item {
194
193
// SAFE: systems run without conflicts with other systems.
195
- // Conflicting queries in QuerySet are not accessible at the same time
196
- // QuerySets are guaranteed to not conflict with other SystemParams
194
+ // Conflicting params in ParamSet are not accessible at the same time
195
+ // ParamSets are guaranteed to not conflict with other SystemParams
197
196
unsafe {
198
- Query :: new ( self . world , & self . query_states . #index, self . last_change_tick , self . change_tick)
197
+ <#param :: Fetch as SystemParamFetch < ' a , ' a>> :: get_param ( & mut self . param_states . #index, & self . system_meta , self . world , self . change_tick)
199
198
}
200
199
}
201
200
} ) ;
202
201
}
203
202
204
- for query_count in 1 ..=max_queries {
205
- let query = & queries[ 0 ..query_count] ;
206
- let filter = & filters[ 0 ..query_count] ;
207
- let query_fn_mut = & query_fn_muts[ 0 ..query_count] ;
203
+ for param_count in 1 ..=max_params {
204
+ let param = & params[ 0 ..param_count] ;
205
+ let param_fetch = & params_fetch[ 0 ..param_count] ;
206
+ let meta = & metas[ 0 ..param_count] ;
207
+ let param_fn_mut = & param_fn_muts[ 0 ..param_count] ;
208
208
tokens. extend ( TokenStream :: from ( quote ! {
209
- impl <' w, ' s, #( #query: WorldQuery + ' static , ) * #( #filter: WorldQuery + ' static , ) * > SystemParam for QuerySet <' w, ' s, ( #( QueryState <#query, #filter>, ) * ) >
210
- where #( #filter:: Fetch : FilterFetch , ) *
209
+ impl <' w, ' s, #( #param: SystemParam , ) * > SystemParam for ParamSet <' w, ' s, ( #( #param, ) * ) >
211
210
{
212
- type Fetch = QuerySetState <( #( QueryState <#query , #filter> , ) * ) >;
211
+ type Fetch = ParamSetState <( #( #param :: Fetch , ) * ) >;
213
212
}
214
213
215
- // SAFE: All Queries are constrained to ReadOnlyFetch, so World is only read
216
- unsafe impl <#( #query: WorldQuery + ' static , ) * #( #filter: WorldQuery + ' static , ) * > ReadOnlySystemParamFetch for QuerySetState <( #( QueryState <#query, #filter>, ) * ) >
217
- where #( #query:: Fetch : ReadOnlyFetch , ) * #( #filter:: Fetch : FilterFetch , ) *
214
+ // SAFE: All parameters are constrained to ReadOnlyFetch, so World is only read
215
+
216
+ unsafe impl <#( #param_fetch: for <' w1, ' s1> SystemParamFetch <' w1, ' s1>, ) * > ReadOnlySystemParamFetch for ParamSetState <( #( #param_fetch, ) * ) >
217
+ where #( #param_fetch: ReadOnlySystemParamFetch , ) *
218
218
{ }
219
219
220
- // SAFE: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemMeta. If any QueryState conflicts
220
+ // SAFE: Relevant parameter ComponentId and ArchetypeComponentId access is applied to SystemMeta. If any ParamState conflicts
221
221
// with any prior access, a panic will occur.
222
- unsafe impl <# ( #query : WorldQuery + ' static , ) * # ( #filter : WorldQuery + ' static , ) * > SystemParamState for QuerySetState < ( # ( QueryState <#query , #filter> , ) * ) >
223
- where #( #filter :: Fetch : FilterFetch , ) *
222
+
223
+ unsafe impl <# ( #param_fetch : for < ' w1 , ' s1> SystemParamFetch < ' w1 , ' s1> , ) * > SystemParamState for ParamSetState < ( #( #param_fetch , ) * ) >
224
224
{
225
225
fn init( world: & mut World , system_meta: & mut SystemMeta ) -> Self {
226
226
#(
227
- let mut #query = QueryState :: <#query, #filter>:: new( world) ;
228
- assert_component_access_compatibility(
229
- & system_meta. name,
230
- std:: any:: type_name:: <#query>( ) ,
231
- std:: any:: type_name:: <#filter>( ) ,
232
- & system_meta. component_access_set,
233
- & #query. component_access,
234
- world,
235
- ) ;
227
+ // Pretend to add each param to the system alone, see if it conflicts
228
+ let mut #meta = system_meta. clone( ) ;
229
+ #meta. component_access_set. clear( ) ;
230
+ #meta. archetype_component_access. clear( ) ;
231
+ #param_fetch:: init( world, & mut #meta) ;
232
+ let #param = #param_fetch:: init( world, & mut system_meta. clone( ) ) ;
236
233
) *
237
234
#(
238
235
system_meta
239
236
. component_access_set
240
- . add ( #query . component_access . clone ( ) ) ;
237
+ . extend ( #meta . component_access_set ) ;
241
238
system_meta
242
239
. archetype_component_access
243
- . extend( & #query . archetype_component_access) ;
240
+ . extend( & #meta . archetype_component_access) ;
244
241
) *
245
- QuerySetState ( ( #( #query , ) * ) )
242
+ ParamSetState ( ( #( #param , ) * ) )
246
243
}
247
244
248
245
fn new_archetype( & mut self , archetype: & Archetype , system_meta: & mut SystemMeta ) {
249
- let ( #( #query , ) * ) = & mut self . 0 ;
246
+ let ( #( #param , ) * ) = & mut self . 0 ;
250
247
#(
251
- #query. new_archetype( archetype) ;
252
- system_meta
253
- . archetype_component_access
254
- . extend( & #query. archetype_component_access) ;
248
+ #param. new_archetype( archetype, system_meta) ;
255
249
) *
256
250
}
257
251
}
258
252
259
- impl <' w, ' s, #( #query: WorldQuery + ' static , ) * #( #filter: WorldQuery + ' static , ) * > SystemParamFetch <' w, ' s> for QuerySetState <( #( QueryState <#query, #filter>, ) * ) >
260
- where #( #filter:: Fetch : FilterFetch , ) *
253
+
254
+
255
+ impl <' w, ' s, #( #param_fetch: for <' w1, ' s1> SystemParamFetch <' w1, ' s1>, ) * > SystemParamFetch <' w, ' s> for ParamSetState <( #( #param_fetch, ) * ) >
261
256
{
262
- type Item = QuerySet <' w, ' s, ( #( QueryState <#query , #filter> , ) * ) >;
257
+ type Item = ParamSet <' w, ' s, ( #( <#param_fetch as SystemParamFetch < ' w , ' s>> :: Item , ) * ) >;
263
258
264
259
#[ inline]
265
260
unsafe fn get_param(
@@ -268,19 +263,19 @@ pub fn impl_query_set(_input: TokenStream) -> TokenStream {
268
263
world: & ' w World ,
269
264
change_tick: u32 ,
270
265
) -> Self :: Item {
271
- QuerySet {
272
- query_states: & state. 0 ,
266
+ ParamSet {
267
+ param_states: & mut state. 0 ,
268
+ system_meta: system_meta. clone( ) ,
273
269
world,
274
- last_change_tick: system_meta. last_change_tick,
275
270
change_tick,
276
271
}
277
272
}
278
273
}
279
274
280
- impl <' w, ' s, #( #query: WorldQuery , ) * #( #filter: WorldQuery , ) * > QuerySet <' w, ' s, ( #( QueryState <#query, #filter>, ) * ) >
281
- where #( #filter:: Fetch : FilterFetch , ) *
275
+ impl <' w, ' s, #( #param: SystemParam , ) * > ParamSet <' w, ' s, ( #( #param, ) * ) >
282
276
{
283
- #( #query_fn_mut) *
277
+
278
+ #( #param_fn_mut) *
284
279
}
285
280
} ) ) ;
286
281
}
0 commit comments