summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2025-05-15 10:30:39 -0600
committerGitHub <noreply@github.com>2025-05-15 10:30:39 -0600
commite7415ec072ee1cdc99a49db658062d4de0b3301c (patch)
tree5b01d3f1921e221d03b05ec101d10d7513624974
parent0e35858050fd00e5871f0ac9d1684edc61251d49 (diff)
Fixes made so far (#198)
* Fixed compile * Moved GetInterpreter() to a single function under the Engine.h
m---------libultraship0
-rw-r--r--src/engine/editor/EditorMath.cpp15
-rw-r--r--src/engine/editor/EditorMath.h2
-rw-r--r--src/port/Engine.cpp22
-rw-r--r--src/port/Engine.h7
-rw-r--r--src/port/Game.cpp2
-rw-r--r--src/port/Variables.cpp2
-rw-r--r--src/port/resource/importers/ArrayFactory.cpp8
-rw-r--r--src/port/resource/importers/ResourceUtil.h1
-rw-r--r--src/port/resource/importers/TrackSectionsFactory.cpp8
-rw-r--r--src/port/resource/importers/TrackWaypointFactory.cpp1
-rw-r--r--src/port/resource/type/Array.cpp2
-rw-r--r--src/port/resource/type/Array.h7
-rw-r--r--src/port/ui/ImguiUI.cpp2
-rw-r--r--src/port/ui/Menu.h1
-rw-r--r--src/port/ui/PortMenu.h9
-rw-r--r--src/port/ui/ResolutionEditor.cpp19
-rw-r--r--src/port/ui/ResolutionEditor.h2
18 files changed, 75 insertions, 35 deletions
diff --git a/libultraship b/libultraship
-Subproject 58b050990526fd6ffa8fe6a7b6682593d02eb96
+Subproject ab9935c0f4313d253e6c72c96ec6212c7ae96cd
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 <limits>
#include <cmath>
+#include <graphic/Fast3D/Fast3dWindow.h>
+#include <graphic/Fast3D/interpreter.h>
+
extern "C" {
#include "common_structs.h"
#include "main.h"
@@ -20,16 +23,15 @@ extern "C" {
#include "camera.h"
}
-std::vector<Mtx> 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 <vector>
#include "GameObject.h"
+#include <graphic/Fast3D/Fast3dWindow.h>
+#include <graphic/Fast3D/interpreter.h>
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 <Fast3D/Fast3dWindow.h>
#include <Fonts.h>
#include "window/gui/resource/Font.h"
#include "window/gui/resource/FontFactory.h"
#include "SpaghettiGui.h"
-#include <Fast3D/gfx_pc.h>
-#include <Fast3D/gfx_rendering_api.h>
+#include <graphic/Fast3D/Fast3dWindow.h>
+#include <graphic/Fast3D/interpreter.h>
+//#include <Fast3D/gfx_rendering_api.h>
#include <SDL2/SDL.h>
#include <utility>
@@ -49,6 +49,16 @@ float gInterpolationStep = 0.0f;
#include "audio/GameAudio.h"
}
+std::weak_ptr<Fast::Interpreter> GameEngine::mInterpreter;
+
+std::shared_ptr<Fast::Interpreter> 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 <vector>
#include <SDL2/SDL.h>
-#include <Fast3D/gfx_pc.h>
+#include <graphic/Fast3D/Fast3dWindow.h>
+#include <graphic/Fast3D/interpreter.h>
#include "libultraship/src/Context.h"
#ifndef IDYES
@@ -46,6 +46,9 @@ class GameEngine {
ImFont* fontMonoLarger;
ImFont* fontMonoLargest;
+ static std::weak_ptr<Fast::Interpreter> mInterpreter;
+ static std::shared_ptr<Fast::Interpreter> GetInterpreter();
+
std::unordered_map<std::string, uint8_t> 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 <Fast3D/gfx_pc.h>
+#include <graphic/Fast3D/Fast3dWindow.h>
#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 <libultraship.h>
-#include <Fast3D/gfx_pc.h>
+#include <graphic/Fast3D/Fast3dWindow.h>
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<Ship::IResource> ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr<Ship::File> file, std::shared_ptr<Ship::ResourceInitData> initData) {
+std::shared_ptr<Ship::IResource>
+ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr<Ship::File> file,
+ std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
@@ -12,13 +14,13 @@ std::shared_ptr<Ship::IResource> ResourceFactoryBinaryArrayV0::ReadResource(std:
auto array = std::make_shared<Array>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(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<Ship::File> file
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
-
+
auto section = std::make_shared<TrackSectionsO2RClass>(initData);
- auto child =
- std::get<std::shared_ptr<tinyxml2::XMLDocument>>(file->Reader)->FirstChildElement()->FirstChildElement();
+ auto child = std::get<std::shared_ptr<tinyxml2::XMLDocument>>(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<Ship::IResource>
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<void> {
size_t ArrayCount;
// OTRTODO: Should be a vector of resource pointers...
std::vector<ScalarData> Scalars;
- std::vector<F3DVtx> Vertices;
+ std::vector<Fast::F3DVtx> 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 <imgui_internal.h>
#include <libultraship/libultraship.h>
-#include <Fast3D/gfx_pc.h>
+#include <graphic/Fast3D/Fast3dWindow.h>
#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 <libultraship/libultraship.h>
#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 <libultraship/libultraship.h>
#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<int32_t, const char*> menuThemeOptions = {
};
static const std::unordered_map<int32_t, const char*> 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<int32_t, const char*> 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 <libultraship/libultraship.h>
#include "UIWidgets.h"
-#include <graphic/Fast3D/gfx_pc.h>
+#include <graphic/Fast3D/Fast3dWindow.h>
+#include <graphic/Fast3D/interpreter.h>
#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 <libultraship/libultraship.h>
+#include <graphic/Fast3D/Fast3dWindow.h>
+#include <graphic/Fast3D/interpreter.h>
namespace GameUI {
bool IsDroppingFrames();