You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
628 B

#include "fpsmanager.h"
namespace segl {
FPSManager::FPSManager(int _fps) {
setFPS(_fps);
frames = 0;
framerate = 0;
lastticks = SDL_GetTicks();
}
void FPSManager::setFPS(int _fps) {
if(_fps<1 || _fps > 500)
return;
tickrate = 1000.0f/(float)_fps;
}
void FPSManager::delay() {
frames++;
Uint32 now = SDL_GetTicks();
Uint32 target = lastticks + (Uint32)(tickrate * (float)frames);
if(now <= target) {
SDL_Delay(target-now);
} else {
framerate = frames/((now-lastticks)/1000.0f);
frames = 0;
lastticks = SDL_GetTicks();
}
}
float FPSManager::getFPS() {
return framerate;
}
} // namespace segl