Game Development Reference
In-Depth Information
virtual bool VAbortEvent(const EventType& type, bool allOfType = false);
virtual bool VTickVUpdate(unsigned long maxMillis = kINFINITE);
};
EventListenerList is a list of EventDelegate objects. EventListenerMap is a
map where the key is an EventType and the data is the EventListenerList . This
is the data structure used to register listener delegate functions. Each event has a list
of delegates to call when the event is triggered. The third typedef , EventQueue ,
defines a list of smart pointers to IEventData objects.
The next block declares the actual data members. The first is the map, and the sec-
ond is an array of event queues. There are two event queues here so that delegate
methods can safely queue up new events. You can imagine an infinite loop where
two events queue up each other. Without two queues, the program would hang in
an infinite loop and never break out of the event VTickVUpdate() function. The
m_activeQueue member is the index of the currently active queue.
The constructor is pretty bare bones:
EventManager::EventManager(char const * const pName, bool setAsGlobal)
: IEventManager(pName, setAsGlobal)
{
m_activeQueue = 0;
}
Here
'
s the code for adding a new delegate function:
bool EventManager::VAddListener(const EventListenerDelegate& eventDelegate,
const EventType& type)
{
// this will find or create the entry
EventListenerList& eventListenerList = m_eventListeners[type];
for (auto it = eventListenerList.begin(); it != eventListenerList.end();
++it)
{
if (eventDelegate == (*it))
{
GCC_WARNING(
Attempting to double-register a delegate
);
return false;
}
}
eventListenerList.push_back(eventDelegate);
return true;
}
Search WWH ::




Custom Search