src/timer/win32/SDL_systimer.c
changeset 1497 420b3f47806d
parent 1480 0a2bd6507477
child 1635 92947e3a18db
equal deleted inserted replaced
1496:405e20dc004c 1497:420b3f47806d
    28 #include "SDL_timer.h"
    28 #include "SDL_timer.h"
    29 #include "../SDL_timer_c.h"
    29 #include "../SDL_timer_c.h"
    30 
    30 
    31 #ifdef _WIN32_WCE
    31 #ifdef _WIN32_WCE
    32   #error This is WinCE. Please use src/timer/wince/SDL_systimer.c instead.
    32   #error This is WinCE. Please use src/timer/wince/SDL_systimer.c instead.
    33 
       
    34   /* but if you really want to use this file, use these #defines... */
       
    35   #define USE_GETTICKCOUNT
       
    36   #define USE_SETTIMER
       
    37 #endif
    33 #endif
    38 
    34 
    39 #define TIME_WRAP_VALUE	(~(DWORD)0)
    35 #define TIME_WRAP_VALUE	(~(DWORD)0)
    40 
    36 
    41 /* The first (low-resolution) ticks value of the application */
    37 /* The first (low-resolution) ticks value of the application */
   109 void SDL_Delay(Uint32 ms)
   105 void SDL_Delay(Uint32 ms)
   110 {
   106 {
   111 	Sleep(ms);
   107 	Sleep(ms);
   112 }
   108 }
   113 
   109 
   114 #ifdef USE_SETTIMER
       
   115 
       
   116 static UINT WIN_timer;
       
   117 
       
   118 int SDL_SYS_TimerInit(void)
       
   119 {
       
   120 	return(0);
       
   121 }
       
   122 
       
   123 void SDL_SYS_TimerQuit(void)
       
   124 {
       
   125 	return;
       
   126 }
       
   127 
       
   128 /* Forward declaration because this is called by the timer callback */
       
   129 int SDL_SYS_StartTimer(void);
       
   130 
       
   131 static VOID CALLBACK TimerCallbackProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
       
   132 {
       
   133 	Uint32 ms;
       
   134 
       
   135 	ms = SDL_alarm_callback(SDL_alarm_interval);
       
   136 	if ( ms != SDL_alarm_interval ) {
       
   137 		KillTimer(NULL, idEvent);
       
   138 		if ( ms ) {
       
   139 			SDL_alarm_interval = ROUND_RESOLUTION(ms);
       
   140 			SDL_SYS_StartTimer();
       
   141 		} else {
       
   142 			SDL_alarm_interval = 0;
       
   143 		}
       
   144 	}
       
   145 }
       
   146 
       
   147 int SDL_SYS_StartTimer(void)
       
   148 {
       
   149 	int retval;
       
   150 
       
   151 	WIN_timer = SetTimer(NULL, 0, SDL_alarm_interval, TimerCallbackProc);
       
   152 	if ( WIN_timer ) {
       
   153 		retval = 0;
       
   154 	} else {
       
   155 		retval = -1;
       
   156 	}
       
   157 	return retval;
       
   158 }
       
   159 
       
   160 void SDL_SYS_StopTimer(void)
       
   161 {
       
   162 	if ( WIN_timer ) {
       
   163 		KillTimer(NULL, WIN_timer);
       
   164 		WIN_timer = 0;
       
   165 	}
       
   166 }
       
   167 
       
   168 #else /* !USE_SETTIMER */
       
   169 
       
   170 /* Data to handle a single periodic alarm */
   110 /* Data to handle a single periodic alarm */
   171 static UINT timerID = 0;
   111 static UINT timerID = 0;
   172 
   112 
   173 static void CALLBACK HandleAlarm(UINT uID,  UINT uMsg, DWORD_PTR dwUser,
   113 static void CALLBACK HandleAlarm(UINT uID,  UINT uMsg, DWORD_PTR dwUser,
   174 						DWORD_PTR dw1, DWORD_PTR dw2)
   114 						DWORD_PTR dw1, DWORD_PTR dw2)
   213 void SDL_SYS_StopTimer(void)
   153 void SDL_SYS_StopTimer(void)
   214 {
   154 {
   215 	return;
   155 	return;
   216 }
   156 }
   217 
   157 
   218 #endif /* USE_SETTIMER */