diff options
Diffstat (limited to 'ecs/examples')
-rw-r--r-- | ecs/examples/multiple_queries.rs | 16 | ||||
-rw-r--r-- | ecs/examples/simple.rs | 18 | ||||
-rw-r--r-- | ecs/examples/with_local.rs | 22 |
3 files changed, 37 insertions, 19 deletions
diff --git a/ecs/examples/multiple_queries.rs b/ecs/examples/multiple_queries.rs index 9a699c2..ed02a69 100644 --- a/ecs/examples/multiple_queries.rs +++ b/ecs/examples/multiple_queries.rs @@ -1,5 +1,6 @@ use std::fmt::Display; +use ecs::event::{Event, Id as EventId}; use ecs::{Component, Query, World}; #[derive(Component)] @@ -57,16 +58,21 @@ fn do_attacks( } #[derive(Debug, PartialEq, Eq, Hash)] -enum Event +struct Start; + +impl Event for Start { - Start, + fn id(&self) -> EventId + { + EventId::of::<Self>() + } } fn main() { - let mut world = World::<Event>::new(); + let mut world = World::new(); - world.register_system(Event::Start, do_attacks); + world.register_system(&Start, do_attacks); world.create_entity(( Health { health: 100 }, @@ -86,5 +92,5 @@ fn main() world.create_entity((AttackStrength::Strong,)); world.create_entity((AttackStrength::Weak,)); - world.emit(&Event::Start); + world.emit(&Start); } diff --git a/ecs/examples/simple.rs b/ecs/examples/simple.rs index 76d9538..9983c4a 100644 --- a/ecs/examples/simple.rs +++ b/ecs/examples/simple.rs @@ -1,3 +1,4 @@ +use ecs::event::{Event, Id as EventId}; use ecs::{Component, Query, World}; #[derive(Component)] @@ -19,17 +20,22 @@ fn say_hello(query: Query<(SomeData, Greeting)>) } } -#[derive(Debug, PartialEq, Eq, Hash)] -enum Event +#[derive(Debug)] +struct Start; + +impl Event for Start { - Start, + fn id(&self) -> EventId + { + EventId::of::<Self>() + } } fn main() { - let mut world = World::<Event>::new(); + let mut world = World::new(); - world.register_system(Event::Start, say_hello); + world.register_system(&Start, say_hello); world.create_entity(( SomeData { num: 987_654 }, @@ -43,5 +49,5 @@ fn main() Greeting { greeting: "Good evening".to_string() }, )); - world.emit(&Event::Start); + world.emit(&Start); } diff --git a/ecs/examples/with_local.rs b/ecs/examples/with_local.rs index b37a5c3..0342930 100644 --- a/ecs/examples/with_local.rs +++ b/ecs/examples/with_local.rs @@ -1,4 +1,5 @@ use ecs::component::Local; +use ecs::event::{Event, Id as EventId}; use ecs::system::{Into, System}; use ecs::{Component, Query, World}; @@ -41,25 +42,30 @@ fn say_whats_up(query: Query<(SomeData, Name)>, mut state: Local<SayHelloState>) } } -#[derive(Debug, PartialEq, Eq, Hash)] -enum Event +#[derive(Debug)] +struct Update; + +impl Event for Update { - Update, + fn id(&self) -> EventId + { + EventId::of::<Self>() + } } fn main() { - let mut world = World::<Event>::new(); + let mut world = World::new(); world.register_system( - Event::Update, + &Update, say_hello .into_system() .initialize((SayHelloState { cnt: 0 },)), ); world.register_system( - Event::Update, + &Update, say_whats_up .into_system() .initialize((SayHelloState { cnt: 0 },)), @@ -69,9 +75,9 @@ fn main() world.create_entity((SomeData { num: 345 },)); - world.emit(&Event::Update); + world.emit(&Update); println!("Haha"); - world.emit(&Event::Update); + world.emit(&Update); } |