diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-09-18 15:11:04 +0200 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-09-18 15:11:04 +0200 |
commit | 61e382cedd71127033f91551298607e2e78c3809 (patch) | |
tree | db946bf0dac5cbb504ac7875fb323243d2a6db74 /gameloop/include/timer.h | |
parent | 7eafe293868d5d3875d0bec147e22a266e4ec86c (diff) |
gameloop save
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; +}; |