Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use specs::System;
- // Tired of writing out a bunch of giant tuples by hand?
- // I have the macro for you!
- struct BananaSystem;
- system! {
- BananaSystem;
- fn run(&mut self,
- comp_a: ReadStorage<ComponentA>,
- mut comp_b: WriteStorage<ComponentB>,
- mut comp_c: WriteStorage<ComponentC>) {
- for (a, mut b, mut c) in (comp_a, comp_b, comp_c).join() {
- // etc.
- }
- }
- }
- // will generate what you'd expect (appropriate SystemData, etc.)
- // Here's the macro definition
- macro_rules! system {
- (
- $name:path;
- fn run(&mut self, $(
- $($bind:ident)+ :
- $type_root:ident < $( $type_args:ty ),* >
- ),+ )
- $contents:block
- ) => {
- impl<'a> System<'a> for $name {
- type SystemData = ( $(
- $type_root <'a, $( $type_args ),* >
- ),* );
- fn run(&mut self, args: Self::SystemData) {
- system_maybe_tuple!( args, $($($bind)+),+ );
- $contents
- }
- }
- };
- }
- macro_rules! system_maybe_tuple {
- ($args:expr, $($bind:ident)+) => (
- let ($($bind)+,) = $args;
- );
- ($args:expr, $($($bind:ident)+),+) => (
- let ($($($bind)+),+) = $args;
- );
- }
Add Comment
Please, Sign In to add comment