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:
parent
13a7805cde
commit
3f7ba739a4
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user