AireEngine
A 3D Open-World Game Engine
Loading...
Searching...
No Matches
source
utils
clock.h
1
#pragma once
2
3
#include <chrono>
4
namespace
Aire {
6
class
Clock
{
7
private
:
9
using
_Clock = std::chrono::steady_clock;
10
13
using
Secondsf = std::chrono::duration<float, std::ratio<1>>;
14
15
//Last recorded point in time. Used to calculate animation delta.
16
_Clock::time_point time;
17
Secondsf deltaT;
18
double
timeSinceStart;
19
public
:
21
Clock
() : time(_Clock::now()), deltaT(0.0f), timeSinceStart(0.0) {
22
}
23
26
void
reset
() {
27
time = _Clock::now();
28
deltaT = Secondsf(0.0f);
29
timeSinceStart = 0.0;
30
}
31
33
void
update
() {
34
const
auto
now = _Clock::now();
35
Secondsf delta = std::chrono::duration_cast<Secondsf>(now - time);
36
time = now;
37
deltaT = delta;
38
timeSinceStart+=double(delta.count());
39
}
40
43
double
t
()
const
{
44
return
timeSinceStart;
45
}
46
49
float
dt
()
const
{
50
return
deltaT.count();
51
}
52
};
53
}
Aire::Clock
Simple clock class.
Definition
clock.h:6
Aire::Clock::Clock
Clock()
Create a new clock. It tracks time passed since creation (in seconds).
Definition
clock.h:21
Aire::Clock::t
double t() const
Definition
clock.h:43
Aire::Clock::reset
void reset()
Definition
clock.h:26
Aire::Clock::update
void update()
Reset the clock and update dt (time since the last update).
Definition
clock.h:33
Aire::Clock::dt
float dt() const
Definition
clock.h:49
Generated by
1.10.0