summaryrefslogtreecommitdiff
path: root/src/engine/editor/SceneManager.cpp
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2025-12-14 21:37:03 -0700
committerGitHub <noreply@github.com>2025-12-14 21:37:03 -0700
commit2995361eb152a5c0c8add52c590e30ec916b81ec (patch)
treef63e989984831b56e3f7bfae421df2edce6a0934 /src/engine/editor/SceneManager.cpp
parent7bc8d6f4be2bc22f7f4815d3c5eac691c4b92c0f (diff)
Fix new track bug (#593)
Diffstat (limited to 'src/engine/editor/SceneManager.cpp')
-rw-r--r--src/engine/editor/SceneManager.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/src/engine/editor/SceneManager.cpp b/src/engine/editor/SceneManager.cpp
index b8e3d93e0..026dfbfe0 100644
--- a/src/engine/editor/SceneManager.cpp
+++ b/src/engine/editor/SceneManager.cpp
@@ -34,17 +34,25 @@ extern "C" {
}
namespace Editor {
- void SaveLevel(Track* track) {
+ void SaveLevel(Track* track, const TrackInfo* info) {
nlohmann::json data;
/**
* Save track properties, static mesh actors, actors, and tour camera
*/
- data["Props"] = track->Props.to_json();
+ try {
+ data["Props"] = track->Props.to_json();
+ } catch (...) {
+ SPDLOG_ERROR("[SceneManager] [SaveLevel] Failed serializing track Props");
+ }
- nlohmann::json staticMesh;
- SaveStaticMeshActors(staticMesh);
- data["StaticMeshActors"] = staticMesh;
+ try {
+ nlohmann::json staticMesh;
+ SaveStaticMeshActors(staticMesh);
+ data["StaticMeshActors"] = staticMesh;
+ } catch (...) {
+ SPDLOG_ERROR("[SceneManager] [SaveLevel] Failed serializing StaticMeshActors");
+ }
nlohmann::json actors;
@@ -75,7 +83,6 @@ namespace Editor {
std::vector<uint8_t> bytes; // Turn the str into raw data
bytes.assign(jsonStr.begin(), jsonStr.end());
- const TrackInfo* info = gTrackRegistry.GetInfo(track->ResourceName);
std::string sceneFile = info->Path + "/scene.json";
// Write file to disk
@@ -304,8 +311,8 @@ namespace Editor {
}
void SaveFog(nlohmann::json& fog) {
+ fog["EnableFog"] = bFog;
if (bFog) {
- fog["EnableFog"] = bFog;
fog["Colour"]["R"] = gFogColour.r;
fog["Colour"]["G"] = gFogColour.g;
fog["Colour"]["B"] = gFogColour.b;
@@ -331,27 +338,34 @@ namespace Editor {
}
void LoadPaths(Track* track, const std::string& trackPath) {
+ SPDLOG_INFO("[SceneManager] [LoadPaths] Loading Paths...");
std::string path_file = (trackPath + "/data_paths").c_str();
auto res = std::dynamic_pointer_cast<MK64::Paths>(ResourceLoad(path_file.c_str()));
+ if (nullptr == res) {
+ SPDLOG_ERROR(" Unable to load path file (data_paths)");
+ SPDLOG_ERROR(" This file is required for custom tracks to work ");
+ SPDLOG_ERROR(" Make sure the first path point is at coordinates 0,0,0");
+ SPDLOG_ERROR(" In blender you may need to apply transformations and then move the point to 0,0,0");
+ }
- if (res != nullptr) {
- auto& paths = res->PathList;
-
- size_t i = 0;
- u16* ptr = &track->Props.PathSizes.unk0;
- for (auto& path : paths) {
- if (i >= ARRAY_COUNT(track->Props.PathTable2)) {
- printf("[Track.cpp] The game can only import 5 paths. Found more than 5. Skipping the rest\n");
- break; // Only 5 paths allowed. 4 track, 1 vehicle
- }
- ptr[i] = path.size();
- track->Props.PathTable2[i] = (TrackPathPoint*) path.data();
+ auto& paths = res->PathList;
- i += 1;
+ size_t i = 0;
+ u16* ptr = &track->Props.PathSizes.unk0;
+ for (auto& path : paths) {
+ if (i >= ARRAY_COUNT(track->Props.PathTable2)) {
+ SPDLOG_INFO(" The game can only import 5 paths. Found more than 5. Skipping the rest");
+ break; // Only 5 paths allowed. 4 track, 1 vehicle
}
+ ptr[i] = path.size();
+ track->Props.PathTable2[i] = (TrackPathPoint*) path.data();
+ SPDLOG_INFO(" Added path {}", i);
+
+ i += 1;
}
gVehiclePathSize = track->Props.PathSizes.unk0; // This is likely incorrect.
+ SPDLOG_INFO("[SceneManager] [LoadPaths] Path Loading Complete!");
}
void LoadTrackInfoData(TrackInfo& info, nlohmann::json& data) {