From f9621dcc174030ed798ea40d999943b3ac0fa169 Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Tue, 16 Aug 2022 23:04:49 -0400 Subject: [PATCH] Cleans up Window class. --- libultraship/libultraship/CMakeLists.txt | 2 - libultraship/libultraship/Window.cpp | 79 +++++++++++++++++++----- libultraship/libultraship/Window.h | 10 +-- libultraship/libultraship/WindowShim.cpp | 67 -------------------- libultraship/libultraship/WindowShim.h | 1 - soh/soh/OTRGlobals.cpp | 14 +---- 6 files changed, 70 insertions(+), 103 deletions(-) delete mode 100644 libultraship/libultraship/WindowShim.cpp delete mode 100644 libultraship/libultraship/WindowShim.h diff --git a/libultraship/libultraship/CMakeLists.txt b/libultraship/libultraship/CMakeLists.txt index 3d7063bfd..49c6ff9b4 100644 --- a/libultraship/libultraship/CMakeLists.txt +++ b/libultraship/libultraship/CMakeLists.txt @@ -138,8 +138,6 @@ set(Source_Files__Globals "LUSMacros.h" "Window.cpp" "Window.h" - "WindowShim.cpp" - "WindowShim.h" ) source_group("Source Files\\Globals" FILES ${Source_Files__Globals}) diff --git a/libultraship/libultraship/Window.cpp b/libultraship/libultraship/Window.cpp index f32ef02bf..7a543d1d8 100644 --- a/libultraship/libultraship/Window.cpp +++ b/libultraship/libultraship/Window.cpp @@ -12,14 +12,23 @@ #include "AudioPlayer.h" #include "Hooks.h" #include "UltraController.h" -#include "Lib/Fast3D/gfx_pc.h" -#include "Lib/Fast3D/gfx_sdl.h" -#include "Lib/Fast3D/gfx_opengl.h" #include #include #include #include "Console.h" #include "ImGuiImpl.h" +#include "PR/ultra64/gbi.h" +#include "Lib/Fast3D/gfx_pc.h" +#include "Lib/Fast3D/gfx_sdl.h" +#include "Lib/Fast3D/gfx_dxgi.h" +#include "Lib/Fast3D/gfx_glx.h" +#include "Lib/Fast3D/gfx_opengl.h" +#include "Lib/Fast3D/gfx_direct3d11.h" +#include "Lib/Fast3D/gfx_direct3d12.h" +#include "Lib/Fast3D/gfx_wiiu.h" +#include "Lib/Fast3D/gfx_gx2.h" +#include "Lib/Fast3D/gfx_window_manager_api.h" +#include #include @@ -206,13 +215,8 @@ extern "C" { } } -extern GfxWindowManagerAPI gfx_sdl; -void SetWindowManager(GfxWindowManagerAPI** WmApi, GfxRenderingAPI** RenderingApi, const std::string& gfx_backend); - namespace Ship { - int32_t Window::lastScancode; - Window::Window(std::shared_ptr Context) : Context(Context), APlayer(nullptr), ControllerApi(nullptr) { WmApi = nullptr; RenderingApi = nullptr; @@ -265,8 +269,8 @@ namespace Ship { } dwMenubar = pConf->getBool("Window.Options", false); - const std::string& gfx_backend = pConf->getString("Window.GfxBackend"); - SetWindowManager(&WmApi, &RenderingApi, gfx_backend); + gfxBackend = pConf->getString("Window.GfxBackend"); + InitializeWindowManager(); gfx_init(WmApi, RenderingApi, GetContext()->GetName().c_str(), bIsFullscreen, dwWidth, dwHeight); WmApi->set_fullscreen_changed_callback(OnFullscreenChanged); @@ -332,12 +336,7 @@ namespace Ship { GlobalCtx2::GetInstance()->GetWindow()->ToggleFullscreen(); } - // OTRTODO: Rig with Kirito's console? - //if (dwScancode == Ship::stoi(Conf["KEYBOARD SHORTCUTS"]["KEY_CONSOLE"])) { - // ToggleConsole(); - //} - - lastScancode = -1; + GlobalCtx2::GetInstance()->GetWindow()->SetLastScancode(-1); bool bIsProcessed = false; auto controlDeck = GlobalCtx2::GetInstance()->GetWindow()->GetControlDeck(); @@ -361,7 +360,7 @@ namespace Ship { } } - lastScancode = dwScancode; + GlobalCtx2::GetInstance()->GetWindow()->SetLastScancode(dwScancode); return bIsProcessed; } @@ -405,6 +404,52 @@ namespace Ship { #endif } + void Window::InitializeWindowManager() { + // First set default +#ifdef ENABLE_OPENGL + RenderingApi = &gfx_opengl_api; +#if defined(__linux__) && defined(X11_SUPPORTED) + // LINUX_TODO: + // *WmApi = &gfx_glx; + WmApi = &gfx_sdl; +#else + WmApi = &gfx_sdl; +#endif +#endif +#ifdef ENABLE_DX12 + RenderingApi = &gfx_direct3d12_api; + WmApi = &gfx_dxgi_api; +#endif +#ifdef ENABLE_DX11 + RenderingApi = &gfx_direct3d11_api; + WmApi = &gfx_dxgi_api; +#endif +#ifdef __WIIU__ + RenderingApi = &gfx_gx2_api; + WmApi = &gfx_wiiu; +#endif + + // Config can override +#ifdef ENABLE_DX11 + if (gfxBackend == "dx11") { + RenderingApi = &gfx_direct3d11_api; + WmApi = &gfx_dxgi_api; + } +#endif +#ifdef ENABLE_OPENGL + if (gfxBackend == "sdl") { + RenderingApi = &gfx_opengl_api; + WmApi = &gfx_sdl; + } +#if defined(__linux__) && defined(X11_SUPPORTED) + if (gfxBackend == "glx") { + RenderingApi = &gfx_opengl_api; + WmApi = &gfx_glx; + } +#endif +#endif + } + void Window::InitializeControlDeck() { ControllerApi = std::make_shared(); } diff --git a/libultraship/libultraship/Window.h b/libultraship/libultraship/Window.h index 52737dd37..54488f4c9 100644 --- a/libultraship/libultraship/Window.h +++ b/libultraship/libultraship/Window.h @@ -2,11 +2,9 @@ #include #include "PR/ultra64/gbi.h" #include "Lib/Fast3D/gfx_pc.h" -#include "UltraController.h" #include "Controller.h" #include "GlobalCtx2.h" #include "ControlDeck.h" -#include #include "Lib/Fast3D/gfx_window_manager_api.h" @@ -15,8 +13,6 @@ namespace Ship { class Window { public: - static int32_t lastScancode; - Window(std::shared_ptr Context); ~Window(); void CreateDefaults(); @@ -40,6 +36,8 @@ namespace Ship { std::shared_ptr GetContext() { return Context.lock(); } std::shared_ptr GetAudioPlayer() { return APlayer; } const char* GetKeyName(int scancode) { return WmApi->get_key_name(scancode); } + int32_t GetLastScancode() { return lastScancode; }; + void SetLastScancode(int32_t scanCode) { lastScancode = scanCode; }; protected: private: @@ -47,12 +45,15 @@ namespace Ship { static bool KeyUp(int32_t dwScancode); static void AllKeysUp(void); static void OnFullscreenChanged(bool bIsNowFullscreen); + void InitializeControlDeck(); void InitializeAudioPlayer(); + void InitializeWindowManager(); std::weak_ptr Context; std::shared_ptr APlayer; std::shared_ptr ControllerApi; + std::string gfxBackend; GfxRenderingAPI* RenderingApi; GfxWindowManagerAPI* WmApi; @@ -60,5 +61,6 @@ namespace Ship { uint32_t dwWidth; uint32_t dwHeight; uint32_t dwMenubar; + int32_t lastScancode; }; } diff --git a/libultraship/libultraship/WindowShim.cpp b/libultraship/libultraship/WindowShim.cpp deleted file mode 100644 index c892566ab..000000000 --- a/libultraship/libultraship/WindowShim.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "PR/ultra64/gbi.h" -#include "Lib/Fast3D/gfx_pc.h" -#include "Lib/Fast3D/gfx_sdl.h" -#include "Lib/Fast3D/gfx_dxgi.h" -#include "Lib/Fast3D/gfx_glx.h" -#include "Lib/Fast3D/gfx_opengl.h" -#include "Lib/Fast3D/gfx_direct3d11.h" -#include "Lib/Fast3D/gfx_direct3d12.h" -#include "Lib/Fast3D/gfx_wiiu.h" -#include "Lib/Fast3D/gfx_gx2.h" -#include "Lib/Fast3D/gfx_window_manager_api.h" - -#include - -/* - * Begin shims for gfx_pc.cpp. Eventually, a file from SOH repo should be moved in here. - */ - -/* - * End empty shims - */ - -void SetWindowManager(struct GfxWindowManagerAPI** WmApi, struct GfxRenderingAPI** RenderingApi, const std::string& gfx_backend) { - // First set default -#ifdef ENABLE_OPENGL - *RenderingApi = &gfx_opengl_api; - #if defined(__linux__) && defined(X11_SUPPORTED) - // LINUX_TODO: - // *WmApi = &gfx_glx; - *WmApi = &gfx_sdl; - #else - *WmApi = &gfx_sdl; - #endif -#endif -#ifdef ENABLE_DX12 - *RenderingApi = &gfx_direct3d12_api; - *WmApi = &gfx_dxgi_api; -#endif -#ifdef ENABLE_DX11 - *RenderingApi = &gfx_direct3d11_api; - *WmApi = &gfx_dxgi_api; -#endif -#ifdef __WIIU__ - *RenderingApi = &gfx_gx2_api; - *WmApi = &gfx_wiiu; -#endif - - // Config can override -#ifdef ENABLE_DX11 - if (gfx_backend == "dx11") { - *RenderingApi = &gfx_direct3d11_api; - *WmApi = &gfx_dxgi_api; - } -#endif -#ifdef ENABLE_OPENGL - if (gfx_backend == "sdl") { - *RenderingApi = &gfx_opengl_api; - *WmApi = &gfx_sdl; - } -#if defined(__linux__) && defined(X11_SUPPORTED) - if (gfx_backend == "glx") { - *RenderingApi = &gfx_opengl_api; - *WmApi = &gfx_glx; - } -#endif -#endif -} \ No newline at end of file diff --git a/libultraship/libultraship/WindowShim.h b/libultraship/libultraship/WindowShim.h deleted file mode 100644 index 6f70f09be..000000000 --- a/libultraship/libultraship/WindowShim.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index d42116de2..db12b8e2c 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -243,8 +243,8 @@ extern "C" void Graph_ProcessFrame(void (*run_one_game_iter)(void)) { extern "C" void Graph_StartFrame() { #ifndef __WIIU__ // Why -1? - int32_t dwScancode = OTRGlobals::Instance->context->GetWindow()->lastScancode; - OTRGlobals::Instance->context->GetWindow()->lastScancode = -1; + int32_t dwScancode = OTRGlobals::Instance->context->GetWindow()->GetLastScancode(); + OTRGlobals::Instance->context->GetWindow()->SetLastScancode(-1); switch (dwScancode - 1) { case SDL_SCANCODE_F5: { @@ -374,16 +374,6 @@ extern "C" uint16_t OTRGetPixelDepth(float x, float y) { return OTRGlobals::Instance->context->GetWindow()->GetPixelDepth(x, y); } -extern "C" int32_t OTRGetLastScancode() -{ - return OTRGlobals::Instance->context->GetWindow()->lastScancode; -} - -extern "C" void OTRResetScancode() -{ - OTRGlobals::Instance->context->GetWindow()->lastScancode = -1; -} - extern "C" uint32_t ResourceMgr_GetGameVersion() { return OTRGlobals::Instance->context->GetResourceManager()->GetGameVersion();