Game Development Reference
In-Depth Information
To use the delegate, you instantiate it and call the bind() method. This overloaded
method will bind your function (or object pointer and function pair) to the delegate
object. If you
re binding C++ functions, the easiest thing to do is to use the global
MakeDelegate() function. This function takes in the object pointer and member
function pointer and returns a newly constructed delegate object.
There
'
ll be
using for the event system presented in this chapter. If you want to see some exam-
ples of how to use this system, download the source code for this topic and check out
the following file:
Source\GCC4\3rdParty\FastDelegate\Demo.cpp
This file comes with the fast delegates source bundle and exists to show off the func-
tionality and interface.
You now know how to create an event and write a delegate method that listens for
events, but you still lack a crucial piece of this puzzle. The Event Manager is the
nexus of events in your game. It receives them from practically anywhere and calls
any registered delegate functions.
'
s a lot more to the fast delegates library, but these are the core features we
'
The Event Manager
As you might expect, the Event Manager is more complicated than the events or the
delegate methods. It has a tough job matching events with listeners and doing it in a
manner that is pretty fast. First, you
ll see the IEventManager interface. The Event
Manager class is set up to be a global singleton, and it manages its own global
pointer. This is pretty useful, since virtually every system in your game will need
access to the Event Manager object.
The interface defines the following methods:
'
n VAddListener : Matches a delegate function with an event type, so anytime
the event type is sent, the delegate will be called.
n VRemoveListener : Removes a delegate. You must call this when the
registering object is destroyed.
n VTriggerEvent: Immediately fires an event to listeners that care about it.
n VQueueEvent : Puts an event in a queue to be fired later.
n VAbortEvent : Removes an event from the queue.
n VUpdate : Processes the events in the queue. This is called every game
loop.
 
 
Search WWH ::




Custom Search