Mario Kart 64
Loading...
Searching...
No Matches
Course.h
Go to the documentation of this file.
1#ifndef ENGINE_COURSE_H
2#define ENGINE_COURSE_H
3
4#include <libultraship/libultraship.h>
5#include "CoreMath.h"
6
7#ifdef __cplusplus
9#include <optional>
10#include <nlohmann/json.hpp>
14extern "C" {
15#endif
16
17#include "camera.h"
18#include "course_offsets.h"
19#include "data/some_data.h"
20#include "defines.h"
21#include "bomb_kart.h"
22#include "path_spawn_metadata.h"
23#include "waypoints.h"
24#include "sounds.h"
25#include "common_structs.h"
26
27#ifdef __cplusplus
28}
29#endif
30
41
42// Extends infinitely in the Y direction
43// If a player is overtop of a water volume then it should use its height
44// Recommend using the new water surface type. This is here to support the stock tracks.
45// Albeit, there's no reason you cannot use this so long as you input a square.
46// How to use: WaterVolumes.push_back({0, -100, 100, -100, 100});
48 float Height; // Y coordinate of the Water level
49 float MinX;
50 float MaxX;
51 float MinZ;
52 float MaxZ;
53};
54
55typedef struct MinimapProps {
56 const char* Texture;
57 int16_t Width;
58 int16_t Height;
59 IVector2D Pos[2]; // Minimap position for players 1 and 2. 3/4 player mode is hard-coded to the center.
60 int32_t PlayerX; // The offset to place the player markers
61 int32_t PlayerY;
62 float PlayerScaleFactor; // Scale factor of the player markers
63 float FinishlineX; // The offset to place the finishline texture on the minimap
65 RGB8 Colour; // Colour of the visible pixels (the track path)
67
68void ResizeMinimap(MinimapProps* minimap);
69void ReverseGfx(Gfx* gfx);
70
71void InvertTriangleWinding(Gfx* gfx);
72void InvertTriangleWindingByName(const char* name);
75
76typedef struct Properties {
77 char Name[128];
78 char DebugName[128];
79 char CourseLength[128];
82 const char* AIBehaviour;
85 float NearPersp;
86 float FarPersp;
87 int16_t* AIDistance;
94 TrackPathPoint* PathTable[4]; // Only used for podium ceremony
95 TrackPathPoint* PathTable2[5]; // The fifth entry is for vehicles
96 uint8_t* CloudTexture;
101 float WaterLevel; // Used for effects, and Lakitu pick up height. Not necessarily the visual water model height.
102
103#ifdef __cplusplus
104 nlohmann::json to_json() const {
105 nlohmann::json j;
106 // j["Id"] = Id ? Id : "";
107 j["Name"] = Name ? Name : "";
108 j["DebugName"] = DebugName ? DebugName : "";
109 j["CourseLength"] = CourseLength ? CourseLength : "";
110 //j["AIBehaviour"] = AIBehaviour ? AIBehaviour : "";
111 j["LakituTowType"] = LakituTowType;
112 j["AIMaximumSeparation"] = AIMaximumSeparation;
113 j["AIMinimumSeparation"] = AIMinimumSeparation;
114 j["NearPersp"] = NearPersp;
115 j["FarPersp"] = FarPersp;
116
117 // AIDistance as a JSON array
118 j["AIDistance"] = std::vector<int16_t>(AIDistance, AIDistance + 32); // gAIDistances array size of 32
119
120 j["AISteeringSensitivity"] = AISteeringSensitivity;
121
122 // PathSizes - Assuming _struct_gCoursePathSizes_0x10 can be serialized similarly
123 // j["PathSizes"] = PathSizes; // Implement your serialization logic here
124
125 j["CurveTargetSpeed"] = { CurveTargetSpeed[0], CurveTargetSpeed[1], CurveTargetSpeed[2], CurveTargetSpeed[3] };
126 j["NormalTargetSpeed"] = { NormalTargetSpeed[0], NormalTargetSpeed[1], NormalTargetSpeed[2], NormalTargetSpeed[3] };
127 j["D_0D0096B8"] = { D_0D0096B8[0], D_0D0096B8[1], D_0D0096B8[2], D_0D0096B8[3] };
128 j["OffTrackTargetSpeed"] = { OffTrackTargetSpeed[0], OffTrackTargetSpeed[1], OffTrackTargetSpeed[2], OffTrackTargetSpeed[3] };
129
130 // Serialize arrays PathTable and PathTable2 (convert pointers into a JSON array if possible)
131 //j["PathTable"] = {{}};
132 //j["PathTable2"] = {{}};
133 // Populate PathTable and PathTable2
134
135 //j["Clouds"] = Clouds ? nlohmann::json{{"x", Clouds->x, "y", Clouds->y, "z", Clouds->z}} : nullptr;
136 //j["CloudList"] = CloudList ? nlohmann::json{{"x", CloudList->x, "y", CloudList->y, "z", CloudList->z}} : nullptr;
137
138 j["MinimapPosition"] = {Minimap.Pos[0].X, Minimap.Pos[0].Y};
139 j["MinimapPosition2P"] = {Minimap.Pos[1].X, Minimap.Pos[1].Y};
140 j["MinimapPlayerX"] = Minimap.PlayerX;
141 j["MinimapPlayerY"] = Minimap.PlayerY;
142 j["MinimapPlayerScaleFactor"] = Minimap.PlayerScaleFactor;
143 j["MinimapFinishlineX"] = Minimap.FinishlineX;
144 j["MinimapFinishlineY"] = Minimap.FinishlineY;
145 j["MinimapColour"] = {static_cast<int>(Minimap.Colour.r), static_cast<int>(Minimap.Colour.g), static_cast<int>(Minimap.Colour.b)};
146 // SkyboxColors - assuming SkyboxColors can be serialized similarly
147
148 #define TO_INT(value) static_cast<int>(value)
149 j["Skybox"] = {
150 TO_INT(Skybox.TopRight.r), TO_INT(Skybox.TopRight.g), TO_INT(Skybox.TopRight.b),
151 TO_INT(Skybox.BottomRight.r), TO_INT(Skybox.BottomRight.g), TO_INT(Skybox.BottomRight.b),
152 TO_INT(Skybox.BottomLeft.r), TO_INT(Skybox.BottomLeft.g), TO_INT(Skybox.BottomLeft.b),
153 TO_INT(Skybox.TopLeft.r), TO_INT(Skybox.TopLeft.g), TO_INT(Skybox.TopLeft.b),
154 TO_INT(Skybox.FloorTopRight.r), TO_INT(Skybox.FloorTopRight.g), TO_INT(Skybox.FloorTopRight.b),
155 TO_INT(Skybox.FloorBottomRight.r), TO_INT(Skybox.FloorBottomRight.g), TO_INT(Skybox.FloorBottomRight.b),
156 TO_INT(Skybox.FloorBottomLeft.r), TO_INT(Skybox.FloorBottomLeft.g), TO_INT(Skybox.FloorBottomLeft.b),
157 TO_INT(Skybox.FloorTopLeft.r), TO_INT(Skybox.FloorTopLeft.g), TO_INT(Skybox.FloorTopLeft.b)
158 };
159 j["Sequence"] = static_cast<int>(Sequence);
160
161 j["WaterLevel"] = static_cast<float>(WaterLevel);
162 #undef CAST_TO_INT
163
164 return j;
165 }
166
167 // Function to load struct from JSON
168 void from_json(const nlohmann::json& j) {
169 //Id = j.at("Id").get<std::string>().c_str();
170// Name = j.at("Name").get<std::string>().c_str();
171 strncpy(Name, j.at("Name").get<std::string>().c_str(), sizeof(Name) - 1);
172 Name[sizeof(Name) - 1] = '\0'; // Ensure null termination
173
174// DebugName = j.at("DebugName").get<std::string>().c_str();
175 strncpy(DebugName, j.at("DebugName").get<std::string>().c_str(), sizeof(DebugName) - 1);
176 DebugName[sizeof(DebugName) - 1] = '\0'; // Ensure null termination
177
178 // CourseLength = j.at("CourseLength").get<std::string>().c_str();
179 strncpy(CourseLength, j.at("CourseLength").get<std::string>().c_str(), sizeof(CourseLength) - 1);
180 CourseLength[sizeof(CourseLength) - 1] = '\0'; // Ensure null termination
181
182 //AIBehaviour = j.at("AIBehaviour").get<std::string>().c_str();
183 LakituTowType = j.at("LakituTowType").get<int>();
184
185 AIMaximumSeparation = j.at("AIMaximumSeparation").get<float>();
186 AIMinimumSeparation = j.at("AIMinimumSeparation").get<float>();
187 NearPersp = j.at("NearPersp").get<float>();
188 FarPersp = j.at("FarPersp").get<float>();
189
190 const auto temp = j.at("AIDistance").get<std::vector<int16_t>>();
191
192 // Ensure the vector has 32 entries
193 if (temp.size() == 32) {
194 // Copy the data into the existing AIDistances array
195 std::copy(temp.begin(), temp.end(), AIDistance);
196 } else {
197 printf("Course::from_json() AIDistance array not size of 32\n");
198 }
199
200 AISteeringSensitivity = j.at("AISteeringSensitivity").get<uint32_t>();
201
202 // Deserialize PathSizes and other custom structs if needed
203
204 CurveTargetSpeed[0] = j.at("CurveTargetSpeed")[0].get<float>();
205 CurveTargetSpeed[1] = j.at("CurveTargetSpeed")[1].get<float>();
206 CurveTargetSpeed[2] = j.at("CurveTargetSpeed")[2].get<float>();
207 CurveTargetSpeed[3] = j.at("CurveTargetSpeed")[3].get<float>();
208
209 NormalTargetSpeed[0] = j.at("NormalTargetSpeed")[0].get<float>();
210 NormalTargetSpeed[1] = j.at("NormalTargetSpeed")[1].get<float>();
211 NormalTargetSpeed[2] = j.at("NormalTargetSpeed")[2].get<float>();
212 NormalTargetSpeed[3] = j.at("NormalTargetSpeed")[3].get<float>();
213
214 D_0D0096B8[0] = j.at("D_0D0096B8")[0].get<float>();
215 D_0D0096B8[1] = j.at("D_0D0096B8")[1].get<float>();
216 D_0D0096B8[2] = j.at("D_0D0096B8")[2].get<float>();
217 D_0D0096B8[3] = j.at("D_0D0096B8")[3].get<float>();
218
219 OffTrackTargetSpeed[0] = j.at("OffTrackTargetSpeed")[0].get<float>();
220 OffTrackTargetSpeed[1] = j.at("OffTrackTargetSpeed")[1].get<float>();
221 OffTrackTargetSpeed[2] = j.at("OffTrackTargetSpeed")[2].get<float>();
222 OffTrackTargetSpeed[3] = j.at("OffTrackTargetSpeed")[3].get<float>();
223
224 // Deserialize arrays PathTable and PathTable2 similarly
225
226 //Clouds = nullptr; // Deserialize if data is present
227 //CloudList = nullptr; // Deserialize if data is present
228 Minimap.Pos[0].X = j.at("MinimapPosition")[0].get<int32_t>();
229 Minimap.Pos[0].Y = j.at("MinimapPosition")[1].get<int32_t>();
230 Minimap.Pos[1].X = j.at("MinimapPosition2P")[0].get<int32_t>();
231 Minimap.Pos[1].Y = j.at("MinimapPosition2P")[1].get<int32_t>();
232 Minimap.PlayerX = j.at("MinimapPlayerX").get<int32_t>();
233 Minimap.PlayerY = j.at("MinimapPlayerY").get<int32_t>();
234 Minimap.PlayerScaleFactor = j.at("MinimapPlayerScaleFactor").get<float>();
235 Minimap.FinishlineX = j.at("MinimapFinishlineX").get<float>();
236 Minimap.FinishlineY = j.at("MinimapFinishlineY").get<float>();
237 Minimap.Colour.r = j.at("MinimapColour")[0].get<uint8_t>();
238 Minimap.Colour.g = j.at("MinimapColour")[1].get<uint8_t>();
239 Minimap.Colour.b = j.at("MinimapColour")[2].get<uint8_t>();
240 //textures = nullptr; // Deserialize textures if present
241
242 Skybox.TopRight.r = j.at("Skybox")[0].get<uint8_t>();
243 Skybox.TopRight.g = j.at("Skybox")[1].get<uint8_t>();
244 Skybox.TopRight.b = j.at("Skybox")[2].get<uint8_t>();
245
246 Skybox.BottomRight.r = j.at("Skybox")[3].get<uint8_t>();
247 Skybox.BottomRight.g = j.at("Skybox")[4].get<uint8_t>();
248 Skybox.BottomRight.b = j.at("Skybox")[5].get<uint8_t>();
249
250 Skybox.BottomLeft.r = j.at("Skybox")[6].get<uint8_t>();
251 Skybox.BottomLeft.g = j.at("Skybox")[7].get<uint8_t>();
252 Skybox.BottomLeft.b = j.at("Skybox")[8].get<uint8_t>();
253
254 Skybox.TopLeft.r = j.at("Skybox")[9].get<uint8_t>();
255 Skybox.TopLeft.g = j.at("Skybox")[10].get<uint8_t>();
256 Skybox.TopLeft.b = j.at("Skybox")[11].get<uint8_t>();
257
258 Skybox.FloorTopRight.r = j.at("Skybox")[12].get<uint8_t>();
259 Skybox.FloorTopRight.g = j.at("Skybox")[13].get<uint8_t>();
260 Skybox.FloorTopRight.b = j.at("Skybox")[14].get<uint8_t>();
261
262 Skybox.FloorBottomRight.r = j.at("Skybox")[15].get<uint8_t>();
263 Skybox.FloorBottomRight.g = j.at("Skybox")[16].get<uint8_t>();
264 Skybox.FloorBottomRight.b = j.at("Skybox")[17].get<uint8_t>();
265
266 Skybox.FloorBottomLeft.r = j.at("Skybox")[18].get<uint8_t>();
267 Skybox.FloorBottomLeft.g = j.at("Skybox")[19].get<uint8_t>();
268 Skybox.FloorBottomLeft.b = j.at("Skybox")[20].get<uint8_t>();
269
270 Skybox.FloorTopLeft.r = j.at("Skybox")[21].get<uint8_t>();
271 Skybox.FloorTopLeft.g = j.at("Skybox")[22].get<uint8_t>();
272 Skybox.FloorTopLeft.b = j.at("Skybox")[23].get<uint8_t>();
273
274 Sequence = static_cast<MusicSeq>(j.at("Sequence").get<int>());
275 WaterLevel = j.at("WaterLevel").get<float>();
276 }
277 void SetText(char* name, const char* title, size_t bufferSize) {
278 // Copy the title into the name buffer, ensuring it's null-terminated and within bounds
279 std::strncpy(name, title, bufferSize - 1);
280 name[bufferSize - 1] = '\0'; // Ensure the string is null-terminated
281 }
282
283 const char* GetName() {
284 return Name;
285 }
286
287 void New() {
288 SetText(Name, "", sizeof(Name));
289 SetText(DebugName, "", sizeof(DebugName));
290 SetText(CourseLength, "", sizeof(CourseLength));
291 }
292#endif
293
295
296#ifdef __cplusplus
297
298
299class World; // <-- Forward declare
300
301class Course {
302
303public:
304 std::string Id;
305 Properties Props;
306
307 // This allows multiple water levels in a map.
308 // Ex. DK Jungle where there's a waterfall and you can drive above and below it.
309 std::vector<WaterVolume> WaterVolumes;
310
311 bool bSpawnFinishline = true;
312 std::optional<FVector> FinishlineSpawnPoint;
313
314 // O2R Loading
315 std::shared_ptr<Ship::Archive> RootArchive;
316 std::string SceneFilePtr;
317 std::string TrackSectionsPtr;
318
319 bool bIsMod = false;
320 std::vector<SpawnParams> SpawnList;
321
322 bool bTourEnabled = false;
323 std::vector<TourCamera::CameraShot> TourShots;
324
325
326 virtual ~Course() = default;
327
328 explicit Course();
329
330 virtual void LoadO2R(std::string trackPath); // Load custom track from o2r
331 virtual void Load(); // Decompress and load stock courses or from o2r but TrackSectionsPtr must be set.
332 virtual void Load(Vtx* vtx, Gfx *gfx); // Load custom track from code. Load must be overridden and then call to this base class method impl.
333 virtual void UnLoad();
334 virtual void ParseCourseSections(TrackSections* sections, size_t size);
335
340 virtual void BeginPlay();
341 void SpawnActors();
342 virtual void TestPath();
343 virtual void InitClouds();
344 virtual void UpdateClouds(s32, Camera*);
345 virtual void SomeCollisionThing(Player *player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4, f32* arg5, f32* arg6, f32* arg7);
346 virtual void InitCourseObjects();
347 virtual void UpdateCourseObjects();
348 virtual void RenderCourseObjects(s32 cameraId);
349 virtual void SomeSounds();
350 virtual void CreditsSpawnActors();
351 virtual void WhatDoesThisDo(Player*, int8_t);
352 virtual void WhatDoesThisDoAI(Player*, int8_t);
353 virtual void SetStaffGhost();
354 virtual void Render(struct UnkStruct_800DC5EC*);
355 virtual void RenderCredits();
356 virtual void Waypoints(Player* player, int8_t playerId);
357 virtual f32 GetWaterLevel(FVector pos, Collision* collision);
358 virtual void ScrollingTextures();
359 // Draw transparent models (water, signs, arrows, etc.)
360 virtual void DrawWater(struct UnkStruct_800DC5EC* screen, uint16_t pathCounter, uint16_t cameraRot,
361 uint16_t playerDirection);
362 virtual void Destroy();
363 virtual bool IsMod();
364
365 private:
366 void Init();
367};
368
369#endif
370
371#endif // ENGINE_COURSE_H
void InvertTriangleWindingByName(const char *name)
Definition Course.cpp:183
void ReverseGfx(Gfx *gfx)
void RestoreTriangleWinding()
Definition Course.cpp:192
struct Properties Properties
void ResizeMinimap(MinimapProps *minimap)
Definition Course.cpp:38
void InvertTriangleWinding(Gfx *gfx)
Definition Course.cpp:179
bool IsTriangleWindingInverted()
Definition Course.cpp:241
Definition World.h:39
f32 Vec3f[3]
Definition common_structs.h:10
f32 Vec4f[4]
Definition common_structs.h:11
#define j
void SpawnActors(std::vector< std::pair< std::string, SpawnParams > > spawnList)
void Destroy()
Definition ImguiUI.cpp:97
@ f32
Definition GenericArray.h:59
struct StarData CloudData
MusicSeq
Definition sounds.h:118
Definition CoreMath.h:115
Definition Course.h:55
IVector2D Pos[2]
Definition Course.h:59
int16_t Width
Definition Course.h:57
RGB8 Colour
Definition Course.h:65
float FinishlineY
Definition Course.h:64
int32_t PlayerY
Definition Course.h:61
const char * Texture
Definition Course.h:56
float PlayerScaleFactor
Definition Course.h:62
float FinishlineX
Definition Course.h:63
int32_t PlayerX
Definition Course.h:60
int16_t Height
Definition Course.h:58
Definition Course.h:76
char Name[128]
Definition Course.h:77
uint8_t * CloudTexture
Definition Course.h:96
_struct_gCoursePathSizes_0x10 PathSizes
Definition Course.h:89
TrackPathPoint * PathTable2[5]
Definition Course.h:95
CloudData * Clouds
Definition Course.h:97
Vec4f D_0D0096B8
Definition Course.h:92
Vec4f CurveTargetSpeed
Definition Course.h:90
float AIMaximumSeparation
Definition Course.h:83
float WaterLevel
Definition Course.h:101
int32_t LakituTowType
Definition Course.h:80
Vec4f OffTrackTargetSpeed
Definition Course.h:93
uint32_t AISteeringSensitivity
Definition Course.h:88
TrackPathPoint * PathTable[4]
Definition Course.h:94
const char * AIBehaviour
Definition Course.h:82
char CourseLength[128]
Definition Course.h:79
float NearPersp
Definition Course.h:85
SkyboxColours Skybox
Definition Course.h:99
float AIMinimumSeparation
Definition Course.h:84
enum MusicSeq Sequence
Definition Course.h:100
int16_t * AIDistance
Definition Course.h:87
char DebugName[128]
Definition Course.h:78
CloudData * CloudList
Definition Course.h:98
float FarPersp
Definition Course.h:86
MinimapProps Minimap
Definition Course.h:81
Vec4f NormalTargetSpeed
Definition Course.h:91
Definition common_structs.h:427
Definition Course.h:31
RGB8 BottomLeft
Definition Course.h:34
RGB8 FloorBottomRight
Definition Course.h:37
RGB8 BottomRight
Definition Course.h:33
RGB8 FloorBottomLeft
Definition Course.h:38
RGB8 TopRight
Definition Course.h:32
RGB8 TopLeft
Definition Course.h:35
RGB8 FloorTopRight
Definition Course.h:36
RGB8 FloorTopLeft
Definition Course.h:39
Definition waypoints.h:14
Definition Course.h:47
float Height
Definition Course.h:48
float MaxX
Definition Course.h:50
float MinZ
Definition Course.h:51
float MinX
Definition Course.h:49
float MaxZ
Definition Course.h:52
Definition path_spawn_metadata.h:9