Do not default to Wayland, add CLI option for choosing SDL video driver. (#61)

This commit is contained in:
Darío 2024-12-22 18:07:27 -03:00 committed by GitHub
parent d6444da62f
commit 02022c3a1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 19 deletions

View file

@ -1311,7 +1311,7 @@ static void CreateImGuiBackend()
static void BeginCommandList(); static void BeginCommandList();
void Video::CreateHostDevice(bool sdlVideoDefault) void Video::CreateHostDevice(const char *sdlVideoDriver)
{ {
for (uint32_t i = 0; i < 16; i++) for (uint32_t i = 0; i < 16; i++)
g_inputSlots[i].index = i; g_inputSlots[i].index = i;
@ -1320,7 +1320,7 @@ void Video::CreateHostDevice(bool sdlVideoDefault)
ImGui::CreateContext(); ImGui::CreateContext();
ImPlot::CreateContext(); ImPlot::CreateContext();
GameWindow::Init(sdlVideoDefault); GameWindow::Init(sdlVideoDriver);
#ifdef SWA_D3D12 #ifdef SWA_D3D12
g_vulkan = DetectWine() || Config::GraphicsAPI == EGraphicsAPI::Vulkan; g_vulkan = DetectWine() || Config::GraphicsAPI == EGraphicsAPI::Vulkan;

View file

@ -14,7 +14,7 @@ using namespace plume;
struct Video struct Video
{ {
static void CreateHostDevice(bool sdlVideoDefault); static void CreateHostDevice(const char *sdlVideoDriver);
static void HostPresent(); static void HostPresent();
static void StartPipelinePrecompilation(); static void StartPipelinePrecompilation();
static void WaitForGPU(); static void WaitForGPU();

View file

@ -145,12 +145,18 @@ int main(int argc, char *argv[])
bool forceInstaller = false; bool forceInstaller = false;
bool forceDLCInstaller = false; bool forceDLCInstaller = false;
bool sdlVideoDefault = false; const char *sdlVideoDriver = nullptr;
for (uint32_t i = 1; i < argc; i++) for (uint32_t i = 1; i < argc; i++)
{ {
forceInstaller = forceInstaller || (strcmp(argv[i], "--install") == 0); forceInstaller = forceInstaller || (strcmp(argv[i], "--install") == 0);
forceDLCInstaller = forceDLCInstaller || (strcmp(argv[i], "--install-dlc") == 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(); Config::Load();
@ -161,7 +167,7 @@ int main(int argc, char *argv[])
bool runInstallerWizard = forceInstaller || forceDLCInstaller || !isGameInstalled; bool runInstallerWizard = forceInstaller || forceDLCInstaller || !isGameInstalled;
if (runInstallerWizard) if (runInstallerWizard)
{ {
Video::CreateHostDevice(sdlVideoDefault); Video::CreateHostDevice(sdlVideoDriver);
if (!InstallerWizard::Run(GAME_INSTALL_DIRECTORY, isGameInstalled && forceDLCInstaller)) 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))); uint32_t entry = LdrLoadModule(std::u8string_view((const char8_t*)(modulePath)));
if (!runInstallerWizard) if (!runInstallerWizard)
Video::CreateHostDevice(sdlVideoDefault); Video::CreateHostDevice(sdlVideoDriver);
Video::StartPipelinePrecompilation(); Video::StartPipelinePrecompilation();

View file

@ -147,23 +147,18 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
return 0; return 0;
} }
void GameWindow::Init(bool sdlVideoDefault) void GameWindow::Init(const char *sdlVideoDriver)
{ {
#ifdef __linux__ #ifdef __linux__
SDL_SetHint("SDL_APP_ID", "io.github.hedge_dev.unleashedrecomp"); 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 #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); SDL_VideoInit(nullptr);
}
const char* videoDriverName = SDL_GetCurrentVideoDriver(); const char* videoDriverName = SDL_GetCurrentVideoDriver();
if (videoDriverName != nullptr) if (videoDriverName != nullptr)

View file

@ -303,6 +303,6 @@ public:
return false; return false;
} }
static void Init(bool sdlVideoDefault); static void Init(const char *sdlVideoDriver);
static void Update(); static void Update();
}; };