add new event

This commit is contained in:
2025-04-18 13:15:38 +03:00
parent a53056b6eb
commit 85500912a5
3 changed files with 24 additions and 17 deletions

View File

@@ -13,11 +13,4 @@ namespace VE
std::any m_data;
int m_id;
};
struct emitter
{
virtual ~emitter();
virtual void on_event(event e) = 0;
virtual void on_attach() = 0;
};
}

View File

@@ -4,6 +4,7 @@
#include <hack/patterns/singleton.hpp>
#include <hack/logger/logger.hpp>
#include <hack/security/uuid.hpp>
#include <hack/exception/exception.hpp>
#include "event.hpp"
@@ -13,25 +14,24 @@ namespace VE
{
void emit(event e)
{
std::size_t i = 0;
try
{
for(auto& f : m_funcs) f.func(e);
}
catch(const std::exception& ex)
{
hack::error()(ex.what());
hack::log()("size funcs", m_funcs.size());
for(;i < m_funcs.size();++i) m_funcs[i].m_func(e);
}
catch(...)
{
hack::error()("ooops...");
hack::error()("call function is error...");
hack::exception ex;
ex.set_data(e);
throw ex;
}
}
struct EventHandler
{
std::function<void(event)> func;
void* obj;
std::function<void(event)> m_func;
void* m_obj;
};
std::vector<EventHandler> m_funcs;
@@ -51,7 +51,7 @@ namespace VE
m_funcs.erase(
std::remove_if(m_funcs.begin(), m_funcs.end(),
[obj](const auto& handler) {
return handler.obj == obj;
return handler.m_obj == obj;
}),
m_funcs.end()
);