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 System {
11
20public:
21 class Player {
22 public:
23 Player();
24 virtual ~Player() {}
25
26 void init();
27 void calc();
28
29 [[nodiscard]] Timer getLapSplit(size_t idx) const;
30
32 [[nodiscard]] u16 checkpointId() const {
33 return m_checkpointId;
34 }
35
36 [[nodiscard]] f32 raceCompletion() const {
37 return m_raceCompletion;
38 }
39
40 [[nodiscard]] s8 jugemId() const {
41 return m_jugemId;
42 }
43
44 [[nodiscard]] const std::array<Timer, 3> &lapTimers() const {
45 return m_lapTimers;
46 }
47
48 [[nodiscard]] const Timer &lapTimer(size_t idx) const {
49 ASSERT(idx < m_lapTimers.size());
50 return m_lapTimers[idx];
51 }
52
53 [[nodiscard]] const Timer &raceTimer() const {
54 return m_raceTimer;
55 }
56
57 [[nodiscard]] const KPad *inputs() const {
58 return m_inputs;
59 }
61
62 private:
63 MapdataCheckPoint *calcCheckpoint(u16 checkpointId, f32 distanceRatio);
64 [[nodiscard]] bool areCheckpointsSubsequent(const MapdataCheckPoint *checkpoint,
65 u16 nextCheckpointId) const;
66
67 void decrementLap();
68 void incrementLap();
69 void endRace(const Timer &finishTime);
70
71 u16 m_checkpointId;
72 f32 m_raceCompletion;
74 f32 m_checkpointStartLapCompletion;
75 f32 m_lapCompletion;
76 s8 m_jugemId;
77 s16 m_currentLap;
78 s8 m_maxLap;
79 s8 m_maxKcp;
80 std::array<Timer, 3> m_lapTimers;
81 Timer m_raceTimer;
82 const KPad *m_inputs;
83 };
84
85 enum class Stage {
86 Intro = 0,
87 Countdown = 1,
88 Race = 2,
89 FinishLocal = 3,
90 FinishGlobal = 4,
91 };
92
93 void init();
94
96 void endPlayerRace(u32 idx);
97
98 void calc();
99
101 [[nodiscard]] bool isStageReached(Stage stage) const {
102 return static_cast<std::underlying_type_t<Stage>>(m_stage) >=
103 static_cast<std::underlying_type_t<Stage>>(stage);
104 }
105
106 [[nodiscard]] MapdataJugemPoint *jugemPoint() const;
107
110 [[nodiscard]] int getCountdownTimer() const {
111 return STAGE_COUNTDOWN_DURATION - m_timer;
112 }
113
114 [[nodiscard]] const Player &player() const {
115 return m_player;
116 }
117
118 [[nodiscard]] const TimerManager &timerManager() const {
119 return m_timerManager;
120 }
121
122 [[nodiscard]] Stage stage() const {
123 return m_stage;
124 }
125
126 [[nodiscard]] u32 timer() const {
127 return m_timer;
128 }
130
131 static RaceManager *CreateInstance();
132 static void DestroyInstance();
133
134 [[nodiscard]] static RaceManager *Instance() {
135 return s_instance;
136 }
137
138private:
139 RaceManager();
140 ~RaceManager() override;
141
142 Random m_random;
143 Player m_player;
144 TimerManager m_timerManager;
145 Stage m_stage;
146 u16 m_introTimer;
147 u32 m_timer;
148
149 static constexpr u16 STAGE_COUNTDOWN_DURATION = 240;
150 static constexpr u32 RNG_SEED = 0x74A1B095;
151
152 static RaceManager *s_instance;
153};
154
155} // namespace System
An interface for ensuring certain structures and classes are destroyed with the heap.
Definition Disposer.hh:11
f32 m_checkpointFactor
The proportion of a lap for the current checkpoint.
Timer getLapSplit(size_t idx) const
Gets the lap split, which is the difference between the given lap and the previous one.
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)
High-level handling for generic system operations, such as input reading, race configuration,...
Definition CourseMap.cc:5
A 3D float vector.
Definition Vector.hh:83
A simple struct to represent a lap or race finish time.