diff options
author | HampusM <hampus@hampusmat.com> | 2024-02-29 19:57:59 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-02-29 19:58:10 +0100 |
commit | 99ea5727ca4638efd2979218a128e56c0ce32c44 (patch) | |
tree | f167d9d88ad8b4cfe7089df3cc67e1be9b0f9a06 /ecs/examples | |
parent | bd627c91819ea98e551b29027de6eaaccbe45ed6 (diff) |
feat(ecs): add iterating over queries non-mutably
Diffstat (limited to 'ecs/examples')
-rw-r--r-- | ecs/examples/multiple_queries.rs | 8 | ||||
-rw-r--r-- | ecs/examples/simple.rs | 4 | ||||
-rw-r--r-- | ecs/examples/with_local.rs | 8 |
3 files changed, 10 insertions, 10 deletions
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::<Event>::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<SayHelloState>) +fn say_hello(query: Query<(SomeData,)>, mut state: Local<SayHelloState>) { - 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<SayHelloState>) +fn say_whats_up(query: Query<(SomeData, Name)>, mut state: Local<SayHelloState>) { - for (data, name) in query.iter_mut() { + for (data, name) in &query { println!( "Whats up, {}. Number is {}. Count {}", name.name, data.num, state.cnt |