Re: [Code] Passing function pointers

From: Christopher J. Dickey (cjd@esca.com)
Date: 10/25/96


On Fri, 25 Oct 1996, Mark Crichton wrote:

>    What I would like to do is to allow the add_queue take the variables time,
> *function, and a varying number of parameters, so *function could be things
> ranging from pulse violence to, (assume I'm sick) a system function call
> like select(), which has a LOT of parameters.
>    I *KNOW* I'm asking for possible problems with this, but I'd like to know
> how it's done.  I know functions like printf() do things like this, but I
> don't have libc code lying around for an example :)  Also, am I only limited
> to functions in my code for the (*func)(ch, vict, info) trick, or could I
> call external functions like select() and what not (note: I wouldn't do 
> something as braindead as call select() every tick, but select() was used as
> an example of a func that takes a good number of parameters)

  If I recall there was this huge thread on the pros and cons of event
driven muds, but at least in my case it seems to work extremely well.
What really matters here is how much coding you really want to get into
and is it worth your time forcing circlemud to do what you want it to or
is it better to just write from scratch.  Personally I chose the second
route, but if you go the first one, besides considering stdargs, you might
think about C++ programming (if you know of course) primarily because
event driven programs (and muds I think) seem to fall naturally under C++.
To make your mud event driven, you'd just create a base class which which
is your event, and have every type of event be derived from it.  Every
object which will be acted upon by events will derive from a base class,
and then your event queue is an object itself.  Events are created by
other events, scheduled by the event queue, and then the queue calls them
up at the appropriate time using timers.  For example, you might have an
attack event which is scheduled at a certain time based on different
circumstances (weapon speeds, character speed, health, etc), it then gets
scheduled say 1.8 seconds later, and then when 1.8 seconds has passed the
attack actually proceeds.  The nice thing about this (and why I used 1.8
seconds as an example) is that you can schedule everything to happen at
pretty much any interval you'd like so that things don't seem so
mechanical in the mud.  You can introduce weapon speeds, casting times,
variations in healing speeds, and probably the nicest thing is the kind of
special procedures you can create out of it (you could give mobs daily
schedules, such as waking up, going to work, going home, going to sleep,
and going out on the weekends).  Instead of the endless running through
lists to make mobs aggressive you could schedule different check times
with fuzz factors so mobs attack at other times than on the heartbeat 
I'd argue it's a tad bit easier with an event queue to create those types
of procedures than with the current implementation.

-cjd

+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/18/00 PST