Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
TimerManager.hh
1
#pragma once
2
3
#include <
Common.hh
>
4
5
namespace
Kinoko::System
{
6
8
struct
Timer
{
9
Timer
();
10
Timer
(u16 min_, u8 sec_, u16 mil_);
11
Timer
(u32 data);
12
~Timer
();
13
14
std::strong_ordering operator<=>(
const
Timer
&rhs)
const
{
15
if
(
auto
cmp = min <=> rhs.min; cmp != 0) {
16
return
cmp;
17
}
18
19
if
(
auto
cmp = sec <=> rhs.sec; cmp != 0) {
20
return
cmp;
21
}
22
23
if
(
auto
cmp =
mil <=>
rhs.
mil
; cmp != 0) {
24
return
cmp;
25
}
26
27
return
valid <=> rhs.valid;
28
}
29
30
bool
operator==(
const
Timer
&rhs)
const
=
default
;
31
bool
operator!=(
const
Timer
&rhs)
const
=
default
;
32
34
Timer
operator-(
const
Timer
&rhs)
const
{
35
s16 addMin = 0;
36
s16 addSec = 0;
37
38
s16 newMs =
mil
- rhs.
mil
;
39
if
(newMs < 0) {
40
addSec = -1;
41
newMs += 1000;
42
}
43
44
s16 newSec = addSec + sec - rhs.sec;
45
if
(newSec < 0) {
46
addMin = -1;
47
newSec += 60;
48
}
49
50
s16 newMin = addMin + min - rhs.min;
51
if
(newMin < 0) {
52
newMin = 0;
53
newSec = 0;
54
newMs = 0;
55
}
56
57
return
Timer
(newMin, newSec, newMs);
58
}
59
60
Timer
operator+(f32 ms)
const
{
61
s16 addMin = 0;
62
s16 addSec = 0;
63
64
s16 newMs =
static_cast<
s16
>
(ms +
static_cast<
f32
>
(
mil
));
65
if
(newMs > 999) {
66
addSec = 1;
67
newMs -= 1000;
68
}
69
70
s16 newSec = addSec + sec;
71
if
(newSec > 59) {
72
addMin = 1;
73
newSec -= 60;
74
}
75
76
s16 newMin = addMin + min;
77
if
(newMin > 999) {
78
newMin = 999;
79
newSec = 59;
80
newMs = 999;
81
}
82
83
return
Timer
(newMin, newSec, newMs);
84
}
85
86
u16 min;
87
u8 sec;
88
u16
mil
;
89
bool
valid;
90
};
91
93
class
TimerManager {
94
public
:
95
TimerManager();
96
~TimerManager();
97
98
void
init();
99
void
calc();
100
102
[[nodiscard]]
const
Timer
¤tTimer()
const
{
103
return
m_currentTimer;
104
}
106
108
void
setStarted(
bool
isSet) {
109
m_started = isSet;
110
}
112
113
private
:
114
Timer
m_currentTimer;
115
bool
m_started;
116
u32 m_frameCounter;
117
};
118
119
}
// namespace Kinoko::System
Common.hh
This header houses common data types such as our integral types and enums.
Kinoko::System
High-level handling for generic system operations, such as input reading, race configuration,...
Definition
CourseMap.cc:5
Kinoko::System::Timer
A simple struct to represent a lap or race finish time.
Definition
TimerManager.hh:8
Kinoko::System::Timer::Timer
Timer()
[Unused] Creates a zeroed timer.
Definition
TimerManager.cc:6
Kinoko::System::Timer::mil
u16 mil
Definition
TimerManager.hh:88
game
system
TimerManager.hh
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0