]> git.tdb.fi Git - libs/game.git/blobdiff - source/game/eventsource.h
Provide a way to request events for existing entities and components
[libs/game.git] / source / game / eventsource.h
index 0856e08c452a7abd48b263db1bcb54092e4c75bb..ccb830fb9fb3d4da7c91b265e6002285d9b1d937 100644 (file)
@@ -41,6 +41,9 @@ private:
 public:
        template<typename T, typename... Args>
        void emit(Args &&...) const;
+
+       template<typename T, typename... Args>
+       void emit_to(EventObserver &, Args &&...) const;
 };
 
 
@@ -61,6 +64,15 @@ inline void EventSource<E...>::emit(Args &&... args) const
        bus.dispatch(event);
 }
 
+template<typename... E>
+template<typename T, typename... Args>
+inline void EventSource<E...>::emit_to(EventObserver &obs, Args &&... args) const
+{
+       T event(std::forward<Args>(args)...);
+       static_cast<const EventDispatcher<T> &>(*this).dispatch_to(obs, event);
+       bus.dispatch_to(obs, event);
+}
+
 } // namespace Msp::Game
 
 #endif