1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00
vcmi/client/SDL_framerate.cpp
beegee1 7f04ed990b Major refactoring. First part: BattleInterface
Introduction of pre compiled headers,...
2011-12-13 21:23:17 +00:00

32 lines
642 B
C++

#include "StdInc.h"
#include "SDL_framerate.h"
#include <SDL.h>
FPSManager::FPSManager(int rate)
{
this->rate = rate;
this->rateticks = (1000.0 / (double) rate);
this->fps = 0;
}
void FPSManager::init()
{
this->lastticks = SDL_GetTicks();
}
void FPSManager::framerateDelay()
{
Uint32 currentTicks = SDL_GetTicks();
double diff = currentTicks - this->lastticks;
if (diff < this->rateticks) // FPS is higher than it should be, then wait some time
{
SDL_Delay(ceil(this->rateticks) - diff);
}
this->fps = ceil(1000. / (SDL_GetTicks() - this->lastticks));
this->lastticks = SDL_GetTicks();
}