diff options
Diffstat (limited to 'gameloop/include/timer.h')
-rw-r--r-- | gameloop/include/timer.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gameloop/include/timer.h b/gameloop/include/timer.h new file mode 100644 index 0000000..2769e4d --- /dev/null +++ b/gameloop/include/timer.h @@ -0,0 +1,31 @@ +#pragma once + +#include <SDL2/SDL.h> + +class LoopTimer { +public: + static LoopTimer& getInstance(); + void start(); + void update(); + float getDeltaTime() const; + float getDeltaTimeMs() const; + float getFixedDeltaTime() const; + int getCurrentTime() const; + void setFPS(int FPS); + int getFPS() const; + void enforceFrameRate(); + float getLag() const; +private: + LoopTimer(); + int FPS = 30; + float frameTargetTime = FPS / 1000; + int lastTime; + float fixedDeltaTime = 2; + float maxDeltaTime = 1; + float fixedTime = 0; + int lastFrameTime; + float deltaTime; + float time = 0; + int frequency; + float lag; +}; |