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