Game Development Reference
In-Depth Information
auto findIt = m_eventListeners.find(eventType);
if (findIt != m_eventListeners.end())
{
const EventListenerList& eventListeners = findIt->second;
// call each listener
for (auto it = eventListeners.begin(); it != eventListeners.end();
++it)
{
EventListenerDelegate listener = (*it);
listener(pEvent);
}
}
// check to see if time ran out
currMs = GetTickCount();
if (maxMillis != IEventManager::kINFINITE && currMs >= maxMs)
{
GCC_LOG(“EventLoop”, “Aborting event processing; time ran out”);
break;
}
}
// If we couldn't process all of the events, push the remaining events to
// the new active queue.
// Note: To preserve sequencing, go back-to-front, inserting them at the
// head of the active queue.
bool queueFlushed = (m_queues[queueToProcess].empty());
if (!queueFlushed)
{
while (!m_queues[queueToProcess].empty())
{
IEventDataPtr pEvent = m_queues[queueToProcess].back();
m_queues[queueToProcess].pop_back();
m_queues[m_activeQueue].push_front(pEvent);
}
}
return queueFlushed;
}
The VUpdate() method takes all of the queued messages and calls the registered
delegate methods. As I said before, there are actually two queues. This is almost like
double buffering in a renderer. Sometimes handling events creates new events; in fact,
it happens all the time. Colliding with an object might cause it to move and collide
with another object. If you always added events to a single queue, you might never
Search WWH ::




Custom Search