From 6b7c8f1a28ee76ad7d9c12a2242e48b5e69a8d67 Mon Sep 17 00:00:00 2001 From: Peakies Date: Mon, 5 Feb 2024 20:58:22 +0330 Subject: [PATCH] fix switch screen and blackscreen on opengl + window borderless --- src/engine/client.h | 2 +- src/engine/client/client.cpp | 42 ++++++++++++++----- src/engine/client/client.h | 2 +- src/engine/shared/config_variables.h | 1 + src/game/client/components/menus_settings.cpp | 4 +- .../engine/shared/rust_version.cpp | 7 ++++ 6 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/engine/client.h b/src/engine/client.h index ab4c28920..6e08b7492 100644 --- a/src/engine/client.h +++ b/src/engine/client.h @@ -173,7 +173,7 @@ public: virtual void ServerBrowserUpdate() = 0; // gfx - virtual void SwitchWindowScreen(int Index) = 0; + virtual void SwitchWindowScreen(int Index, int WindowMode = -1) = 0; virtual void SetWindowParams(int FullscreenMode, bool IsBorderless) = 0; virtual void ToggleWindowVSync() = 0; virtual void Notify(const char *pTitle, const char *pMessage) = 0; diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index cdd8d90db..bd1354601 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -3880,21 +3880,41 @@ int CClient::HandleChecksum(int Conn, CUuid Uuid, CUnpacker *pUnpacker) return 0; } -void CClient::SwitchWindowScreen(int Index) +void CClient::SwitchWindowScreen(int Index, int WindowMode) { - // Todo SDL: remove this when fixed (changing screen when in fullscreen is bugged) - if(g_Config.m_GfxFullscreen) + SetWindowParams(0, false); + if(Graphics()->SetWindowScreen(Index)) { - SetWindowParams(0, g_Config.m_GfxBorderless); - if(Graphics()->SetWindowScreen(Index)) - g_Config.m_GfxScreen = Index; - SetWindowParams(g_Config.m_GfxFullscreen, g_Config.m_GfxBorderless); + g_Config.m_GfxScreen = Index; } - else + static const int MAX_RESOLUTIONS = 256; + static CVideoMode s_aModes[MAX_RESOLUTIONS]; + static int s_NumNodes = Graphics()->GetVideoModes(s_aModes, MAX_RESOLUTIONS, g_Config.m_GfxScreen); + for(int i = 0; i < s_NumNodes; ++i) { - if(Graphics()->SetWindowScreen(Index)) - g_Config.m_GfxScreen = Index; + SetWindowParams(3, false); + if(s_aModes[i].m_WindowWidth == g_Config.m_GfxDesktopWidth && s_aModes[i].m_WindowHeight == g_Config.m_GfxDesktopHeight) + { + const int Depth = s_aModes[i].m_Red + s_aModes[i].m_Green + s_aModes[i].m_Blue > 16 ? 24 : 16; + g_Config.m_GfxColorDepth = Depth; + g_Config.m_GfxScreenWidth = s_aModes[i].m_WindowWidth; + g_Config.m_GfxScreenHeight = s_aModes[i].m_WindowHeight; + g_Config.m_GfxScreenRefreshRate = s_aModes[i].m_RefreshRate; + Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxScreenRefreshRate); + break; + } } + + if(WindowMode == 0) + SetWindowParams(0, false); + else if(WindowMode == 1) + SetWindowParams(0, true); + else if(WindowMode == 2) + SetWindowParams(3, false); + else if(WindowMode == 3) + SetWindowParams(2, false); + else if(WindowMode == 4) + SetWindowParams(1, false); } void CClient::ConchainWindowScreen(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData) @@ -3903,7 +3923,7 @@ void CClient::ConchainWindowScreen(IConsole::IResult *pResult, void *pUserData, if(pSelf->Graphics() && pResult->NumArguments()) { if(g_Config.m_GfxScreen != pResult->GetInteger(0)) - pSelf->SwitchWindowScreen(pResult->GetInteger(0)); + pSelf->SwitchWindowScreen(pResult->GetInteger(0), g_Config.m_GfxWindowMode); } else pfnCallback(pResult, pCallbackUserData); diff --git a/src/engine/client/client.h b/src/engine/client/client.h index e392f55c3..c15aacacb 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -457,7 +457,7 @@ public: virtual int HandleChecksum(int Conn, CUuid Uuid, CUnpacker *pUnpacker); // gfx - void SwitchWindowScreen(int Index) override; + void SwitchWindowScreen(int Index, int WindowMode = -1) override; void SetWindowParams(int FullscreenMode, bool IsBorderless) override; void ToggleWindowVSync() override; void Notify(const char *pTitle, const char *pMessage) override; diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 79b5c1deb..90586f8c0 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -318,6 +318,7 @@ MACRO_CONFIG_INT(SndServerMessage, snd_servermessage, 1, 0, 1, CFGFLAG_SAVE | CF MACRO_CONFIG_INT(SndHighlight, snd_highlight, 1, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Enable highlighted chat sound") MACRO_CONFIG_INT(GfxScreen, gfx_screen, 0, 0, 15, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Screen index") +MACRO_CONFIG_INT(GfxWindowMode, gfx_window_mode, 0, 0, 5, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Screen window mode") MACRO_CONFIG_INT(GfxScreenWidth, gfx_screen_width, 0, 0, 0, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Screen resolution width") MACRO_CONFIG_INT(GfxScreenHeight, gfx_screen_height, 0, 0, 0, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Screen resolution height") MACRO_CONFIG_INT(GfxScreenRefreshRate, gfx_screen_refresh_rate, 0, 0, 0, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Screen refresh rate") diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 3d48f34ed..35e1ff42e 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -1551,6 +1551,8 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) Client()->SetWindowParams(2, false); else if(NewWindowMode == 4) Client()->SetWindowParams(1, false); + + g_Config.m_GfxWindowMode = NewWindowMode; } if(Graphics()->GetNumScreens() > 1) @@ -1578,7 +1580,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) const int NewScreen = UI()->DoDropDown(&ScreenDropDown, g_Config.m_GfxScreen, s_vpScreenNames.data(), s_vpScreenNames.size(), s_ScreenDropDownState); if(NewScreen != g_Config.m_GfxScreen) { - Client()->SwitchWindowScreen(NewScreen); + Client()->SwitchWindowScreen(NewScreen, g_Config.m_GfxWindowMode); s_NumNodes = Graphics()->GetVideoModes(s_aModes, MAX_RESOLUTIONS, g_Config.m_GfxScreen); } } diff --git a/src/rust-bridge/engine/shared/rust_version.cpp b/src/rust-bridge/engine/shared/rust_version.cpp index dbd568568..d0e6ae502 100644 --- a/src/rust-bridge/engine/shared/rust_version.cpp +++ b/src/rust-bridge/engine/shared/rust_version.cpp @@ -14,3 +14,10 @@ void RustVersionPrint(const ::IConsole &console) noexcept { void RustVersionRegister(::IConsole &console) noexcept { cxxbridge1$RustVersionRegister(console); } +void cxxbridge1$RustVersionPrint(const ::IConsole &console) noexcept +{ +} + +void cxxbridge1$RustVersionRegister(::IConsole &console) noexcept +{ +}