blob: 62e2809d03ae0fbb558154b013a1558d56477e61 (
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
46
47
48
49
|
#pragma once
#include "Common/Pure.hpp"
#include "Common/Sizes.hpp"
namespace MC {
class Time {
public:
// TODO: Document exact units of types.
using Timestamp = U64;
using Tick = U64;
// TODO: Create `Time::Duration` type.
Time() = default;
void start_frame();
void end_frame();
// The total number of frames that have been rendered.
// Starts at 1, with 0 being reserved as the empty value.
PURE U64 total_frames() const;
// The current frame number.
// Starts at 1, with 0 being reserved as the empty value.
// This is the same as total_frames(), but is more descriptive, sometimes.
// :)
PURE Tick tick() const;
// The time in seconds that has passed since the last frame.
// This is always a value between `0.001` and `0.1`.
PURE Real delta() const;
// The time in seconds that has passed since the last frame.
// Unlike `delta()`, this value is not clamped, and can be any positive value.
PURE Real delta_raw() const;
PURE Timestamp frame_start() const;
static Timestamp now();
private:
static constexpr Real delta_max = 1.0 / 10.0;
static constexpr Real delta_min = 1.0 / 1000.0;
U64 m_total_frames = 1;
Timestamp m_current_frame_start = 0;
Real m_delta = 0;
};
}
|