A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
TimerManager.cc
1#include "TimerManager.hh"
2
3namespace System {
4
6Timer::Timer() : min(0), sec(0), mil(0), valid(false) {}
7
8Timer::Timer(u16 min_, u8 sec_, u16 mil_) : min(min_), sec(sec_), mil(mil_), valid(true) {}
9
12Timer::Timer(u32 data) {
13 min = static_cast<u16>(data >> 0x19);
14 sec = static_cast<u8>(data >> 0x12) & 0x7F;
15 mil = static_cast<u16>(data >> 8) & 0x3FF;
16 valid = true;
17}
18
20Timer::~Timer() = default;
21
23TimerManager::TimerManager() {
24 init();
25}
26
28TimerManager::~TimerManager() = default;
29
31void TimerManager::init() {
32 m_currentTimer.min = 0;
33 m_currentTimer.sec = 0;
34 m_currentTimer.mil = 0;
35 m_currentTimer.valid = true;
36
37 m_started = false;
38 m_frameCounter = 0;
39}
40
42void TimerManager::calc() {
43 constexpr f32 REFRESH_PERIOD = 1000.0f / 59.94f;
44 constexpr f32 MILLISECONDS_TO_MINUTES = 1.0f / 60000.0f;
45 constexpr f32 MILLISECONDS_TO_SECONDS = 1.0f / 1000.0f;
46 constexpr f32 SECONDS_TO_MILLISECONDS = 1000.0f;
47 constexpr f32 MINUTES_TO_MILLISECONDS = 60000.0f;
48
49 if (!m_started) {
50 return;
51 }
52
53 u32 minutesMs = static_cast<u32>(static_cast<f32>(m_frameCounter) * REFRESH_PERIOD);
54 u16 minutes = static_cast<u16>(static_cast<f32>(minutesMs) * MILLISECONDS_TO_MINUTES);
55 u32 secondsMs = static_cast<u32>(
56 static_cast<f32>(minutesMs) - static_cast<f32>(minutes) * MINUTES_TO_MILLISECONDS);
57 u8 seconds = static_cast<u8>(static_cast<f32>(secondsMs) * MILLISECONDS_TO_SECONDS);
58 u16 milliseconds = static_cast<u16>(
59 static_cast<f32>(secondsMs) - static_cast<f32>(seconds) * SECONDS_TO_MILLISECONDS);
60
61 m_currentTimer.min = minutes;
62 m_currentTimer.sec = seconds;
63 m_currentTimer.mil = milliseconds;
64 m_currentTimer.valid = true;
65
66 ++m_frameCounter;
67}
68
69} // namespace System
High-level handling for generic system operations, such as input reading, race configuration,...
Definition CourseMap.cc:5
Timer()
[Unused] Creates a zero'd timer.