From e7415ec072ee1cdc99a49db658062d4de0b3301c Mon Sep 17 00:00:00 2001 From: MegaMech Date: Thu, 15 May 2025 10:30:39 -0600 Subject: [PATCH] Fixes made so far (#198) * Fixed compile * Moved GetInterpreter() to a single function under the Engine.h --- libultraship | 2 +- src/engine/editor/EditorMath.cpp | 15 ++++++++----- src/engine/editor/EditorMath.h | 2 ++ src/port/Engine.cpp | 22 ++++++++++++++++--- src/port/Engine.h | 7 ++++-- src/port/Game.cpp | 2 +- src/port/Variables.cpp | 2 +- src/port/resource/importers/ArrayFactory.cpp | 8 ++++--- src/port/resource/importers/ResourceUtil.h | 1 + .../importers/TrackSectionsFactory.cpp | 8 +++---- .../importers/TrackWaypointFactory.cpp | 1 + src/port/resource/type/Array.cpp | 2 +- src/port/resource/type/Array.h | 7 ++++-- src/port/ui/ImguiUI.cpp | 2 +- src/port/ui/Menu.h | 1 - src/port/ui/PortMenu.h | 9 ++++---- src/port/ui/ResolutionEditor.cpp | 19 +++++++++++----- src/port/ui/ResolutionEditor.h | 2 ++ 18 files changed, 76 insertions(+), 36 deletions(-) diff --git a/libultraship b/libultraship index 58b050990..ab9935c0f 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit 58b050990526fd6ffa8fe6a7b6682593d02eb968 +Subproject commit ab9935c0f4313d253e6c72c96ec6212c7ae96cda diff --git a/src/engine/editor/EditorMath.cpp b/src/engine/editor/EditorMath.cpp index 533c0c2b5..a3e19716c 100644 --- a/src/engine/editor/EditorMath.cpp +++ b/src/engine/editor/EditorMath.cpp @@ -10,6 +10,9 @@ #include #include +#include +#include + extern "C" { #include "common_structs.h" #include "main.h" @@ -20,16 +23,15 @@ extern "C" { #include "camera.h" } -std::vector EditorMatrix; - bool IsInGameScreen() { auto wnd = GameEngine::Instance->context->GetWindow(); Ship::Coords mouse = wnd->GetMousePos(); // Define viewport boundaries - int left = gfx_current_game_window_viewport.x; + auto gfx_current_game_window_viewport = GameEngine::GetInterpreter().get()->mGameWindowViewport; + int left = gfx_current_game_window_viewport.width; int right = left + OTRGetGameRenderWidth(); - int top = gfx_current_game_window_viewport.y; + int top = gfx_current_game_window_viewport.height; int bottom = top + OTRGetGameRenderHeight(); // Check if the mouse is within the game render area @@ -41,8 +43,9 @@ FVector ScreenRayTrace() { Camera* camera = &cameras[0]; Ship::Coords mouse = wnd->GetMousePos(); - mouse.x -= gfx_current_game_window_viewport.x; - mouse.y -= gfx_current_game_window_viewport.y; + auto gfx_current_game_window_viewport = GameEngine::GetInterpreter().get()->mGameWindowViewport; + mouse.x -= gfx_current_game_window_viewport.width; + mouse.y -= gfx_current_game_window_viewport.height; // Get screen dimensions uint32_t width = OTRGetGameViewportWidth(); uint32_t height = OTRGetGameViewportHeight(); diff --git a/src/engine/editor/EditorMath.h b/src/engine/editor/EditorMath.h index abc694976..d5d75fe13 100644 --- a/src/engine/editor/EditorMath.h +++ b/src/engine/editor/EditorMath.h @@ -6,6 +6,8 @@ #include "../CoreMath.h" #include #include "GameObject.h" +#include +#include extern "C" { #include "common_structs.h" diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 958f27183..440363efa 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -19,14 +19,14 @@ #include "resource/importers/UnkActorSpawnDataFactory.h" #include "resource/importers/ArrayFactory.h" #include "resource/importers/MinimapFactory.h" -#include #include #include "window/gui/resource/Font.h" #include "window/gui/resource/FontFactory.h" #include "SpaghettiGui.h" -#include -#include +#include +#include +//#include #include #include @@ -49,6 +49,16 @@ float gInterpolationStep = 0.0f; #include "audio/GameAudio.h" } +std::weak_ptr GameEngine::mInterpreter; + +std::shared_ptr GameEngine::GetInterpreter() { + auto intP = mInterpreter.lock(); + if (!intP) { + assert(false && "Lost reference to Fast::Interpreter"); + } + return intP; +} + GameEngine* GameEngine::Instance; GameEngine::GameEngine() { @@ -533,6 +543,7 @@ extern "C" void GameEngine_UnloadSequence(const uint8_t seqId) { } extern "C" float GameEngine_GetAspectRatio() { + auto gfx_current_dimensions = GameEngine::GetInterpreter().get()->mCurDimensions; return gfx_current_dimensions.aspect_ratio; } @@ -606,6 +617,7 @@ extern "C" void Timer_SetValue(int32_t* address, int32_t value) { // } extern "C" float OTRGetAspectRatio() { + auto gfx_current_dimensions = GameEngine::GetInterpreter().get()->mCurDimensions; return gfx_current_dimensions.aspect_ratio; } @@ -649,18 +661,22 @@ extern "C" uint32_t OTRCalculateCenterOfAreaFromLeftEdge(int32_t center) { // Gets the width of the current render target area extern "C" uint32_t OTRGetGameRenderWidth() { + auto gfx_current_dimensions = GameEngine::GetInterpreter().get()->mCurDimensions; return gfx_current_dimensions.width; } // Gets the height of the current render target area extern "C" uint32_t OTRGetGameRenderHeight() { + auto gfx_current_dimensions = GameEngine::GetInterpreter().get()->mCurDimensions; return gfx_current_dimensions.height; } extern "C" uint32_t OTRGetGameViewportWidth() { + auto gfx_current_game_window_viewport = GameEngine::GetInterpreter().get()->mGameWindowViewport; return gfx_current_game_window_viewport.width; } extern "C" uint32_t OTRGetGameViewportHeight() { + auto gfx_current_game_window_viewport = GameEngine::GetInterpreter().get()->mGameWindowViewport; return gfx_current_game_window_viewport.height; } \ No newline at end of file diff --git a/src/port/Engine.h b/src/port/Engine.h index fb277a5ad..6136ff06a 100644 --- a/src/port/Engine.h +++ b/src/port/Engine.h @@ -1,6 +1,5 @@ #pragma once - #define LOAD_ASSET(path) \ (path == NULL ? NULL \ : (GameEngine_OTRSigCheck((const char*) path) ? ResourceGetDataByName((const char*) path) : path)) @@ -9,7 +8,8 @@ #ifdef __cplusplus #include #include -#include +#include +#include #include "libultraship/src/Context.h" #ifndef IDYES @@ -46,6 +46,9 @@ class GameEngine { ImFont* fontMonoLarger; ImFont* fontMonoLargest; + static std::weak_ptr mInterpreter; + static std::shared_ptr GetInterpreter(); + std::unordered_map bankMapTable; GameEngine(); static bool GenAssetFile(); diff --git a/src/port/Game.cpp b/src/port/Game.cpp index 483971a48..2c0ec3a0a 100644 --- a/src/port/Game.cpp +++ b/src/port/Game.cpp @@ -3,7 +3,7 @@ #include "Game.h" #include "port/Engine.h" -#include +#include #include "engine/World.h" #include "engine/courses/Course.h" #include "engine/courses/MarioRaceway.h" diff --git a/src/port/Variables.cpp b/src/port/Variables.cpp index e0afab0ac..9609f1b45 100644 --- a/src/port/Variables.cpp +++ b/src/port/Variables.cpp @@ -1,5 +1,5 @@ #include -#include +#include extern "C" { diff --git a/src/port/resource/importers/ArrayFactory.cpp b/src/port/resource/importers/ArrayFactory.cpp index 07f166be1..dfec6bc86 100644 --- a/src/port/resource/importers/ArrayFactory.cpp +++ b/src/port/resource/importers/ArrayFactory.cpp @@ -4,7 +4,9 @@ #include "graphic/Fast3D/lus_gbi.h" namespace MK64 { -std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr file, std::shared_ptr initData) { +std::shared_ptr +ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } @@ -12,13 +14,13 @@ std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std: auto array = std::make_shared(initData); auto reader = std::get>(file->Reader); - array->ArrayType = (ArrayResourceType) reader->ReadUInt32(); + array->ArrayType = (ArrayResourceType)reader->ReadUInt32(); array->ArrayCount = reader->ReadUInt32(); for (uint32_t i = 0; i < array->ArrayCount; i++) { if (array->ArrayType == ArrayResourceType::Vertex) { // OTRTODO: Implement Vertex arrays as just a vertex resource. - F3DVtx data; + Fast::F3DVtx data; data.v.ob[0] = reader->ReadInt16(); data.v.ob[1] = reader->ReadInt16(); data.v.ob[2] = reader->ReadInt16(); diff --git a/src/port/resource/importers/ResourceUtil.h b/src/port/resource/importers/ResourceUtil.h index 69d03a7d9..55ab0624a 100644 --- a/src/port/resource/importers/ResourceUtil.h +++ b/src/port/resource/importers/ResourceUtil.h @@ -1,6 +1,7 @@ #pragma once #include "resourcebridge.h" +#include "libultraship/src/resource/ResourceManager.h" #include "Context.h" namespace SM64 { diff --git a/src/port/resource/importers/TrackSectionsFactory.cpp b/src/port/resource/importers/TrackSectionsFactory.cpp index 3c4bd9e12..2abce35d4 100644 --- a/src/port/resource/importers/TrackSectionsFactory.cpp +++ b/src/port/resource/importers/TrackSectionsFactory.cpp @@ -2,6 +2,7 @@ #include "../type/TrackSections.h" #include "spdlog/spdlog.h" #include "libultraship/libultra/gbi.h" +#include "tinyxml2.h" extern "C" { //#include "memory.h" // Removed to prevent C linkage errors likely related with #include common_structs.h @@ -43,13 +44,12 @@ ResourceFactoryXMLTrackSectionsV0::ReadResource(std::shared_ptr file if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - + auto section = std::make_shared(initData); - auto child = - std::get>(file->Reader)->FirstChildElement()->FirstChildElement(); + auto child = std::get>(file->Reader)->FirstChildElement("TrackSections"); while (child != nullptr) { - std::string childName = child->Name(); + std::string childName = std::string(child->Name()); if (childName == "Section") { TrackSectionsO2R data; diff --git a/src/port/resource/importers/TrackWaypointFactory.cpp b/src/port/resource/importers/TrackWaypointFactory.cpp index 75707c5ce..fab0428e3 100644 --- a/src/port/resource/importers/TrackWaypointFactory.cpp +++ b/src/port/resource/importers/TrackWaypointFactory.cpp @@ -2,6 +2,7 @@ #include "../type/TrackWaypoint.h" #include "spdlog/spdlog.h" #include "libultraship/libultra/gbi.h" +#include "tinyxml2.h" namespace MK64 { std::shared_ptr diff --git a/src/port/resource/type/Array.cpp b/src/port/resource/type/Array.cpp index 225ce3d51..81839e8ae 100644 --- a/src/port/resource/type/Array.cpp +++ b/src/port/resource/type/Array.cpp @@ -23,7 +23,7 @@ size_t Array::GetPointerSize() { size_t typeSize = 0; switch (ArrayType) { case ArrayResourceType::Vertex: - typeSize = sizeof(F3DVtx); + typeSize = sizeof(Fast::F3DVtx); break; case ArrayResourceType::Scalar: default: diff --git a/src/port/resource/type/Array.h b/src/port/resource/type/Array.h index 50ed335e6..2dbb7a8ed 100644 --- a/src/port/resource/type/Array.h +++ b/src/port/resource/type/Array.h @@ -2,7 +2,10 @@ #include "resource/Resource.h" -union F3DVtx; +namespace Fast { + union F3DVtx; +} + namespace MK64 { typedef union ScalarData { uint8_t u8; @@ -80,6 +83,6 @@ class Array : public Ship::Resource { size_t ArrayCount; // OTRTODO: Should be a vector of resource pointers... std::vector Scalars; - std::vector Vertices; + std::vector Vertices; }; } // namespace MK64 diff --git a/src/port/ui/ImguiUI.cpp b/src/port/ui/ImguiUI.cpp index 56a814de7..3b1a33ed8 100644 --- a/src/port/ui/ImguiUI.cpp +++ b/src/port/ui/ImguiUI.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include "port/Engine.h" #include "PortMenu.h" diff --git a/src/port/ui/Menu.h b/src/port/ui/Menu.h index fc2a77556..9857737e6 100644 --- a/src/port/ui/Menu.h +++ b/src/port/ui/Menu.h @@ -3,7 +3,6 @@ #include #include "UIWidgets.h" -#include "graphic/Fast3D/gfx_rendering_api.h" #include "MenuTypes.h" extern "C" { diff --git a/src/port/ui/PortMenu.h b/src/port/ui/PortMenu.h index 209166a9e..12eb60379 100644 --- a/src/port/ui/PortMenu.h +++ b/src/port/ui/PortMenu.h @@ -4,7 +4,8 @@ #include #include "UIWidgets.h" #include "Menu.h" -#include "graphic/Fast3D/gfx_rendering_api.h" +#include "Fast3D/backends/gfx_rendering_api.h" + namespace GameUI { @@ -26,9 +27,9 @@ static const std::unordered_map menuThemeOptions = { }; static const std::unordered_map textureFilteringMap = { - { FILTER_THREE_POINT, "Three-Point" }, - { FILTER_LINEAR, "Linear" }, - { FILTER_NONE, "None" }, + { Fast::FilteringMode::FILTER_THREE_POINT, "Three-Point" }, + { Fast::FilteringMode::FILTER_LINEAR, "Linear" }, + { Fast::FilteringMode::FILTER_NONE, "None" }, }; static const std::unordered_map motionBlurOptions = { diff --git a/src/port/ui/ResolutionEditor.cpp b/src/port/ui/ResolutionEditor.cpp index 8da2643ad..4bf44ee7e 100644 --- a/src/port/ui/ResolutionEditor.cpp +++ b/src/port/ui/ResolutionEditor.cpp @@ -3,7 +3,8 @@ #include #include "UIWidgets.h" -#include +#include +#include #include "port/Engine.h" #include "PortMenu.h" @@ -95,12 +96,14 @@ void RegisterResolutionWidgets() { // Resolution visualiser mPortMenu->AddWidget(path, "Viewport dimensions: {} x {}", WIDGET_TEXT).PreFunc([](WidgetInfo& info) { - info.name = fmt::format("Viewport dimensions: {} x {}", gfx_current_game_window_viewport.width, - gfx_current_game_window_viewport.height); + auto captured_window_viewport = GameEngine::GetInterpreter().get()->mGameWindowViewport; + info.name = fmt::format("Viewport dimensions: {} x {}", captured_window_viewport.width, + captured_window_viewport.height); }); mPortMenu->AddWidget(path, "Internal resolution: {} x {}", WIDGET_TEXT).PreFunc([](WidgetInfo& info) { + auto captured_current_dimensions = GameEngine::GetInterpreter().get()->mCurDimensions; info.name = - fmt::format("Internal resolution: {} x {}", gfx_current_dimensions.width, gfx_current_dimensions.height); + fmt::format("Internal resolution: {} x {}", captured_current_dimensions.width, captured_current_dimensions.height); }); // UIWidgets::PaddedSeparator(true, true, 3.0f, 3.0f); @@ -171,6 +174,8 @@ void RegisterResolutionWidgets() { } } else if (showHorizontalResField) { // Show calculated aspect ratio if (item_aspectRatio) { + auto gfx_current_game_window_viewport = GameEngine::GetInterpreter().get()->mGameWindowViewport; + auto gfx_current_dimensions = GameEngine::GetInterpreter().get()->mCurDimensions; ImGui::Dummy({ 0, 2 }); const float resolvedAspectRatio = (float)gfx_current_dimensions.width / gfx_current_dimensions.height; ImGui::Text("Aspect ratio: %.2f:1", resolvedAspectRatio); @@ -497,13 +502,15 @@ void UpdateResolutionVars() { short integerScale_maximumBounds = 1; // can change when window is resized // This is mostly just for UX purposes, as Fit Automatically logic is part of LUS. + auto gfx_current_game_window_viewport = GameEngine::GetInterpreter().get()->mGameWindowViewport; + auto gfx_current_dimensions = GameEngine::GetInterpreter().get()->mCurDimensions; if (((float)gfx_current_game_window_viewport.width / gfx_current_game_window_viewport.height) > ((float)gfx_current_dimensions.width / gfx_current_dimensions.height)) { // Scale to window height - integerScale_maximumBounds = gfx_current_game_window_viewport.height / gfx_current_dimensions.height; + integerScale_maximumBounds = gfx_current_game_window_viewport.height / gfx_current_game_window_viewport.height; } else { // Scale to window width - integerScale_maximumBounds = gfx_current_game_window_viewport.width / gfx_current_dimensions.width; + integerScale_maximumBounds = gfx_current_game_window_viewport.width / gfx_current_game_window_viewport.width; } // Lower-clamping maximum bounds value to 1 is no-longer necessary as that's accounted for in LUS. // Letting it go below 1 in this Editor will even allow for checking if screen bounds are being exceeded. diff --git a/src/port/ui/ResolutionEditor.h b/src/port/ui/ResolutionEditor.h index a287bb282..6a1cff80b 100644 --- a/src/port/ui/ResolutionEditor.h +++ b/src/port/ui/ResolutionEditor.h @@ -2,6 +2,8 @@ #define RESOLUTIONEDITOR_H #include +#include +#include namespace GameUI { bool IsDroppingFrames();