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/MapdataCannonPoint.hh"
5#include "game/system/map/MapdataCheckPath.hh"
6#include "game/system/map/MapdataCheckPoint.hh"
7#include "game/system/map/MapdataFileAccessor.hh"
8#include "game/system/map/MapdataGeoObj.hh"
9#include "game/system/map/MapdataJugemPoint.hh"
10#include "game/system/map/MapdataPointInfo.hh"
11#include "game/system/map/MapdataStageInfo.hh"
12#include "game/system/map/MapdataStartPoint.hh"
13
14#include <egg/math/Vector.hh>
15
16namespace Host {
17
18class Context;
19
20} // namespace Host
21
24namespace System {
25
26template <typename T>
27concept MapdataDerived = is_derived_from_template_v<MapdataAccessorBase, T>;
28
33 friend class Host::Context;
34
35public:
36 void init();
37
38 template <MapdataDerived T>
39 [[nodiscard]] T *parseMapdata(u32 sectionName) const {
40 const MapSectionHeader *sectionPtr = m_course->findSection(sectionName);
41 return sectionPtr ? new T(sectionPtr) : nullptr;
42 }
43
44 [[nodiscard]] s16 findSector(const EGG::Vector3f &pos, u16 checkpointIdx, f32 &distanceRatio);
45 [[nodiscard]] s16 findRecursiveSector(const EGG::Vector3f &pos, s16 depth,
46 bool searchBackwardsFirst, MapdataCheckPoint *checkpoint, f32 &completion,
47 bool playerIsForwards) const;
48
50 [[nodiscard]] u16 getCheckPointEntryOffsetMs(u16 i, const EGG::Vector3f &pos,
51 const EGG::Vector3f &prevPos) const;
52 [[nodiscard]] f32 getCheckPointEntryOffsetExact(u16 i, const EGG::Vector3f &pos,
53 const EGG::Vector3f &prevPos) const;
54
56 [[nodiscard]] MapdataCannonPoint *getCannonPoint(u16 i) const {
57 return i < getCannonPointCount() ? m_cannonPoint->get(i) : nullptr;
58 }
59
61 [[nodiscard]] MapdataCheckPath *getCheckPath(u16 i) const {
62 return i < getCheckPathCount() ? m_checkPath->get(i) : nullptr;
63 }
64
66 [[nodiscard]] MapdataCheckPoint *getCheckPoint(u16 i) const {
67 return i < getCheckPointCount() ? m_checkPoint->get(i) : nullptr;
68 }
69
71 [[nodiscard]] MapdataGeoObj *getGeoObj(u16 i) const {
72 return i < getGeoObjCount() ? m_geoObj->get(i) : nullptr;
73 }
74
76 [[nodiscard]] MapdataPointInfo *getPointInfo(u16 i) const {
77 return i < getPointInfoCount() ? m_pointInfo->get(i) : nullptr;
78 }
79
81 [[nodiscard]] MapdataJugemPoint *getJugemPoint(u16 i) const {
82 return i < getJugemPointCount() ? m_jugemPoint->get(i) : nullptr;
83 }
84
86 [[nodiscard]] MapdataStageInfo *getStageInfo() const {
87 return getStageInfoCount() != 0 ? m_stageInfo->get(0) : nullptr;
88 }
89
91 [[nodiscard]] MapdataStartPoint *getStartPoint(u16 i) const {
92 return i < getStartPointCount() ? m_startPoint->get(i) : nullptr;
93 }
94
95 [[nodiscard]] u16 getCannonPointCount() const {
96 return m_cannonPoint ? m_cannonPoint->size() : 0;
97 }
98
99 [[nodiscard]] u16 getCheckPathCount() const {
100 return m_checkPath ? m_checkPath->size() : 0;
101 }
102
103 [[nodiscard]] u16 getCheckPointCount() const {
104 return m_checkPoint ? m_checkPoint->size() : 0;
105 }
106
107 [[nodiscard]] u16 getGeoObjCount() const {
108 return m_geoObj ? m_geoObj->size() : 0;
109 }
110
111 [[nodiscard]] u16 getPointInfoCount() const {
112 return m_pointInfo ? m_pointInfo->size() : 0;
113 }
114
115 [[nodiscard]] u16 getJugemPointCount() const {
116 return m_jugemPoint ? m_jugemPoint->size() : 0;
117 }
118
119 [[nodiscard]] u16 getStageInfoCount() const {
120 return m_stageInfo ? m_stageInfo->size() : 0;
121 }
122
123 [[nodiscard]] u16 getStartPointCount() const {
124 return m_startPoint ? m_startPoint->size() : 0;
125 }
126
127 [[nodiscard]] u32 version() const {
128 return m_course->version();
129 }
130
131 [[nodiscard]] MapdataCheckPathAccessor *checkPath() const {
132 return m_checkPath;
133 }
134
135 [[nodiscard]] MapdataCheckPointAccessor *checkPoint() const {
136 return m_checkPoint;
137 }
138
139 [[nodiscard]] f32 startTmpAngle() const {
140 return m_startTmpAngle;
141 }
142
143 [[nodiscard]] f32 startTmp0() const {
144 return m_startTmp0;
145 }
146
147 [[nodiscard]] f32 startTmp1() const {
148 return m_startTmp1;
149 }
150
151 [[nodiscard]] f32 startTmp2() const {
152 return m_startTmp2;
153 }
154
155 [[nodiscard]] f32 startTmp3() const {
156 return m_startTmp3;
157 }
159
160 static CourseMap *CreateInstance();
161 static void DestroyInstance();
162
163 [[nodiscard]] static CourseMap *Instance() {
164 return s_instance;
165 }
166
167private:
168 CourseMap();
169 ~CourseMap() override;
170
171 [[nodiscard]] s16 findSectorBetweenSides(const EGG::Vector3f &pos,
172 MapdataCheckPoint *checkpoint, f32 &distanceRatio);
173 [[nodiscard]] s16 findSectorOutsideSector(const EGG::Vector3f &pos,
174 MapdataCheckPoint *checkpoint, f32 &distanceRatio);
175 [[nodiscard]] s16 findSectorRegional(const EGG::Vector3f &pos, MapdataCheckPoint *checkpoint,
176 f32 &distanceRatio);
177 [[nodiscard]] s16 searchNextCheckpoint(const EGG::Vector3f &pos, s16 depth,
178 const MapdataCheckPoint *checkpoint, f32 &completion, bool playerIsForwards,
179 bool useCache) const;
180 [[nodiscard]] s16 searchPrevCheckpoint(const EGG::Vector3f &pos, s16 depth,
181 const MapdataCheckPoint *checkpoint, f32 &completion, bool playerIsForwards,
182 bool useCache) const;
183 void clearSectorChecked();
184
185 MapdataFileAccessor *m_course;
186 MapdataStartPointAccessor *m_startPoint;
187 MapdataCheckPathAccessor *m_checkPath;
188 MapdataCheckPointAccessor *m_checkPoint;
189 MapdataPointInfoAccessor *m_pointInfo;
190 MapdataGeoObjAccessor *m_geoObj;
191 MapdataJugemPointAccessor *m_jugemPoint;
192 MapdataCannonPointAccessor *m_cannonPoint;
193 MapdataStageInfoAccessor *m_stageInfo;
194
195 // TODO: Better names
196 f32 m_startTmpAngle;
197 f32 m_startTmp0;
198 f32 m_startTmp1;
199 f32 m_startTmp2;
200 f32 m_startTmp3;
201
202 static void *LoadFile(const char *filename);
203
204 static CourseMap *s_instance;
205};
206
207} // 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:32
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:87