// ***************************************************************************** void cEventManager::VUpdate(const TICK tickCurrent, const float fElapsedTime) { // swap active queues and clear the new queue after the swap int queueToProcess = m_activeQueue; m_activeQueue = (m_activeQueue + 1) % 2; m_queues[m_activeQueue].clear(); // Process the queue while (!m_queues[queueToProcess].empty()) { // pop the front of the queue IEventDataPtr pEvent = m_queues[queueToProcess].front(); m_queues[queueToProcess].pop_front(); Log_Write(ILogger::LT_EVENT, 3 , "Processing Event : " + pEvent->VGetEventName()); // find all the delegate functions registered for this event auto findIt = m_eventListeners.find(pEvent->VGetEventID()); if (findIt != m_eventListeners.end()) { const EventListenerList& eventListeners = findIt->second; // call each listener for (auto it = eventListeners.begin(); it != eventListeners.end(); ++it) { EventListenerCallBackFn listener = (*it); listener(pEvent); } } } }
// ***************************************************************************** void cEventManager::VQueueEvent(const IEventDataPtr & pEvent) { // make sure the event is valid if (!pEvent) { Log_Write(ILogger::LT_ERROR, 1, "Invalid event in VQueueEvent()"); return; } auto findIt = m_eventListeners.find(pEvent->VGetEventID()); if (findIt != m_eventListeners.end()) { m_queues[m_activeQueue].push_back(pEvent); } else { Log_Write(ILogger::LT_EVENT, 2, "Skipping event since there are no delegates registered to receive it: " + pEvent->VGetEventName()); } }