From 54f1409090519445558b77ff17e44254ac64fac9 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Sun, 18 Oct 2009 17:12:02 +0000 Subject: [PATCH] Gave the frame limiter some smarts so it can sleep the EEcore a bit if there's nothing to do for a while. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2033 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/Counters.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pcsx2/Counters.cpp b/pcsx2/Counters.cpp index 3524e0ba89..a4b53141bd 100644 --- a/pcsx2/Counters.cpp +++ b/pcsx2/Counters.cpp @@ -322,11 +322,22 @@ static __forceinline void frameLimit() m_iStart = uExpectedEnd; - while( sDeltaTime < 0 ) + // Shortcut for cases where no waiting is needed (they're running slow already, + // so don't bog 'em down with extra math...) + if( sDeltaTime >= 0 ) return; + + // If we're way ahead then we can afford to sleep the thread a bit. + + s32 msec = (int)((sDeltaTime*-1000) / (s64)GetTickFrequency()); + if( msec > 2 ) Threading::Sleep( msec - 2 ); + + // + while( true ) { - Timeslice(); iEnd = GetCPUTicks(); sDeltaTime = iEnd - uExpectedEnd; + if( sDeltaTime >= 0 ) break; + Timeslice(); } }