Merge pull request #3 from h4570/timer-rework

Timer rework
This commit is contained in:
Sandro Sobczyński
2020-12-03 20:08:37 +01:00
committed by GitHub
3 changed files with 9 additions and 20 deletions
+1 -1
View File
@@ -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);
+2 -1
View File
@@ -12,6 +12,7 @@
#define _TYRA_TIMER_
#include <tamtypes.h>
#include <timer.h>
/** 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:
+6 -18
View File
@@ -10,16 +10,11 @@
#include "../include/modules/timer.hpp"
#include <timer.h>
// ----
// 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()