new frame limiter was sleeping too much

This commit is contained in:
zerofrog
2007-11-24 19:17:10 +00:00
parent ef3ce7ed52
commit 3be557e7fb

View File

@@ -172,7 +172,7 @@ u64 GetCPUTicks()
void FrameLimiter()
{
static unsigned __int64 iStart=0, iEnd=0;
static u64 iStart=0, iEnd=0;
if(iStart==0)
iStart = GetCPUTicks();
@@ -188,16 +188,16 @@ void FrameLimiter()
iEnd = GetCPUTicks();
if(iEnd>iExpectedEnd)
{
if(iEnd>iExpectedEnd) {
u64 diff = iEnd-iExpectedEnd;
if((diff>>3)>iTicks) iExpectedEnd=iEnd;
}
do {
while(iEnd+iTicks/2<iExpectedEnd) { // only should sleep when necessary, so add an offset
Sleep(1);
iEnd = GetCPUTicks();
} while(iEnd<iExpectedEnd);
}
iStart = iExpectedEnd; //remember the expected value frame. improves smoothness
}
}