Re: Modeling events that occur in a game world
- From: Alvin Ryder <alvin321@xxxxxxxxxxx>
- Date: 23 Apr 2007 20:12:06 -0700
On Apr 22, 3:24 am, "Aaron J. M." <ajm...@xxxxxxxxxxxxxxx> wrote:
I need a way of representing and tracking different events that occur
in a game
I'm working on. I have a world composed of one or more Maps. Each
Map location
(coordinate) may or may not have a Creature. A Creature is controlled
by an AI,
which may also be the player's UI, though the Creatures themselves are
not
necessarily aware of their AIs. Creatures may move to different
coordinates or
attack other Creatures.
Right now the two events I know I'll want to keep track of is when a
Creature
attacks another Creature and when a Creature dies, and I see myself
coming up
with new events as my game grows more intricate. Different parts of
my game
would be interested in different kinds of events. The graphical
display would
be interested in all events so that it may display an appropriate
animation.
More importantly, the different AIs would need to observe recent
events to
modify their behaviour. If a Creature is attacked, the AI controlling
it has a
vested interest in knowing about it.
I'm having trouble modeling this because the different kinds of events
would
keep potentially arbitrary information, making it hard to generalize.
An attack
event would know the attacking Creature, the target Creature, and the
amount of
damage done. A death event would just know the Creature that died. I
might
also implement Creatures grabbing and throwing other Creatures, so a
throw event
would need to know the throwing Creature, the thrown Creature, and
where the
thrown Creature landed. For this reason I can't really make them
subclasses of
a single Event class, since they hold such different information.
So how would I model these events and let my system handle and respond
to them?
Thanks
Hi,
Hmm, looks like google gobbled up my first reply, drats.
I reckon all you need is simple and direct object calls, where an
object is said to "send a message to another object" but these are
just *ordinary method calls*, as in
[code]
bigMonster.take*** (zapper.inflictPain());
[/code]
The backbone of all game engines I've worked with is a "game loop" and
not an Event Message architecture. Inside the game loop you
essentially just
1. *poll* for inputs
2. read incoming network traffic,
3. adjust the model accordingly (calcs, ai, physics...), then
4. output to network and
5. finally feed the renderer...
An Event Message / Queue architecture is an extra level of
indirection, which might not sound like much but I'll bet it's ten
times more work and it'll slow the engine down too much. To thump out
60 frames per second you get all of 16.7 milliseconds to do
everything, no time to waste. If the queue builds up with too many
messages you'll have an ugly controller lag situation. You loose
immediacy.
Actually Microsoft Windows is based on an Event Message / Queue
architecture, you move the mouse, MouseEvents are generated and put in
a Queue(s), interested apps can read the Events and react accordingly.
Mind you I reckon you can use something similar for games but I can't
imagine what you'll gain?
Even if your game is more of a simulation rather than a real-time one,
direct object calls would still be the way to go, think Simula.
Not to confuse matters; most game engines actually employ a scripting
language which sits on top of everything, these may have some event
related stuff in them but they are more of an artist and game designer
friendly wrapper rather than an Event Message backbone.
You're using Python, is that with some OpenGL or Direct/X wrapper or
something? Maybe Python can act as your scripting language around an
engine with speed in all the right places (usually C/C++/assembler
based). I know one really good engine that uses a dialect of LISP as
its outer layer ... so why not Python, it might be really cool.
HTH,
Cheers.
.
- Follow-Ups:
- Re: Modeling events that occur in a game world
- From: Aaron J. M.
- Re: Modeling events that occur in a game world
- From: Aaron J. M.
- Re: Modeling events that occur in a game world
- References:
- Modeling events that occur in a game world
- From: Aaron J. M.
- Modeling events that occur in a game world
- Prev by Date: Re: Modeling events that occur in a game world
- Next by Date: Re: What is the difference between set and class?
- 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):