1
1
use std:: marker:: PhantomData ;
2
2
3
3
use super :: * ;
4
- use super :: set:: { Set , LockedSubset } ;
4
+ use super :: set:: { LockGroup , LockedSubset } ;
5
5
6
6
/// Filters are used to test properties of entities' data.
7
7
///
@@ -40,13 +40,14 @@ impl<T: Component> Filter for Has<T> {
40
40
/// and `Push`.
41
41
pub trait Pipeline < ' a > : Sized {
42
42
type Item : ' a ;
43
+ type LockGroup : for < ' b > LockGroup < ' b > ;
43
44
44
45
/// Consume self along with handles to ECS state to pass all entities
45
46
/// fulfilling the pipeline's predicates to the functions along with
46
47
/// relevant component data. This will output a vector of the returned
47
48
/// outputs from the function.
48
- fn for_each < F , U : Send , S : LockedSubset > ( self , & S , & EntityManager , F ) -> Vec < U >
49
- where F : Sync + for < ' b > Fn ( VerifiedEntity , < Self as Pipeline < ' b > > :: Item ) -> U ;
49
+ fn for_each < F , U : Send , S : LockedSubset > ( self , & ' a S , & ' a EntityManager , F ) -> Vec < U >
50
+ where F : Sync + Fn ( VerifiedEntity , Self :: Item ) -> U ;
50
51
}
51
52
52
53
/// Convenience trait for extending tuples of filters.
@@ -75,7 +76,7 @@ pub struct Query<'a, S: Set + 'a, P: 'a> {
75
76
pipeline : P ,
76
77
}
77
78
78
- impl < ' a , S : ' a + Set , P : ' a + Pipeline < ' a > > Query < ' a , S , P > {
79
+ impl < ' a , S : ' a + Set , P > Query < ' a , S , P > where P : ' a + for < ' b > Pipeline < ' b > {
79
80
/// Create a new query. Use of `WorldHandle::query()` is advised
80
81
/// over this.
81
82
pub fn new ( s : & ' a S , entities : & ' a EntityManager , pipeline : P ) -> Self {
@@ -113,11 +114,9 @@ impl<'a, S: 'a + Set, P: 'a + Pipeline<'a>> Query<'a, S, P> {
113
114
/// Perform an action for each entity which fits the properties of
114
115
/// the filter.
115
116
pub fn for_each < F , U : Send > ( self , f : F ) -> Vec < U >
116
- where F : Sync + for < ' b > Fn ( VerifiedEntity , <P as Pipeline < ' b > >:: Item ) -> U {
117
- // TODO: amend Pipeline so that we can get a LockGroup to pass to lock_subset.
118
- // TODO: have for_each return the locked subset along with the items.
119
- let empty = :: ecs:: set:: Empty ;
120
- self . pipeline . for_each ( & empty, self . entities , f)
117
+ where F : Sync + for < ' r > Fn ( VerifiedEntity , <P as Pipeline < ' r > >:: Item ) -> U {
118
+ let subset = self . set . lock_subset :: < P :: LockGroup > ( ) ;
119
+ self . pipeline . for_each ( & subset, self . entities , f)
121
120
}
122
121
}
123
122
@@ -163,10 +162,10 @@ macro_rules! factory {
163
162
} ;
164
163
}
165
164
166
- // factory!(A B C D E F);
167
- // factory!(A B C D E);
168
- // factory!(A B C D);
169
- // factory!(A B C);
165
+ factory ! ( A B C D E F ) ;
166
+ factory ! ( A B C D E ) ;
167
+ factory ! ( A B C D ) ;
168
+ factory ! ( A B C ) ;
170
169
factory ! ( A B ) ;
171
170
factory ! ( A ) ;
172
171
factory ! ( ) ;
@@ -208,9 +207,10 @@ macro_rules! pipeline_impl {
208
207
( ) => {
209
208
impl <' a> Pipeline <' a> for ( ) {
210
209
type Item = ( ) ;
210
+ type LockGroup = ( ) ;
211
211
212
- fn for_each<F , U : Send , S : LockedSubset >( self , _: & S , _: & EntityManager , _: F ) -> Vec <U >
213
- where F : ' a + Sync + for < ' b> Fn ( VerifiedEntity , < Self as Pipeline < ' b>> :: Item ) -> U {
212
+ fn for_each<F , U : Send , S : LockedSubset >( self , _: & ' a S , _: & ' a EntityManager , _: F ) -> Vec <U >
213
+ where F : ' a + Sync + Fn ( VerifiedEntity , Self :: Item ) -> U {
214
214
Vec :: new( )
215
215
}
216
216
}
@@ -219,11 +219,12 @@ macro_rules! pipeline_impl {
219
219
( $f_id: ident $f_num: tt $( $id: ident $num: tt) * ) => {
220
220
impl <' a, $f_id: Filter , $( $id: Filter , ) * > Pipeline <' a> for
221
221
( $f_id, $( $id, ) * ) {
222
- type Item = ( & ' a <$f_id as Filter >:: Component , $( & ' a <$id as Filter >:: Component , ) * ) ;
222
+ type Item = ( & ' a $f_id:: Component , $( & ' a $id:: Component , ) * ) ;
223
+ type LockGroup = ( $f_id:: Component , $( $id:: Component , ) * ) ;
223
224
224
225
#[ allow( unused_mut) ]
225
- fn for_each<OP , U : Send , SET : LockedSubset >( self , set: & SET , entities: & EntityManager , f: OP ) -> Vec <U >
226
- where OP : ' a + Sync + for < ' b> Fn ( VerifiedEntity , < Self as Pipeline < ' b>> :: Item ) -> U {
226
+ fn for_each<OP , U : Send , SET : LockedSubset >( self , set: & ' a SET , entities: & ' a EntityManager , f: OP ) -> Vec <U >
227
+ where OP : ' a + Sync + Fn ( VerifiedEntity , Self :: Item ) -> U {
227
228
// it's ok to unwrap the calls to get_storage() since this function is called with a subset
228
229
// that has been locked with this pipeline in mind.
229
230
@@ -253,10 +254,10 @@ macro_rules! pipeline_impl {
253
254
} ;
254
255
}
255
256
256
- // pipeline_impl!(A 0 B 1 C 2 D 3 E 4 F 5);
257
- // pipeline_impl!(A 0 B 1 C 2 D 3 E 4);
258
- // pipeline_impl!(A 0 B 1 C 2 D 3);
259
- // pipeline_impl!(A 0 B 1 C 2);
257
+ pipeline_impl ! ( A 0 B 1 C 2 D 3 E 4 F 5 ) ;
258
+ pipeline_impl ! ( A 0 B 1 C 2 D 3 E 4 ) ;
259
+ pipeline_impl ! ( A 0 B 1 C 2 D 3 ) ;
260
+ pipeline_impl ! ( A 0 B 1 C 2 ) ;
260
261
pipeline_impl ! ( A 0 B 1 ) ;
261
262
pipeline_impl ! ( A 0 ) ;
262
263
pipeline_impl ! ( ) ;
0 commit comments