macro_rules! define_system {
(/param_defs/ $table:ident / $func_body:block / |$param_name:ident: $param_type:ty|) => { ... };
(/param_defs/ $table:ident / $func_body:block / |$param_name:ident: $param_type:ty, $($rest_names:ident: $rest_types:ty),+|) => { ... };
(|$handle_name:pat_param, $($param_name:ident: $param_type:ty),+| $func_body:block) => { ... };
}
Expand description
Gutputs a closure that can be passed into Scene::run_system
, handling
extracting properly typed component columns based on the parameter list.
The GameObjectHandleIterator
parameter from Scene::run_system
is
always assigned to first parameter of the closure.
The generated closure extracts the relevant component slices from the
anonymous ComponentColumn
s, and makes them available to the closure body
as variables, using the names from the parameter list.
For simplicity, the parameters after the first one can only be mutable
slices, but note that Scene::run_system
takes a FnMut
, so the
closure can borrow and even mutate their captured environment.
ยงExample
let mut game_object_handle = None;
scene.run_system(define_system!(|handles, pos: &mut [Position], vel: &[Velocity]| {
for ((handle, pos), vel) in handles.zip(pos).zip(vel) {
pos.x += vel.x;
pos.y += vel.y;
game_object_handle = Some(handle);
}
}));
if let Some(handle) = game_object_handle {
scene.delete(&mut [handle]).unwrap();
}