Fixes made so far (#198)

* Fixed compile

* Moved GetInterpreter() to a single function under the Engine.h
This commit is contained in:
MegaMech
2025-05-15 10:30:39 -06:00
committed by GitHub
parent 0e35858050
commit e7415ec072
18 changed files with 76 additions and 36 deletions
+9 -6
View File
@@ -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();
+2
View File
@@ -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"
+19 -3
View File
@@ -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;
}
+5 -2
View File
@@ -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();
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -1,5 +1,5 @@
#include <libultraship.h>
#include <Fast3D/gfx_pc.h>
#include <graphic/Fast3D/Fast3dWindow.h>
extern "C" {
+5 -3
View File
@@ -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();
@@ -1,6 +1,7 @@
#pragma once
#include "resourcebridge.h"
#include "libultraship/src/resource/ResourceManager.h"
#include "Context.h"
namespace SM64 {
@@ -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;
@@ -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>
+1 -1
View File
@@ -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:
+5 -2
View File
@@ -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
+1 -1
View File
@@ -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"
-1
View File
@@ -3,7 +3,6 @@
#include <libultraship/libultraship.h>
#include "UIWidgets.h"
#include "graphic/Fast3D/gfx_rendering_api.h"
#include "MenuTypes.h"
extern "C" {
+5 -4
View File
@@ -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 = {
+13 -6
View File
@@ -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.
+2
View File
@@ -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();