A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
CourseMap.hh
1#pragma once
2
3#include "game/system/map/MapdataAccessorBase.hh"
4#include "game/system/map/MapdataArea.hh"
5#include "game/system/map/MapdataCannonPoint.hh"
6#include "game/system/map/MapdataCheckPath.hh"
7#include "game/system/map/MapdataCheckPoint.hh"
8#include "game/system/map/MapdataFileAccessor.hh"
9#include "game/system/map/MapdataGeoObj.hh"
10#include "game/system/map/MapdataJugemPoint.hh"
11#include "game/system/map/MapdataPointInfo.hh"
12#include "game/system/map/MapdataStageInfo.hh"
13#include "game/system/map/MapdataStartPoint.hh"
14
15#include <egg/math/Vector.hh>
16
17namespace Kinoko {
18
19namespace Host {
20
21class Context;
22
23} // namespace Host
24
27namespace System {
28
29template <typename T>
30concept MapdataDerived = is_derived_from_template_v<MapdataAccessorBase, T>;
31
36 friend class Host::Context;
37
38public:
39 void init();
40
41 template <MapdataDerived T>
42 [[nodiscard]] T *parseMapdata(u32 sectionName) const {
43 const MapSectionHeader *sectionPtr = m_course->findSection(sectionName);
44 return sectionPtr ? new T(sectionPtr) : nullptr;
45 }
46
47 [[nodiscard]] s16 findSector(const EGG::Vector3f &pos, u16 checkpointIdx, f32 &distanceRatio);
48 [[nodiscard]] s16 findRecursiveSector(const EGG::Vector3f &pos, s16 depth,
49 bool searchBackwardsFirst, MapdataCheckPoint *checkpoint, f32 &completion,
50 bool playerIsForwards) const;
51
53 [[nodiscard]] u16 getCheckPointEntryOffsetMs(u16 i, const EGG::Vector3f &pos,
54 const EGG::Vector3f &prevPos) const;
55 [[nodiscard]] f32 getCheckPointEntryOffsetExact(u16 i, const EGG::Vector3f &pos,
56 const EGG::Vector3f &prevPos) const;
57 [[nodiscard]] s16 getCurrentAreaID(s16 i, const EGG::Vector3f &pos,
58 MapdataAreaBase::Type type) const;
59
61 [[nodiscard]] MapdataCannonPoint *getCannonPoint(u16 i) const {
62 return i < getCannonPointCount() ? m_cannonPoint->get(i) : nullptr;
63 }
64
66 [[nodiscard]] MapdataCheckPath *getCheckPath(u16 i) const {
67 return i < getCheckPathCount() ? m_checkPath->get(i) : nullptr;
68 }
69
71 [[nodiscard]] MapdataCheckPoint *getCheckPoint(u16 i) const {
72 return i < getCheckPointCount() ? m_checkPoint->get(i) : nullptr;
73 }
74
76 [[nodiscard]] MapdataGeoObj *getGeoObj(u16 i) const {
77 return i < getGeoObjCount() ? m_geoObj->get(i) : nullptr;
78 }
79
81 [[nodiscard]] MapdataAreaBase *getArea(u16 i) const {
82 return i < getAreaCount() ? m_area->get(i) : nullptr;
83 }
84
86 [[nodiscard]] MapdataAreaBase *getAreaSorted(u16 i) const {
87 return i < getAreaCount() ? m_area->getSorted(i) : nullptr;
88 }
89
91 [[nodiscard]] MapdataPointInfo *getPointInfo(u16 i) const {
92 return i < getPointInfoCount() ? m_pointInfo->get(i) : nullptr;
93 }
94
96 [[nodiscard]] MapdataJugemPoint *getJugemPoint(u16 i) const {
97 return i < getJugemPointCount() ? m_jugemPoint->get(i) : nullptr;
98 }
99
101 [[nodiscard]] MapdataStageInfo *getStageInfo() const {
102 return getStageInfoCount() != 0 ? m_stageInfo->get(0) : nullptr;
103 }
104
106 [[nodiscard]] MapdataStartPoint *getStartPoint(u16 i) const {
107 return i < getStartPointCount() ? m_startPoint->get(i) : nullptr;
108 }
109
110 [[nodiscard]] u16 getCannonPointCount() const {
111 return m_cannonPoint ? m_cannonPoint->size() : 0;
112 }
113
114 [[nodiscard]] u16 getCheckPathCount() const {
115 return m_checkPath ? m_checkPath->size() : 0;
116 }
117
118 [[nodiscard]] u16 getCheckPointCount() const {
119 return m_checkPoint ? m_checkPoint->size() : 0;
120 }
121
122 [[nodiscard]] u16 getGeoObjCount() const {
123 return m_geoObj ? m_geoObj->size() : 0;
124 }
125
127 [[nodiscard]] u16 getAreaCount() const {
128 return m_area ? m_area->size() : 0;
129 }
130
131 [[nodiscard]] u16 getPointInfoCount() const {
132 return m_pointInfo ? m_pointInfo->size() : 0;
133 }
134
135 [[nodiscard]] u16 getJugemPointCount() const {
136 return m_jugemPoint ? m_jugemPoint->size() : 0;
137 }
138
139 [[nodiscard]] u16 getStageInfoCount() const {
140 return m_stageInfo ? m_stageInfo->size() : 0;
141 }
142
143 [[nodiscard]] u16 getStartPointCount() const {
144 return m_startPoint ? m_startPoint->size() : 0;
145 }
146
147 [[nodiscard]] u32 version() const {
148 return m_course->version();
149 }
150
151 [[nodiscard]] MapdataCheckPathAccessor *checkPath() const {
152 return m_checkPath;
153 }
154
155 [[nodiscard]] MapdataCheckPointAccessor *checkPoint() const {
156 return m_checkPoint;
157 }
158
159 [[nodiscard]] f32 startTmpAngle() const {
160 return m_startTmpAngle;
161 }
162
163 [[nodiscard]] f32 startTmp0() const {
164 return m_startTmp0;
165 }
166
167 [[nodiscard]] f32 startTmp1() const {
168 return m_startTmp1;
169 }
170
171 [[nodiscard]] f32 startTmp2() const {
172 return m_startTmp2;
173 }
174
175 [[nodiscard]] f32 startTmp3() const {
176 return m_startTmp3;
177 }
179
180 static CourseMap *CreateInstance();
181 static void DestroyInstance();
182
183 [[nodiscard]] static CourseMap *Instance() {
184 return s_instance;
185 }
186
187private:
188 CourseMap();
189 ~CourseMap() override;
190
191 [[nodiscard]] s16 findSectorBetweenSides(const EGG::Vector3f &pos,
192 MapdataCheckPoint *checkpoint, f32 &distanceRatio);
193 [[nodiscard]] s16 findSectorOutsideSector(const EGG::Vector3f &pos,
194 MapdataCheckPoint *checkpoint, f32 &distanceRatio);
195 [[nodiscard]] s16 findSectorRegional(const EGG::Vector3f &pos, MapdataCheckPoint *checkpoint,
196 f32 &distanceRatio);
197 [[nodiscard]] s16 searchNextCheckpoint(const EGG::Vector3f &pos, s16 depth,
198 const MapdataCheckPoint *checkpoint, f32 &completion, bool playerIsForwards,
199 bool useCache) const;
200 [[nodiscard]] s16 searchPrevCheckpoint(const EGG::Vector3f &pos, s16 depth,
201 const MapdataCheckPoint *checkpoint, f32 &completion, bool playerIsForwards,
202 bool useCache) const;
203 void clearSectorChecked();
204
205 MapdataFileAccessor *m_course;
206 MapdataStartPointAccessor *m_startPoint;
207 MapdataCheckPathAccessor *m_checkPath;
208 MapdataCheckPointAccessor *m_checkPoint;
209 MapdataPointInfoAccessor *m_pointInfo;
210 MapdataGeoObjAccessor *m_geoObj;
211 MapdataAreaAccessor *m_area;
212 MapdataJugemPointAccessor *m_jugemPoint;
213 MapdataCannonPointAccessor *m_cannonPoint;
214 MapdataStageInfoAccessor *m_stageInfo;
215
216 // TODO: Better names
217 f32 m_startTmpAngle;
218 f32 m_startTmp0;
219 f32 m_startTmp1;
220 f32 m_startTmp2;
221 f32 m_startTmp3;
222
223 static void *LoadFile(const char *filename);
224
225 static CourseMap *s_instance;
226};
227
228} // namespace System
229
230} // namespace Kinoko
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:71
Contains course metadata, notably the starting position.
Definition CourseMap.hh:35
This class represents the course's respawn positions.
A 3D float vector.
Definition Vector.hh:107