yospe at hawaii.edu
Thu Apr 3 18:23:30 New Zealand Daylight Time 1997
On Thu, 3 Apr 1997, Michael Hohensee wrote:
:Precisely how does an event-driven mud work? I understand the idea, but
:I don't see how it could be run efficiently, and be coded neatly...
:Can somebody enlighten me?
Well, there are a few factors involved here... one, important one, is the
threads/processes driving the execution. In a looped model, there is going
to be a series of checks repeated every x time units. In an event model,
there are a series of threads waiting to do something, either as one per
event (inefficient) or in some sort of pool (Chris Lawrance is doing
something like this, I believe) or en mass, with seperate queues, like my
model, where each time a new event is added to the queue, the thread is
told to wake at time ((new < old) ? new : old). When the thread wakes, it
handles all ripe events, then sets its next waking time to the shortest
event on the queue and goes back to sleep. A simple pseudocode (well,
almost C++) model follows:
// . . .
bool threadSleep(TimeState t);
bool threadWake(); // autocalled by threads, wake and execute.
bool threadWait(ConditionCheckFunction wakeUpCheck);
ContainerClass<Event> events; // probably a linklist, at a guess.
// Or one of my chain classes.
void addEvent(Event&); // schedule an event;
Event *getRipeEvents(TimeState t);
Or something along those lines. The whole point is, you never have to
check through every object in the game to see if they have to do
something, or have objects keep track of when to do things (I refer of
course, to the item decay flags, the affect expiration flags, etc, that
must be updated every tick on a diku.) Another benefit is the
extermination of the annoying clumps of simultanious occurances that
result from a set of ticks... each of which is a direct product of a
subloop of a loop system. To tell the truth, loops look like hacks to my
eyes, and I don't see how _they_ can be coded neatly. Event models, on the
other hand, can be quite neat. Even without object orientation, I would
think, though I have not tried to accomplish it myself.
__ _ __ _ _ , , , ,
/_ / / ) /_ /_) / ) /| /| / /\ First Light of a Nova Dawn
/ / / \ /_ /_) / \ /-|/ |/ /_/ Final Night of a World Gone
Nathan F. Yospe - University of Hawaii Dept of Physics - yospe at hawaii.edu
More information about the MUD-Dev