]> git.tdb.fi Git - libs/game.git/commitdiff
Support emitting preconstructed events without copying
authorMikko Rasa <tdb@tdb.fi>
Sun, 13 Apr 2025 13:47:43 +0000 (16:47 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 14 Apr 2025 10:17:49 +0000 (13:17 +0300)
source/game/eventsource.h

index 1748f156f16588629b410dc030ac9326026ad487..4be345b65a4c02aa0e5d3aff9f613a57620622f4 100644 (file)
@@ -39,6 +39,9 @@ private:
        void cancel_observation();
 
 public:
+       template<typename T>
+       void emit(const T &) const;
+
        template<typename T, typename... Args>
        void emit(Args &&...) const;
 
@@ -55,13 +58,20 @@ inline void EventSource<E...>::cancel_observation()
                h.observer->remove_source(*this);
 }
 
+template<typename... E>
+template<typename T>
+inline void EventSource<E...>::emit(const T &event) const
+{
+       static_cast<const EventDispatcher<T> &>(*this).dispatch(event);
+       bus.dispatch(event);
+}
+
 template<typename... E>
 template<typename T, typename... Args>
 inline void EventSource<E...>::emit(Args &&... args) const
 {
        T event(std::forward<Args>(args)...);
-       static_cast<const EventDispatcher<T> &>(*this).dispatch(event);
-       bus.dispatch(event);
+       emit(event);
 }
 
 template<typename... E>