From 1978a24d1edd55e7092553c553e26a7ede3e78bb Mon Sep 17 00:00:00 2001 From: Samsonium Date: Mon, 28 Sep 2026 17:33:03 +0300 Subject: [PATCH] upd: change event bus - Make `.subscribeOnce` return listener id - Make `.cancel` and `.isCanceled` methods in `MscEvent` implemented --- include/engine/core/engine_bus.hpp | 15 ++++++++++++--- src/engine/core/event_bus.cpp | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/engine/core/engine_bus.hpp b/include/engine/core/engine_bus.hpp index 2818789..e3820bf 100644 --- a/include/engine/core/engine_bus.hpp +++ b/include/engine/core/engine_bus.hpp @@ -18,10 +18,19 @@ public: virtual std::string getName() const = 0; /// @brief Is current event is canceled - virtual bool isCanceled() const = 0; + bool isCanceled() const + { + return canceled; + } /// @brief Cancel current event - virtual void cancel() = 0; + void cancel() + { + canceled = true; + } + +private: + bool canceled = false; }; /// @brief Engine event bus @@ -47,7 +56,7 @@ public: /// @brief Subscribe to specified event and execute once on publish /// @param name event name /// @param listener event handler - void subscribeOnce(const std::string &name, Listener listener); + SubscriptionId subscribeOnce(const std::string &name, Listener listener); /// @brief Unsubscribe listener by its own id /// @param id subscription id diff --git a/src/engine/core/event_bus.cpp b/src/engine/core/event_bus.cpp index 7d6420a..a7a8a52 100644 --- a/src/engine/core/event_bus.cpp +++ b/src/engine/core/event_bus.cpp @@ -48,9 +48,9 @@ MscEventBus::SubscriptionId MscEventBus::subscribe(const std::string &name, List return _subscribe(name, std::move(listener), false); } -void MscEventBus::subscribeOnce(const std::string &name, Listener listener) +MscEventBus::SubscriptionId MscEventBus::subscribeOnce(const std::string &name, Listener listener) { - _subscribe(name, std::move(listener), true); + return _subscribe(name, std::move(listener), true); } bool MscEventBus::unsubscribe(SubscriptionId id)