Game Development Reference
In-Depth Information
run out of events to process. This problem is handled easily with two queues: one for
the events being actively processed and the other for new events.
The code is very much like what you saw in the VTriggerEvent() method, with
one more difference than the fact the events are being pulled from one of the queues.
It also can be called with a maximum time allowed. If the amount of time is
exceeded, the method exits, even if there are messages still in the queue.
This can be pretty useful for smoothing out some frame rate stutter if you attempt to
handle too many events in one game loop. If your game events start to pile up and your
queue always seems to stay full, perhaps you ' d better work on a little optimization.
Example: Bringing It All Together
Let
ll look at what
happens when you destroy an actor. The first step is to define the event data by writ-
ing a new class that inherits from BaseEventData . You
'
s look at a simple example to bring it all together. In this case, we
'
'
ve already seen this class;
it
'
s EvtData_Destroy_Actor event above, so let
'
s use that. Flip back to earlier in
this chapter if you need a refresher on that class.
The next step is to define the delegate methods that need to handle this event. Here
'
s
what it might look like:
void RoleSystem::DestroyActorDelegate(IEventDataPtr pEventData)
{
// cast the base event pointer to the actual event data we need
shared_ptr<EvtData_Destroy_Actor> pCastEventData =
static_pointer_cast<EvtData_Destroy_Actor>(pEventData);
// Remove the actor from the map of roles. Assume the role map is
// defined as follows:
// std::map<ActorId, RoleData> m_roleMap;
m_roleMap.erase(pCastEventData->GetActorId());
}
Somewhere in the initialization of the role system, you also need to register the
delegate:
bool RoleSystem::VInit(void)
{
// create the delegate function object
EventListenerDelegate delegateFunc =
MakeDelegate(this, &RoleSystem::DestroyActorDelegate);
// register the delegate with the event manager
 
 
Search WWH ::




Custom Search