summaryrefslogtreecommitdiff
path: root/src/port/hooks/impl/EventSystem.cpp
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2024-12-27 16:11:32 -0600
committerKiritoDv <kiritodev01@gmail.com>2024-12-27 16:11:32 -0600
commit4b0eacaef7b60d42f03f9c3299751e57be2cbad4 (patch)
tree1f2c7d7a3a6b9d7f594485966784ed3926bdd479 /src/port/hooks/impl/EventSystem.cpp
parent8954d28dc482e84881f69073f9371c23ca6f754f (diff)
Hook system PoC
Diffstat (limited to 'src/port/hooks/impl/EventSystem.cpp')
-rw-r--r--src/port/hooks/impl/EventSystem.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/port/hooks/impl/EventSystem.cpp b/src/port/hooks/impl/EventSystem.cpp
new file mode 100644
index 00000000..5aa74bc0
--- /dev/null
+++ b/src/port/hooks/impl/EventSystem.cpp
@@ -0,0 +1,29 @@
+#include "EventSystem.h"
+
+EventSystem* EventSystem::Instance = new EventSystem();
+
+size_t EventSystem::RegisterListener(EventID id, EventPriority priority, EventCallback callback) {
+ if (std::find(this->mEventListeners[id].begin(), this->mEventListeners[id].end(), callback) != this->mEventListeners[id].end()) {
+ throw std::runtime_error("Listener already registered");
+ }
+
+ this->mEventListeners[id].push_back(callback);
+}
+
+void EventSystem::CallEvent(EventID id, IEvent* event) {
+ if (this->mEventListeners[id].empty()) {
+ return;
+ }
+
+ for (auto& callback : this->mEventListeners[id]) {
+ callback(event);
+ }
+}
+
+extern "C" size_t EventSystem_RegisterListener(EventID id, EventPriority priority, EventCallback callback) {
+ return EventSystem::Instance->RegisterListener(id, priority, callback);
+}
+
+extern "C" void EventSystem_CallEvent(EventID id, void* event) {
+ EventSystem::Instance->CallEvent(id, static_cast<IEvent*>(event));
+} \ No newline at end of file