From cdde3cca3897cf8102e304217478edbda6af2f66 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Sat, 11 Nov 2023 09:56:03 -0600 Subject: [PATCH] Add handler for vid_wait Allows vid_wait to toggle without changing modes --- src/cvars.cpp | 9 ++++++++- src/sdl/i_video.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/cvars.cpp b/src/cvars.cpp index 4b0897dcf..aa2a52db4 100644 --- a/src/cvars.cpp +++ b/src/cvars.cpp @@ -460,7 +460,14 @@ consvar_t cv_usemouse = Player("use_mouse", "Off").values({{0, "Off"}, {1, "On"} consvar_t cv_vhseffect = Player("vhspause", "On").on_off(); // synchronize page flipping with screen refresh -consvar_t cv_vidwait = GraphicsDriver("vid_wait", "Off").on_off(); +extern "C++" +{ +namespace srb2::cvarhandler +{ +void on_set_vid_wait(); +} +} +consvar_t cv_vidwait = GraphicsDriver("vid_wait", "Off").on_off().onchange(srb2::cvarhandler::on_set_vid_wait); // if true, all sounds are loaded at game startup consvar_t precachesound = Player("precachesound", "Off").on_off(); diff --git a/src/sdl/i_video.cpp b/src/sdl/i_video.cpp index 88dd01eff..c2d42f009 100644 --- a/src/sdl/i_video.cpp +++ b/src/sdl/i_video.cpp @@ -1810,3 +1810,38 @@ UINT32 I_GetRefreshRate(void) // trouble querying mode over and over again. return refresh_rate; } + +namespace srb2::cvarhandler +{ +void on_set_vid_wait(); +} + +void srb2::cvarhandler::on_set_vid_wait() +{ + int interval = 0; + if (cv_vidwait.value > 0) + { + interval = 1; + } + + switch (rendermode) + { + case render_soft: + if (sdlglcontext == nullptr || SDL_GL_GetCurrentContext() != sdlglcontext) + { + return; + } + SDL_GL_SetSwapInterval(interval); + break; +#ifdef HWRENDER + case render_opengl: + if (g_legacy_gl_context == nullptr || SDL_GL_GetCurrentContext() != g_legacy_gl_context) + { + return; + } + SDL_GL_SetSwapInterval(interval); +#endif + default: + break; + } +}