X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Feventsource.h;h=1748f156f16588629b410dc030ac9326026ad487;hb=316a4432767efbea70c1409edf5f546e61077c54;hp=0856e08c452a7abd48b263db1bcb54092e4c75bb;hpb=db01a6ed506ea2352b20f10b2694e249d2bba6c5;p=libs%2Fgame.git diff --git a/source/game/eventsource.h b/source/game/eventsource.h index 0856e08..1748f15 100644 --- a/source/game/eventsource.h +++ b/source/game/eventsource.h @@ -29,7 +29,7 @@ public: template void add_observer(EventObserver &obs, std::function cb) - { static_cast &>(*this).add_observer(obs, std::move(cb)); } + { static_cast &>(*this).add_observer(&obs, std::move(cb)); } void remove_observer(EventObserver &obs) override { (static_cast &>(*this).remove_observer(&obs), ...); } @@ -41,6 +41,9 @@ private: public: template void emit(Args &&...) const; + + template + void emit_to(EventObserver &, Args &&...) const; }; @@ -61,6 +64,15 @@ inline void EventSource::emit(Args &&... args) const bus.dispatch(event); } +template +template +inline void EventSource::emit_to(EventObserver &obs, Args &&... args) const +{ + T event(std::forward(args)...); + static_cast &>(*this).dispatch_to(obs, event); + bus.dispatch_to(obs, event); +} + } // namespace Msp::Game #endif