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]] bool drivingWrongWay() const {
55 return m_drivingWrongWay;
56 }
57
58 [[nodiscard]] const std::array<Timer, 3> &lapTimers() const {
59 return m_lapTimers;
60 }
61
62 [[nodiscard]] const Timer &lapTimer(size_t idx) const {
63 ASSERT(idx < m_lapTimers.size());
64 return m_lapTimers[idx];
65 }
66
67 [[nodiscard]] const Timer &raceTimer() const {
68 return m_raceTimer;
69 }
70
71 [[nodiscard]] const KPad *inputs() const {
72 return m_inputs;
73 }
75
76 private:
77 MapdataCheckPoint *calcCheckpoint(u16 checkpointId, f32 distanceRatio);
78 [[nodiscard]] bool areCheckpointsSubsequent(const MapdataCheckPoint *checkpoint,
79 u16 nextCheckpointId) const;
80
81 void decrementLap();
82 void incrementLap();
83 void endRace(const Timer &finishTime);
84
85 u16 m_checkpointId;
86 f32 m_raceCompletion;
88 f32 m_checkpointStartLapCompletion;
89 f32 m_lapCompletion;
90 s8 m_jugemId;
91 s16 m_currentLap;
92 s8 m_maxLap;
93 s8 m_maxKcp;
94 bool m_drivingWrongWay;
95 std::array<Timer, 3> m_lapTimers;
96 Timer m_raceTimer;
97 const KPad *m_inputs;
98 };
99
100 enum class Stage {
101 Intro = 0,
102 Countdown = 1,
103 Race = 2,
104 FinishLocal = 3,
105 FinishGlobal = 4,
106 };
107
108 void init();
109
111 void endPlayerRace(u32 idx);
112
113 void calc();
114
116 [[nodiscard]] bool isStageReached(Stage stage) const {
117 return static_cast<std::underlying_type_t<Stage>>(m_stage) >=
118 static_cast<std::underlying_type_t<Stage>>(stage);
119 }
120
121 [[nodiscard]] MapdataJugemPoint *jugemPoint() const;
122
125 [[nodiscard]] int getCountdownTimer() const {
126 return STAGE_COUNTDOWN_DURATION - m_timer;
127 }
128
129 [[nodiscard]] Random &random() {
130 return m_random;
131 }
132
133 [[nodiscard]] const Player &player() const {
134 return m_player;
135 }
136
137 [[nodiscard]] const TimerManager &timerManager() const {
138 return m_timerManager;
139 }
140
141 [[nodiscard]] Stage stage() const {
142 return m_stage;
143 }
144
145 [[nodiscard]] u32 timer() const {
146 return m_timer;
147 }
149
150 static RaceManager *CreateInstance();
151 static void DestroyInstance();
152
153 [[nodiscard]] static RaceManager *Instance() {
154 return s_instance;
155 }
156
157private:
158 RaceManager();
159 ~RaceManager() override;
160
161 Random m_random;
162 Player m_player;
163 TimerManager m_timerManager;
164 Stage m_stage;
165 u16 m_introTimer;
166 u32 m_timer;
167
168 static constexpr u16 STAGE_COUNTDOWN_DURATION = 240;
169 static constexpr u32 RNG_SEED = 0x74A1B095;
170
171 static RaceManager *s_instance;
172};
173
174} // namespace System
175
176} // 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:71
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.