1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-22 18:28:52 -05:00

Replaced std::bind and std::function to reduce code overhead. Simplified EventDispatcher templating

This commit is contained in:
Gordon McCann 2022-01-09 17:13:09 -05:00
parent 13a7805cde
commit 3f7ba739a4
2 changed files with 4 additions and 7 deletions

View File

@ -47,21 +47,18 @@ namespace Navigator {
class NAV_API EventDispatcher
{
template<typename T>
using EventFunc = std::function<bool(T&)>;
public:
EventDispatcher(Event& e) :
m_event(e)
{
}
template<typename T>
bool Dispatch(EventFunc<T> function)
template<typename T, typename F>
bool Dispatch(const F& function)
{
if(m_event.GetEventType() == T::GetStaticType())
{
m_event.handledFlag = function(*(T*)&m_event);
m_event.handledFlag = function(static_cast<T&>(m_event));
return true;
}
else

View File

@ -16,6 +16,6 @@
//Bit field setter
#define BIT(x) (1<<x)
#define BIND_EVENT_FUNCTION(x) std::bind(&x, this, std::placeholders::_1)
#define BIND_EVENT_FUNCTION(x) [this](auto&&... args) -> decltype(auto) { return this->x(std::forward<decltype(args)>(args)...); }
#endif