Crossfire Server, Branches 1.12  R18729
timers.h
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* Crossfire timers support - (C) 2001 by Yann Chachkoff. */
3 /* This code is placed under the GPL. */
4 /*****************************************************************************/
5 
12 #ifndef TIMERS_H
13 #define TIMERS_H
14 
15 #include <global.h>
16 #include <object.h>
17 
18 #ifdef HAVE_TIME_H
19 #include <time.h>
20 #endif
21 
22 /*****************************************************************************/
23 /* A timer is a kind of "clock" associated with an object. When the counter */
24 /* of a timer reaches 0, it is removed from the list of active timers and an */
25 /* EVENT_TIMER is generated for the target object. */
26 /* Important note: don't confuse "EVENT_TIMER" and "EVENT_TIME" - the first */
27 /* one is called when a timer delay has reached 0 while EVENT_TIME is */
28 /* triggered each time the object gets the opportunity to move. */
29 /*****************************************************************************/
30 /* Timer counting methods. */
31 /* You can either count the time in seconds or in "crossfire cycles". */
32 /* If mode = TIMER_MODE_SECONDS, delay will store the "time to reach" in sec.*/
33 /* For example, if a timer is created at t=2044s to be triggered 10 seconds */
34 /* later, delay = 2054. */
35 /* If mode = TIMER_MODE_CYCLES, delay will store the "time remaining", given */
36 /* in crossfire cycles. For example, if a timer is to be triggered 10 seconds*/
37 /* later, delay = 10. */
38 /*****************************************************************************/
39 /* Timer limits. */
40 /* You can't create more than 1000 timers (I created the timers table as a */
41 /* static one not (only) because I was too lazy/incompetent to implement is */
42 /* as a dynamic linked-list, but because 1) 1000 should be quite enough, 2) */
43 /* 1000 does not use a lot of memory, 3) it would be easier to adapt to some */
44 /* form of multithreading support with a static list. */
45 /* Anyway, if you think 1000 is not enough, you can safely increase this - */
46 /* memory should not be a problem in that case, given the size of a cftimer. */
47 /*****************************************************************************/
48 
49 #define TIMER_MODE_DEAD 0
50 #define TIMER_MODE_SECONDS 1
51 #define TIMER_MODE_CYCLES 2
56 typedef struct _cftimer {
57  int mode;
58  long delay;
60 } cftimer;
61 
63 #define MAX_TIMERS 1000
64 
67 
68 #define TIMER_ERR_NONE 0
69 #define TIMER_ERR_ID -1
70 #define TIMER_ERR_OBJ -2
71 #define TIMER_ERR_MODE -3
73 #endif /* TIMERS_H */
int mode
Definition: timers.h:57
struct _cftimer cftimer
tag_t ob_tag
Definition: timers.h:59
long delay
Definition: timers.h:58
uint32 tag_t
Definition: object.h:40
#define MAX_TIMERS
Definition: timers.h:63
cftimer timers_table[MAX_TIMERS]
Definition: timers.c:46