Skip to content

Commit

Permalink
Add a busy loop frame limiter so people can have less load on their G…
Browse files Browse the repository at this point in the history
…PU if they want.
  • Loading branch information
xwidghet committed Sep 8, 2016
1 parent 72f4612 commit c7107ef
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/RageDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ RageDisplay* DISPLAY = NULL; // global and accessible from anywhere in our prog

Preference<bool> LOG_FPS( "LogFPS", true );
Preference<float> g_fFrameLimitPercent( "FrameLimitPercent", 0.0f );
Preference<int> g_fFrameLimit("FrameLimit", 0.0f);

static const char *RagePixelFormatNames[] = {
"RGBA8",
Expand Down Expand Up @@ -925,15 +926,24 @@ void RageDisplay::FrameLimitBeforeVsync( int iFPS )
}

if( !HOOKS->AppHasFocus() )
iDelayMicroseconds = max( iDelayMicroseconds, 10000 ); // give some time to other processes and threads
iDelayMicroseconds = max( iDelayMicroseconds, 10000 );

if (iDelayMicroseconds > 0)
usleep(iDelayMicroseconds);
else if (g_fFrameLimit.Get() > 0 && !g_LastFrameEndedAt.IsZero())
{
double expectedDelta = 1.0 / g_fFrameLimit.Get();
double advanceDelay = expectedDelta - g_LastFrameEndedAt.GetDeltaTime();

if( iDelayMicroseconds > 0 )
usleep( iDelayMicroseconds );
while (advanceDelay > 0.0)
advanceDelay -= g_LastFrameEndedAt.GetDeltaTime();
}

}

void RageDisplay::FrameLimitAfterVsync()
{
if( g_fFrameLimitPercent.Get() == 0.0f )
if( g_fFrameLimitPercent.Get() == 0.0f && g_fFrameLimit.Get() == 0)
return;

g_LastFrameEndedAt.Touch();
Expand Down

0 comments on commit c7107ef

Please sign in to comment.