add new struct and events

This commit is contained in:
2025-04-08 15:16:20 +03:00
parent ff3122c74d
commit 1ab87dd53d
35 changed files with 264 additions and 624 deletions

41
src/event/event_manager.hpp Executable file
View File

@@ -0,0 +1,41 @@
#pragma once
#include <hack/patterns/singleton.hpp>
#include <hack/logger/logger.hpp>
#include "event.hpp"
#include "utils/using.hpp"
namespace VE
{
struct event_manager : public hack::patterns::singleton<event_manager>
{
std::vector<event_fn<event>> m_funcs;
template<typename T>
void connect(T* obj, void (T::*method)(event))
{
m_funcs.push_back(std::bind(method, obj, std::placeholders::_1));
}
void emit(event e)
{
try
{
for (std::size_t i = 0; i < m_funcs.size(); ++i)
{
m_funcs[i](e);
}
}
catch(const std::exception& ex)
{
hack::error()(ex.what());
hack::log()("size funcs", m_funcs.size());
}
catch(...)
{
hack::error()("ooops...");
}
}
};
}