Added delay to make sure the app does not hog all CPU.

This commit is contained in:
Mikko Mononen 2011-02-25 08:24:30 +00:00
parent fdb4ad30f7
commit d1dde08d35
2 changed files with 12 additions and 1 deletions

View File

@ -419,7 +419,18 @@ int main(int /*argc*/, char** /*argv*/)
}
simIter++;
}
// Clamp the framerate so that we do not hog all the CPU.
const float FRAME_RATE = 40;
if (dt < FRAME_RATE)
{
int ms = (int)((FRAME_RATE - dt)*1000.0f);
if (ms > 10) ms = 10;
if (ms >= 0)
SDL_Delay(ms);
}
// Update and render
glViewport(0, 0, width, height);
glClearColor(0.3f, 0.3f, 0.32f, 1.0f);