Crossfire Server, Branch 1.12  R12190
timers.h
Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /* Crossfire timers support - (C) 2001 by Yann Chachkoff.                    */
00003 /* This code is placed under the GPL.                                        */
00004 /*****************************************************************************/
00005 
00012 #ifndef TIMERS_H
00013 #define TIMERS_H
00014 
00015 #include <global.h>
00016 #include <object.h>
00017 
00018 #ifdef HAVE_TIME_H
00019 #include <time.h>
00020 #endif
00021 
00022 /*****************************************************************************/
00023 /* A timer is a kind of "clock" associated with an object. When the counter  */
00024 /* of a timer reaches 0, it is removed from the list of active timers and an */
00025 /* EVENT_TIMER is generated for the target object.                           */
00026 /* Important note: don't confuse "EVENT_TIMER" and "EVENT_TIME" - the first  */
00027 /* one is called when a timer delay has reached 0 while EVENT_TIME is        */
00028 /* triggered each time the object gets the opportunity to move.              */
00029 /*****************************************************************************/
00030 /* Timer counting methods.                                                   */
00031 /* You can either count the time in seconds or in "crossfire cycles".        */
00032 /* If mode = TIMER_MODE_SECONDS, delay will store the "time to reach" in sec.*/
00033 /* For example, if a timer is created at t=2044s to be triggered 10 seconds  */
00034 /* later, delay = 2054.                                                      */
00035 /* If mode = TIMER_MODE_CYCLES, delay will store the "time remaining", given */
00036 /* in crossfire cycles. For example, if a timer is to be triggered 10 seconds*/
00037 /* later, delay = 10.                                                        */
00038 /*****************************************************************************/
00039 /* Timer limits.                                                             */
00040 /* You can't create more than 1000 timers (I created the timers table as a   */
00041 /* static one not (only) because I was too lazy/incompetent to implement is  */
00042 /* as a dynamic linked-list, but because 1) 1000 should be quite enough, 2)  */
00043 /* 1000 does not use a lot of memory, 3) it would be easier to adapt to some */
00044 /* form of multithreading support with a static list.                        */
00045 /* Anyway, if you think 1000 is not enough, you can safely increase this -   */
00046 /* memory should not be a problem in that case, given the size of a cftimer. */
00047 /*****************************************************************************/
00048 
00049 #define TIMER_MODE_DEAD    0 
00050 #define TIMER_MODE_SECONDS 1 
00051 #define TIMER_MODE_CYCLES  2 
00056 typedef struct _cftimer {
00057     int     mode;   
00058     long    delay;  
00059     tag_t   ob_tag; 
00060 } cftimer;
00061 
00063 #define MAX_TIMERS 1000
00064 
00066 extern cftimer timers_table[MAX_TIMERS];
00067 
00068 #define TIMER_ERR_NONE      0   
00069 #define TIMER_ERR_ID       -1   
00070 #define TIMER_ERR_OBJ      -2   
00071 #define TIMER_ERR_MODE     -3   
00073 #endif /* TIMERS_H */