summaryrefslogtreecommitdiff
path: root/src
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
parent7bc8d6f4be2bc22f7f4815d3c5eac691c4b92c0f (diff)
Fix new track bug (#593)
Diffstat (limited to 'src')
-rw-r--r--src/engine/TrackBrowser.cpp12
-rw-r--r--src/engine/editor/SceneManager.cpp54
-rw-r--r--src/engine/editor/SceneManager.h2
-rw-r--r--src/engine/tracks/Track.cpp1
-rw-r--r--src/port/ui/Tools.cpp4
5 files changed, 48 insertions, 25 deletions
diff --git a/src/engine/TrackBrowser.cpp b/src/engine/TrackBrowser.cpp
index 37a4712bb..7d76a46bc 100644
--- a/src/engine/TrackBrowser.cpp
+++ b/src/engine/TrackBrowser.cpp
@@ -37,22 +37,30 @@ void TrackBrowser::FindCustomTracks() {
// then it must at least be a valid track.
// So lets add it as an uninitialized track.
if (manager->HasFile(file)) {
+ printf("[TrackBrowser] [FindCustomTracks] Found a new custom track!\n");
+ printf(" Creating scene.json so the track can be configured in the editor\n");
+
TrackInfo info;
std::string resName = std::string("mods:") + name;
info.ResourceName = resName;
info.Name = name;
info.DebugName = name;
+ info.Path = dir;
auto archive = manager->GetArchiveFromFile(file);
//mNewTracks.push_back({info, "", dir, archive});
auto track = std::make_unique<Track>();
- Editor::SaveLevel(track.get()); // Write scene file so it will show up in the track browser
+ track->Archive = archive;
+ track->ResourceName = info.ResourceName;
+ Editor::SaveLevel(track.get(), &info); // Write scene file so it will show up in the track browser
+ printf("[TrackBrowser] [FindCustomTracks] Saved scene.json to new track!\n");
+ // Passing these through seems kinda bad. But it works?
gTrackRegistry.Add(info, [info, archive]() {
auto track = std::make_unique<Track>();
- track->ResourceName = info.ResourceName;
track->Archive = archive;
+ track->ResourceName = info.ResourceName;
GetWorld()->SetCurrentTrack(std::move(track));
});
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) {
diff --git a/src/engine/editor/SceneManager.h b/src/engine/editor/SceneManager.h
index 551d79e32..7adff2af9 100644
--- a/src/engine/editor/SceneManager.h
+++ b/src/engine/editor/SceneManager.h
@@ -7,7 +7,7 @@
#include <nlohmann/json.hpp>
namespace Editor {
- void SaveLevel(Track* track);
+ void SaveLevel(Track* track, const TrackInfo* info);
void LoadTrackDataFromJson(Track* track, const std::string& trackPath);
void LoadTrackInfo(TrackInfo& info, std::shared_ptr<Ship::Archive> archive, std::string sceneFile);
void Load_AddStaticMeshActor(const nlohmann::json& actorJson);
diff --git a/src/engine/tracks/Track.cpp b/src/engine/tracks/Track.cpp
index 3f898754e..49fcddabf 100644
--- a/src/engine/tracks/Track.cpp
+++ b/src/engine/tracks/Track.cpp
@@ -352,6 +352,7 @@ bool IsTriangleWindingInverted() {
Track::Track() {
+ Props.SetText(Props.ResourceName, "mod:blank_track", sizeof(Props.ResourceName));
Props.SetText(Props.Name, "Blank Track", sizeof(Props.Name));
Props.SetText(Props.DebugName, "blnktrck", sizeof(Props.DebugName));
Props.SetText(Props.TrackLength, "100m", sizeof(Props.TrackLength));
diff --git a/src/port/ui/Tools.cpp b/src/port/ui/Tools.cpp
index 496dfb9f9..75dd3ac10 100644
--- a/src/port/ui/Tools.cpp
+++ b/src/port/ui/Tools.cpp
@@ -36,7 +36,7 @@ namespace Editor {
// Save button
if (ImGui::Button(ICON_FA_FLOPPY_O, ImVec2(50, 25))) {
if (gEditor.IsPaused()) {
- SaveLevel(GetWorld()->GetTrack());
+ SaveLevel(GetWorld()->GetTrack(), gTrackRegistry.GetInfo(GetWorld()->GetTrack()->ResourceName));
} else {
printf("[Editor] Cannot save during simulation\n Please switch back to edit mode!\n\n");
}
@@ -140,7 +140,7 @@ namespace Editor {
ImGui::PushStyleColor(ImGuiCol_Button, defaultColor);
if (ImGui::Button(gEditor.IsPaused() ? ICON_FA_PLAY : ICON_FA_STOP, ImVec2(50, 25))) {
if (gEditor.IsPaused()) {
- SaveLevel(GetWorld()->GetTrack());
+ SaveLevel(GetWorld()->GetTrack(), gTrackRegistry.GetInfo(GetWorld()->GetTrack()->ResourceName));
CVarSetInteger("gFreecam", false);
CM_SetFreeCamera(false);
} else {