diff --git a/CMakeLists.txt b/CMakeLists.txt index d27231954..34b110bc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -401,6 +401,9 @@ if(USE_NETWORKING) target_compile_definitions(${PROJECT_NAME} PRIVATE USE_NETWORKING) if(CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") target_link_libraries(${PROJECT_NAME} PRIVATE SDL2_net) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + find_package(SDL2_net REQUIRED) + target_link_libraries(${PROJECT_NAME} PRIVATE SDL2_net::SDL2_net) else() find_package(SDL2_net REQUIRED) target_link_libraries(${PROJECT_NAME} PRIVATE SDL2_net::SDL2_net-static) diff --git a/assets/shaders/directx/default.shader.hlsl b/assets/shaders/directx/default.shader.hlsl index f36c2daed..980becb8c 100644 --- a/assets/shaders/directx/default.shader.hlsl +++ b/assets/shaders/directx/default.shader.hlsl @@ -186,7 +186,7 @@ float4 PSMain(PSInput input, float4 screenSpace : SV_Position) : SV_TARGET { float2 tc@{i} = input.uv@{i}; @{s = o_clamp[i][0]} @{t = o_clamp[i][1]} - @if(s && t) + @if(s || t) int2 texSize@{i}; g_texture@{i}.GetDimensions(texSize@{i}.x, texSize@{i}.y); @if(s && t) @@ -224,7 +224,7 @@ float4 PSMain(PSInput input, float4 screenSpace : SV_Position) : SV_TARGET { @else float4 blendVal@{i} = float4(0, 0, 0, 0); @end - texval@{i} = lerp(texVal@{i}, blendVal@{i}, g_textureMask@{i}.Sample(g_sampler@{i}, tc@{i}).a); + texVal@{i} = lerp(texVal@{i}, blendVal@{i}, g_textureMask@{i}.Sample(g_sampler@{i}, tc@{i}).a); @end } @else @@ -329,4 +329,4 @@ float4 PSMain(PSInput input, float4 screenSpace : SV_Position) : SV_TARGET { return float4(texel, 1.0); @end @end -} \ No newline at end of file +} diff --git a/assets/shaders/metal/default.shader.metal b/assets/shaders/metal/default.shader.metal index 63d89fd39..a771ba10c 100644 --- a/assets/shaders/metal/default.shader.metal +++ b/assets/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 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/assets/shaders/opengl/default.shader.fs b/assets/shaders/opengl/default.shader.fs index b15e1598c..404caae62 100644 --- a/assets/shaders/opengl/default.shader.fs +++ b/assets/shaders/opengl/default.shader.fs @@ -44,6 +44,10 @@ out vec4 vOutColor; uniform int frame_count; uniform float noise_scale; +uniform int texture_width[2]; +uniform int texture_height[2]; +uniform int texture_filtering[2]; + #define TEX_OFFSET(off) @{texture}(tex, texCoord - off / texSize) #define WRAP(x, low, high) mod((x)-(low), (high)-(low)) + (low) @@ -59,7 +63,6 @@ vec4 fromLinear(vec4 linearRGB){ return vec4(mix(higher, lower, cutoff), linearRGB.a); } -@if(o_current_filter == FILTER_THREE_POINT) vec4 filter3point(in sampler2D tex, in vec2 texCoord, in vec2 texSize) { vec2 offset = fract(texCoord*texSize - vec2(0.5)); offset -= step(1.0, offset.x + offset.y); @@ -69,14 +72,16 @@ vec4 filter3point(in sampler2D tex, in vec2 texCoord, in vec2 texSize) { return c0 + abs(offset.x)*(c1-c0) + abs(offset.y)*(c2-c0); } -vec4 hookTexture2D(in sampler2D tex, in vec2 uv, in vec2 texSize) { - return filter3point(tex, uv, texSize); -} -@else -vec4 hookTexture2D(in sampler2D tex, in vec2 uv, in vec2 texSize) { +vec4 hookTexture2D(in int id, sampler2D tex, in vec2 uv, in vec2 texSize) { +@if(o_three_point_filtering) + if(texture_filtering[id] == @{FILTER_THREE_POINT}) { + return filter3point(tex, uv, texSize); + } +@end return @{texture}(tex, uv); } -@end + +#define TEX_SIZE(tex) vec2(texture_width[tex], texture_height[tex]) void main() { @for(i in 0..2) @@ -84,11 +89,7 @@ void main() { @{s = o_clamp[i][0]} @{t = o_clamp[i][1]} - @if(opengles) - vec2 texSize@{i} = vec2(textureSize(uTex@{i}, 0)); - @else - vec2 texSize@{i} = textureSize(uTex@{i}, 0); - @end + vec2 texSize@{i} = TEX_SIZE(@{i}); @if(!s && !t) vec2 vTexCoordAdj@{i} = vTexCoord@{i}; @@ -102,7 +103,7 @@ void main() { @end @end - vec4 texVal@{i} = hookTexture2D(uTex@{i}, vTexCoordAdj@{i}, texSize@{i}); + vec4 texVal@{i} = hookTexture2D(@{i}, uTex@{i}, vTexCoordAdj@{i}, texSize@{i}); @if(o_masks[i]) @if(opengles) @@ -111,10 +112,10 @@ void main() { vec2 maskSize@{i} = textureSize(uTexMask@{i}, 0); @end - vec4 maskVal@{i} = hookTexture2D(uTexMask@{i}, vTexCoordAdj@{i}, maskSize@{i}); + vec4 maskVal@{i} = hookTexture2D(@{i}, uTexMask@{i}, vTexCoordAdj@{i}, maskSize@{i}); @if(o_blend[i]) - vec4 blendVal@{i} = hookTexture2D(uTexBlend@{i}, vTexCoordAdj@{i}, texSize@{i}); + vec4 blendVal@{i} = hookTexture2D(@{i}, uTexBlend@{i}, vTexCoordAdj@{i}, texSize@{i}); @else vec4 blendVal@{i} = vec4(0, 0, 0, 0); @end diff --git a/include/PR/os_time.h b/include/PR/os_time.h index a243cdf2d..c29ac76de 100644 --- a/include/PR/os_time.h +++ b/include/PR/os_time.h @@ -20,7 +20,6 @@ typedef u64 OSTime; /* Functions */ OSTime osGetTime(void); -void osSetTime(OSTime time); u32 osSetTimer(OSTimer*, OSTime, u64, OSMesgQueue*, OSMesg); #endif diff --git a/include/stubs.h b/include/stubs.h index 008e4b53a..67a8d7a4e 100644 --- a/include/stubs.h +++ b/include/stubs.h @@ -28,7 +28,6 @@ s32 osPfsDeleteFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, s32 osPfsReadWriteFile(OSPfs* pfs, s32 file_no, u8 flag, int offset, int size_in_bytes, u8* data_buffer); s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name, int file_size_in_bytes, s32* file_no); -void osSetTime(OSTime time); s32 osPfsIsPlug(OSMesgQueue* queue, u8* pattern); s32 osPfsInit(OSMesgQueue* queue, OSPfs* pfs, int channel); s32 osPfsNumFiles(OSPfs* pfs, s32* max_files, s32* files_used); diff --git a/src/engine/editor/Editor.cpp b/src/engine/editor/Editor.cpp index 446da7487..dc5a69cde 100644 --- a/src/engine/editor/Editor.cpp +++ b/src/engine/editor/Editor.cpp @@ -30,6 +30,7 @@ namespace Editor { Editor::Editor() { } + std::vector EditorMatrix; void Editor::Load() { printf("Editor: Loading Editor...\n"); eObjectPicker.Load(); diff --git a/src/engine/editor/EditorMath.cpp b/src/engine/editor/EditorMath.cpp index a3e19716c..4c36a17a2 100644 --- a/src/engine/editor/EditorMath.cpp +++ b/src/engine/editor/EditorMath.cpp @@ -28,7 +28,7 @@ bool IsInGameScreen() { Ship::Coords mouse = wnd->GetMousePos(); // Define viewport boundaries - auto gfx_current_game_window_viewport = GameEngine::GetInterpreter().get()->mGameWindowViewport; + auto gfx_current_game_window_viewport = GetInterpreter()->mGameWindowViewport; int left = gfx_current_game_window_viewport.width; int right = left + OTRGetGameRenderWidth(); int top = gfx_current_game_window_viewport.height; @@ -43,7 +43,7 @@ FVector ScreenRayTrace() { Camera* camera = &cameras[0]; Ship::Coords mouse = wnd->GetMousePos(); - auto gfx_current_game_window_viewport = GameEngine::GetInterpreter().get()->mGameWindowViewport; + auto gfx_current_game_window_viewport = GetInterpreter()->mGameWindowViewport; mouse.x -= gfx_current_game_window_viewport.width; mouse.y -= gfx_current_game_window_viewport.height; // Get screen dimensions diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 440363efa..788af51ab 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -49,14 +49,11 @@ 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; +Fast::Interpreter* GetInterpreter() { + return static_pointer_cast(Ship::Context::GetInstance()->GetWindow()) + ->GetInterpreterWeak() + .lock() + .get(); } GameEngine* GameEngine::Instance; @@ -543,7 +540,7 @@ extern "C" void GameEngine_UnloadSequence(const uint8_t seqId) { } extern "C" float GameEngine_GetAspectRatio() { - auto gfx_current_dimensions = GameEngine::GetInterpreter().get()->mCurDimensions; + auto gfx_current_dimensions = GetInterpreter()->mCurDimensions; return gfx_current_dimensions.aspect_ratio; } @@ -617,8 +614,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; + return GetInterpreter()->mCurDimensions.aspect_ratio; } extern "C" float OTRGetDimensionFromLeftEdge(float v) { @@ -661,22 +657,18 @@ 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; + return GetInterpreter()->mCurDimensions.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; + return GetInterpreter()->mCurDimensions.height; } extern "C" uint32_t OTRGetGameViewportWidth() { - auto gfx_current_game_window_viewport = GameEngine::GetInterpreter().get()->mGameWindowViewport; - return gfx_current_game_window_viewport.width; + return GetInterpreter()->mGameWindowViewport.width; } extern "C" uint32_t OTRGetGameViewportHeight() { - auto gfx_current_game_window_viewport = GameEngine::GetInterpreter().get()->mGameWindowViewport; - return gfx_current_game_window_viewport.height; + return GetInterpreter()->mGameWindowViewport.height; } \ No newline at end of file diff --git a/src/port/Engine.h b/src/port/Engine.h index 6136ff06a..bd6cf1ce0 100644 --- a/src/port/Engine.h +++ b/src/port/Engine.h @@ -25,6 +25,8 @@ #define NUM_AUDIO_CHANNELS 2 #define SAMPLES_PER_FRAME (SAMPLES_HIGH * NUM_AUDIO_CHANNELS * 2) +Fast::Interpreter* GetInterpreter(); + struct CtlEntry; struct AudioBankSample; struct AudioSequenceData; @@ -46,9 +48,6 @@ class GameEngine { ImFont* fontMonoLarger; ImFont* fontMonoLargest; - static std::weak_ptr mInterpreter; - static std::shared_ptr GetInterpreter(); - std::unordered_map bankMapTable; GameEngine(); static bool GenAssetFile(); @@ -82,6 +81,7 @@ class GameEngine { private: ImFont* CreateFontWithSize(float size, std::string fontPath = ""); }; + #endif #ifdef __cplusplus diff --git a/src/port/SpaghettiGui.cpp b/src/port/SpaghettiGui.cpp index 1e0618ff2..3f096c5fa 100644 --- a/src/port/SpaghettiGui.cpp +++ b/src/port/SpaghettiGui.cpp @@ -27,7 +27,7 @@ #endif #if defined(ENABLE_DX11) || defined(ENABLE_DX12) -#include +#include #include #include diff --git a/src/port/ui/ImguiUI.cpp b/src/port/ui/ImguiUI.cpp index 3b1a33ed8..237e8d27f 100644 --- a/src/port/ui/ImguiUI.cpp +++ b/src/port/ui/ImguiUI.cpp @@ -50,10 +50,10 @@ void SetupGuiElements() { mPortMenu = std::make_shared("gOpenMenu", "Port Menu"); gui->SetMenu(mPortMenu); - mMultiplayerWindow = gui->GetGuiWindow("Multiplayer"); - if (mMultiplayerWindow == nullptr) { - SPDLOG_ERROR("Could not find multiplayer window"); - } + //mMultiplayerWindow = gui->GetGuiWindow("Multiplayer"); + //if (mMultiplayerWindow == nullptr) { + // SPDLOG_ERROR("Could not find multiplayer window"); + //} mStatsWindow = gui->GetGuiWindow("Stats"); if (mStatsWindow == nullptr) { diff --git a/src/port/ui/ResolutionEditor.cpp b/src/port/ui/ResolutionEditor.cpp index 4bf44ee7e..ca47cb15e 100644 --- a/src/port/ui/ResolutionEditor.cpp +++ b/src/port/ui/ResolutionEditor.cpp @@ -96,12 +96,12 @@ void RegisterResolutionWidgets() { // Resolution visualiser mPortMenu->AddWidget(path, "Viewport dimensions: {} x {}", WIDGET_TEXT).PreFunc([](WidgetInfo& info) { - auto captured_window_viewport = GameEngine::GetInterpreter().get()->mGameWindowViewport; + auto captured_window_viewport = GetInterpreter()->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; + auto captured_current_dimensions = GetInterpreter()->mCurDimensions; info.name = fmt::format("Internal resolution: {} x {}", captured_current_dimensions.width, captured_current_dimensions.height); }); @@ -174,8 +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; + auto gfx_current_game_window_viewport = GetInterpreter()->mGameWindowViewport; + auto gfx_current_dimensions = GetInterpreter()->mCurDimensions; ImGui::Dummy({ 0, 2 }); const float resolvedAspectRatio = (float)gfx_current_dimensions.width / gfx_current_dimensions.height; ImGui::Text("Aspect ratio: %.2f:1", resolvedAspectRatio); @@ -502,8 +502,8 @@ 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; + auto gfx_current_game_window_viewport = GetInterpreter()->mGameWindowViewport; + auto gfx_current_dimensions = GetInterpreter()->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 diff --git a/src/stubs.c b/src/stubs.c index 866215f9c..b197ec6e3 100644 --- a/src/stubs.c +++ b/src/stubs.c @@ -96,11 +96,6 @@ s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name return PFS_NO_ERROR; } -#ifndef __SWITCH__ -void osSetTime(OSTime time) { -} -#endif - s32 osPfsIsPlug(OSMesgQueue* queue, u8* pattern) { }