Game Development Reference
In-Depth Information
The most common (and correct) way of sending events is by using the VQueueEvent
method:
bool EventManager::VQueueEvent(const IEventDataPtr& pEvent)
{
GCC_ASSERT(m_activeQueue >= 0);
GCC_ASSERT(m_activeQueue < EVENTMANAGER_NUM_QUEUES);
auto findIt = m_eventListeners.find(pEvent->VGetEventType());
if (findIt != m_eventListeners.end())
{
m_queues[m_activeQueue].push_back(pEvent);
return true;
}
else
{
return false;
}
}
This function is also pretty simple. First, it finds the associated event listener list. If it
finds this list, it adds the event to the currently active queue. This keeps the Event
Manager from processing events for which there are no listeners.
Of course, you could change your mind about a queued message and want to take it
back, like some of those emails I sent to my boss.
bool EventManager::VAbortEvent(const EventType& inType, bool allOfType)
{
GCC_ASSERT(m_activeQueue >= 0);
GCC_ASSERT(m_activeQueue < EVENTMANAGER_NUM_QUEUES);
bool success = false;
EventListenerMap::iterator findIt = m_eventListeners.find(inType);
if (findIt != m_eventListeners.end())
{
EventQueue& eventQueue = m_queues[m_activeQueue];
auto it = eventQueue.begin();
while (it != eventQueue.end())
{
// Removing an item from the queue will invalidate the iterator, so
// have it point to the next member. All work inside this loop will
// be done using thisIt.
auto thisIt = it;
++it;
Search WWH ::




Custom Search