aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/manager
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-12-22 00:12:23 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-12-22 00:12:23 +0100
commita3097a20daaf58e4e3852bfb36315dc5e14d3e52 (patch)
treeeb628cc3ec9e92b917d2861fb9b58cc3676f5627 /src/crepe/manager
parent7bcee4f662b20b8e2e7183bb6bd4cb061fa14e12 (diff)
parentf5d2ef9a5a335509f6ade05470938f0fbbbb74ad (diff)
Merge branch 'master' of github.com:lonkaars/crepe into jaro/main-menu
Diffstat (limited to 'src/crepe/manager')
-rw-r--r--src/crepe/manager/EventManager.h2
-rw-r--r--src/crepe/manager/EventManager.hpp7
2 files changed, 7 insertions, 2 deletions
diff --git a/src/crepe/manager/EventManager.h b/src/crepe/manager/EventManager.h
index 639e37f..0a57fb1 100644
--- a/src/crepe/manager/EventManager.h
+++ b/src/crepe/manager/EventManager.h
@@ -106,7 +106,7 @@ private:
* \brief Represents an entry in the event queue.
*/
struct QueueEntry {
- std::unique_ptr<Event> event; ///< The event instance.
+ std::unique_ptr<Event, std::function<void(Event *)>> event; ///< The event instance.
event_channel_t channel = CHANNEL_ALL; ///< The channel associated with the event.
std::type_index type; ///< The type of the event.
};
diff --git a/src/crepe/manager/EventManager.hpp b/src/crepe/manager/EventManager.hpp
index a5f4556..b2090d0 100644
--- a/src/crepe/manager/EventManager.hpp
+++ b/src/crepe/manager/EventManager.hpp
@@ -22,7 +22,12 @@ void EventManager::queue_event(const EventType & event, event_channel_t channel)
static_assert(std::is_base_of<Event, EventType>::value,
"EventType must derive from Event");
this->events_queue.push_back(QueueEntry{
- .event = std::make_unique<EventType>(event),
+ // unique_ptr w/ custom destructor implementation is used because the base Event interface
+ // can't be polymorphic (= have default virtual destructor)
+ .event = {
+ new EventType(event),
+ [](Event * ev) { delete static_cast<EventType *>(ev); },
+ },
.channel = channel,
.type = typeid(EventType),
});