Quote:Original post by Lode the FPS counter switches between 333.33333fps and 250.0000fps constantly, because it sees that the frame either took 3 milliseconds or 4 milliseconds. |
Is the only reason you want a high-performance timer to keep the fps from jumping nearly a 100 fps each frame? If this is the case, then I would agree with what other posters have said and average the fps over a few frames.
Personally, I would do something like this:
...globals
int start_time, current_time, fps;
...in main()
start_time = SDL_GetTicks();
...in your Main Game Loop
static int frames_passed++;
current_time = SDL_GetTicks();
if( time_passed - start_time > 1000 )
{
fps = frames_passed;
start_time = current_time;
frames_passed = 0;
}
The code may have some errors in it because I just wrote it off the top of my head. By sampling fps this way, you actually will get the number of frames that are executed every second, instead of basing fps on a each frame.