split out GameLoop ...
This commit is contained in:
@@ -1463,94 +1463,6 @@ bool AppHasFocus()
|
|||||||
return g_bHasFocus;
|
return g_bHasFocus;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CheckSkips( float fDeltaTime )
|
|
||||||
{
|
|
||||||
if( !PREFSMAN->m_bLogSkips )
|
|
||||||
return;
|
|
||||||
|
|
||||||
static int iLastFPS = 0;
|
|
||||||
int iThisFPS = DISPLAY->GetFPS();
|
|
||||||
|
|
||||||
/* If vsync is on, and we have a solid framerate (vsync == refresh and we've sustained this
|
|
||||||
* for at least one frame), we expect the amount of time for the last frame to be 1/FPS. */
|
|
||||||
|
|
||||||
if( iThisFPS != DISPLAY->GetVideoModeParams().rate || iThisFPS != iLastFPS )
|
|
||||||
{
|
|
||||||
iLastFPS = iThisFPS;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float fExpectedTime = 1.0f / iThisFPS;
|
|
||||||
const float fDifference = fDeltaTime - fExpectedTime;
|
|
||||||
if( fabsf(fDifference) > 0.002f && fabsf(fDifference) < 0.100f )
|
|
||||||
LOG->Trace("GameLoop timer skip: %i FPS, expected %.3f, got %.3f (%.3f difference)",
|
|
||||||
iThisFPS, fExpectedTime, fDeltaTime, fDifference );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void GameLoop()
|
|
||||||
{
|
|
||||||
RageTimer timer;
|
|
||||||
while(!g_bQuitting)
|
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Update
|
|
||||||
*/
|
|
||||||
float fDeltaTime = timer.GetDeltaTime();
|
|
||||||
|
|
||||||
if( PREFSMAN->m_fConstantUpdateDeltaSeconds > 0 )
|
|
||||||
fDeltaTime = PREFSMAN->m_fConstantUpdateDeltaSeconds;
|
|
||||||
|
|
||||||
CheckSkips( fDeltaTime );
|
|
||||||
|
|
||||||
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, KEY_TAB) ) ) {
|
|
||||||
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, KEY_ACCENT) ) )
|
|
||||||
fDeltaTime = 0; /* both; stop time */
|
|
||||||
else
|
|
||||||
fDeltaTime *= 4;
|
|
||||||
}
|
|
||||||
else if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, KEY_ACCENT) ) )
|
|
||||||
{
|
|
||||||
fDeltaTime /= 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update SOUNDMAN early (before any RageSound::GetPosition calls), to flush position data. */
|
|
||||||
SOUNDMAN->Update( fDeltaTime );
|
|
||||||
|
|
||||||
/* Update song beat information -before- calling update on all the classes that
|
|
||||||
* depend on it. If you don't do this first, the classes are all acting on old
|
|
||||||
* information and will lag. (but no longer fatally, due to timestamping -glenn) */
|
|
||||||
SOUND->Update( fDeltaTime );
|
|
||||||
TEXTUREMAN->Update( fDeltaTime );
|
|
||||||
GAMESTATE->Update( fDeltaTime );
|
|
||||||
SCREENMAN->Update( fDeltaTime );
|
|
||||||
MEMCARDMAN->Update( fDeltaTime );
|
|
||||||
NSMAN->Update( fDeltaTime );
|
|
||||||
|
|
||||||
/* Important: Process input AFTER updating game logic, or input will be acting on song beat from last frame */
|
|
||||||
HandleInputEvents( fDeltaTime );
|
|
||||||
|
|
||||||
LIGHTSMAN->Update( fDeltaTime );
|
|
||||||
|
|
||||||
HOOKS->Update( fDeltaTime );
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Render
|
|
||||||
*/
|
|
||||||
SCREENMAN->Draw();
|
|
||||||
|
|
||||||
/* If we don't have focus, give up lots of CPU. */
|
|
||||||
if( !g_bHasFocus )
|
|
||||||
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
|
|
||||||
* this more intelligently. */
|
|
||||||
else
|
|
||||||
usleep( 1000 ); // give some time to other processes and threads
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) 2001-2004 Chris Danford, Glenn Maynard
|
* (c) 2001-2004 Chris Danford, Glenn Maynard
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|||||||
Reference in New Issue
Block a user