diff options
| author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-06 12:55:10 +0200 | 
|---|---|---|
| committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-06 12:55:10 +0200 | 
| commit | b649adda67ed52c2e3bdcd5aa2cb4b9b0954cf16 (patch) | |
| tree | e8be67b24a30c4321c6bbf458cf0f128c207f187 /mwe/gameloop/src/timer.cpp | |
| parent | 765550bce8a81c6f0c79c0083b14ef68e0c900b2 (diff) | |
| parent | f8b2f9f3a2557313d37d53042dd36f0063f2ee61 (diff) | |
merge master into loek/scripts
Diffstat (limited to 'mwe/gameloop/src/timer.cpp')
| -rw-r--r-- | mwe/gameloop/src/timer.cpp | 13 | 
1 files changed, 4 insertions, 9 deletions
| diff --git a/mwe/gameloop/src/timer.cpp b/mwe/gameloop/src/timer.cpp index 61e144d..97baef6 100644 --- a/mwe/gameloop/src/timer.cpp +++ b/mwe/gameloop/src/timer.cpp @@ -1,15 +1,11 @@  #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; @@ -17,16 +13,14 @@ void LoopTimer::start() {  	deltaTime = 0;  } -// Update the timer, calculate deltaTime  void LoopTimer::update() {  	uint64_t currentFrameTime = SDL_GetTicks64(); -	deltaTime -		= (currentFrameTime - lastFrameTime) / 1000.0; // Convert to seconds +	deltaTime = (currentFrameTime - lastFrameTime) / 1000.0;  	if (deltaTime > maximumDeltaTime) {  		deltaTime = maximumDeltaTime;  	} - +	deltaTime *= gameScale;  	elapsedTime += deltaTime;  	lastFrameTime = currentFrameTime;  } @@ -44,7 +38,8 @@ void LoopTimer::setFPS(int FPS) {  }  int LoopTimer::getFPS() const { return FPS; } - +void LoopTimer::setGameScale(double value) { gameScale = value; }; +double LoopTimer::getGameScale() { return gameScale; }  void LoopTimer::enforceFrameRate() {  	uint64_t currentFrameTime = SDL_GetTicks64();  	double frameDuration = (currentFrameTime - lastFrameTime) / 1000.0; |