diff --git a/src/main.rs b/src/main.rs index 23280f2..c058787 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ struct Velocity(f64, f64); struct VelocitySystem; impl System for VelocitySystem { fn on_update(&self, ctx: &mut engine::Context, delta: f64) -> Result<(), engine::Error> { - for id in engine::Quwi::<(Velocity, Position)>::new().run(&ctx) { + for id in run_quwi::(ctx) { let vel = ctx.entity_component::(id).clone(); let Position(x, y) = ctx.entity_component::(id); *x += vel.0 * delta; @@ -38,7 +38,7 @@ struct Gravity; struct GravitySystem; impl System for GravitySystem { fn on_update(&self, ctx: &mut engine::Context, delta: f64) -> Result<(), engine::Error> { - for id in engine::Quwi::<(Gravity, Velocity)>::new().run(&ctx) { + for id in run_quwi::(ctx) { let Velocity(_, y) = ctx.entity_component::(id); *y = if *y < 800.0 { *y + 400.0 * delta } else { *y }; } @@ -64,12 +64,12 @@ impl System for CloudSystem { ]); } - for id in engine::Quwi::<(Cloud, Velocity)>::new().run(&ctx) { + for id in run_quwi::(ctx) { let Velocity(x, _) = ctx.entity_component::(id); *x = if *x < 200.0 { *x + 200.0 * delta } else { *x }; } - for id in engine::Quwi::<(Cloud, Position)>::new().run(&ctx) { + for id in run_quwi::(ctx) { let Position(x, _) = ctx.entity_component::(id); if *x > 1400.0 { ctx.despawn(id); @@ -79,10 +79,14 @@ impl System for CloudSystem { } } +fn run_quwi(ctx: &mut engine::Context) -> Vec { + engine::Quwi::<(A, B)>::new().run(&ctx) +} + struct SpriteRenderer; impl System for SpriteRenderer { fn on_update(&self, ctx: &mut engine::Context, _delta: f64) -> Result<(), engine::Error> { - for id in engine::Quwi::<(Sprite, Position)>::new().run(&ctx) { + for id in run_quwi::(ctx) { let &mut Position(x, y) = ctx.entity_component::(id); let sprite = ctx.entity_component::(id).sprite; @@ -98,7 +102,7 @@ struct PlayerMovement; struct PlayerMovementSystem; impl System for PlayerMovementSystem { fn on_update(&self, ctx: &mut engine::Context, _delta: f64) -> Result<(), engine::Error> { - for id in engine::Quwi::<(PlayerMovement, Velocity)>::new().run(&ctx) { + for id in run_quwi::(ctx) { let d_down = ctx.key_pressed(engine::Keycode::D); let a_down = ctx.key_pressed(engine::Keycode::A); let Velocity(x, _) = ctx.entity_component::(id);