From e0a85521c9e2880776dbd5d4959461398931f128 Mon Sep 17 00:00:00 2001 From: Thilo Schulz Date: Mon, 31 Jan 2011 20:23:05 +0000 Subject: [PATCH] Explicitly set timer resolution on windows --- code/sys/sys_local.h | 1 + code/sys/sys_unix.c | 11 +++++++++++ code/sys/sys_win32.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/code/sys/sys_local.h b/code/sys/sys_local.h index 71dade7d..08f4a0eb 100644 --- a/code/sys/sys_local.h +++ b/code/sys/sys_local.h @@ -51,6 +51,7 @@ char *Sys_StripAppBundle( char *pwd ); void Sys_GLimpSafeInit( void ); void Sys_GLimpInit( void ); void Sys_PlatformInit( void ); +void Sys_PlatformExit( void ); void Sys_SigHandler( int signal ); void Sys_ErrorDialog( const char *error ); void Sys_AnsiColorPrint( const char *msg ); diff --git a/code/sys/sys_unix.c b/code/sys/sys_unix.c index e1b87ed2..a71b652a 100644 --- a/code/sys/sys_unix.c +++ b/code/sys/sys_unix.c @@ -739,6 +739,17 @@ void Sys_PlatformInit( void ) !( term && ( !strcmp( term, "raw" ) || !strcmp( term, "dumb" ) ) ); } +/* +============== +Sys_PlatformExit + +Unix specific deinitialisation +============== +*/ +void Sys_PlatformExit( void ) +{ +} + /* ============== Sys_SetEnv diff --git a/code/sys/sys_win32.c b/code/sys/sys_win32.c index df0d474c..76a1cecc 100644 --- a/code/sys/sys_win32.c +++ b/code/sys/sys_win32.c @@ -41,6 +41,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // Used to determine where to store user-specific files static char homePath[ MAX_OSPATH ] = { 0 }; +static UINT timerResolution = 0; + #ifdef __WIN64__ void Sys_SnapVector( float *v ) { @@ -696,6 +698,9 @@ Windows specific initialisation */ void Sys_PlatformInit( void ) { + TIMECAPS ptc; + UINT res; + #ifndef DEDICATED const char *SDL_VIDEODRIVER = getenv( "SDL_VIDEODRIVER" ); @@ -708,6 +713,34 @@ void Sys_PlatformInit( void ) else SDL_VIDEODRIVER_externallySet = qfalse; #endif + + if(timeGetDevCaps(&ptc, sizeof(ptc)) == MMSYSERR_NOERROR) + { + timerResolution = ptc.wPeriodMin; + + if(timerResolution > 1) + { + Com_Printf("Warning: Minimum supported timer resolution is %ums " + "on this system, recommended resolution 1ms\n", timerResolution); + } + + timeBeginPeriod(timerResolution); + } + else + timerResolution = 0; +} + +/* +============== +Sys_PlatformExit + +Windows specific initialisation +============== +*/ +void Sys_PlatformExit( void ) +{ + if(timerResolution) + timeEndPeriod(timerResolution); } /*