aboutsummaryrefslogtreecommitdiff
path: root/gameloop/src/timer.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-09-21 15:31:58 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-09-21 15:31:58 +0200
commitca393b6b47618e48c107ad5c021d86700343648e (patch)
tree298bff793ee331566b6be1840c8d7404409b5198 /gameloop/src/timer.cpp
parent8bf919f750807060f3ac2c640b8a02300af1733c (diff)
move gameloop poc to mwe
Diffstat (limited to 'gameloop/src/timer.cpp')
-rw-r--r--gameloop/src/timer.cpp68
1 files changed, 0 insertions, 68 deletions
diff --git a/gameloop/src/timer.cpp b/gameloop/src/timer.cpp
deleted file mode 100644
index 1e3045f..0000000
--- a/gameloop/src/timer.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-#include "timer.h"
-
-// Constructor (private)
-LoopTimer::LoopTimer(){}
-
-// Get the singleton instance of the timer
-LoopTimer& LoopTimer::getInstance() {
- static LoopTimer instance;
- return instance;
-}
-
-// Start the timer (initialize frame time)
-void LoopTimer::start() {
- lastFrameTime = SDL_GetTicks64();
- elapsedTime = 0;
- elapsedFixedTime = 0;
- deltaTime = 0;
-}
-
-// Update the timer, calculate deltaTime
-void LoopTimer::update() {
- uint64_t currentFrameTime = SDL_GetTicks64();
- deltaTime = (currentFrameTime - lastFrameTime) / 1000.0; // Convert to seconds
-
- if (deltaTime > maximumDeltaTime) {
- deltaTime = maximumDeltaTime;
- }
-
- elapsedTime += deltaTime;
- lastFrameTime = currentFrameTime;
-}
-
-double LoopTimer::getDeltaTime() const {
- return deltaTime;
-}
-int LoopTimer::getCurrentTime() const {
- return SDL_GetTicks();
-}
-
-void LoopTimer::advanceFixedUpdate() {
- elapsedFixedTime += fixedDeltaTime;
-}
-
-double LoopTimer::getFixedDeltaTime() const {
- return fixedDeltaTime;
-}
-
-void LoopTimer::setFPS(int FPS) {
- this->FPS = FPS;
- frameTargetTime = 1.0 / FPS;
-}
-
-int LoopTimer::getFPS() const {
- return FPS;
-}
-
-void LoopTimer::enforceFrameRate() {
- uint64_t currentFrameTime = SDL_GetTicks64();
- double frameDuration = (currentFrameTime - lastFrameTime) / 1000.0;
-
- if (frameDuration < frameTargetTime) {
- uint32_t delayTime = (uint32_t)((frameTargetTime - frameDuration) * 1000.0);
- SDL_Delay(delayTime);
- }
-}
-double LoopTimer::getLag() const {
- return elapsedTime - elapsedFixedTime;
-}