Re: Modeling events that occur in a game world
- From: "Aaron J. M." <ajmacd@xxxxxxxxxxxxxxx>
- Date: 21 Apr 2007 13:21:40 -0700
On Apr 21, 2:48 pm, "Leslie Sanford" <jabberdab...@xxxxxxxxxxxxxxxxx>
wrote:
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.
<snip>
As far as accompanying data for each event, you may have to do some
casting.
<snip>
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.
An event queue was what I thought up at first. I thought of having a
generic
Event class that goes into this queue, and there'd be subclasses like
AttackEvent, DeathEvent, BurningRobotAppearsEvent, etc. The problem
with that
is how the information attached to each specific event is lost. The
Visitor
pattern looked like it may address this, considering that there are
several
potential EventVisitors such as the AI or the GUI. However, not all
parts of
the system are likely to be interested in every single type of event,
especially
if I come up with several kinds of events.
Your idea for events having unique IDs is interesting. It doesn't
help with
data carried with the event though. Rather than have a unique ID and
try to
unpack the information like you suggested, it may seem simpler to just
check the
type of the event object directly and then cast it. That may lead to
a lot of
case statements though.
.
- Follow-Ups:
- Re: Modeling events that occur in a game world
- From: Leslie Sanford
- Re: Modeling events that occur in a game world
- References:
- Modeling events that occur in a game world
- From: Aaron J. M.
- Re: Modeling events that occur in a game world
- From: Leslie Sanford
- Modeling events that occur in a game world
- Prev by Date: Re: Modeling events that occur in a game world
- Next by Date: Re: Modeling events that occur in a game world
- Previous by thread: Re: Modeling events that occur in a game world
- Next by thread: Re: Modeling events that occur in a game world
- Index(es):