From 54a4d76b6ffd6b276a951224b62881fa6c4ff9a9 Mon Sep 17 00:00:00 2001 From: Alejandro Asenjo Nitti <96613413+sonicdcer@users.noreply.github.com> Date: Fri, 18 Apr 2025 03:22:13 -0400 Subject: [PATCH] Bump LUS (#191) * Bump LUS (#190) * Bump LUS * Disabled shader-based linear conversion on metal * Fixed missing mInterpolationIndex * Bump LUS --------- Co-authored-by: KiritoDv * restore console * bump LUS * Reverted linear conversion on shader --------- Co-authored-by: KiritoDv --- libultraship | 2 +- src/engine/fox_bg.c | 2 +- src/port/Engine.cpp | 56 +++++++++++++++++++------------- src/port/Engine.h | 16 +++++---- src/port/GBIMiddleware.cpp | 2 -- src/port/Game.cpp | 2 +- src/port/Variables.cpp | 6 ---- src/port/ui/ImguiUI.cpp | 2 +- src/port/ui/ResolutionEditor.cpp | 20 +++++++----- 9 files changed, 59 insertions(+), 49 deletions(-) delete mode 100644 src/port/Variables.cpp diff --git a/libultraship b/libultraship index ec63c739..dda07c8a 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit ec63c7390050c452b34c3f78be7499f88fae2636 +Subproject commit dda07c8ac6033ff98d37a05bc28406440c7769e4 diff --git a/src/engine/fox_bg.c b/src/engine/fox_bg.c index 862851bc..65831bc4 100644 --- a/src/engine/fox_bg.c +++ b/src/engine/fox_bg.c @@ -258,7 +258,7 @@ void Background_DrawStarfield(void) { float originalWidth = currentScreenWidth / 3; float originalAspect = originalWidth / (currentScreenHeight / 3); - float renderMaskWidth = originalWidth * (OTRGetAspectRatio() / originalAspect); + float renderMaskWidth = originalWidth * (GameEngine_GetAspectRatio() / originalAspect); float marginX = (currentScreenWidth - renderMaskWidth) / 2; float renderMaskHeight = currentScreenHeight / 3; diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index a64c6c3f..d8d34711 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -41,7 +41,7 @@ #include "port/patches/DisplayListPatch.h" #include "port/mods/PortEnhancements.h" -#include +#include #include #ifdef __SWITCH__ @@ -453,14 +453,16 @@ void GameEngine::RunCommands(Gfx* Commands, const std::vectorGetInterpreterWeak().lock().get(); + // Process window events for resize, mouse, keyboard events wnd->HandleEvents(); - gInterpolationIndex = 0; + interpreter->mInterpolationIndex = 0; for (const auto& m : mtx_replacements) { wnd->DrawAndRunGraphicsCommands(Commands, m); - gInterpolationIndex++; + interpreter->mInterpolationIndex++; } bool curAltAssets = CVarGetInteger("gEnhancements.Mods.AlternateAssets", 0); @@ -616,8 +618,16 @@ extern "C" uint32_t GameEngine_GetSamplesPerFrame() { // End +Fast::Interpreter* GameEngine_GetInterpreter() { + return static_pointer_cast(Ship::Context::GetInstance()->GetWindow()) + ->GetInterpreterWeak() + .lock() + .get(); +} + extern "C" float GameEngine_GetAspectRatio() { - return gfx_current_dimensions.aspect_ratio; + auto interpreter = GameEngine_GetInterpreter(); + return interpreter->mCurDimensions.aspect_ratio; } extern "C" uint32_t GameEngine_GetGameVersion() { @@ -730,34 +740,33 @@ extern "C" uint32_t OTRGetCurrentHeight() { return GameEngine::Instance->context->GetWindow()->GetHeight(); } -extern "C" float OTRGetAspectRatio() { - return gfx_current_dimensions.aspect_ratio; -} - extern "C" float OTRGetHUDAspectRatio() { - if (CVarGetInteger("gHUDAspectRatio.Enabled", 0) == 0 || CVarGetInteger("gHUDAspectRatio.X", 0) == 0 || CVarGetInteger("gHUDAspectRatio.Y", 0) == 0) - { - return OTRGetAspectRatio(); + if (CVarGetInteger("gHUDAspectRatio.Enabled", 0) == 0 || CVarGetInteger("gHUDAspectRatio.X", 0) == 0 || CVarGetInteger("gHUDAspectRatio.Y", 0) == 0) { + return GameEngine_GetAspectRatio(); } return ((float)CVarGetInteger("gHUDAspectRatio.X", 1) / (float)CVarGetInteger("gHUDAspectRatio.Y", 1)); } extern "C" float OTRGetDimensionFromLeftEdge(float v) { - return (gfx_native_dimensions.width / 2 - gfx_native_dimensions.height / 2 * OTRGetAspectRatio() + (v)); + auto interpreter = GameEngine_GetInterpreter(); + return (interpreter->mNativeDimensions.width / 2 - interpreter->mNativeDimensions.height / 2 * interpreter->mCurDimensions.aspect_ratio + (v)); } extern "C" float OTRGetDimensionFromRightEdge(float v) { - return (gfx_native_dimensions.width / 2 + gfx_native_dimensions.height / 2 * OTRGetAspectRatio() - - (gfx_native_dimensions.width - v)); + auto interpreter = GameEngine_GetInterpreter(); + return (interpreter->mNativeDimensions.width / 2 + interpreter->mNativeDimensions.height / 2 * interpreter->mCurDimensions.aspect_ratio - + (interpreter->mNativeDimensions.width - v)); } extern "C" float OTRGetDimensionFromLeftEdgeForcedAspect(float v, float aspectRatio) { - return (gfx_native_dimensions.width / 2 - gfx_native_dimensions.height / 2 * (aspectRatio > 0 ? aspectRatio : OTRGetAspectRatio()) + (v)); + auto interpreter = GameEngine_GetInterpreter(); + return (interpreter->mNativeDimensions.width / 2 - interpreter->mNativeDimensions.height / 2 * (aspectRatio > 0 ? aspectRatio : interpreter->mCurDimensions.aspect_ratio) + (v)); } extern "C" float OTRGetDimensionFromRightEdgeForcedAspect(float v, float aspectRatio) { - return (gfx_native_dimensions.width / 2 + gfx_native_dimensions.height / 2 * (aspectRatio > 0 ? aspectRatio : OTRGetAspectRatio()) - - (gfx_native_dimensions.width - v)); + auto interpreter = GameEngine_GetInterpreter(); + return (interpreter->mNativeDimensions.width / 2 + interpreter->mNativeDimensions.height / 2 * (aspectRatio > 0 ? aspectRatio : interpreter->mCurDimensions.aspect_ratio) - + (interpreter->mNativeDimensions.width - v)); } extern "C" float OTRGetDimensionFromLeftEdgeOverride(float v) { @@ -770,12 +779,14 @@ extern "C" float OTRGetDimensionFromRightEdgeOverride(float v) { // Gets the width of the current render target area extern "C" uint32_t OTRGetGameRenderWidth() { - return gfx_current_dimensions.width; + auto interpreter = GameEngine_GetInterpreter(); + return interpreter->mCurDimensions.width; } // Gets the height of the current render target area extern "C" uint32_t OTRGetGameRenderHeight() { - return gfx_current_dimensions.height; + auto interpreter = GameEngine_GetInterpreter(); + return interpreter->mCurDimensions.height; } extern "C" int16_t OTRGetRectDimensionFromLeftEdge(float v) { @@ -803,9 +814,10 @@ extern "C" int16_t OTRGetRectDimensionFromRightEdgeOverride(float v) { } extern "C" int32_t OTRConvertHUDXToScreenX(int32_t v) { - float gameAspectRatio = gfx_current_dimensions.aspect_ratio; - int32_t gameHeight = gfx_current_dimensions.height; - int32_t gameWidth = gfx_current_dimensions.width; + auto interpreter = GameEngine_GetInterpreter(); + float gameAspectRatio = interpreter->mCurDimensions.aspect_ratio; + int32_t gameHeight = interpreter->mCurDimensions.height; + int32_t gameWidth = interpreter->mCurDimensions.width; float hudAspectRatio = 4.0f / 3.0f; int32_t hudHeight = gameHeight; int32_t hudWidth = hudHeight * hudAspectRatio; diff --git a/src/port/Engine.h b/src/port/Engine.h index 43dbf066..bbb50c60 100644 --- a/src/port/Engine.h +++ b/src/port/Engine.h @@ -12,7 +12,7 @@ typedef enum { #ifdef __cplusplus #include #include -#include +#include #include "libultraship/src/Context.h" #ifndef IDYES @@ -48,21 +48,23 @@ class GameEngine { static bool HasVersion(SF64Version ver); }; -extern "C" void* GameEngine_Malloc(size_t size); - +Fast::Interpreter* GameEngine_GetInterpreter(); #define memallocn(type, n) (type*) GameEngine_Malloc(sizeof(type) * n) #define memalloc(type) memallocn(type, 1) +extern "C" { #else #include +#define memalloc(size) GameEngine_Malloc(size) +#endif +void* GameEngine_Malloc(size_t size); bool GameEngine_HasVersion(SF64Version ver); void GameEngine_ProcessGfxCommands(Gfx* commands); float GameEngine_GetAspectRatio(); -uint8_t GameEngine_OTRSigCheck(char* imgData); +uint8_t GameEngine_OTRSigCheck(const char* imgData); uint32_t OTRGetCurrentWidth(void); uint32_t OTRGetCurrentHeight(void); -float OTRGetAspectRatio(void); float OTRGetHUDAspectRatio(); int32_t OTRConvertHUDXToScreenX(int32_t v); float OTRGetDimensionFromLeftEdge(float v); @@ -83,5 +85,7 @@ void* GameEngine_Malloc(size_t size); void GameEngine_GetTextureInfo(const char* path, int32_t* width, int32_t* height, float* scale, bool* custom); void gDPSetTileSizeInterp(Gfx* pkt, int t, float uls, float ult, float lrs, float lrt); uint32_t GameEngine_GetInterpolationFrameCount(); -#define memalloc(size) GameEngine_Malloc(size) + +#ifdef __cplusplus +} #endif \ No newline at end of file diff --git a/src/port/GBIMiddleware.cpp b/src/port/GBIMiddleware.cpp index e0355a6d..152d0203 100644 --- a/src/port/GBIMiddleware.cpp +++ b/src/port/GBIMiddleware.cpp @@ -3,8 +3,6 @@ #include "Engine.h" #include "DisplayList.h" -extern "C" uint8_t GameEngine_OTRSigCheck(const char* data); - extern "C" void gSPDisplayList(Gfx* pkt, Gfx* dl) { char* imgData = (char*)dl; diff --git a/src/port/Game.cpp b/src/port/Game.cpp index 18a4c312..ef7894be 100644 --- a/src/port/Game.cpp +++ b/src/port/Game.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include "Engine.h" extern "C" { diff --git a/src/port/Variables.cpp b/src/port/Variables.cpp deleted file mode 100644 index f7ccf0eb..00000000 --- a/src/port/Variables.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include -#include - -extern "C" { - -} \ No newline at end of file diff --git a/src/port/ui/ImguiUI.cpp b/src/port/ui/ImguiUI.cpp index 1748523a..615a07d0 100644 --- a/src/port/ui/ImguiUI.cpp +++ b/src/port/ui/ImguiUI.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include "port/Engine.h" #include "port/notification/notification.h" #include "utils/StringHelper.h" diff --git a/src/port/ui/ResolutionEditor.cpp b/src/port/ui/ResolutionEditor.cpp index cac3b8be..cc78edaf 100644 --- a/src/port/ui/ResolutionEditor.cpp +++ b/src/port/ui/ResolutionEditor.cpp @@ -1,10 +1,11 @@ #include "ResolutionEditor.h" #include "UIWidgets.h" #include "libultraship/src/Context.h" +#include "port/Engine.h" #include #include -#include +#include /* Console Variables are grouped under gAdvancedResolution. (e.g. "gAdvancedResolution.Enabled") @@ -59,6 +60,7 @@ namespace AdvancedResolutionSettings { for (unsigned short i = 0; i < sizeof(setting); i++) update[i] = false; static short updateCountdown = 0; + auto interpreter = GameEngine_GetInterpreter(); short countdownStartingValue = CVarGetInteger("gInterpolationFPS", 60) / 2; // half of a second, in frames. // Initialise integer scale bounds. @@ -67,13 +69,13 @@ namespace AdvancedResolutionSettings { 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. - if (((float)gfx_current_game_window_viewport.width / gfx_current_game_window_viewport.height) > - ((float)gfx_current_dimensions.width / gfx_current_dimensions.height)) { + if (((float)interpreter->mGameWindowViewport.width / interpreter->mGameWindowViewport.height) > + ((float)interpreter->mCurDimensions.width / interpreter->mCurDimensions.height)) { // Scale to window height - integerScale_maximumBounds = gfx_current_game_window_viewport.height / gfx_current_dimensions.height; + integerScale_maximumBounds = interpreter->mGameWindowViewport.height / interpreter->mCurDimensions.height; } else { // Scale to window width - integerScale_maximumBounds = gfx_current_game_window_viewport.width / gfx_current_dimensions.width; + integerScale_maximumBounds = interpreter->mGameWindowViewport.width / interpreter->mCurDimensions.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. @@ -136,9 +138,9 @@ namespace AdvancedResolutionSettings { } } // Resolution visualiser - ImGui::Text("Viewport dimensions: %d x %d", gfx_current_game_window_viewport.width, - gfx_current_game_window_viewport.height); - ImGui::Text("Internal resolution: %d x %d", gfx_current_dimensions.width, gfx_current_dimensions.height); + ImGui::Text("Viewport dimensions: %d x %d", interpreter->mGameWindowViewport.width, + interpreter->mGameWindowViewport.height); + ImGui::Text("Internal resolution: %d x %d", interpreter->mCurDimensions.width, interpreter->mCurDimensions.height); UIWidgets::PaddedSeparator(true, true, 3.0f, 3.0f); @@ -171,7 +173,7 @@ namespace AdvancedResolutionSettings { } else if (showHorizontalResField) { // Show calculated aspect ratio if (item_aspectRatio) { UIWidgets::Spacer(2); - float resolvedAspectRatio = (float)gfx_current_dimensions.height / gfx_current_dimensions.width; + float resolvedAspectRatio = (float)interpreter->mCurDimensions.height / interpreter->mCurDimensions.width; ImGui::Text("Aspect ratio: %.4f", resolvedAspectRatio); } else { UIWidgets::Spacer(enhancementSpacerHeight);