From 3a973eecbb61d2b209a0ca473b95f2bc88b48bc0 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 7 Feb 2005 09:35:07 +0000 Subject: [PATCH] move priority boosting stuff to ArchHooks --- stepmania/src/StepMania.cpp | 57 +++---------------- stepmania/src/arch/ArchHooks/ArchHooks.h | 3 + .../src/arch/ArchHooks/ArchHooks_Win32.cpp | 33 +++++++++++ .../src/arch/ArchHooks/ArchHooks_Win32.h | 3 + 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 3e6fcc45f6..ec28934d35 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -317,38 +317,6 @@ static bool ChangeAppPri() return true; } -static void BoostAppPri() -{ - if( !ChangeAppPri() ) - return; - -#ifdef _WINDOWS - /* We just want a slight boost, so we don't skip needlessly if something happens - * in the background. We don't really want to be high-priority--above normal should - * be enough. However, ABOVE_NORMAL_PRIORITY_CLASS is only supported in Win2000 - * and later. */ - OSVERSIONINFO version; - version.dwOSVersionInfoSize=sizeof(version); - if( !GetVersionEx(&version) ) - { - LOG->Warn( werr_ssprintf(GetLastError(), "GetVersionEx failed") ); - return; - } - -#ifndef ABOVE_NORMAL_PRIORITY_CLASS -#define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 -#endif - - DWORD pri = HIGH_PRIORITY_CLASS; - if( version.dwMajorVersion >= 5 ) - pri = ABOVE_NORMAL_PRIORITY_CLASS; - - /* Be sure to boost the app, not the thread, to make sure the - * sound thread stays higher priority than the main thread. */ - SetPriorityClass( GetCurrentProcess(), pri ); -#endif -} - static void CheckSettings() { #if defined(WIN32) @@ -737,17 +705,6 @@ RageDisplay *CreateDisplay() RageException::Throw( error ); } -static void RestoreAppPri() -{ - if(!ChangeAppPri()) - return; - -#ifdef _WINDOWS - SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); -#endif -} - - #define GAMEPREFS_INI_PATH "Data/GamePrefs.ini" #define STATIC_INI_PATH "Data/Static.ini" @@ -1169,7 +1126,8 @@ int main(int argc, char* argv[]) /* People may want to do something else while songs are loading, so do * this after loading songs. */ - BoostAppPri(); + if( ChangeAppPri() ) + HOOKS->BoostPriority(); ResetGame(); @@ -1489,10 +1447,13 @@ void FocusChanged( bool bHasFocus ) /* If we lose focus, we may lose input events, especially key releases. */ INPUTFILTER->Reset(); - if(g_bHasFocus) - BoostAppPri(); - else - RestoreAppPri(); + if( ChangeAppPri() ) + { + if( g_bHasFocus ) + HOOKS->BoostPriority(); + else + HOOKS->UnBoostPriority(); + } } static void CheckSkips( float fDeltaTime ) diff --git a/stepmania/src/arch/ArchHooks/ArchHooks.h b/stepmania/src/arch/ArchHooks/ArchHooks.h index 465c57b5e6..68b9844372 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks.h @@ -23,6 +23,9 @@ public: virtual void SetTime( tm newtime ) { } + virtual void BoostPriority() { } + virtual void UnBoostPriority() { } + /* * Return the amount of time since the program started. (This may actually be * since the initialization of HOOKS. diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp index 049cd8b989..95afa9f863 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp @@ -1,6 +1,7 @@ #include "global.h" #include "ArchHooks_Win32.h" #include "RageUtil.h" +#include "RageLog.h" #include "RageThreads.h" #include "PrefsManager.h" #include "ProductInfo.h" @@ -185,6 +186,38 @@ void ArchHooks_Win32::SetTime( tm newtime ) SetLocalTime( &st ); } +void ArchHooks_Win32::BoostPriority() +{ + /* We just want a slight boost, so we don't skip needlessly if something happens + * in the background. We don't really want to be high-priority--above normal should + * be enough. However, ABOVE_NORMAL_PRIORITY_CLASS is only supported in Win2000 + * and later. */ + OSVERSIONINFO version; + version.dwOSVersionInfoSize=sizeof(version); + if( !GetVersionEx(&version) ) + { + LOG->Warn( werr_ssprintf(GetLastError(), "GetVersionEx failed") ); + return; + } + +#ifndef ABOVE_NORMAL_PRIORITY_CLASS +#define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 +#endif + + DWORD pri = HIGH_PRIORITY_CLASS; + if( version.dwMajorVersion >= 5 ) + pri = ABOVE_NORMAL_PRIORITY_CLASS; + + /* Be sure to boost the app, not the thread, to make sure the + * sound thread stays higher priority than the main thread. */ + SetPriorityClass( GetCurrentProcess(), pri ); +} + +void ArchHooks_Win32::UnBoostPriority() +{ + SetPriorityClass( GetCurrentProcess(), NORMAL_PRIORITY_CLASS ); +} + static bool g_bTimerInitialized; static DWORD g_iStartTime; diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h index c9a6b51f08..9c0a3d29d2 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h @@ -18,6 +18,9 @@ public: void ExitTimeCriticalSection(); void SetTime( tm newtime ); + void BoostPriority(); + void UnBoostPriority(); + private: void CheckVideoDriver(); };