This commit is contained in:
2025-04-17 18:52:22 +03:00
parent 63c3e911f8
commit a53056b6eb

View File

@@ -11,27 +11,11 @@ namespace VE
{ {
struct event_manager : public hack::patterns::singleton<event_manager> struct event_manager : public hack::patterns::singleton<event_manager>
{ {
// std::map<std::string, event_fn<event>> m_funcs;
//
// template<typename T>
// std::string connect(T* obj, void (T::*method)(event))
// {
// std::string key = hack::security::generate_uuid();
// m_funcs[key] = std::bind(method, obj, std::placeholders::_1);
// return key;
// }
//
// void disconnect(std::string key)
// {
// auto it = m_funcs.find(key);
// m_funcs.erase(it);
// }
void emit(event e) void emit(event e)
{ {
try try
{ {
for(auto& f : m_funcs) f.m_func(e); for(auto& f : m_funcs) f.func(e);
} }
catch(const std::exception& ex) catch(const std::exception& ex)
{ {
@@ -46,8 +30,8 @@ namespace VE
struct EventHandler struct EventHandler
{ {
std::function<void(event)> m_func; std::function<void(event)> func;
void* m_obj; void* obj;
}; };
std::vector<EventHandler> m_funcs; std::vector<EventHandler> m_funcs;
@@ -57,8 +41,7 @@ namespace VE
{ {
m_funcs.push_back({ m_funcs.push_back({
std::bind(method, obj, std::placeholders::_1), std::bind(method, obj, std::placeholders::_1),
static_cast<void*>(obj), static_cast<void*>(obj)
reinterpret_cast<void*>(&method)
}); });
} }
@@ -68,7 +51,7 @@ namespace VE
m_funcs.erase( m_funcs.erase(
std::remove_if(m_funcs.begin(), m_funcs.end(), std::remove_if(m_funcs.begin(), m_funcs.end(),
[obj](const auto& handler) { [obj](const auto& handler) {
return handler.m_obj == obj; return handler.obj == obj;
}), }),
m_funcs.end() m_funcs.end()
); );