BARE2D
Timer.cpp
Go to the documentation of this file.
1
#include "
Timer.hpp
"
2
3
#include <math.h>
4
5
#include "
Logger.hpp
"
6
7
namespace
BARE2D
{
8
9
Timer::Timer
()
10
{
11
m_frameTime
= 0.0;
12
}
13
14
bool
Timer::integrateFrame
()
15
{
16
if
(
m_frameTime
>
m_minDeltaTime
) {
17
m_frameTime
-= std::min(
m_frameTime
,
m_minDeltaTime
);
18
return
true
;
19
}
else
{
20
return
false
;
21
}
22
}
23
24
double
Timer::getDeltaTime
()
25
{
26
return
m_minDeltaTime
> 1.0/100000.0 ? std::min(
m_frameTime
,
m_minDeltaTime
) :
m_frameTime
;
27
}
28
29
void
Timer::startTimer
()
30
{
31
m_startTime
= std::chrono::steady_clock::now();
32
}
33
34
void
Timer::endTimer
()
35
{
36
std::chrono::steady_clock::time_point newTime = std::chrono::steady_clock::now();
37
38
double
deltaMicroseconds = std::chrono::duration_cast<std::chrono::microseconds>(newTime -
m_startTime
).count();
39
40
// Convert from microseconds to fractional seconds.
41
m_frameTime
+= deltaMicroseconds / 1000000.0;
42
}
43
44
void
Timer::setDeltaTimeLimit
(
double
minDt)
45
{
46
m_minDeltaTime
= minDt;
47
}
48
49
}
BARE2D::Timer::Timer
Timer()
Definition:
Timer.cpp:9
BARE2D
Definition:
App.cpp:13
BARE2D::Timer::m_frameTime
double m_frameTime
Definition:
Timer.hpp:44
BARE2D::Timer::endTimer
void endTimer()
To be called at the end of a frame.
Definition:
Timer.cpp:34
BARE2D::Timer::m_startTime
std::chrono::steady_clock::time_point m_startTime
Definition:
Timer.hpp:45
BARE2D::Timer::getDeltaTime
double getDeltaTime()
Definition:
Timer.cpp:24
BARE2D::Timer::m_minDeltaTime
double m_minDeltaTime
Definition:
Timer.hpp:43
BARE2D::Timer::setDeltaTimeLimit
void setDeltaTimeLimit(double minDt)
Sets the maximum value of dt. Naturally, there is no minimum. This doesn't take away from accuracy....
Definition:
Timer.cpp:44
BARE2D::Timer::startTimer
void startTimer()
To be called at the start of a frame.
Definition:
Timer.cpp:29
BARE2D::Timer::integrateFrame
bool integrateFrame()
IntegrateFrame gives an indication of whether we should be updatign again with dt or if we should exi...
Definition:
Timer.cpp:14
Timer.hpp
Logger.hpp
Source
Timer.cpp
Generated by
1.8.17