A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
RaceManager.hh
1#pragma once
2
3#include "game/system/KPadController.hh"
4#include "game/system/Random.hh"
5#include "game/system/map/MapdataCheckPoint.hh"
6#include "game/system/map/MapdataJugemPoint.hh"
7
8#include <egg/math/Vector.hh>
9
10namespace Kinoko {
11
12namespace Host {
13
14class Context;
15
16} // namespace Host
17
18namespace System {
19
28 friend class Host::Context;
29
30public:
31 class Player {
32 public:
33 Player();
34 virtual ~Player() {}
35
36 void init();
37 void calc();
38
39 [[nodiscard]] Timer getLapSplit(size_t idx) const;
40
42 [[nodiscard]] u16 checkpointId() const {
43 return m_checkpointId;
44 }
45
46 [[nodiscard]] f32 raceCompletion() const {
47 return m_raceCompletion;
48 }
49
50 [[nodiscard]] s8 jugemId() const {
51 return m_jugemId;
52 }
53
54 [[nodiscard]] const std::array<Timer, 3> &lapTimers() const {
55 return m_lapTimers;
56 }
57
58 [[nodiscard]] const Timer &lapTimer(size_t idx) const {
59 ASSERT(idx < m_lapTimers.size());
60 return m_lapTimers[idx];
61 }
62
63 [[nodiscard]] const Timer &raceTimer() const {
64 return m_raceTimer;
65 }
66
67 [[nodiscard]] const KPad *inputs() const {
68 return m_inputs;
69 }
71
72 private:
73 MapdataCheckPoint *calcCheckpoint(u16 checkpointId, f32 distanceRatio);
74 [[nodiscard]] bool areCheckpointsSubsequent(const MapdataCheckPoint *checkpoint,
75 u16 nextCheckpointId) const;
76
77 void decrementLap();
78 void incrementLap();
79 void endRace(const Timer &finishTime);
80
81 u16 m_checkpointId;
82 f32 m_raceCompletion;
84 f32 m_checkpointStartLapCompletion;
85 f32 m_lapCompletion;
86 s8 m_jugemId;
87 s16 m_currentLap;
88 s8 m_maxLap;
89 s8 m_maxKcp;
90 std::array<Timer, 3> m_lapTimers;
91 Timer m_raceTimer;
92 const KPad *m_inputs;
93 };
94
95 enum class Stage {
96 Intro = 0,
97 Countdown = 1,
98 Race = 2,
99 FinishLocal = 3,
100 FinishGlobal = 4,
101 };
102
103 void init();
104
106 void endPlayerRace(u32 idx);
107
108 void calc();
109
111 [[nodiscard]] bool isStageReached(Stage stage) const {
112 return static_cast<std::underlying_type_t<Stage>>(m_stage) >=
113 static_cast<std::underlying_type_t<Stage>>(stage);
114 }
115
116 [[nodiscard]] MapdataJugemPoint *jugemPoint() const;
117
120 [[nodiscard]] int getCountdownTimer() const {
121 return STAGE_COUNTDOWN_DURATION - m_timer;
122 }
123
124 [[nodiscard]] Random &random() {
125 return m_random;
126 }
127
128 [[nodiscard]] const Player &player() const {
129 return m_player;
130 }
131
132 [[nodiscard]] const TimerManager &timerManager() const {
133 return m_timerManager;
134 }
135
136 [[nodiscard]] Stage stage() const {
137 return m_stage;
138 }
139
140 [[nodiscard]] u32 timer() const {
141 return m_timer;
142 }
144
145 static RaceManager *CreateInstance();
146 static void DestroyInstance();
147
148 [[nodiscard]] static RaceManager *Instance() {
149 return s_instance;
150 }
151
152private:
153 RaceManager();
154 ~RaceManager() override;
155
156 Random m_random;
157 Player m_player;
158 TimerManager m_timerManager;
159 Stage m_stage;
160 u16 m_introTimer;
161 u32 m_timer;
162
163 static constexpr u16 STAGE_COUNTDOWN_DURATION = 240;
164 static constexpr u32 RNG_SEED = 0x74A1B095;
165
166 static RaceManager *s_instance;
167};
168
169} // namespace System
170
171} // namespace Kinoko
An interface for ensuring certain structures and classes are destroyed with the heap.
Definition Disposer.hh:11
Contexts can be used to restore a previous memory state for the current session.
Definition Context.hh:70
Timer getLapSplit(size_t idx) const
Gets the lap split, which is the difference between the given lap and the previous one.
f32 m_checkpointFactor
The proportion of a lap for the current checkpoint.
Manages the timers that track the stages of a race. Also acts as the interface between the physics en...
void findKartStartPoint(EGG::Vector3f &pos, EGG::Vector3f &angles)
A 3D float vector.
Definition Vector.hh:107
A simple struct to represent a lap or race finish time.