From 99ea5727ca4638efd2979218a128e56c0ce32c44 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 29 Feb 2024 19:57:59 +0100 Subject: feat(ecs): add iterating over queries non-mutably --- ecs/examples/multiple_queries.rs | 8 ++++---- ecs/examples/simple.rs | 4 ++-- ecs/examples/with_local.rs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'ecs/examples') diff --git a/ecs/examples/multiple_queries.rs b/ecs/examples/multiple_queries.rs index 4f4198a..9a699c2 100644 --- a/ecs/examples/multiple_queries.rs +++ b/ecs/examples/multiple_queries.rs @@ -29,12 +29,12 @@ impl Display for EnemyName } } -fn say_hello( - mut query: Query<(AttackStrength,)>, +fn do_attacks( + attacker_query: Query<(AttackStrength,)>, mut enemy_query: Query<(Health, EnemyName)>, ) { - for (attack_strength,) in query.iter_mut() { + for (attack_strength,) in &attacker_query { for (health, enemy_name) in enemy_query.iter_mut() { let damage = match attack_strength { AttackStrength::Strong => 20, @@ -66,7 +66,7 @@ fn main() { let mut world = World::::new(); - world.register_system(Event::Start, say_hello); + world.register_system(Event::Start, do_attacks); world.create_entity(( Health { health: 100 }, diff --git a/ecs/examples/simple.rs b/ecs/examples/simple.rs index b8dc50f..76d9538 100644 --- a/ecs/examples/simple.rs +++ b/ecs/examples/simple.rs @@ -12,9 +12,9 @@ struct Greeting greeting: String, } -fn say_hello(mut query: Query<(SomeData, Greeting)>) +fn say_hello(query: Query<(SomeData, Greeting)>) { - for (data, greeting) in query.iter_mut() { + for (data, greeting) in &query { println!("{}: {}", greeting.greeting, data.num); } } diff --git a/ecs/examples/with_local.rs b/ecs/examples/with_local.rs index 334f129..b37a5c3 100644 --- a/ecs/examples/with_local.rs +++ b/ecs/examples/with_local.rs @@ -20,18 +20,18 @@ struct SayHelloState cnt: usize, } -fn say_hello(mut query: Query<(SomeData,)>, mut state: Local) +fn say_hello(query: Query<(SomeData,)>, mut state: Local) { - for (data,) in query.iter_mut() { + for (data,) in &query { println!("Hello there. Count {}: {}", state.cnt, data.num); state.cnt += 1; } } -fn say_whats_up(mut query: Query<(SomeData, Name)>, mut state: Local) +fn say_whats_up(query: Query<(SomeData, Name)>, mut state: Local) { - for (data, name) in query.iter_mut() { + for (data, name) in &query { println!( "Whats up, {}. Number is {}. Count {}", name.name, data.num, state.cnt -- cgit v1.2.3-18-g5258