summaryrefslogtreecommitdiff
path: root/ecs/src/event.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/event.rs')
-rw-r--r--ecs/src/event.rs35
1 files changed, 29 insertions, 6 deletions
diff --git a/ecs/src/event.rs b/ecs/src/event.rs
index 93d4545..0caa56f 100644
--- a/ecs/src/event.rs
+++ b/ecs/src/event.rs
@@ -1,10 +1,21 @@
use std::any::TypeId;
use std::fmt::Debug;
-use std::hash::Hash;
+use std::hash::{DefaultHasher, Hash, Hasher};
use seq_macro::seq;
-pub trait Event: Debug + 'static {}
+pub mod component;
+
+pub trait Event: Debug + 'static
+{
+ /// Returns the ID of this event.
+ fn id() -> Id
+ where
+ Self: Sized,
+ {
+ Id::new::<Self, ()>(None)
+ }
+}
pub mod start;
@@ -13,15 +24,27 @@ pub mod start;
pub struct Id
{
inner: TypeId,
+ extra: Option<u64>,
}
impl Id
{
- /// Returns the id of a [`Event`];
#[must_use]
- pub fn of<EventT: Event>() -> Self
+ pub fn new<EventT, Extra>(extra: Option<Extra>) -> Self
+ where
+ EventT: Event,
+ Extra: Hash,
{
- Self { inner: TypeId::of::<EventT>() }
+ Self {
+ inner: TypeId::of::<EventT>(),
+ extra: extra.map(|extra| {
+ let mut hasher = DefaultHasher::new();
+
+ extra.hash(&mut hasher);
+
+ hasher.finish()
+ }),
+ }
}
}
@@ -59,7 +82,7 @@ macro_rules! impl_sequence {
fn ids() -> Self::Ids {
[#(
- Id::of::<Event~I>(),
+ Event~I::id(),
)*]
}
}