summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------libultraship0
-rw-r--r--port/shaders/metal/default.shader.metal15
-rw-r--r--src/engine/fox_bg.c2
-rw-r--r--src/port/Engine.cpp56
-rw-r--r--src/port/Engine.h16
-rw-r--r--src/port/GBIMiddleware.cpp2
-rw-r--r--src/port/Game.cpp2
-rw-r--r--src/port/Variables.cpp6
-rw-r--r--src/port/ui/ImguiUI.cpp2
-rw-r--r--src/port/ui/ResolutionEditor.cpp20
10 files changed, 60 insertions, 61 deletions
diff --git a/libultraship b/libultraship
-Subproject ec63c7390050c452b34c3f78be7499f88fae263
+Subproject 1a8a2f70d1a2624130a40baa7f8b0ce52231455
diff --git a/port/shaders/metal/default.shader.metal b/port/shaders/metal/default.shader.metal
index 63d89fd3..a771ba10 100644
--- a/port/shaders/metal/default.shader.metal
+++ b/port/shaders/metal/default.shader.metal
@@ -147,17 +147,6 @@ float random(float3 value) {
return fract(sin(random) * 143758.5453);
}
-float4 fromLinear(float4 linearRGB) {
- float3 threshold = float3(0.0031308);
- float3 gamma = float3(1.0 / 2.4);
- float3 scale = float3(12.92);
- float3 offset = float3(1.055);
- float3 subtract = float3(0.055);
- float3 higher = offset * fast::pow(linearRGB.xyz, gamma) - subtract;
- float3 lower = linearRGB.xyz * scale;
- return float4(select(higher, lower, linearRGB.xyz < threshold), linearRGB.w);
-}
-
fragment float4 fragmentShader(ProjectedVertex in [[stage_in]], constant FrameUniforms &frameUniforms [[buffer(0)]]
@if(o_textures[0])
, texture2d<float> uTex0 [[texture(0)]], sampler uTex0Smplr [[sampler(0)]]
@@ -288,8 +277,8 @@ fragment float4 fragmentShader(ProjectedVertex in [[stage_in]], constant FrameUn
@if(o_invisible)
texel.w = 0.0;
@end
- return fromLinear(texel);
+ return texel;
@else
- return fromLinear(float4(texel, 1.0));
+ return float4(texel, 1.0);
@end
} \ No newline at end of file
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 de023957..1786157e 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 <Fast3D/gfx_pc.h>
+#include <Fast3D/interpreter.h>
#include <filesystem>
#ifdef __SWITCH__
@@ -453,14 +453,16 @@ void GameEngine::RunCommands(Gfx* Commands, const std::vector<std::unordered_map
return;
}
+ auto interpreter = wnd->GetInterpreterWeak().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<Fast::Fast3dWindow>(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 <vector>
#include <SDL2/SDL.h>
-#include <Fast3D/gfx_pc.h>
+#include <Fast3D/interpreter.h>
#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 <stdint.h>
+#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 <libultraship.h>
-#include <Fast3D/gfx_pc.h>
+#include <Fast3D/interpreter.h>
#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 <libultraship.h>
-#include <Fast3D/gfx_pc.h>
-
-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 <imgui_internal.h>
#include <libultraship/libultraship.h>
-#include <Fast3D/gfx_pc.h>
+#include <Fast3D/interpreter.h>
#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 <imgui.h>
#include <libultraship/libultraship.h>
-#include <graphic/Fast3D/gfx_pc.h>
+#include <graphic/Fast3D/interpreter.h>
/* 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);