diff --git a/stepmania/src/GameLoop.cpp b/stepmania/src/GameLoop.cpp index b8e280f60f..6a173da753 100644 --- a/stepmania/src/GameLoop.cpp +++ b/stepmania/src/GameLoop.cpp @@ -22,8 +22,6 @@ #include "RageTimer.h" #include "RageInput.h" -#include "StepMania.h" - static bool g_bQuitting = false; static RageTimer g_GameplayTimer; @@ -57,8 +55,69 @@ static void CheckGameLoopTimerSkips( float fDeltaTime ) iThisFPS, fExpectedTime, fDeltaTime, fDifference ); } +static bool ChangeAppPri() +{ + if( PREFSMAN->m_BoostAppPriority.Get() == PrefsManager::BOOST_NO ) + return false; + + // if using NTPAD don't boost or else input is laggy +#if defined(_WINDOWS) + if( PREFSMAN->m_BoostAppPriority == PrefsManager::BOOST_AUTO ) + { + vector vDevices; + vector vDescriptions; + + // This can get called before INPUTMAN is constructed. + if( INPUTMAN ) + { + INPUTMAN->GetDevicesAndDescriptions(vDevices,vDescriptions); + CString sInputDevices = join( ",", vDescriptions ); + if( sInputDevices.find("NTPAD") != string::npos ) + { + LOG->Trace( "Using NTPAD. Don't boost priority." ); + return false; + } + } + } +#endif + + /* If -1 and this is a debug build, don't. It makes the debugger sluggish. */ +#ifdef DEBUG + if( PREFSMAN->m_BoostAppPriority == PrefsManager::BOOST_AUTO ) + return false; +#endif + + return true; +} + +static void CheckFocus() +{ + static bool bHasFocus = true; + + bool bHasFocusNow = HOOKS->AppHasFocus(); + if( bHasFocus == bHasFocusNow ) + return; + bHasFocus = bHasFocusNow; + + /* If we lose focus, we may lose input events, especially key releases. */ + INPUTFILTER->Reset(); + + if( ChangeAppPri() ) + { + if( bHasFocus ) + HOOKS->BoostPriority(); + else + HOOKS->UnBoostPriority(); + } +} + void GameLoop() { + /* People may want to do something else while songs are loading, so do + * this after loading songs. */ + if( ChangeAppPri() ) + HOOKS->BoostPriority(); + while( !UserQuit() ) { /* @@ -83,6 +142,8 @@ void GameLoop() fDeltaTime /= 4; } + CheckFocus(); + /* Update SOUNDMAN early (before any RageSound::GetPosition calls), to flush position data. */ SOUNDMAN->Update( fDeltaTime ); @@ -117,7 +178,7 @@ void GameLoop() /* If we don't have focus, give up lots of CPU. */ // XXX: do this in DISPLAY EndFrame? - if( !StepMania::AppHasFocus() ) + if( !HOOKS->AppHasFocus() ) usleep( 10000 );// give some time to other processes and threads #if defined(_WINDOWS) /* In Windows, we want to give up some CPU for other threads. Most OS's do diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index d9dbe00ca0..9d5126632c 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -81,7 +81,6 @@ #define ZIPS_DIR "Packages/" -static bool g_bHasFocus = true; static Preference g_bAllowMultipleInstances( "AllowMultipleInstances", false ); void ReadGamePrefsFromDisk( bool bSwitchToLastPlayedGame ); @@ -304,41 +303,6 @@ void StepMania::ResetGame() PREFSMAN->SavePrefsToDisk(); } -static bool ChangeAppPri() -{ - if( PREFSMAN->m_BoostAppPriority.Get() == PrefsManager::BOOST_NO ) - return false; - - // if using NTPAD don't boost or else input is laggy -#if defined(_WINDOWS) - if( PREFSMAN->m_BoostAppPriority == PrefsManager::BOOST_AUTO ) - { - vector vDevices; - vector vDescriptions; - - // This can get called before INPUTMAN is constructed. - if( INPUTMAN ) - { - INPUTMAN->GetDevicesAndDescriptions(vDevices,vDescriptions); - CString sInputDevices = join( ",", vDescriptions ); - if( sInputDevices.find("NTPAD") != string::npos ) - { - LOG->Trace( "Using NTPAD. Don't boost priority." ); - return false; - } - } - } -#endif - - /* If -1 and this is a debug build, don't. It makes the debugger sluggish. */ -#ifdef DEBUG - if( PREFSMAN->m_BoostAppPriority == PrefsManager::BOOST_AUTO ) - return false; -#endif - - return true; -} - static void CheckSettings() { #if defined(WIN32) @@ -1120,11 +1084,6 @@ int main(int argc, char* argv[]) // we re-run scripts that may add to them. THEME->UpdateLuaGlobals(); - /* People may want to do something else while songs are loading, so do - * this after loading songs. */ - if( ChangeAppPri() ) - HOOKS->BoostPriority(); - StepMania::ResetGame(); /* Now that GAMESTATE is reset, tell SCREENMAN to update the theme (load @@ -1375,7 +1334,7 @@ void HandleInputEvents(float fDeltaTime) INPUTFILTER->GetInputEvents( ieArray ); /* If we don't have focus, discard input. */ - if( !g_bHasFocus ) + if( !HOOKS->AppHasFocus() ) return; for( unsigned i=0; iTrace( "App %s focus", g_bHasFocus? "has":"doesn't have" ); - - /* If we lose focus, we may lose input events, especially key releases. */ - INPUTFILTER->Reset(); - - if( ChangeAppPri() ) - { - if( g_bHasFocus ) - HOOKS->BoostPriority(); - else - HOOKS->UnBoostPriority(); - } -} - -bool StepMania::AppHasFocus() -{ - return g_bHasFocus; -} - /* * (c) 2001-2004 Chris Danford, Glenn Maynard * All rights reserved. diff --git a/stepmania/src/StepMania.h b/stepmania/src/StepMania.h index 25ab7572a0..e4a64cf88e 100644 --- a/stepmania/src/StepMania.h +++ b/stepmania/src/StepMania.h @@ -17,8 +17,6 @@ namespace StepMania void NORETURN HandleException( CString error ); void ResetGame(); void ChangeCurrentGame( const Game* g ); - void FocusChanged( bool bHasFocus ); - bool AppHasFocus(); // If successful, return filename of screenshot in sDir, else return "" CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature, int iIndex = -1 );