From 02022c3a1d8257d61f17e4c0c3612effc7012f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo?= Date: Sun, 22 Dec 2024 18:07:27 -0300 Subject: [PATCH] Do not default to Wayland, add CLI option for choosing SDL video driver. (#61) --- UnleashedRecomp/gpu/video.cpp | 4 ++-- UnleashedRecomp/gpu/video.h | 2 +- UnleashedRecomp/main.cpp | 14 ++++++++++---- UnleashedRecomp/ui/game_window.cpp | 17 ++++++----------- UnleashedRecomp/ui/game_window.h | 2 +- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index 376d10c..69a5d99 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -1311,7 +1311,7 @@ static void CreateImGuiBackend() static void BeginCommandList(); -void Video::CreateHostDevice(bool sdlVideoDefault) +void Video::CreateHostDevice(const char *sdlVideoDriver) { for (uint32_t i = 0; i < 16; i++) g_inputSlots[i].index = i; @@ -1320,7 +1320,7 @@ void Video::CreateHostDevice(bool sdlVideoDefault) ImGui::CreateContext(); ImPlot::CreateContext(); - GameWindow::Init(sdlVideoDefault); + GameWindow::Init(sdlVideoDriver); #ifdef SWA_D3D12 g_vulkan = DetectWine() || Config::GraphicsAPI == EGraphicsAPI::Vulkan; diff --git a/UnleashedRecomp/gpu/video.h b/UnleashedRecomp/gpu/video.h index 9270cf4..8718a09 100644 --- a/UnleashedRecomp/gpu/video.h +++ b/UnleashedRecomp/gpu/video.h @@ -14,7 +14,7 @@ using namespace plume; struct Video { - static void CreateHostDevice(bool sdlVideoDefault); + static void CreateHostDevice(const char *sdlVideoDriver); static void HostPresent(); static void StartPipelinePrecompilation(); static void WaitForGPU(); diff --git a/UnleashedRecomp/main.cpp b/UnleashedRecomp/main.cpp index b5ab376..bc23967 100644 --- a/UnleashedRecomp/main.cpp +++ b/UnleashedRecomp/main.cpp @@ -145,12 +145,18 @@ int main(int argc, char *argv[]) bool forceInstaller = false; bool forceDLCInstaller = false; - bool sdlVideoDefault = false; + const char *sdlVideoDriver = nullptr; for (uint32_t i = 1; i < argc; i++) { forceInstaller = forceInstaller || (strcmp(argv[i], "--install") == 0); forceDLCInstaller = forceDLCInstaller || (strcmp(argv[i], "--install-dlc") == 0); - sdlVideoDefault = sdlVideoDefault || (strcmp(argv[i], "--sdl-video-default") == 0); + if (strcmp(argv[i], "--sdl-video-driver") == 0) + { + if ((i + 1) < argc) + sdlVideoDriver = argv[++i]; + else + fmt::println("No argument was specified for --sdl-video-driver. Option was ignored."); + } } Config::Load(); @@ -161,7 +167,7 @@ int main(int argc, char *argv[]) bool runInstallerWizard = forceInstaller || forceDLCInstaller || !isGameInstalled; if (runInstallerWizard) { - Video::CreateHostDevice(sdlVideoDefault); + Video::CreateHostDevice(sdlVideoDriver); if (!InstallerWizard::Run(GAME_INSTALL_DIRECTORY, isGameInstalled && forceDLCInstaller)) { @@ -177,7 +183,7 @@ int main(int argc, char *argv[]) uint32_t entry = LdrLoadModule(std::u8string_view((const char8_t*)(modulePath))); if (!runInstallerWizard) - Video::CreateHostDevice(sdlVideoDefault); + Video::CreateHostDevice(sdlVideoDriver); Video::StartPipelinePrecompilation(); diff --git a/UnleashedRecomp/ui/game_window.cpp b/UnleashedRecomp/ui/game_window.cpp index 9b6655e..899640e 100644 --- a/UnleashedRecomp/ui/game_window.cpp +++ b/UnleashedRecomp/ui/game_window.cpp @@ -147,23 +147,18 @@ int Window_OnSDLEvent(void*, SDL_Event* event) return 0; } -void GameWindow::Init(bool sdlVideoDefault) +void GameWindow::Init(const char *sdlVideoDriver) { #ifdef __linux__ SDL_SetHint("SDL_APP_ID", "io.github.hedge_dev.unleashedrecomp"); - - if (!sdlVideoDefault) - { - int videoRes = SDL_VideoInit("wayland"); - if (videoRes != 0) - sdlVideoDefault = true; - } -#else - sdlVideoDefault = true; #endif - if (sdlVideoDefault) + int videoRes = SDL_VideoInit(sdlVideoDriver); + if (videoRes != 0 && sdlVideoDriver != nullptr) + { + fmt::println("Failed to initialize the specified SDL Video Driver {}. Falling back to default.", sdlVideoDriver); SDL_VideoInit(nullptr); + } const char* videoDriverName = SDL_GetCurrentVideoDriver(); if (videoDriverName != nullptr) diff --git a/UnleashedRecomp/ui/game_window.h b/UnleashedRecomp/ui/game_window.h index 82ad144..180c558 100644 --- a/UnleashedRecomp/ui/game_window.h +++ b/UnleashedRecomp/ui/game_window.h @@ -303,6 +303,6 @@ public: return false; } - static void Init(bool sdlVideoDefault); + static void Init(const char *sdlVideoDriver); static void Update(); };