Event-driven?
Nathan Yospe
yospe at hawaii.edu
Thu Apr 3 18:23:30 CEST 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?
:
:Michael Hohensee
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:
class Threaded{
// . . .
public:
bool threadStart();
bool threadSleep(TimeState t);
bool threadWake(); // autocalled by threads, wake and execute.
bool threadDie();
bool threadWait(ConditionCheckFunction wakeUpCheck);
};
class Event{
FunctionContainer doIt;
public:
bool Execute();
};
class Queue{
ContainerClass<Event> events; // probably a linklist, at a guess.
// Or one of my chain classes.
public:
void addEvent(Event&); // schedule an event;
void killEventChain(Chain&);
void killEvent(Event&);
void postponeEvent(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-archive
mailing list