Problem with simple timer function
I'm writing a simple function to regulate frames per second, but somethings going wrong and as far as I can see it should work. Heres the code:
For those of you that don't use SDL SDL_GetTicks() is like a portable version of clock(), and SDL_Delay() sets the prog to sleep for however many millisecs.
void FPS_Cap(unsigned cap)
static unsigned this_frame;
unsigned last_frame, time_taken;
cap = 1000 / cap;
last_frame = this_frame;
this_frame = SDL_GetTicks();
time_taken = this_frame - last_frame;
if(time_taken >= cap) return;
When using this in a simple program capped at 60 the frame rate is only being restricted to ~95. In theory it should only be possible to be <= 60. Is there something wrong with my maths here?