2022-05-23 01:13:28 -07:00
|
|
|
#include "fps_limiter.h"
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
|
2022-09-23 05:43:44 -07:00
|
|
|
namespace fallout {
|
|
|
|
|
2022-12-26 01:03:14 -08:00
|
|
|
FpsLimiter::FpsLimiter(unsigned int fps)
|
2022-05-23 01:13:28 -07:00
|
|
|
: _fps(fps)
|
|
|
|
, _ticks(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FpsLimiter::mark()
|
|
|
|
{
|
|
|
|
_ticks = SDL_GetTicks();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FpsLimiter::throttle() const
|
|
|
|
{
|
|
|
|
if (1000 / _fps > SDL_GetTicks() - _ticks) {
|
|
|
|
SDL_Delay(1000 / _fps - (SDL_GetTicks() - _ticks));
|
|
|
|
}
|
|
|
|
}
|
2022-09-23 05:43:44 -07:00
|
|
|
|
|
|
|
} // namespace fallout
|