add new event
This commit is contained in:
@@ -27,8 +27,22 @@ namespace example
|
||||
VE_PUSH_FONT(REGULAR, 20);
|
||||
if (ImGui::Button("Test signal", ImVec2(128, 130)))
|
||||
VE::EMIT(test_event::TEST_EVEN, std::string("test event message"));
|
||||
|
||||
// try
|
||||
// {
|
||||
// if (ImGui::Button("Test signal log error", ImVec2(128, 130)))
|
||||
// VE::EMIT(test_event::TEST_EVEN, std::string("test event message"));
|
||||
// }
|
||||
// catch(hack::exception& e)
|
||||
// {
|
||||
// e.log();
|
||||
// auto data = std::any_cast<VE::event>(e.get_data());
|
||||
// hack::log()(data.m_id);
|
||||
// }
|
||||
|
||||
VE_POP_FONT();
|
||||
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user