diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 1b5cf2da..e3cdfc10 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -153,7 +153,7 @@ set(SWA_UI_CXX_SOURCES "ui/options_menu_thumbnails.cpp" "ui/options_menu.cpp" "ui/sdl_listener.cpp" - "ui/window.cpp" + "ui/game_window.cpp" ) set(SWA_INSTALL_CXX_SOURCES diff --git a/UnleashedRecomp/app.cpp b/UnleashedRecomp/app.cpp index 94cc4191..2001b148 100644 --- a/UnleashedRecomp/app.cpp +++ b/UnleashedRecomp/app.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include @@ -41,7 +41,7 @@ PPC_FUNC(sub_822C1130) SDL_PumpEvents(); SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); - Window::Update(); + GameWindow::Update(); AudioPatches::Update(App::s_deltaTime); __imp__sub_822C1130(ctx, base); diff --git a/UnleashedRecomp/exports.cpp b/UnleashedRecomp/exports.cpp index ee4eb0dd..9a5d166e 100644 --- a/UnleashedRecomp/exports.cpp +++ b/UnleashedRecomp/exports.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include SWA_API void Game_PlaySound(const char* pName) @@ -31,5 +31,5 @@ SWA_API void Game_PlaySound(const char* pName) SWA_API void Window_SetFullscreen(bool isEnabled) { - Window::SetFullscreen(isEnabled); + GameWindow::SetFullscreen(isEnabled); } diff --git a/UnleashedRecomp/gpu/rhi/plume_render_interface_types.h b/UnleashedRecomp/gpu/rhi/plume_render_interface_types.h index 9f563e85..f90182e3 100644 --- a/UnleashedRecomp/gpu/rhi/plume_render_interface_types.h +++ b/UnleashedRecomp/gpu/rhi/plume_render_interface_types.h @@ -19,9 +19,7 @@ #elif defined(__ANDROID__) #include "android/native_window.h" #elif defined(__linux__) -#define Window X11Window #include "X11/Xlib.h" -#undef Window #undef None #undef Status #undef LockMask @@ -40,7 +38,7 @@ namespace plume { #elif defined(__linux__) struct RenderWindow { Display* display; - X11Window* window; + Window* window; bool operator==(const struct RenderWindow& rhs) const { return display == rhs.display && window == rhs.window; } diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index fcf4f402..5a0d13d7 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include @@ -1041,7 +1041,7 @@ static void ProcSetRenderState(const RenderCommand& cmd) } } -static const std::pair g_setRenderStateFunctions[] = +static const std::pair g_setRenderStateFunctions[] = { { D3DRS_ZENABLE, HostToGuestFunction> }, { D3DRS_ZWRITEENABLE, HostToGuestFunction> }, @@ -1096,11 +1096,13 @@ static std::unique_ptr g_enhancedMotionBlurShader; #endif +#ifdef _WIN32 static bool DetectWine() { HMODULE dllHandle = GetModuleHandle("ntdll.dll"); return dllHandle != nullptr && GetProcAddress(dllHandle, "wine_get_version") != nullptr; } +#endif static constexpr size_t TEXTURE_DESCRIPTOR_SIZE = 65536; static constexpr size_t SAMPLER_DESCRIPTOR_SIZE = 1024; @@ -1163,7 +1165,7 @@ static void CreateImGuiBackend() OptionsMenu::Init(); InstallerWizard::Init(); - ImGui_ImplSDL2_InitForOther(Window::s_pWindow); + ImGui_ImplSDL2_InitForOther(GameWindow::s_pWindow); #ifdef ENABLE_IM_FONT_ATLAS_SNAPSHOT g_imFontTexture = LoadTexture( @@ -1313,7 +1315,7 @@ void Video::CreateHostDevice() IMGUI_CHECKVERSION(); ImGui::CreateContext(); - Window::Init(); + GameWindow::Init(); #ifdef SWA_D3D12 g_vulkan = DetectWine() || Config::GraphicsAPI == EGraphicsAPI::Vulkan; @@ -1358,7 +1360,7 @@ void Video::CreateHostDevice() break; } - g_swapChain = g_queue->createSwapChain(Window::s_handle, bufferCount, BACKBUFFER_FORMAT); + g_swapChain = g_queue->createSwapChain(GameWindow::s_handle, bufferCount, BACKBUFFER_FORMAT); g_swapChain->setVsyncEnabled(Config::VSync); g_swapChainValid = !g_swapChain->needsResize(); diff --git a/UnleashedRecomp/hid/driver/sdl_hid.cpp b/UnleashedRecomp/hid/driver/sdl_hid.cpp index f849d327..ac140824 100644 --- a/UnleashedRecomp/hid/driver/sdl_hid.cpp +++ b/UnleashedRecomp/hid/driver/sdl_hid.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #define TRANSLATE_INPUT(S, X) SDL_GameControllerGetButton(controller, S) << FirstBitLow(X) @@ -66,7 +66,7 @@ public: bool CanPoll() { - return controller && (Window::s_isFocused || Config::AllowBackgroundInput); + return controller && (GameWindow::s_isFocused || Config::AllowBackgroundInput); } void PollAxis() diff --git a/UnleashedRecomp/kernel/xam.cpp b/UnleashedRecomp/kernel/xam.cpp index 88d07d11..50f664bc 100644 --- a/UnleashedRecomp/kernel/xam.cpp +++ b/UnleashedRecomp/kernel/xam.cpp @@ -2,7 +2,7 @@ #include "xam.h" #include "xdm.h" #include -#include +#include #include #include #include @@ -232,7 +232,6 @@ SWA_API uint32_t XamShowMessageBoxUI(uint32_t dwUserIndex, be* wszTitl TASKDIALOGCONFIG config{}; config.cbSize = sizeof(config); - // config.hwndParent = Window::s_hWnd; config.pszWindowTitle = texts[0].c_str(); config.pszContent = texts[1].c_str(); config.cButtons = cButtons; @@ -406,7 +405,7 @@ SWA_API uint32_t XamInputGetState(uint32_t userIndex, uint32_t flags, XAMINPUT_S uint32_t result = hid::GetState(userIndex, state); - if (Window::s_isFocused) + if (GameWindow::s_isFocused) { auto keyboardState = SDL_GetKeyboardState(NULL); diff --git a/UnleashedRecomp/patches/camera_patches.cpp b/UnleashedRecomp/patches/camera_patches.cpp index 9b70e525..83ec4dfa 100644 --- a/UnleashedRecomp/patches/camera_patches.cpp +++ b/UnleashedRecomp/patches/camera_patches.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include constexpr float m_baseAspectRatio = 16.0f / 9.0f; @@ -8,7 +8,7 @@ constexpr float m_baseAspectRatio = 16.0f / 9.0f; bool CameraAspectRatioMidAsmHook(PPCRegister& r31) { auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32); - auto newAspectRatio = (float)Window::s_width / (float)Window::s_height; + auto newAspectRatio = (float)GameWindow::s_width / (float)GameWindow::s_height; // Dynamically adjust horizontal aspect ratio to window dimensions. pCamera->m_HorzAspectRatio = newAspectRatio; @@ -27,7 +27,7 @@ bool CameraBoostAspectRatioMidAsmHook(PPCRegister& r31, PPCRegister& f0, PPCRegi { auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32); - if (Window::s_width < Window::s_height) + if (GameWindow::s_width < GameWindow::s_height) { pCamera->m_VertFieldOfView = pCamera->m_HorzFieldOfView + f10.f64; } diff --git a/UnleashedRecomp/patches/fps_patches.cpp b/UnleashedRecomp/patches/fps_patches.cpp index 41d6cb2b..684421cb 100644 --- a/UnleashedRecomp/patches/fps_patches.cpp +++ b/UnleashedRecomp/patches/fps_patches.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/UnleashedRecomp/patches/misc_patches.cpp b/UnleashedRecomp/patches/misc_patches.cpp index 3c69e3bc..7a368849 100644 --- a/UnleashedRecomp/patches/misc_patches.cpp +++ b/UnleashedRecomp/patches/misc_patches.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/UnleashedRecomp/patches/player_patches.cpp b/UnleashedRecomp/patches/player_patches.cpp index dfa1142d..d33887a6 100644 --- a/UnleashedRecomp/patches/player_patches.cpp +++ b/UnleashedRecomp/patches/player_patches.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -126,7 +126,7 @@ PPC_FUNC(sub_823B49D8) { __imp__sub_823B49D8(ctx, base); - SDL_User_EvilSonic(Window::s_pWindow, true); + SDL_User_EvilSonic(GameWindow::s_pWindow, true); } // SWA::Player::CEvilSonicContext::Dtor @@ -135,5 +135,5 @@ PPC_FUNC(sub_823B4590) { __imp__sub_823B4590(ctx, base); - SDL_User_EvilSonic(Window::s_pWindow, false); + SDL_User_EvilSonic(GameWindow::s_pWindow, false); } diff --git a/UnleashedRecomp/patches/video_patches.cpp b/UnleashedRecomp/patches/video_patches.cpp index 5e407feb..e0ff0e05 100644 --- a/UnleashedRecomp/patches/video_patches.cpp +++ b/UnleashedRecomp/patches/video_patches.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include // TODO: to be removed. constexpr float m_baseAspectRatio = 16.0f / 9.0f; @@ -12,7 +12,7 @@ void CSDAspectRatioMidAsmHook(PPCRegister& f1, PPCRegister& f2) if (Config::UIScaleMode == EUIScaleMode::Stretch) return; - auto newAspectRatio = (float)Window::s_width / (float)Window::s_height; + auto newAspectRatio = (float)GameWindow::s_width / (float)GameWindow::s_height; if (newAspectRatio > m_baseAspectRatio) { diff --git a/UnleashedRecomp/ui/window.cpp b/UnleashedRecomp/ui/game_window.cpp similarity index 72% rename from UnleashedRecomp/ui/window.cpp rename to UnleashedRecomp/ui/game_window.cpp index 57021448..25ee8d14 100644 --- a/UnleashedRecomp/ui/window.cpp +++ b/UnleashedRecomp/ui/game_window.cpp @@ -1,4 +1,4 @@ -#include "window.h" +#include "game_window.h" #include "sdl_listener.h" #include #include @@ -31,10 +31,10 @@ int Window_OnSDLEvent(void*, SDL_Event* event) if (!(event->key.keysym.mod & KMOD_ALT) || !m_isFullscreenKeyReleased) break; - Config::Fullscreen = Window::SetFullscreen(!Window::IsFullscreen()); + Config::Fullscreen = GameWindow::SetFullscreen(!GameWindow::IsFullscreen()); if (!Config::Fullscreen) - Config::WindowState = Window::SetMaximised(Config::WindowState == EWindowState::Maximised); + Config::WindowState = GameWindow::SetMaximised(Config::WindowState == EWindowState::Maximised); // Block holding ALT+ENTER spamming window changes. m_isFullscreenKeyReleased = false; @@ -44,17 +44,17 @@ int Window_OnSDLEvent(void*, SDL_Event* event) // Restore original window dimensions on F2. case SDLK_F2: - Config::Fullscreen = Window::SetFullscreen(false); - Window::SetDimensions(DEFAULT_WIDTH, DEFAULT_HEIGHT); + Config::Fullscreen = GameWindow::SetFullscreen(false); + GameWindow::SetDimensions(DEFAULT_WIDTH, DEFAULT_HEIGHT); break; // Recentre window on F3. case SDLK_F3: { - if (Window::IsFullscreen()) + if (GameWindow::IsFullscreen()) break; - Window::SetDimensions(Window::s_width, Window::s_height); + GameWindow::SetDimensions(GameWindow::s_width, GameWindow::s_height); break; } @@ -79,16 +79,16 @@ int Window_OnSDLEvent(void*, SDL_Event* event) switch (event->window.event) { case SDL_WINDOWEVENT_FOCUS_LOST: - Window::s_isFocused = false; + GameWindow::s_isFocused = false; SDL_ShowCursor(SDL_ENABLE); break; case SDL_WINDOWEVENT_FOCUS_GAINED: { - Window::s_isFocused = true; + GameWindow::s_isFocused = true; - if (Window::IsFullscreen()) - SDL_ShowCursor(Window::s_isFullscreenCursorVisible ? SDL_ENABLE : SDL_DISABLE); + if (GameWindow::IsFullscreen()) + SDL_ShowCursor(GameWindow::s_isFullscreenCursorVisible ? SDL_ENABLE : SDL_DISABLE); break; } @@ -103,14 +103,14 @@ int Window_OnSDLEvent(void*, SDL_Event* event) case SDL_WINDOWEVENT_RESIZED: m_isResizing = true; - Window::s_width = event->window.data1; - Window::s_height = event->window.data2; - Window::SetTitle(fmt::format("{} - [{}x{}]", Window::GetTitle(), Window::s_width, Window::s_height).c_str()); + GameWindow::s_width = event->window.data1; + GameWindow::s_height = event->window.data2; + GameWindow::SetTitle(fmt::format("{} - [{}x{}]", GameWindow::GetTitle(), GameWindow::s_width, GameWindow::s_height).c_str()); break; case SDL_WINDOWEVENT_MOVED: - Window::s_x = event->window.data1; - Window::s_y = event->window.data2; + GameWindow::s_x = event->window.data1; + GameWindow::s_y = event->window.data2; break; } @@ -119,13 +119,13 @@ int Window_OnSDLEvent(void*, SDL_Event* event) case SDL_USER_EVILSONIC: { - Window::s_isIconNight = event->user.code; - Window::SetIcon(Window::s_isIconNight); + GameWindow::s_isIconNight = event->user.code; + GameWindow::SetIcon(GameWindow::s_isIconNight); break; } } - if (!Window::IsFullscreen()) + if (!GameWindow::IsFullscreen()) { if (event->type == SDL_CONTROLLERBUTTONDOWN || event->type == SDL_CONTROLLERBUTTONUP || event->type == SDL_CONTROLLERAXISMOTION) { @@ -142,7 +142,7 @@ int Window_OnSDLEvent(void*, SDL_Event* event) return 0; } -void Window::Init() +void GameWindow::Init() { SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); @@ -194,14 +194,14 @@ void Window::Init() SDL_ShowWindow(s_pWindow); } -void Window::Update() +void GameWindow::Update() { - if (!Window::IsFullscreen() && !Window::IsMaximised()) + if (!GameWindow::IsFullscreen() && !GameWindow::IsMaximised()) { - Config::WindowX = Window::s_x; - Config::WindowY = Window::s_y; - Config::WindowWidth = Window::s_width; - Config::WindowHeight = Window::s_height; + Config::WindowX = GameWindow::s_x; + Config::WindowY = GameWindow::s_y; + Config::WindowWidth = GameWindow::s_width; + Config::WindowHeight = GameWindow::s_height; } if (m_isResizing) diff --git a/UnleashedRecomp/ui/window.h b/UnleashedRecomp/ui/game_window.h similarity index 98% rename from UnleashedRecomp/ui/window.h rename to UnleashedRecomp/ui/game_window.h index c7875c8c..5be28b01 100644 --- a/UnleashedRecomp/ui/window.h +++ b/UnleashedRecomp/ui/game_window.h @@ -15,7 +15,7 @@ #define DEFAULT_WIDTH 1280 #define DEFAULT_HEIGHT 720 -class Window +class GameWindow { public: static inline SDL_Window* s_pWindow; @@ -109,7 +109,7 @@ public: { SDL_SetWindowFullscreen(s_pWindow, 0); SDL_ShowCursor(SDL_ENABLE); - SetIcon(Window::s_isIconNight); + SetIcon(GameWindow::s_isIconNight); } return isEnabled; diff --git a/UnleashedRecomp/ui/installer_wizard.cpp b/UnleashedRecomp/ui/installer_wizard.cpp index c68cc51a..9e327840 100644 --- a/UnleashedRecomp/ui/installer_wizard.cpp +++ b/UnleashedRecomp/ui/installer_wizard.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include @@ -1439,18 +1439,18 @@ bool InstallerWizard::Run(bool skipGame) g_currentPage = g_firstPage; } - Window::SetFullscreenCursorVisibility(true); + GameWindow::SetFullscreenCursorVisibility(true); s_isVisible = true; while (s_isVisible) { SDL_PumpEvents(); SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); - Window::Update(); + GameWindow::Update(); Video::HostPresent(); } - Window::SetFullscreenCursorVisibility(false); + GameWindow::SetFullscreenCursorVisibility(false); NFD_Quit(); InstallerWizard::Shutdown(); diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index d9153783..88902f8c 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -1,7 +1,7 @@ #include "options_menu.h" #include "options_menu_thumbnails.h" #include "imgui_utils.h" -#include "window.h" +#include "game_window.h" #include "exports.h" #include @@ -971,8 +971,8 @@ static void DrawInfoPanel() auto resScale = round(*(float*)g_selectedItem->GetValue() * 1000) / 1000; std::snprintf(buf, sizeof(buf), desc.c_str(), - (int)((float)Window::s_width * resScale), - (int)((float)Window::s_height * resScale)); + (int)((float)GameWindow::s_width * resScale), + (int)((float)GameWindow::s_height * resScale)); desc = buf; } diff --git a/UnleashedRecomp/ui/window_events.h b/UnleashedRecomp/ui/window_events.h index 6e94e3a6..1f1acaa7 100644 --- a/UnleashedRecomp/ui/window_events.h +++ b/UnleashedRecomp/ui/window_events.h @@ -1,7 +1,7 @@ #pragma once #include -#include "ui/window.h" +#include "ui/game_window.h" #define SDL_USER_EVILSONIC (SDL_USEREVENT + 1)