event/muxevent.h

Go to the documentation of this file.
00001 
00002 /*
00003  * $Id: muxevent.h,v 1.1 2005/06/22 22:09:45 murrayma Exp $
00004  *
00005  * Author: Markus Stenberg <fingon@iki.fi>
00006  *
00007  *  Copyright (c) 1996 Markus Stenberg
00008  *       All rights reserved
00009  *
00010  * Created: Tue Aug 27 19:02:00 1996 fingon
00011  * Last modified: Sat Jun  6 22:20:36 1998 fingon
00012  *
00013  */
00014 
00015 #ifndef MUXEVENT_H
00016 #define MUXEVENT_H
00017 
00018 #include <event.h>
00019 
00020 /* EVENT_DEBUG adds some useful debugging information to the structure
00021    / allows more diverse set of error messages to be shown. However,
00022    for a run-time version it's practically useless. */
00023 
00024 /* #undef EVENT_DEBUG */
00025 
00026 #define FLAG_FREE_DATA      1   /* Free the 1st data segment after execution */
00027 #define FLAG_FREE_DATA2     2   /* Free the 2nd data segment after execution */
00028 #define FLAG_ZOMBIE         4   /* Exists there just because we're too
00029                                    lazy to search for it everywhere - dud */
00030 
00031 /* ZOMBIE events aren't moved during reschedule, they instead die then.
00032    Killing them outside event_run is kinda unhealthy, therefore we set things
00033    just ZOMBIE and delete if it's convenient for us. */
00034 
00035 /* Main idea: Events are arranged as follows:
00036    - next 1-60sec (depending on present timing) each their own
00037      linked list
00038    - next hour with each min in the own linked list
00039    - next 60 hours with each hour in the own linked list
00040    - the rest in one huge 'stack', ordered according to time
00041      */
00042 
00043 /* typedef unsigned char byte; */
00044 
00045 typedef struct my_event_type {
00046     char flags;
00047     void (*function) (struct my_event_type *);
00048     void *data;
00049     void *data2;
00050     int tick;                   /* The tick this baby was first scheduled to go off */
00051     char type;
00052     struct my_event_type *next;
00053     struct my_event_type *next_in_main;
00054     struct my_event_type *prev_in_main;
00055     struct my_event_type *prev_in_type;
00056     struct my_event_type *next_in_type;
00057     struct event ev;
00058 } MUXEVENT;
00059 
00060 /* Some external things _do_ use this one */
00061 extern int muxevent_tick;
00062 extern int events_scheduled;
00063 extern int events_executed;
00064 extern int events_zombies;
00065 
00066 #include "p.event.h"
00067 
00068 /* Simplified event adding is more or less irrelevant, most programs
00069    tend to make their own macros for it. This is an example,
00070    though. */
00071 #define muxevent_add_simple_arg(time,func,data) muxevent_add(time,0,0,func,data, NULL)
00072 #define muxevent_add_simple_noarg(time,func) muxevent_add(time,0,0,func,NULL, NULL)
00073 
00074 /* Macros for handling simple lists 
00075    Where it applies: a = main list, b = thing to be added, c = prev
00076    field, d = next field (c = next field in case of single-linked
00077    model */
00078 
00079 #define REMOVE_FROM_LIST(a,c,b) if (a == b ) a = b->c; else { MUXEVENT *t; \
00080 for (t=a;t->c != b;t=t->c); t->c = b->c; }
00081 #define REMOVE_FROM_BIDIR_LIST(a,c,d,b) if (b->c) b->c->d = b->d; \
00082  if (b->d) b->d->c = b->c; if (a==b) { a=b->d; if (a) a->c=NULL; }
00083 
00084 #define ADD_TO_LIST_HEAD(a,c,b) b->c = a ; a = b
00085 #define ADD_TO_BIDIR_LIST_HEAD(a,c,d,b) b->d=a ; if (a) a->c = b ; a=b ; \
00086                                         b->c=NULL
00087 
00088 
00089 void muxevent_add(int time, int flags, int type, void (*func) (MUXEVENT *),
00090     void *data, void *data2);
00091 void muxevent_gothru_type_data(int type, void *data, void (*func) (MUXEVENT *));
00092 void event_gothru_type(int type, void (*func) (MUXEVENT *));
00093 
00094 
00095 
00096 /* Did I mention cproto is braindead? */
00097 
00098 #endif                          /* MUXEVENT_H */

Generated on Mon May 28 04:25:18 2007 for BattletechMUX by  doxygen 1.4.7