Re: Modeling events that occur in a game world




"Aaron J. M."

<snip>

So how would I model these events and let my system handle and respond
to them?

Perhaps have each event represented by a unique ID? The ID would just be
an integer representing the event. So the events wouldn't necessarily be
represented by a class hierarchy.

In your app you could have an event queue. Objects that are capable of
generating events have access to the queue and can post events to it.
Objects that are interested in events can register with the queue to be
notified when certain events occur, e.g. tell me when a creature is
slain, etc.

So when a creature in your game does something interesting, it posts an
event to the event queue. Objects that are interested in this event are
notified when the event queue processes the event.

As far as accompanying data for each event, you may have to do some
casting. When an event is enqueued, some accompanying data is enqueued
with it in a generic form, e.g. a void pointer in C or an Object in C#
or Java. Later when the event is dequeued, this generic object is cast
to the proper type. It would require either the event queue or the
receiver of the event know how to unpack the data.


.