equal
deleted
inserted
replaced
35 #ifdef __cplusplus |
35 #ifdef __cplusplus |
36 extern "C" { |
36 extern "C" { |
37 #endif |
37 #endif |
38 |
38 |
39 /** This is the OS scheduler timeslice, in milliseconds */ |
39 /** This is the OS scheduler timeslice, in milliseconds */ |
40 #define SDL_TIMESLICE 10 |
40 #define SDL_TIMESLICE 10 |
41 |
41 |
42 /** This is the maximum resolution of the SDL timer on all platforms */ |
42 /** This is the maximum resolution of the SDL timer on all platforms */ |
43 #define TIMER_RESOLUTION 10 /**< Experimentally determined */ |
43 #define TIMER_RESOLUTION 10 /**< Experimentally determined */ |
44 |
44 |
45 /** |
45 /** |
46 * Get the number of milliseconds since the SDL library initialization. |
46 * Get the number of milliseconds since the SDL library initialization. |
47 * Note that this value wraps if the program runs for more than ~49 days. |
47 * Note that this value wraps if the program runs for more than ~49 days. |
48 */ |
48 */ |
49 extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void); |
49 extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void); |
50 |
50 |
51 /** Wait a specified number of milliseconds before returning */ |
51 /** Wait a specified number of milliseconds before returning */ |
52 extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms); |
52 extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms); |
53 |
53 |
55 typedef Uint32 (SDLCALL *SDL_TimerCallback)(Uint32 interval); |
55 typedef Uint32 (SDLCALL *SDL_TimerCallback)(Uint32 interval); |
56 |
56 |
57 /** |
57 /** |
58 * Set a callback to run after the specified number of milliseconds has |
58 * Set a callback to run after the specified number of milliseconds has |
59 * elapsed. The callback function is passed the current timer interval |
59 * elapsed. The callback function is passed the current timer interval |
60 * and returns the next timer interval. If the returned value is the |
60 * and returns the next timer interval. If the returned value is the |
61 * same as the one passed in, the periodic alarm continues, otherwise a |
61 * same as the one passed in, the periodic alarm continues, otherwise a |
62 * new alarm is scheduled. If the callback returns 0, the periodic alarm |
62 * new alarm is scheduled. If the callback returns 0, the periodic alarm |
63 * is cancelled. |
63 * is cancelled. |
64 * |
64 * |
65 * To cancel a currently running timer, call SDL_SetTimer(0, NULL); |
65 * To cancel a currently running timer, call SDL_SetTimer(0, NULL); |
68 * main code, and so shouldn't call any functions from within itself. |
68 * main code, and so shouldn't call any functions from within itself. |
69 * |
69 * |
70 * The maximum resolution of this timer is 10 ms, which means that if |
70 * The maximum resolution of this timer is 10 ms, which means that if |
71 * you request a 16 ms timer, your callback will run approximately 20 ms |
71 * you request a 16 ms timer, your callback will run approximately 20 ms |
72 * later on an unloaded system. If you wanted to set a flag signaling |
72 * later on an unloaded system. If you wanted to set a flag signaling |
73 * a frame update at 30 frames per second (every 33 ms), you might set a |
73 * a frame update at 30 frames per second (every 33 ms), you might set a |
74 * timer for 30 ms: |
74 * timer for 30 ms: |
75 * @code SDL_SetTimer((33/10)*10, flag_update); @endcode |
75 * @code SDL_SetTimer((33/10)*10, flag_update); @endcode |
76 * |
76 * |
77 * If you use this function, you need to pass SDL_INIT_TIMER to SDL_Init(). |
77 * If you use this function, you need to pass SDL_INIT_TIMER to SDL_Init(). |
78 * |
78 * |