summaryrefslogtreecommitdiff
path: root/ecs/examples/simple.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-03-02 12:00:01 +0100
committerHampusM <hampus@hampusmat.com>2024-03-02 12:00:01 +0100
commit6f8aeb236725f673f199bce7a6f3942eb56a8318 (patch)
tree5ed2b80d57f9115843be8b11118d44e6ec973215 /ecs/examples/simple.rs
parent7c6391c1bea40c5260f4a750adc9d3c648b05db9 (diff)
feat(ecs): add event trait
Diffstat (limited to 'ecs/examples/simple.rs')
-rw-r--r--ecs/examples/simple.rs18
1 files changed, 12 insertions, 6 deletions
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);
}