Browse Source

engine: platform: sdl: slightly rework previous patch to not call SDL each frame and check for NULL pointers

master
Alibek Omarov 9 months ago
parent
commit
e95a2da6d0
  1. 4
      engine/client/vid_common.c
  2. 2
      engine/client/vid_common.h
  3. 23
      engine/platform/sdl/in_sdl.c

4
engine/client/vid_common.c

@ -20,8 +20,6 @@ GNU General Public License for more details.
#include "vid_common.h" #include "vid_common.h"
#include "platform/platform.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_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_rotate, "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "screen rotation (0-3)" );
static CVAR_DEFINE_AUTO( vid_scale, "1.0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "pixel scale" ); 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_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_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( 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_xpos, "_window_xpos", "-1", FCVAR_RENDERINFO, "window position by horizontal" );
CVAR_DEFINE( window_ypos, "_window_ypos", "-1", FCVAR_RENDERINFO, "window position by vertical" ); CVAR_DEFINE( window_ypos, "_window_ypos", "-1", FCVAR_RENDERINFO, "window position by vertical" );

2
engine/client/vid_common.h

@ -38,6 +38,8 @@ extern glwstate_t glw_state;
extern convar_t vid_fullscreen; extern convar_t vid_fullscreen;
extern convar_t vid_maximized; extern convar_t vid_maximized;
extern convar_t vid_highdpi; extern convar_t vid_highdpi;
extern convar_t window_width;
extern convar_t window_height;
extern convar_t window_xpos; extern convar_t window_xpos;
extern convar_t window_ypos; extern convar_t window_ypos;
extern convar_t gl_msaa_samples; extern convar_t gl_msaa_samples;

23
engine/platform/sdl/in_sdl.c

@ -43,18 +43,19 @@ Platform_GetMousePos
*/ */
void GAME_EXPORT Platform_GetMousePos( int *x, int *y ) 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 ); 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;
}
} }
/* /*

Loading…
Cancel
Save