Game Development Reference
In-Depth Information
maxMillis == IEventManager::kINFINITE
? IEventManager::kINFINITE
: (curMs + maxMillis );
EventListenerMap::const_iterator itWC = m_registry.find( 0 );
// This section added to handle events from other threads
//-----------------------------------------------------
IEventDataPtr pRealtimeEvent;
while (m_RealtimeEventQueue.try_pop(pRealtimeEvent))
{
VQueueEvent(pRealtimeEvent);
curMs = GetTickCount();
if ( maxMillis != IEventManager::kINFINITE )
{
if ( curMs >= maxMs )
{
GCC_ERROR(“A realtime process is spamming the event manager!”);
}
}
}
// -----------------------------------------------------
// swap active queues, make sure new queue is empty after the
// swap ...
// THE REST OF VUpdate() IS UNCHANGED!!!!
There is a new section of code at the top of the method to handle events from real-
time processes. The call to try_pop() grabs an event out of the real-time queue if it
exists, but if the queue is empty, it returns immediately. Since real-time processes can
run at a higher priority, it is possible they could spam the Event Manager faster than
the Event Manager could consume them, so a check is made to compare the current
tick count against the maximum amount of time the Event Manager is supposed to
run before exiting.
Receiving Events in Real-Time Processes
Real-time processes should also be able to receive events from other game subsys-
tems. This requires the same strategy as before, using a thread-safe queue. Here
'
s
the definition of a real-time process that can listen for events:
class EventReaderProcess : public RealtimeProcess
{
public:
 
 
Search WWH ::




Custom Search