It's RageDisplay::EndFrame()'s job to give up CPU between frames. Currently,
we're doing this partially in EndFrame (in FrameLimitBeforeVsync and/or the actual vblank wait), and partially in RunGameLoop. These serve the same purpose, so merge them. (The renderer itself should have more control over this, but this is an improvement.)
This commit is contained in:
@@ -179,17 +179,6 @@ void GameLoop::RunGameLoop()
|
||||
* Render
|
||||
*/
|
||||
SCREENMAN->Draw();
|
||||
|
||||
/* If we don't have focus, give up lots of CPU. */
|
||||
// XXX: do this in DISPLAY EndFrame?
|
||||
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
|
||||
* this more intelligently. */
|
||||
else
|
||||
usleep( 1000 ); // give some time to other processes and threads
|
||||
#endif
|
||||
}
|
||||
|
||||
if( ChangeAppPri() )
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "RageSurface.h"
|
||||
#include "Preference.h"
|
||||
#include "LocalizedString.h"
|
||||
#include "arch/ArchHooks/ArchHooks.h"
|
||||
|
||||
//
|
||||
// Statistics stuff
|
||||
@@ -774,12 +775,9 @@ void RageDisplay::FrameLimitBeforeVsync( int iFPS )
|
||||
{
|
||||
ASSERT( iFPS != 0 );
|
||||
|
||||
if( g_LastFrameEndedAt.IsZero() )
|
||||
return;
|
||||
|
||||
if( g_fFrameLimitPercent.Get() == 0.0f )
|
||||
return;
|
||||
|
||||
int iDelayMicroseconds = 0;
|
||||
if( g_fFrameLimitPercent.Get() > 0.0f && !g_LastFrameEndedAt.IsZero() )
|
||||
{
|
||||
float fFrameTime = g_LastFrameEndedAt.GetDeltaTime();
|
||||
float fExpectedTime = 1.0f / iFPS;
|
||||
|
||||
@@ -790,8 +788,20 @@ void RageDisplay::FrameLimitBeforeVsync( int iFPS )
|
||||
* Frame limiting is disabled by setting this to 0. */
|
||||
fExpectedTime *= g_fFrameLimitPercent.Get();
|
||||
float fExtraTime = fExpectedTime - fFrameTime;
|
||||
if( fExtraTime > 0 )
|
||||
usleep( int(fExtraTime * 1000000) );
|
||||
|
||||
iDelayMicroseconds = int(fExtraTime * 1000000);
|
||||
}
|
||||
|
||||
if( !HOOKS->AppHasFocus() )
|
||||
iDelayMicroseconds = max( iDelayMicroseconds, 10000 ); // give some time to other processes and threads
|
||||
|
||||
#if defined(_WINDOWS)
|
||||
/* In Windows, always explicitly give up a minimum amount of CPU for other threads. */
|
||||
iDelayMicroseconds = max( iDelayMicroseconds, 1000 );
|
||||
#endif
|
||||
|
||||
if( iDelayMicroseconds > 0 )
|
||||
usleep( iDelayMicroseconds );
|
||||
}
|
||||
|
||||
void RageDisplay::FrameLimitAfterVsync()
|
||||
|
||||
Reference in New Issue
Block a user