Re: Modeling events that occur in a game world
- From: "Aaron J. M." <ajmacd@xxxxxxxxxxxxxxx>
- Date: 22 Apr 2007 06:40:06 -0700
On Apr 21, 9:57 pm, "Leslie Sanford" <jabberdab...@xxxxxxxxxxxxxxxxx>
wrote:
When the event queue dequeues an event, it checks the event's ID and
notifies all objects interested in that event by passing the
GameEventArgs object to them. It's then up to the receiver of the event
to unpack it, i.e. cast it to its specific type:
public class Creature : EventListener
{
public void ProcessEvent(GameEventArgs e)
{
switch(e.ID)
{
case EventID.Attack:
{
AttackEventArgs attackEvent = (AttackEventArgs)e;
// Do something in response to the attack...
}
break;
default:
Debug.Fail("Unknown event");
break;
}
}
}
O.K. However, if I'm going to have to do casting and have a bunch of
switch
statements anyway, what's wrong with:
if e instanceof AttackEventArgs
AttackEventArgs attackEvent = (AttackEventArgs)e
else if ...
I'm only asking because using instanceof seems a bit easier. Would
the ID
number be better for performance though?
On Apr 22, 4:17 am, "Dmitry A. Kazakov" <mail...@xxxxxxxxxxxxxxxxx>
wrote:
Why are they events? I would say, that death, under attack, flight etc are
not events, they are states. If creatures are models of physical objects,
then the only event they need is a timer or scheduling event. The object
reads the sensors, changes its state and writes the actuators.
So what you're suggesting is that my "events" should become internal
to the
creature, right? For example, if a creature starts attacking
something, it should
keep track of what it's attacking and how much damage it did by
itself, where this
information would be visible to other objects that can observe the
creature.
However, what if I have events that are not generated by creatures?
For example,
I may decide to have an earthquake happen for some reason, and I want
some
creature AIs to be able to tell that an earthquake happened so that
they can get
scared off. How would I model that?
.
- Follow-Ups:
- Re: Modeling events that occur in a game world
- From: Dmitry A. Kazakov
- 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: Dmitry A. Kazakov
- 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):