Trouble Capping Framerate
Posted: Fri Jul 16, 2010 7:31 pm
Hey, I am trying to ensure that my application runs at a certain frame rate, but keep getting stuck in probably some infinite loop. Here is what I am doing in code, if someone could take a look...
// inside the while(1) loop
int currentTime = SDL_GetTicks();
int msBetween = currentTime - lastTime;
bool delay = false;
if(msBetween < (1000 / FPS))
{
delay = true;
}
if(delay)
{
SDL_Delay((1000 / FPS) - msBetween);
delay = false;
}
// inside the while(1) loop
int currentTime = SDL_GetTicks();
int msBetween = currentTime - lastTime;
bool delay = false;
if(msBetween < (1000 / FPS))
{
delay = true;
}
if(delay)
{
SDL_Delay((1000 / FPS) - msBetween);
delay = false;
}