From c70e06c6d879208eb2822f6207ea7b29d47c2087 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 10 Apr 2024 19:51:46 +0200 Subject: chore(ecs): remove Event trait id method & take events by value --- ecs/src/event.rs | 5 +---- ecs/src/lib.rs | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'ecs/src') diff --git a/ecs/src/event.rs b/ecs/src/event.rs index 9545318..6a4c3a8 100644 --- a/ecs/src/event.rs +++ b/ecs/src/event.rs @@ -4,10 +4,7 @@ use std::hash::Hash; use seq_macro::seq; -pub trait Event: Debug + 'static -{ - fn id(&self) -> Id; -} +pub trait Event: Debug + 'static {} /// The ID of a [`Event`]. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 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::()) .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(&self, event: EventT) + where + EventT: Event, { - self.emit_event_by_id(event.id()); + self.emit_event_by_id(EventId::of::()); + + drop(event); } pub fn query(&self) -> Query -- cgit v1.2.3-18-g5258