12#ifndef ECS__EVENT_DISPATCHER_H__
13#define ECS__EVENT_DISPATCHER_H__
18namespace ECS {
namespace Event {
namespace Internal {
47 this->m_PendingRemoveDelegates.clear();
48 this->m_EventCallbacks.clear();
54 this->m_Locked =
true;
56 LOG_INFO(
"Dispatch event {}",
typeid(T).name());
59 if (this->m_PendingRemoveDelegates.empty() ==
false)
61 for (
auto EC : this->m_PendingRemoveDelegates)
66 return other->operator==(EC);
79 this->m_PendingRemoveDelegates.clear();
82 for (
auto EC : this->m_EventCallbacks)
84 assert(EC !=
nullptr &&
"Invalid event callback.");
88 this->m_Locked =
false;
95 auto result = eastl::find_if(this->m_PendingRemoveDelegates.begin(), this->m_PendingRemoveDelegates.end(),
98 return other->operator==(eventDelegate);
101 if (result != this->m_PendingRemoveDelegates.end())
103 this->m_PendingRemoveDelegates.erase(result);
107 this->m_EventCallbacks.push_back(eventDelegate);
112 if (this->m_Locked ==
false)
114 auto result = eastl::find_if(this->m_EventCallbacks.begin(), this->m_EventCallbacks.end(),
117 return other->operator==(eventDelegate);
120 if (result != this->m_EventCallbacks.end())
124 this->m_EventCallbacks.erase(result);
132 auto result = eastl::find_if(this->m_EventCallbacks.begin(), this->m_EventCallbacks.end(),
135 return other->operator==(eventDelegate);
138 assert(result != this->m_EventCallbacks.end() &&
"");
139 this->m_PendingRemoveDelegates.push_back((*result));
#define DECLARE_STATIC_LOGGER
#define LOG_INFO(format,...)
#define DEFINE_STATIC_LOGGER_TEMPLATE(clazz, T, name)
PendingRemoveDelegates m_PendingRemoveDelegates
virtual size_t GetEventCallbackCount() const override
virtual ~EventDispatcher()
EventDelegateList m_EventCallbacks
virtual void AddEventCallback(IEventDelegate *const eventDelegate) override
void Dispatch(IEvent *event) override
virtual void RemoveEventCallback(IEventDelegate *eventDelegate) override
Divide::vector< IEventDelegate * > PendingRemoveDelegates
Divide::vector< IEventDelegate * > EventDelegateList
eastl::vector< Type > vector