Posted Wednesday, August 12th @ 11:27:19 PM, by George Greer in the Utils dept.
Added Dec 4, 1996. Click the link below to read it or download it.
From: the root of all evil <skylar@ifconfig.intserv.com>
Subject: Timed Events
Here's a simple way to add an event system, it's a little hairy to code
if you're not familiar with linked lists, but the concept is easy and you
should be able to tweak it to suit your needs...
You need:
An event_data structure... I use:
struct event_data {
struct char_data *ch; /* char this event happens to */
int cmd;
/* command number */
char *args; /* typed in args */
int count; /* pulses to event completion */
struct event_data *next; /* next command event in list */
};
A global linked list of events waiting to happen.
A fuction, event_activity(), to execute or disrupt the events.
Now, inside of commands, ACMD(whatever), that I want to be delayed, I
call them with SCMD_DELAY (which I have defined as 0, which is the
default), If the subcmd is SCMD_DELAY, I'll call a function called
add_event() using args that are already available inside of the
command's function like ch, cmd and argument, then I just give it a
timer for how long until the event is supposed to be executed and
return. If the subcmd is not SCMD_DELAY (which means it got called
from event_activity) then I assume the event is up and just execute
the command normally. The function event_activity() is called from
comm.c, along with the rest of the PULSE stuff like mobile_activity(),
every second and just cycles the event_list and checks if any should
be executed, if so, it calls the cmd and removes the event from the queue.
Here's what my event_activity() function looks like...
void event_activity(void)
{
struct event_data *event, *temp;
int i;
for (event = event_list, i=0; i<event_top; ++i) {
--event->count;
if (event->count < 1) {
((*cmd_info[event->cmd].command_pointer) (event->ch, event->line, event->
cmd,
SCMD_EXECUTE));
REMOVE_FROM_LIST(event, event_list, next);
--event_top;
}
event = event->next;
}
}
Not sure if this response was actually helpful, or just confusing... :)
Goodluck,
-Skylar
<< Equipment Ordering [by Lord Kyu] | Reply | View as text | Flattened | Examine (for Objects) [by Andy Hubbard] >> |
|
Related Links |
|
|
|
CircleMUD Snippets |
|
|
Note: Not all of these snippets will work perfectly with
your version of code, so be prepared to fix one
or two bugs that may arise, and please let me know
what you needed to do to fix it. Sending a corrected
version is always welcome.
|
Finally, if you wish to use any of the snippets from this
page, you are more than welcome, just mention the
authors in your credits. If you wish to release any
of these snippets to the public on another site,
contact me FIRST.
|
|
|
|
|
|
|