A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
RailManager.cc
1#include "RailManager.hh"
2
3#include "game/system/CourseMap.hh"
4#include "game/system/map/MapdataGeoObj.hh"
5
6namespace Field {
7
9RailManager *RailManager::CreateInstance() {
10 ASSERT(!s_instance);
11 s_instance = new RailManager;
12 s_instance->createPaths();
13 return s_instance;
14}
15
17void RailManager::DestroyInstance() {
18 ASSERT(s_instance);
19 auto *instance = s_instance;
20 s_instance = nullptr;
21 delete instance;
22}
23
25RailManager::RailManager() = default;
26
28RailManager::~RailManager() = default;
29
31void RailManager::createPaths() {
32 auto *courseMap = System::CourseMap::Instance();
33 m_pointCount = courseMap->getPointInfoCount();
34 m_extraInterplatorCount = 8;
35 u16 geoCount = courseMap->getGeoObjCount();
36 m_rails.reserve(m_pointCount + m_extraInterplatorCount);
37 m_interpolatorTotal = m_pointCount;
38
39 // For now, assume screenCount of 1 instead of calling into RaceScenario
40 m_cameraPointCount = m_pointCount * 1;
41 m_interpolatorTotal = m_pointCount * 1 + m_extraInterplatorCount;
42 m_cameraCount = 1;
43
44 // The base game indexes based on i and j, so we need to resize regardless of isObjectRoute.
45 m_interpolators = std::span<RailInterpolator *>(new RailInterpolator *[m_interpolatorTotal],
46 m_interpolatorTotal);
47
48 for (u16 i = 0; i < m_pointCount; ++i) {
49 bool isObjectRoute = false;
50 auto *pointInfo = courseMap->getPointInfo(i);
51 bool isSpline = pointInfo->setting(0);
52
53 for (u16 j = 0; j < geoCount; ++j) {
54 auto *geoObj = courseMap->getGeoObj(j);
55
56 if (geoObj->pathId() != i) {
57 continue;
58 }
59
60 if (isSpline) {
61 m_rails.push_back(new RailSpline(i, pointInfo));
62 } else {
63 m_rails.push_back(new RailLine(i, pointInfo));
64 }
65
66 isObjectRoute = true;
67 break;
68 }
69
70 if (isObjectRoute) {
71 continue;
72 }
73
74 if (isSpline) {
75 m_rails.push_back(new RailSpline(i, pointInfo));
76
77 for (u16 j = 0; j < m_cameraCount; ++j) {
78 m_interpolators[j + i * m_cameraCount] = new RailSmoothInterpolator(0.0f, i);
79 }
80 } else {
81 m_rails.push_back(new RailLine(i, pointInfo));
82
83 for (u16 j = 0; j < m_cameraCount; ++j) {
84 m_interpolators[j + i * m_cameraCount] = new RailLinearInterpolator(0.0f, i);
85 }
86 }
87 }
88}
89
90RailManager *RailManager::s_instance = nullptr;
91
92} // namespace Field
Pertains to collision.