A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
RaceConfig.cc
1#include "RaceConfig.hh"
2
3#include "game/system/KPadDirector.hh"
4
5#include <abstract/File.hh>
6
7namespace System {
8
10void RaceConfig::init() {
11 m_raceScenario.init();
12}
13
18 m_raceScenario.playerCount = 1;
19
20 if (s_onInitCallback) {
22 }
23
25}
26
31 switch (m_raceScenario.players[0].type) {
32 case Player::Type::Ghost:
33 initGhost();
34 break;
35 case Player::Type::Local:
36 KPadDirector::Instance()->setHostPad(m_raceScenario.players[0].driftIsAuto);
37 break;
38 default:
39 PANIC("Players must be either local or ghost!");
40 break;
41 }
42}
43
48 GhostFile ghost(m_ghost);
49
50 m_raceScenario.course = ghost.course();
51 Player &player = m_raceScenario.players[0];
52 player.character = ghost.character();
53 player.vehicle = ghost.vehicle();
54 player.driftIsAuto = ghost.driftIsAuto();
55
56 KPadDirector::Instance()->setGhostPad(ghost.inputs(), ghost.driftIsAuto());
57}
58
60RaceConfig *RaceConfig::CreateInstance() {
61 ASSERT(!s_instance);
62 s_instance = new RaceConfig;
63 return s_instance;
64}
65
67void RaceConfig::DestroyInstance() {
68 ASSERT(s_instance);
69 auto *instance = s_instance;
70 s_instance = nullptr;
71 delete instance;
72}
73
75RaceConfig::RaceConfig() = default;
76
78RaceConfig::~RaceConfig() {
79 if (s_instance) {
80 s_instance = nullptr;
81 WARN("RaceConfig instance not explicitly handled!");
82 }
83}
84
86void RaceConfig::Scenario::init() {
87 playerCount = 0;
88 course = Course::GCN_Mario_Circuit;
89
90 for (size_t i = 0; i < players.size(); ++i) {
91 Player &player = players[i];
92 player.character = Character::Mario;
93 player.vehicle = Vehicle::Standard_Kart_M;
94 player.type = Player::Type::None;
95 }
96}
97
98RaceConfig *RaceConfig::s_instance = nullptr;
99
108RaceConfig::InitCallback RaceConfig::s_onInitCallback = nullptr;
109
111void *RaceConfig::s_onInitCallbackArg = nullptr;
112
113} // namespace System
Parsed representation of a binary ghost file.
Definition GhostFile.hh:77
Initializes the player with parameters specified in the provided ghost file.
Definition RaceConfig.hh:15
static void * s_onInitCallbackArg
The argument sent into the callback. This is expected to be reinterpret_casted.
Definition RaceConfig.hh:85
void initGhost()
Initializes the ghost.
Definition RaceConfig.cc:47
static InitCallback s_onInitCallback
Host-agnostic way of initializing RaceConfig. The type of the first player must be set to either Loca...
Definition RaceConfig.hh:84
void initControllers()
Initializes the controllers.
Definition RaceConfig.cc:30
High-level handling for generic system operations, such as input reading, race configuration,...
Definition CourseMap.cc:5