21 */ |
21 */ |
22 |
22 |
23 #ifndef _SDL_timer_h |
23 #ifndef _SDL_timer_h |
24 #define _SDL_timer_h |
24 #define _SDL_timer_h |
25 |
25 |
26 /* Header for the SDL time management routines */ |
26 /** |
|
27 * \file SDL_timer.h |
|
28 * |
|
29 * Header for the SDL time management routines |
|
30 */ |
27 |
31 |
28 #include "SDL_stdinc.h" |
32 #include "SDL_stdinc.h" |
29 #include "SDL_error.h" |
33 #include "SDL_error.h" |
30 |
34 |
31 #include "begin_code.h" |
35 #include "begin_code.h" |
32 /* Set up for C function definitions, even when using C++ */ |
36 /* Set up for C function definitions, even when using C++ */ |
33 #ifdef __cplusplus |
37 #ifdef __cplusplus |
|
38 /* *INDENT-OFF* */ |
34 extern "C" { |
39 extern "C" { |
|
40 /* *INDENT-ON* */ |
35 #endif |
41 #endif |
36 |
42 |
37 /* This is the OS scheduler timeslice, in milliseconds */ |
43 /* This is the OS scheduler timeslice, in milliseconds */ |
38 #define SDL_TIMESLICE 10 |
44 #define SDL_TIMESLICE 10 |
39 |
45 |
40 /* This is the maximum resolution of the SDL timer on all platforms */ |
46 /* This is the maximum resolution of the SDL timer on all platforms */ |
41 #define TIMER_RESOLUTION 10 /* Experimentally determined */ |
47 #define TIMER_RESOLUTION 10 /* Experimentally determined */ |
42 |
48 |
43 /* Get the number of milliseconds since the SDL library initialization. |
49 /* Get the number of milliseconds since the SDL library initialization. |
44 * Note that this value wraps if the program runs for more than ~49 days. |
50 * Note that this value wraps if the program runs for more than ~49 days. |
45 */ |
51 */ |
46 extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void); |
52 extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void); |
47 |
53 |
48 /* Wait a specified number of milliseconds before returning */ |
54 /* Wait a specified number of milliseconds before returning */ |
49 extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms); |
55 extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms); |
50 |
56 |
51 /* Function prototype for the timer callback function */ |
57 /* Function prototype for the timer callback function */ |
52 typedef Uint32 (SDLCALL *SDL_TimerCallback)(Uint32 interval); |
58 typedef Uint32(SDLCALL * SDL_TimerCallback) (Uint32 interval); |
53 |
59 |
54 /* Set a callback to run after the specified number of milliseconds has |
60 /* Set a callback to run after the specified number of milliseconds has |
55 * elapsed. The callback function is passed the current timer interval |
61 * elapsed. The callback function is passed the current timer interval |
56 * and returns the next timer interval. If the returned value is the |
62 * and returns the next timer interval. If the returned value is the |
57 * same as the one passed in, the periodic alarm continues, otherwise a |
63 * same as the one passed in, the periodic alarm continues, otherwise a |
77 * should not use this function in multi-threaded applications as signals |
83 * should not use this function in multi-threaded applications as signals |
78 * to multi-threaded apps have undefined behavior in some implementations. |
84 * to multi-threaded apps have undefined behavior in some implementations. |
79 * |
85 * |
80 * This function returns 0 if successful, or -1 if there was an error. |
86 * This function returns 0 if successful, or -1 if there was an error. |
81 */ |
87 */ |
82 extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval, SDL_TimerCallback callback); |
88 extern DECLSPEC int SDLCALL SDL_SetTimer(Uint32 interval, |
|
89 SDL_TimerCallback callback); |
83 |
90 |
84 /* New timer API, supports multiple timers |
91 /* New timer API, supports multiple timers |
85 * Written by Stephane Peter <megastep@lokigames.com> |
92 * Written by Stephane Peter <megastep@lokigames.com> |
86 */ |
93 */ |
87 |
94 |
89 * The callback function is passed the current timer interval and returns |
96 * The callback function is passed the current timer interval and returns |
90 * the next timer interval. If the returned value is the same as the one |
97 * the next timer interval. If the returned value is the same as the one |
91 * passed in, the periodic alarm continues, otherwise a new alarm is |
98 * passed in, the periodic alarm continues, otherwise a new alarm is |
92 * scheduled. If the callback returns 0, the periodic alarm is cancelled. |
99 * scheduled. If the callback returns 0, the periodic alarm is cancelled. |
93 */ |
100 */ |
94 typedef Uint32 (SDLCALL *SDL_NewTimerCallback)(Uint32 interval, void *param); |
101 typedef Uint32(SDLCALL * SDL_NewTimerCallback) (Uint32 interval, void *param); |
95 |
102 |
96 /* Definition of the timer ID type */ |
103 /* Definition of the timer ID type */ |
97 typedef struct _SDL_TimerID *SDL_TimerID; |
104 typedef struct _SDL_TimerID *SDL_TimerID; |
98 |
105 |
99 /* Add a new timer to the pool of timers already running. |
106 /* Add a new timer to the pool of timers already running. |
100 Returns a timer ID, or NULL when an error occurs. |
107 Returns a timer ID, or NULL when an error occurs. |
101 */ |
108 */ |
102 extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param); |
109 extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval, |
|
110 SDL_NewTimerCallback |
|
111 callback, void *param); |
103 |
112 |
104 /* Remove one of the multiple timers knowing its ID. |
113 /* Remove one of the multiple timers knowing its ID. |
105 * Returns a boolean value indicating success. |
114 * Returns a boolean value indicating success. |
106 */ |
115 */ |
107 extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID t); |
116 extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID t); |
108 |
117 |
109 /* Ends C function definitions when using C++ */ |
118 /* Ends C function definitions when using C++ */ |
110 #ifdef __cplusplus |
119 #ifdef __cplusplus |
|
120 /* *INDENT-OFF* */ |
111 } |
121 } |
|
122 /* *INDENT-ON* */ |
112 #endif |
123 #endif |
113 #include "close_code.h" |
124 #include "close_code.h" |
114 |
125 |
115 #endif /* _SDL_timer_h */ |
126 #endif /* _SDL_timer_h */ |
|
127 |
|
128 /* vi: set ts=4 sw=4 expandtab: */ |