mirror of
https://github.com/gwm17/Specter.git
synced 2024-12-03 07:28:50 -05:00
Replaced std::bind and std::function to reduce code overhead. Simplified EventDispatcher templating
This commit is contained in:
parent
13a7805cde
commit
3f7ba739a4
|
@ -47,21 +47,18 @@ namespace Navigator {
|
||||||
|
|
||||||
class NAV_API EventDispatcher
|
class NAV_API EventDispatcher
|
||||||
{
|
{
|
||||||
template<typename T>
|
|
||||||
using EventFunc = std::function<bool(T&)>;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EventDispatcher(Event& e) :
|
EventDispatcher(Event& e) :
|
||||||
m_event(e)
|
m_event(e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T, typename F>
|
||||||
bool Dispatch(EventFunc<T> function)
|
bool Dispatch(const F& function)
|
||||||
{
|
{
|
||||||
if(m_event.GetEventType() == T::GetStaticType())
|
if(m_event.GetEventType() == T::GetStaticType())
|
||||||
{
|
{
|
||||||
m_event.handledFlag = function(*(T*)&m_event);
|
m_event.handledFlag = function(static_cast<T&>(m_event));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -16,6 +16,6 @@
|
||||||
//Bit field setter
|
//Bit field setter
|
||||||
#define BIT(x) (1<<x)
|
#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
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user