blob: a9608cc2f2366e28c2a0cee2713f4f804e987f66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include "Time.hpp"
#include "Common/Casts.hpp"
#include <chrono>
#include <algorithm>
namespace MC {
void Time::start_frame() {
m_current_frame_start = now();
}
void Time::end_frame() {
auto frame_end = now();
m_delta = TO(Real, frame_end - m_current_frame_start) / 1000.0;
m_total_frames++;
}
U64 Time::total_frames() const {
return m_total_frames;
}
Time::Tick Time::tick() const {
return total_frames();
}
Real Time::delta() const {
return std::clamp(m_delta, delta_min, delta_max);
}
Real Time::delta_raw() const {
return m_delta;
}
Time::Timestamp Time::frame_start() const {
return m_current_frame_start;
}
Time::Timestamp Time::now() {
auto time = std::chrono::system_clock::now().time_since_epoch();
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(time);
return ms.count();
}
}
|