Event-driven?

Shawn Halpenny rsh at dos.nortel.com
Fri Apr 4 10:05:35 CEST 1997


On Apr 3,  6:23pm, Nathan Yospe wrote:
NY> Subject: Re: Event-driven?
NY> On Thu, 3 Apr 1997, Michael Hohensee wrote:
NY>
NY> :Precisely how does an event-driven mud work?  I understand the idea, but
NY> :I don't see how it could be run efficiently, and be coded neatly...
NY> :
NY> :Can somebody enlighten me?
NY> :
NY> :Michael Hohensee

[ C++ extract cut ]

In addition to Nathan's snippet, sometimes it's helpful to see an
event-driven "example" of a sort.  Take healing of a player.
Normally, every ~30 seconds the mud loops over all the players,
healing each (and also checking to see if those who aren't injured
need healing).  In an event model though, you can have much more
variety.  One instance:  when the player is injured, an event can be
queued to heal the player in 30 seconds.  Then, somewhat magically, 30
seconds later, the player heals a little bit.  But the nifty thing is,
that if that player is still injured, the execution of the healing
event can queue _another_ healing event to execute some number of
seconds later, and so on until the player is well again.  Then, there
are no more healing events queued for that player until the next
injury.  To generalize, objects (that is, items, rooms, players, or
whatever) are only really processed whenever something of interest
needs to be done to them, or if they are doing something of interest.
Which means:

NY>                             The whole point is, you never have to
NY> check through every object in the game to see if they have to do
NY> something, or have objects keep track of when to do things (I refer of
NY> course, to the item decay flags, the affect expiration flags, etc, that
NY> must be updated every tick on a diku.) Another benefit is the

As for efficiency, one thing I concluded when I started pursuing an event
driven model, was that it's not so much of "Gee, now how do I make all this
work efficiently" but rather "Now that I have an efficient model, look at all
the interesting stuff I can do."  Not having obscene loops frees up so much
time for other things (which can now be much more intricate).

--
Shawn Halpenny
    - proudly .sig-less -- Oops




More information about the mud-dev-archive mailing list