summaryrefslogtreecommitdiff
path: root/ecs/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-04-10 19:51:46 +0200
committerHampusM <hampus@hampusmat.com>2024-04-10 19:51:46 +0200
commitc70e06c6d879208eb2822f6207ea7b29d47c2087 (patch)
tree06b5b7ae8fbf69d6041fff1c576d7610ff6fba6a /ecs/src/lib.rs
parent9d8c73dd2671131929967214433dae5479e95b5b (diff)
chore(ecs): remove Event trait id method & take events by value
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r--ecs/src/lib.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs
index ce1a7d1..c93781d 100644
--- a/ecs/src/lib.rs
+++ b/ecs/src/lib.rs
@@ -103,19 +103,22 @@ impl World
self.data.single_component_storage.insert(single_component)
}
- pub fn register_system<'this, SystemImpl>(
+ pub fn register_system<'this, EventT, SystemImpl>(
&'this mut self,
- event: &impl Event,
+ event: EventT,
system: impl System<'this, SystemImpl>,
- )
+ ) where
+ EventT: Event,
{
self.systems.push(system.into_type_erased());
self.data
.events
- .entry(event.id())
+ .entry(EventId::of::<EventT>())
.or_default()
.push(self.systems.len() - 1);
+
+ drop(event);
}
/// Emits a event, running all systems listening to the event for each compatible
@@ -123,9 +126,13 @@ impl World
///
/// # Panics
/// Will panic if a system has dissapeared.
- pub fn emit(&self, event: &impl Event)
+ pub fn emit<EventT>(&self, event: EventT)
+ where
+ EventT: Event,
{
- self.emit_event_by_id(event.id());
+ self.emit_event_by_id(EventId::of::<EventT>());
+
+ drop(event);
}
pub fn query<Comps>(&self) -> Query<Comps>