Game Development Reference
In-Depth Information
virtual bool VTickVUpdate(unsigned long maxMillis = kINFINITE) = 0;
// Getter for the main global event manager. This is the event manager that
// is used by the majority of the engine, though you are free to define your
// own as long as you instantiate it with setAsGlobal set to false.
// It is not valid to have more than one global event manager.
static IEventManager* Get(void);
};
You can take a look at the comments above each method to see what it is supposed
to do. The implementation of IEventManager manages two sets of objects: event
data and listener delegates. As events are processed by the system, the Event Manager
matches them up with subscribed listener delegate functions and calls each one with
events they care about.
There are two ways to send events
by queue and by trigger. By queue means the
event will sit in line with other events until the game processes IEventManager::
VUpdate() .Bytrigger means the event will be sent immediately almost like calling
each delegate function directly from your calling code.
Now you
'
re ready to see how an Event Manager class implements the interface:
const unsigned int EVENTMANAGER_NUM_QUEUES = 2;
class EventManager : public IEventManager
{
typedef std::list<EventListenerDelegate> EventListenerList;
typedef std::map<EventType, EventListenerList> EventListenerMap;
typedef std::list<IEventDataPtr> EventQueue;
EventListenerMap m_eventListeners;
EventQueue m_queues[EVENTMANAGER_NUM_QUEUES];
int m_activeQueue; // index of actively processing queue; events
// enque to the opposing queue
public:
explicit EventManager(const char* pName, bool setAsGlobal);
virtual
EventManager(void) { }
˜
virtual bool VAddListener(const EventListenerDelegate& eventDelegate,
const EventType& type);
virtual bool VRemoveListener(const EventListenerDelegate& eventDelegate,
const EventType& type);
virtual bool VTriggerVTriggerEvent(const IEventDataPtr& pEvent) const;
virtual bool VQueueEvent(const IEventDataPtr& pEvent);
Search WWH ::




Custom Search