diff options
author | HampusM <hampus@hampusmat.com> | 2024-04-10 19:51:46 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-04-10 19:51:46 +0200 |
commit | c70e06c6d879208eb2822f6207ea7b29d47c2087 (patch) | |
tree | 06b5b7ae8fbf69d6041fff1c576d7610ff6fba6a /ecs/examples | |
parent | 9d8c73dd2671131929967214433dae5479e95b5b (diff) |
chore(ecs): remove Event trait id method & take events by value
Diffstat (limited to 'ecs/examples')
-rw-r--r-- | ecs/examples/event_loop.rs | 32 | ||||
-rw-r--r-- | ecs/examples/multiple_queries.rs | 14 | ||||
-rw-r--r-- | ecs/examples/simple.rs | 14 | ||||
-rw-r--r-- | ecs/examples/with_local.rs | 18 | ||||
-rw-r--r-- | ecs/examples/with_single.rs | 26 |
5 files changed, 28 insertions, 76 deletions
diff --git a/ecs/examples/event_loop.rs b/ecs/examples/event_loop.rs index b6a10e3..8d8d84f 100644 --- a/ecs/examples/event_loop.rs +++ b/ecs/examples/event_loop.rs @@ -1,5 +1,5 @@ use ecs::actions::Actions; -use ecs::event::{Event, Id as EventId}; +use ecs::event::Event; use ecs::{Component, Query, World}; #[derive(Component)] @@ -67,43 +67,25 @@ fn age(query: Query<(Health, Name)>, mut actions: Actions) #[derive(Debug)] struct EventA; -impl Event for EventA -{ - fn id(&self) -> EventId - { - EventId::of::<Self>() - } -} +impl Event for EventA {} #[derive(Debug)] struct EventB; -impl Event for EventB -{ - fn id(&self) -> EventId - { - EventId::of::<Self>() - } -} +impl Event for EventB {} #[derive(Debug)] struct EventC; -impl Event for EventC -{ - fn id(&self) -> EventId - { - EventId::of::<Self>() - } -} +impl Event for EventC {} fn main() { let mut world = World::new(); - world.register_system(&EventA, sheer); - world.register_system(&EventB, feed); - world.register_system(&EventC, age); + world.register_system(EventA, sheer); + world.register_system(EventB, feed); + world.register_system(EventC, age); world.create_entity(( Wool { remaining: 30 }, diff --git a/ecs/examples/multiple_queries.rs b/ecs/examples/multiple_queries.rs index e914cc6..ab442be 100644 --- a/ecs/examples/multiple_queries.rs +++ b/ecs/examples/multiple_queries.rs @@ -1,6 +1,6 @@ use std::fmt::Display; -use ecs::event::{Event, Id as EventId}; +use ecs::event::Event; use ecs::{Component, Query, World}; #[derive(Component)] @@ -60,19 +60,13 @@ fn do_attacks( #[derive(Debug, PartialEq, Eq, Hash)] struct Start; -impl Event for Start -{ - fn id(&self) -> EventId - { - EventId::of::<Self>() - } -} +impl Event for Start {} fn main() { let mut world = World::new(); - world.register_system(&Start, do_attacks); + world.register_system(Start, do_attacks); world.create_entity(( Health { health: 100 }, @@ -92,5 +86,5 @@ fn main() world.create_entity((AttackStrength::Strong,)); world.create_entity((AttackStrength::Weak,)); - world.emit(&Start); + world.emit(Start); } diff --git a/ecs/examples/simple.rs b/ecs/examples/simple.rs index 9983c4a..6949308 100644 --- a/ecs/examples/simple.rs +++ b/ecs/examples/simple.rs @@ -1,4 +1,4 @@ -use ecs::event::{Event, Id as EventId}; +use ecs::event::Event; use ecs::{Component, Query, World}; #[derive(Component)] @@ -23,19 +23,13 @@ fn say_hello(query: Query<(SomeData, Greeting)>) #[derive(Debug)] struct Start; -impl Event for Start -{ - fn id(&self) -> EventId - { - EventId::of::<Self>() - } -} +impl Event for Start {} fn main() { let mut world = World::new(); - world.register_system(&Start, say_hello); + world.register_system(Start, say_hello); world.create_entity(( SomeData { num: 987_654 }, @@ -49,5 +43,5 @@ fn main() Greeting { greeting: "Good evening".to_string() }, )); - world.emit(&Start); + world.emit(Start); } diff --git a/ecs/examples/with_local.rs b/ecs/examples/with_local.rs index eb5de28..5890b90 100644 --- a/ecs/examples/with_local.rs +++ b/ecs/examples/with_local.rs @@ -1,5 +1,5 @@ use ecs::component::local::Local; -use ecs::event::{Event, Id as EventId}; +use ecs::event::Event; use ecs::system::{Into, System}; use ecs::{Component, Query, World}; @@ -45,27 +45,21 @@ fn say_whats_up(query: Query<(SomeData, Name)>, mut state: Local<SayHelloState>) #[derive(Debug)] struct Update; -impl Event for Update -{ - fn id(&self) -> EventId - { - EventId::of::<Self>() - } -} +impl Event for Update {} fn main() { let mut world = World::new(); world.register_system( - &Update, + Update, say_hello .into_system() .initialize((SayHelloState { cnt: 0 },)), ); world.register_system( - &Update, + Update, say_whats_up .into_system() .initialize((SayHelloState { cnt: 0 },)), @@ -75,9 +69,9 @@ fn main() world.create_entity((SomeData { num: 345 },)); - world.emit(&Update); + world.emit(Update); println!("Haha"); - world.emit(&Update); + world.emit(Update); } diff --git a/ecs/examples/with_single.rs b/ecs/examples/with_single.rs index 25b73d1..d222f76 100644 --- a/ecs/examples/with_single.rs +++ b/ecs/examples/with_single.rs @@ -1,5 +1,5 @@ use ecs::component::single::Single; -use ecs::event::{Event, Id as EventId}; +use ecs::event::Event; use ecs::{Component, Query, World}; #[derive(Component)] @@ -33,31 +33,19 @@ fn print_total_ammo_count(ammo_counter: Single<AmmoCounter>) #[derive(Debug)] struct EventA; -impl Event for EventA -{ - fn id(&self) -> EventId - { - EventId::of::<Self>() - } -} +impl Event for EventA {} #[derive(Debug)] struct EventB; -impl Event for EventB -{ - fn id(&self) -> EventId - { - EventId::of::<Self>() - } -} +impl Event for EventB {} fn main() { let mut world = World::new(); - world.register_system(&EventA, count_ammo); - world.register_system(&EventB, print_total_ammo_count); + world.register_system(EventA, count_ammo); + world.register_system(EventB, print_total_ammo_count); world.create_entity((Ammo { ammo_left: 4 },)); world.create_entity((Ammo { ammo_left: 7 },)); @@ -65,7 +53,7 @@ fn main() world.add_single_component(AmmoCounter::default()).unwrap(); - world.emit(&EventA); + world.emit(EventA); - world.emit(&EventB); + world.emit(EventB); } |