Page 1 of 1

Trouble Capping Framerate

Posted: Fri Jul 16, 2010 7:31 pm
by JarrodParkes
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;
}

Re: Trouble Capping Framerate

Posted: Fri Jul 16, 2010 10:33 pm
by xiphirx
JarrodParkes wrote: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;
}
You never modify lastTime ;)

Re: Trouble Capping Framerate

Posted: Mon Jul 19, 2010 10:18 am
by JarrodParkes
thanks! i got it fixed now =)

Re: Trouble Capping Framerate

Posted: Mon Jul 19, 2010 11:18 am
by Falco Girgis
Nice, I must have missed this post. Did that fix the problem we were talking about the other day?

Re: Trouble Capping Framerate

Posted: Mon Jul 19, 2010 6:24 pm
by JarrodParkes
which problem? i think it so though :mrgreen: