From e95a2da6d04aabb6cb4a74d59d9a1043bde7a686 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 23 Feb 2024 20:54:26 +0300 Subject: [PATCH] engine: platform: sdl: slightly rework previous patch to not call SDL each frame and check for NULL pointers --- engine/client/vid_common.c | 4 ++-- engine/client/vid_common.h | 2 ++ engine/platform/sdl/in_sdl.c | 23 ++++++++++++----------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/engine/client/vid_common.c b/engine/client/vid_common.c index fcc29b92..c5c8ea22 100644 --- a/engine/client/vid_common.c +++ b/engine/client/vid_common.c @@ -20,8 +20,6 @@ GNU General Public License for more details. #include "vid_common.h" #include "platform/platform.h" -static CVAR_DEFINE( window_width, "width", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen width" ); -static CVAR_DEFINE( window_height, "height", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen height" ); static CVAR_DEFINE_AUTO( vid_mode, "0", FCVAR_RENDERINFO, "current video mode index (used only for storage)" ); static CVAR_DEFINE_AUTO( vid_rotate, "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen rotation (0-3)" ); static CVAR_DEFINE_AUTO( vid_scale, "1.0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "pixel scale" ); @@ -29,6 +27,8 @@ static CVAR_DEFINE_AUTO( vid_scale, "1.0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "p CVAR_DEFINE_AUTO( vid_highdpi, "1", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable High-DPI mode" ); CVAR_DEFINE_AUTO( vid_maximized, "0", FCVAR_RENDERINFO, "window maximized state, read-only" ); CVAR_DEFINE( vid_fullscreen, "fullscreen", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "fullscreen state (0 windowed, 1 fullscreen, 2 borderless)" ); +CVAR_DEFINE( window_width, "width", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen width" ); +CVAR_DEFINE( window_height, "height", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen height" ); CVAR_DEFINE( window_xpos, "_window_xpos", "-1", FCVAR_RENDERINFO, "window position by horizontal" ); CVAR_DEFINE( window_ypos, "_window_ypos", "-1", FCVAR_RENDERINFO, "window position by vertical" ); diff --git a/engine/client/vid_common.h b/engine/client/vid_common.h index fc0bc08e..8b9d0d3f 100644 --- a/engine/client/vid_common.h +++ b/engine/client/vid_common.h @@ -38,6 +38,8 @@ extern glwstate_t glw_state; extern convar_t vid_fullscreen; extern convar_t vid_maximized; extern convar_t vid_highdpi; +extern convar_t window_width; +extern convar_t window_height; extern convar_t window_xpos; extern convar_t window_ypos; extern convar_t gl_msaa_samples; diff --git a/engine/platform/sdl/in_sdl.c b/engine/platform/sdl/in_sdl.c index 7231a626..9301d267 100644 --- a/engine/platform/sdl/in_sdl.c +++ b/engine/platform/sdl/in_sdl.c @@ -43,18 +43,19 @@ Platform_GetMousePos */ void GAME_EXPORT Platform_GetMousePos( int *x, int *y ) { - float factorX; - float factorY; - { - int w1, w2, h1, h2; - SDL_GL_GetDrawableSize( host.hWnd, &w1, &h1 ); - SDL_GetWindowSize( host.hWnd, &w2, &h2 ); - factorX = (float)w1 / w2; - factorY = (float)h1 / h2; - } SDL_GetMouseState( x, y ); - *x = *x * factorX; - *y = *y * factorY; + + if( x && window_width.value && window_width.value != refState.width ) + { + float factor = refState.width / window_width.value; + *x = *x * factor; + } + + if( y && window_height.value && window_height.value != refState.height ) + { + float factor = refState.height / window_height.value; + *y = *y * factor; + } } /*