fix event manager
This commit is contained in:
@@ -5,7 +5,7 @@ namespace sandbox
|
|||||||
{
|
{
|
||||||
void local_panel::on_attach()
|
void local_panel::on_attach()
|
||||||
{
|
{
|
||||||
VE_CONNECT("local_panel", local_panel);
|
VE_CONNECT(local_panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void local_panel::render()
|
void local_panel::render()
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace sandbox
|
|||||||
|
|
||||||
void opengl_panel::on_attach()
|
void opengl_panel::on_attach()
|
||||||
{
|
{
|
||||||
VE_CONNECT("opengl_panel", opengl_panel);
|
VE_CONNECT(opengl_panel);
|
||||||
hack::log()("on_attach");
|
hack::log()("on_attach");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace sandbox
|
|||||||
{
|
{
|
||||||
void test_panel::on_attach()
|
void test_panel::on_attach()
|
||||||
{
|
{
|
||||||
VE_CONNECT("test_panel", test_panel);
|
VE_CONNECT(test_panel);
|
||||||
hack::log()("on_attach", VE::application::get()->get_glfw()->width());
|
hack::log()("on_attach", VE::application::get()->get_glfw()->width());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace sandbox
|
|||||||
{
|
{
|
||||||
void test_panel_2::on_attach()
|
void test_panel_2::on_attach()
|
||||||
{
|
{
|
||||||
VE_CONNECT("test_panel_2", test_panel_2);
|
VE_CONNECT(test_panel_2);
|
||||||
|
|
||||||
// ATTENTION: активировать сигнальную систему в детях-компонентах
|
// ATTENTION: активировать сигнальную систему в детях-компонентах
|
||||||
m_local_panel.on_attach();
|
m_local_panel.on_attach();
|
||||||
|
|||||||
@@ -39,21 +39,18 @@ namespace VE
|
|||||||
struct event_manager : public hack::patterns::singleton<event_manager>
|
struct event_manager : public hack::patterns::singleton<event_manager>
|
||||||
{
|
{
|
||||||
std::vector<VE::event_fn<VE::event>> m_funcs;
|
std::vector<VE::event_fn<VE::event>> m_funcs;
|
||||||
std::vector<std::string> m_name;
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void connect(std::string name, T* obj, void (T::*method)(event))
|
void connect(T* obj, void (T::*method)(event))
|
||||||
{
|
{
|
||||||
m_funcs.push_back(std::bind(method, obj, std::placeholders::_1));
|
m_funcs.push_back(std::bind(method, obj, std::placeholders::_1));
|
||||||
m_name.push_back(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void emit(event e)
|
void emit(event e)
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (; i < m_funcs.size(); ++i)
|
for (std::size_t i = 0; i < m_funcs.size(); ++i)
|
||||||
{
|
{
|
||||||
m_funcs[i](e);
|
m_funcs[i](e);
|
||||||
}
|
}
|
||||||
@@ -62,29 +59,11 @@ namespace VE
|
|||||||
{
|
{
|
||||||
hack::error()(e.what());
|
hack::error()(e.what());
|
||||||
hack::log()("size funcs", m_funcs.size());
|
hack::log()("size funcs", m_funcs.size());
|
||||||
hack::log()("key", m_name[i]);
|
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
hack::error()("ooops...");
|
hack::error()("ooops...");
|
||||||
}
|
}
|
||||||
|
|
||||||
// for(auto& func : m_funcs)
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// func(e);
|
|
||||||
// }
|
|
||||||
// catch(std::exception& e)
|
|
||||||
// {
|
|
||||||
// hack::error()(e.what());
|
|
||||||
// hack::log()("size funcs", m_funcs.size());
|
|
||||||
// }
|
|
||||||
// catch(...)
|
|
||||||
// {
|
|
||||||
// hack::error()("ooops...");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,7 @@
|
|||||||
void update() override;\
|
void update() override;\
|
||||||
void on_event(VE::event e) override
|
void on_event(VE::event e) override
|
||||||
|
|
||||||
// #define VE_CONNECT(DEF_NAME, DEF_CLASS) VE::event_manager::instance().connect(DEF_NAME, std::bind(&DEF_CLASS::on_event, this, std::placeholders::_1));
|
#define VE_CONNECT(DEF_CLASS) VE::event_manager::instance().connect(this, &DEF_CLASS::on_event);
|
||||||
|
|
||||||
#define VE_CONNECT(DEF_NAME, DEF_CLASS) VE::event_manager::instance().connect(DEF_NAME, this, &DEF_CLASS::on_event);
|
|
||||||
|
|
||||||
#define VE_EMIT(e) VE::event_manager::instance().emit(e)
|
#define VE_EMIT(e) VE::event_manager::instance().emit(e)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user