add name for test
This commit is contained in:
@@ -5,7 +5,7 @@ namespace sandbox
|
||||
{
|
||||
void local_panel::on_attach()
|
||||
{
|
||||
VE_CONNECT(local_panel);
|
||||
VE_CONNECT("local_panel", local_panel);
|
||||
}
|
||||
|
||||
void local_panel::render()
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace sandbox
|
||||
|
||||
void opengl_panel::on_attach()
|
||||
{
|
||||
VE_CONNECT(opengl_panel);
|
||||
VE_CONNECT("opengl_panel", opengl_panel);
|
||||
hack::log()("on_attach");
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace sandbox
|
||||
{
|
||||
void test_panel::on_attach()
|
||||
{
|
||||
VE_CONNECT(test_panel);
|
||||
VE_CONNECT("test_panel", test_panel);
|
||||
hack::log()("on_attach", VE::application::get()->get_glfw()->width());
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace sandbox
|
||||
{
|
||||
void test_panel_2::on_attach()
|
||||
{
|
||||
VE_CONNECT(test_panel_2);
|
||||
VE_CONNECT("test_panel_2", test_panel_2);
|
||||
|
||||
// ATTENTION: активировать сигнальную систему в детях-компонентах
|
||||
m_local_panel.on_attach();
|
||||
|
||||
@@ -39,31 +39,52 @@ namespace VE
|
||||
struct event_manager : public hack::patterns::singleton<event_manager>
|
||||
{
|
||||
std::vector<VE::event_fn<VE::event>> m_funcs;
|
||||
std::vector<std::string> m_name;
|
||||
|
||||
template<typename T>
|
||||
void connect(T* obj, void (T::*method)(event))
|
||||
void connect(std::string name, T* obj, void (T::*method)(event))
|
||||
{
|
||||
m_funcs.push_back(std::bind(method, obj, std::placeholders::_1));
|
||||
m_name.push_back(name);
|
||||
}
|
||||
|
||||
void emit(event e)
|
||||
{
|
||||
for(auto func : m_funcs)
|
||||
{
|
||||
int i = 0;
|
||||
try
|
||||
{
|
||||
func(e);
|
||||
for (; i < m_funcs.size(); ++i)
|
||||
{
|
||||
m_funcs[i](e);
|
||||
}
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
hack::error()(e.what());
|
||||
hack::log()("size funcs", m_funcs.size());
|
||||
hack::log()("key", m_name[i]);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
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...");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
// #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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user