Name: Anonymous 2010-02-08 16:35
This is my broken attempt at a FPS limitor
but it keeps going back and forth, it does slow it down but after another 5000 it goes back to uncapped and then again capped after another 5000 again and again
but it keeps going back and forth, it does slow it down but after another 5000 it goes back to uncapped and then again capped after another 5000 again and again
unsigned int maxfps = 60, framesrendered = 0;
unsigned int lasttime = 0, thistime = 0;
unsigned int fpsdelay = 0, updatelapse = 5000;
float msperframe = 0;
void fpscap(void) { // FIX ME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (thistime - lasttime > updatelapse) {
fpsdelay = 0;
msperframe = 1000 / (framesrendered / (updatelapse / 1000));
fprintf(stdout, "%f ms\n", msperframe);
fprintf(stdout, "%i FPS\n", framesrendered / (updatelapse / 1000));
fflush(stdout);
fpsdelay = (1000 / maxfps) - msperframe;
framesrendered = 0;
lasttime = thistime;
msperframe = 0;
} else {
thistime = SDL_GetTicks();
framesrendered++;
SDL_Delay(fpsdelay);
}
}