diff src/timer/wince/SDL_systimer.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 92947e3a18db
children 4da1ee79c9af
line wrap: on
line diff
--- a/src/timer/wince/SDL_systimer.c	Sun May 21 17:27:13 2006 +0000
+++ b/src/timer/wince/SDL_systimer.c	Sun May 28 13:04:16 2006 +0000
@@ -34,62 +34,68 @@
 static Uint64 start_date;
 static Uint64 start_ticks;
 
-static Uint64 wce_ticks(void)
+static Uint64
+wce_ticks (void)
 {
-  return((Uint64)GetTickCount());
+    return ((Uint64) GetTickCount ());
 }
 
-static Uint64 wce_date(void)
+static Uint64
+wce_date (void)
 {
-  union
-  {
-	FILETIME ftime;
-	Uint64 itime;
-  } ftime;
-  SYSTEMTIME stime;
+    union
+    {
+        FILETIME ftime;
+        Uint64 itime;
+    } ftime;
+    SYSTEMTIME stime;
 
-  GetSystemTime(&stime);
-  SystemTimeToFileTime(&stime,&ftime.ftime);
-  ftime.itime/=10000; // Convert 100ns intervals to 1ms intervals
-  // Remove ms portion, which can't be relied on
-  ftime.itime -= (ftime.itime % 1000);
-  return(ftime.itime);
+    GetSystemTime (&stime);
+    SystemTimeToFileTime (&stime, &ftime.ftime);
+    ftime.itime /= 10000;       // Convert 100ns intervals to 1ms intervals
+    // Remove ms portion, which can't be relied on
+    ftime.itime -= (ftime.itime % 1000);
+    return (ftime.itime);
 }
 
-static Sint32 wce_rel_ticks(void)
+static Sint32
+wce_rel_ticks (void)
 {
-  return((Sint32)(wce_ticks()-start_ticks));
+    return ((Sint32) (wce_ticks () - start_ticks));
 }
 
-static Sint32 wce_rel_date(void)
+static Sint32
+wce_rel_date (void)
 {
-  return((Sint32)(wce_date()-start_date));
+    return ((Sint32) (wce_date () - start_date));
 }
 
 /* Return time in ms relative to when SDL was started */
-Uint32 SDL_GetTicks()
+Uint32
+SDL_GetTicks ()
 {
-  Sint32 offset=wce_rel_date()-wce_rel_ticks();
-  if((offset < -1000) || (offset > 1000))
-  {
+    Sint32 offset = wce_rel_date () - wce_rel_ticks ();
+    if ((offset < -1000) || (offset > 1000)) {
 //    fprintf(stderr,"Time desync(%+d), resyncing\n",offset/1000);
-	start_ticks-=offset;
-  }
+        start_ticks -= offset;
+    }
 
-  return((Uint32)wce_rel_ticks());
+    return ((Uint32) wce_rel_ticks ());
 }
 
 /* Give up approx. givem milliseconds to the OS. */
-void SDL_Delay(Uint32 ms)
+void
+SDL_Delay (Uint32 ms)
 {
-  Sleep(ms);
+    Sleep (ms);
 }
 
 /* Recard start-time of application for reference */
-void SDL_StartTicks(void)
+void
+SDL_StartTicks (void)
 {
-  start_date=wce_date();
-  start_ticks=wce_ticks();
+    start_date = wce_date ();
+    start_ticks = wce_ticks ();
 }
 
 static UINT WIN_timer;
@@ -99,46 +105,47 @@
 static HANDLE timersThread = 0;
 static HANDLE timersQuitEvent = 0;
 
-DWORD TimersThreadProc(void *data)
+DWORD
+TimersThreadProc (void *data)
 {
-	while(WaitForSingleObject(timersQuitEvent, 10) == WAIT_TIMEOUT)
-	{
-		SDL_ThreadedTimerCheck();
-	}
-	return 0;
+    while (WaitForSingleObject (timersQuitEvent, 10) == WAIT_TIMEOUT) {
+        SDL_ThreadedTimerCheck ();
+    }
+    return 0;
 }
 
-int SDL_SYS_TimerInit(void)
+int
+SDL_SYS_TimerInit (void)
 {
-	// create a thread to process a threaded timers
-	// SetTimer does not suit the needs because 
-	// TimerCallbackProc will be called only when WM_TIMER occured
+    // create a thread to process a threaded timers
+    // SetTimer does not suit the needs because 
+    // TimerCallbackProc will be called only when WM_TIMER occured
 
-	timersQuitEvent = CreateEvent(0, TRUE, FALSE, 0);
-	if( !timersQuitEvent )
-	{
-		SDL_SetError("Cannot create event for timers thread");
-		return -1;
-	}
-	timersThread = CreateThread(NULL, 0, TimersThreadProc, 0, 0, 0);
-	if( !timersThread )
-	{
-		SDL_SetError("Cannot create timers thread, check amount of RAM available");
-		return -1;
-	}
-	SetThreadPriority(timersThread, THREAD_PRIORITY_HIGHEST);
+    timersQuitEvent = CreateEvent (0, TRUE, FALSE, 0);
+    if (!timersQuitEvent) {
+        SDL_SetError ("Cannot create event for timers thread");
+        return -1;
+    }
+    timersThread = CreateThread (NULL, 0, TimersThreadProc, 0, 0, 0);
+    if (!timersThread) {
+        SDL_SetError
+            ("Cannot create timers thread, check amount of RAM available");
+        return -1;
+    }
+    SetThreadPriority (timersThread, THREAD_PRIORITY_HIGHEST);
 
-	return(SDL_SetTimerThreaded(1));
+    return (SDL_SetTimerThreaded (1));
 }
 
-void SDL_SYS_TimerQuit(void)
+void
+SDL_SYS_TimerQuit (void)
 {
-	SetEvent(timersQuitEvent);
-	if( WaitForSingleObject(timersThread, 2000) == WAIT_TIMEOUT )
-		TerminateThread(timersThread, 0);
-	CloseHandle(timersThread);
-	CloseHandle(timersQuitEvent);
-	return;
+    SetEvent (timersQuitEvent);
+    if (WaitForSingleObject (timersThread, 2000) == WAIT_TIMEOUT)
+        TerminateThread (timersThread, 0);
+    CloseHandle (timersThread);
+    CloseHandle (timersQuitEvent);
+    return;
 }
 
 #else
@@ -148,51 +155,57 @@
 /* Data to handle a single periodic alarm */
 static UINT timerID = 0;
 
-static void CALLBACK HandleAlarm(UINT uID,  UINT uMsg, DWORD dwUser,
-						DWORD dw1, DWORD dw2)
+static void CALLBACK
+HandleAlarm (UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
 {
-	SDL_ThreadedTimerCheck();
+    SDL_ThreadedTimerCheck ();
 }
 
 
-int SDL_SYS_TimerInit(void)
+int
+SDL_SYS_TimerInit (void)
 {
-	MMRESULT result;
+    MMRESULT result;
 
-	/* Set timer resolution */
-	result = timeBeginPeriod(TIMER_RESOLUTION);
-	if ( result != TIMERR_NOERROR ) {
-		SDL_SetError("Warning: Can't set %d ms timer resolution",
-							TIMER_RESOLUTION);
-	}
-	/* Allow 10 ms of drift so we don't chew on CPU */
-	timerID = timeSetEvent(TIMER_RESOLUTION,1,HandleAlarm,0,TIME_PERIODIC);
-	if ( ! timerID ) {
-		SDL_SetError("timeSetEvent() failed");
-		return(-1);
-	}
-	return(SDL_SetTimerThreaded(1));
+    /* Set timer resolution */
+    result = timeBeginPeriod (TIMER_RESOLUTION);
+    if (result != TIMERR_NOERROR) {
+        SDL_SetError ("Warning: Can't set %d ms timer resolution",
+                      TIMER_RESOLUTION);
+    }
+    /* Allow 10 ms of drift so we don't chew on CPU */
+    timerID =
+        timeSetEvent (TIMER_RESOLUTION, 1, HandleAlarm, 0, TIME_PERIODIC);
+    if (!timerID) {
+        SDL_SetError ("timeSetEvent() failed");
+        return (-1);
+    }
+    return (SDL_SetTimerThreaded (1));
 }
 
-void SDL_SYS_TimerQuit(void)
+void
+SDL_SYS_TimerQuit (void)
 {
-	if ( timerID ) {
-		timeKillEvent(timerID);
-	}
-	timeEndPeriod(TIMER_RESOLUTION);
+    if (timerID) {
+        timeKillEvent (timerID);
+    }
+    timeEndPeriod (TIMER_RESOLUTION);
 }
 
 #endif
 
-int SDL_SYS_StartTimer(void)
+int
+SDL_SYS_StartTimer (void)
 {
-	SDL_SetError("Internal logic error: WinCE uses threaded timer");
-	return(-1);
+    SDL_SetError ("Internal logic error: WinCE uses threaded timer");
+    return (-1);
 }
 
-void SDL_SYS_StopTimer(void)
+void
+SDL_SYS_StopTimer (void)
 {
-	return;
+    return;
 }
 
 #endif /* SDL_TIMER_WINCE */
+/* vi: set ts=4 sw=4 expandtab: */