[SDL] Problems calculating time between frames using SDL_GetTicks.
grimfang4 at hotmail.com
Tue Jun 3 05:21:52 PDT 2008
Well, as long as everything else is done properly, here are the only ways this can happen:
SDL_GetTicks() returns bad stuff. This isn't likely.
maxFPS <= 0. I trust you, so this is not likely.
Another function is messing it up. Ditto the last one.
Casting (1000.0 / this->maxFPS) - (SDL_GetTicks() - this->beforeFrameTime) as a Uint32 gives a result of 0.
Now this might be it. You can generally be very sure of SDL_Delay() giving an actual delay. In fact, you should probably make sure that it doesn't delay too much due to its poor resolution (email me for code if you want to fix that). If you're calling SDL_Delay(), you'll never get SDL_GetTicks() to equal your previous call. Unless, however, you're casting it to an integer when you have a float originally (well, double), then you might be calling SDL_Delay(0)! That could possibly do it. The way to fix that is to make your test identical to your argument:
// regulate fps
if((this->maxFPS > 0) && ((SDL_GetTicks() - this->beforeFrameTime) < (Uint32)(1000.0 / this->maxFPS)))
// wait until the desired time has passed
SDL_Delay((Uint32)((1000.0 / this->maxFPS) - (SDL_GetTicks() - this->beforeFrameTime)));
Boy, I hope that's it.
Now you can invite friends from Facebook and other groups to join you on Windows Live™ Messenger. Add now.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SDL