implement framerate limiting. This is imprecise; it's intended for giving

up CPU before waiting for vsync, and not for limiting to a precise framerate.
This commit is contained in:
Glenn Maynard
2005-07-13 06:16:37 +00:00
parent 989565227b
commit 94ff3eca36
2 changed files with 42 additions and 0 deletions
+35
View File
@@ -27,10 +27,12 @@ static int g_iFramesRenderedSinceLastCheck,
g_iFramesRenderedSinceLastReset,
g_iVertsRenderedSinceLastCheck,
g_iNumChecksSinceLastReset;
static RageTimer g_LastFrameEndedAt( RageZeroTimer );
RageDisplay* DISPLAY = NULL;
Preference<bool> LOG_FPS( "LogFPS", true );
Preference<bool> g_fFrameLimitPercent( "FrameLimitPercent", 0.0f );
CString RageDisplay::PixelFormatToString( PixelFormat pixfmt )
{
@@ -736,6 +738,39 @@ void RageDisplay::DrawCircle( const RageSpriteVertex &v, float radius )
this->DrawCircleInternal( v, radius );
}
void RageDisplay::FrameLimitBeforeVsync( int iFPS )
{
ASSERT( iFPS != 0 );
if( g_LastFrameEndedAt.IsZero() )
return;
if( g_fFrameLimitPercent.Get() == 0.0f )
return;
float fFrameTime = g_LastFrameEndedAt.GetDeltaTime();
float fExpectedTime = 1.0f / iFPS;
/* This is typically used to turn some of the delay that would normally
* be waiting for vsync and turn it into a usleep, to make sure we give
* up the CPU. If we overshoot the sleep, then we'll miss the vsync,
* so allow tweaking the amount of time we expect a frame to take.
* Frame limiting is disabled by setting this to 0. */
fExpectedTime *= g_fFrameLimitPercent.Get();
float fExtraTime = fExpectedTime - fFrameTime;
if( fExtraTime > 0 )
usleep( int(fExtraTime * 1000000) );
}
void RageDisplay::FrameLimitAfterVsync()
{
if( g_fFrameLimitPercent.Get() == 0.0f )
return;
g_LastFrameEndedAt.Touch();
}
RageCompiledGeometry::~RageCompiledGeometry()
{
m_bNeedsNormals = false;