add new struct and events
This commit is contained in:
41
src/event/event_manager.hpp
Executable file
41
src/event/event_manager.hpp
Executable file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <hack/patterns/singleton.hpp>
|
||||
#include <hack/logger/logger.hpp>
|
||||
|
||||
#include "event.hpp"
|
||||
#include "utils/using.hpp"
|
||||
|
||||
namespace VE
|
||||
{
|
||||
struct event_manager : public hack::patterns::singleton<event_manager>
|
||||
{
|
||||
std::vector<event_fn<event>> m_funcs;
|
||||
|
||||
template<typename T>
|
||||
void connect(T* obj, void (T::*method)(event))
|
||||
{
|
||||
m_funcs.push_back(std::bind(method, obj, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void emit(event e)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (std::size_t i = 0; i < m_funcs.size(); ++i)
|
||||
{
|
||||
m_funcs[i](e);
|
||||
}
|
||||
}
|
||||
catch(const std::exception& ex)
|
||||
{
|
||||
hack::error()(ex.what());
|
||||
hack::log()("size funcs", m_funcs.size());
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
hack::error()("ooops...");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user