Game Development Reference
In-Depth Information
IEventManager::Get()->VAddListener(delegateFunc,
EvtData_Destroy_Actor::sk_EventType);
}
You also need to remember to remove it in the destructor:
RoleSystem::~RoleSystem(void)
{
// Create a delegate function object. This will have the same value as
// the one previously registered in VInit(). Another way to do this would
// be to cache the delegate object. This is a memory vs performance trade-
// off. Since the performance gain would only be during shut-down, memory
// is the better way to go here.
EventListenerDelegate delegateFunc =
MakeDelegate(this, &RoleSystem::DestroyActorDelegate);
// remove the delegate from the event manager
IEventManager::Get()->VRemoveListener(delegateFunc,
EvtData_Destroy_Actor::sk_EventType);
}
That
'
s all you need to do in order to register events. Here
'
s the code to send the
event:
// Instantiate the event. The event system tracks all events with smart
// pointers, so you must instantiate the event using a smart pointer.
shared_ptr<EvtData_New_Actor> pDestroyEvent(
GCC_NEW EvtData_Destroy_Actor(pActor->GetId());
// Queue the event.
IEventManager::Get()->VQueueEvent(pDestroyEvent);
// Or, if you prefer, force the event to resolve immediately with VTrigger()
// with VTriggerEvent()
IEventManager::Get()->VTriggerVTriggerEvent(pDestroyEvent);
And there you have it, a simple event system!
What Game Events Are Important?
It
t
it? A game like Tetris might care about a few simple events such as Brick Created,
'
s a little something of a cop-out, but it completely depends on your game, doesn
'
A game like The Sims Medie-
val had dozens, if not hundreds, of different game events. Table 11.1 shows an exam-
ple of the kind of game events you might send in just about any game:
Brick Moved,
”“
Brick Rotated,
and
Brick Collision.
 
 
Search WWH ::




Custom Search