1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00
vcmi/client/SDL_framerate.cpp

32 lines
642 B
C++
Raw Normal View History

#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();
}