diff options
Diffstat (limited to 'ecs/examples/with_sole.rs')
-rw-r--r-- | ecs/examples/with_sole.rs | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/ecs/examples/with_sole.rs b/ecs/examples/with_sole.rs index a387bea..689e562 100644 --- a/ecs/examples/with_sole.rs +++ b/ecs/examples/with_sole.rs @@ -1,6 +1,7 @@ -use ecs::event::Event; +use ecs::phase::{Phase, UPDATE as UPDATE_PHASE}; +use ecs::relationship::{ChildOf, Relationship}; use ecs::sole::Single; -use ecs::{Component, Query, Sole, World}; +use ecs::{static_entity, Component, Query, Sole, World}; #[derive(Component)] struct Ammo @@ -14,7 +15,7 @@ struct AmmoCounter counter: u32, } -fn count_ammo(query: Query<(Ammo,)>, mut ammo_counter: Single<AmmoCounter>) +fn count_ammo(query: Query<(&Ammo,)>, mut ammo_counter: Single<AmmoCounter>) { for (ammo,) in &query { println!("Found {} ammo", ammo.ammo_left); @@ -30,22 +31,17 @@ fn print_total_ammo_count(ammo_counter: Single<AmmoCounter>) assert_eq!(ammo_counter.counter, 19); } -#[derive(Debug)] -struct EventA; - -impl Event for EventA {} - -#[derive(Debug)] -struct EventB; - -impl Event for EventB {} +static_entity!( + PRINT_AMMO_COUNT_PHASE, + (Phase, <Relationship<ChildOf, Phase>>::new(*UPDATE_PHASE)) +); fn main() { let mut world = World::new(); - world.register_system(EventA, count_ammo); - world.register_system(EventB, print_total_ammo_count); + world.register_system(*UPDATE_PHASE, count_ammo); + world.register_system(*PRINT_AMMO_COUNT_PHASE, print_total_ammo_count); world.create_entity((Ammo { ammo_left: 4 },)); world.create_entity((Ammo { ammo_left: 7 },)); @@ -53,7 +49,5 @@ fn main() world.add_sole(AmmoCounter::default()).unwrap(); - world.emit(EventA); - - world.emit(EventB); + world.step(); } |