Game Development Reference
In-Depth Information
'
general-purpose game event system. We
ll start first by exploring game events, and
then we ' ll build a basic Event Manager that you can use as a building block for
your own games.
Game Events
Whenever some authoritative system in your game makes something important
happen, such as destroying an actor, it fires off an event. Your game must then notify
all the appropriate subsystems that the event has occurred so that they can handle
the event in their own way. A good example of an authoritative system is the game
logic, which is responsible for all the actors in the game. An example of a subsystem
that consumes events is the game renderer (or human view). The view needs to know
the actor
s correct position. It also needs to know when the actor is destroyed so that
it can destroy its own internal representation of the actor and remove it from the
scene.
The game logic could try to keep track of all the systems that need to know about
actors, such as the renderer, and call each system
'
s API to tell each one that an
actor has been destroyed. If there are a number of systems that need to know about
actors, the game logic must call into each one, probably using a slightly different API
and parameter list. Yuck!
Fortunately, there
'
s a much better way to do this. Instead of calling each system every
time an actor is destroyed, the game logic could create a game event and send it into
a system that knows how to distribute the event to any subsystem that wants to lis-
ten. One side effect of this solution is that it cleans up the relationship between game
subsystems. Mostly, they don
'
'
t care about anything but themselves and the event
management system.
A system such as an audio system already knows what events it should listen to. In
this case, it would listen to
On the other
hand, there might be tons of other messages that the audio system could safely
ignore, such as an event that signals the end of an animation.
In a well-designed game, each subsystem should be responsible for subscribing to and
handling game events as they pass through the system. The game event system is
global to the application and therefore makes a good candidate to sit in the applica-
tion layer. It manages all communications going on between the game logic and
game views. If the game logic moves or destroys an actor, an event is sent, and all
the game views will receive it. If a game view wants to send a command to the
game logic, it does so through the event system. The game event system is the glue
that holds the entire game logic and game view architecture together.
object collided
or
object destroyed.
 
Search WWH ::




Custom Search