From f45f5c39c74694ebc9c6f699d1d278e61dd06001 Mon Sep 17 00:00:00 2001 From: h4570 Date: Thu, 3 Dec 2020 20:04:35 +0100 Subject: [PATCH] small rework of timer class --- src/engine/engine.cpp | 2 +- src/engine/include/modules/timer.hpp | 3 ++- src/engine/modules/timer.cpp | 24 ++++++------------------ 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 76b7614..4a604ba 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -94,7 +94,7 @@ void Engine::gameLoop() fps = timer.getFPS(); fpsDelayer = 0; } - timer.primeTimer(); + timer.prime(); renderer->endFrame(fps); /** -6~ FPS */ SetAlarm(150, &Engine::wakeup, &mainThreadId); diff --git a/src/engine/include/modules/timer.hpp b/src/engine/include/modules/timer.hpp index 424e8ca..6e9dcd2 100644 --- a/src/engine/include/modules/timer.hpp +++ b/src/engine/include/modules/timer.hpp @@ -12,6 +12,7 @@ #define _TYRA_TIMER_ #include +#include /** Class responsible for fps counting */ class Timer @@ -22,7 +23,7 @@ public: ~Timer(); u32 getTimeDelta(); - void primeTimer(); + inline void prime() { lastTime = *T3_COUNT; } float getFPS(); private: diff --git a/src/engine/modules/timer.cpp b/src/engine/modules/timer.cpp index e62f76e..ac20ba8 100644 --- a/src/engine/modules/timer.cpp +++ b/src/engine/modules/timer.cpp @@ -10,16 +10,11 @@ #include "../include/modules/timer.hpp" -#include - // ---- // Constructors/Destructors // ---- -Timer::Timer() -{ - this->lastTime = *T3_COUNT; -} +Timer::Timer() { prime(); } Timer::~Timer() {} @@ -29,20 +24,13 @@ Timer::~Timer() {} u32 Timer::getTimeDelta() { - this->time = *T3_COUNT; + time = *T3_COUNT; - if (this->time < this->lastTime) // The counter has wrapped - this->change = this->time + (65536 - this->lastTime); + if (time < lastTime) // The counter has wrapped + change = time + (65536 - lastTime); else - this->change = this->time - this->lastTime; - - this->lastTime = this->time; - return this->change; -} - -void Timer::primeTimer() -{ - lastTime = *T3_COUNT; + change = time - lastTime; + return change; } float Timer::getFPS()