Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
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
10
namespace
Kinoko {
11
12
namespace
Host
{
13
14
class
Context
;
15
16
}
// namespace Host
17
18
namespace
System
{
19
27
class
RaceManager :
EGG::Disposer
{
28
friend
class
Host::Context
;
29
30
public
:
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;
87
f32
m_checkpointFactor
;
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
110
void
findKartStartPoint
(
EGG::Vector3f
&pos,
EGG::Vector3f
&angles);
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
157
private
:
158
EGG_NEW_DELETE_FRIEND
159
160
RaceManager();
161
~RaceManager()
override
;
162
163
Random m_random;
164
Player
m_player;
165
TimerManager m_timerManager;
166
Stage m_stage;
167
u16 m_introTimer;
168
u32 m_timer;
169
170
static
constexpr
u16 STAGE_COUNTDOWN_DURATION = 240;
171
static
constexpr
u32 RNG_SEED = 0x74A1B095;
172
173
static
RaceManager *s_instance;
174
};
175
176
}
// namespace System
177
178
}
// namespace Kinoko
Kinoko::EGG::Disposer
An interface for ensuring certain structures and classes are destroyed with the heap.
Definition
Disposer.hh:11
Kinoko::Host::Context
Contexts can be used to restore a previous memory state for the current session.
Definition
Context.hh:71
Kinoko::System::KPad
Definition
KPadController.hh:311
Kinoko::System::MapdataCheckPoint
Definition
MapdataCheckPoint.hh:19
Kinoko::System::RaceManager::Player
Definition
RaceManager.hh:31
Kinoko::System::RaceManager::Player::getLapSplit
Timer getLapSplit(size_t idx) const
Gets the lap split, which is the difference between the given lap and the previous one.
Definition
RaceManager.cc:182
Kinoko::System::RaceManager::Player::m_checkpointFactor
f32 m_checkpointFactor
The proportion of a lap for the current checkpoint.
Definition
RaceManager.hh:87
Kinoko::System::RaceManager::findKartStartPoint
void findKartStartPoint(EGG::Vector3f &pos, EGG::Vector3f &angles)
Definition
RaceManager.cc:21
Kinoko::Host
Represents the host application.
Definition
HeapCommon.hh:11
Kinoko::System
High-level handling for generic system operations, such as input reading, race configuration,...
Definition
CourseMap.cc:5
Kinoko::EGG::Vector3f
A 3D float vector.
Definition
Vector.hh:107
Kinoko::System::Timer
A simple struct to represent a lap or race finish time.
Definition
TimerManager.hh:8
game
system
RaceManager.hh
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0