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