From 96e0167e479c78f4d644d8c0913cc266adc2c6c7 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 22 Oct 2018 01:09:43 +0300 Subject: [PATCH] platform: add GetMousePos, SetMousePos calls, fix typo --- engine/client/cl_game.c | 39 ++++------------------------------ engine/client/in_touch.c | 2 +- engine/client/input.c | 18 ++++++---------- engine/client/vgui/vgui_draw.c | 2 +- engine/platform/platform.h | 3 +++ engine/platform/sdl/events.c | 2 +- engine/platform/sdl/in_sdl.c | 22 +++++++++++++++++++ 7 files changed, 38 insertions(+), 50 deletions(-) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index 500aab82..abf3b487 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -29,9 +29,7 @@ GNU General Public License for more details. #include "library.h" #include "vgui_draw.h" #include "sound.h" // SND_STOP_LOOPING -#ifdef XASH_SDL -#include -#endif +#include "platform/platform.h" #define MAX_LINELENGTH 80 #define MAX_TEXTCHANNELS 8 // must be power of two (GoldSrc uses 4 channels) @@ -2021,22 +2019,6 @@ static float pfnGetClientMaxspeed( void ) return cl.local.maxspeed; } -/* -============= -CL_GetMousePosition - -============= -*/ -void CL_GetMousePosition( int *mx, int *my ) -{ -#ifdef XASH_SDL - SDL_GetMouseState( mx, my ); -#else - if( mx ) *mx = 0; - if( my ) *my = 0; -#endif -} - /* ============= pfnIsNoClipping @@ -2747,20 +2729,7 @@ void pfnGetMousePos( struct tagPOINT *ppt ) if( !ppt ) return; - CL_GetMousePosition( &ppt->x, &ppt->y ); -} - -/* -============= -pfnSetMousePos - -============= -*/ -void pfnSetMousePos( int mx, int my ) -{ -#ifdef XASH_SDL - SDL_WarpMouseInWindow( host.hWnd, mx, my ); -#endif + Platform_GetMousePos( &ppt->x, &ppt->y ); } /* @@ -4002,7 +3971,7 @@ static cl_enginefunc_t gEngfuncs = pfnGetClientMaxspeed, COM_CheckParm, Key_Event, - CL_GetMousePosition, + Platform_GetMousePos, pfnIsNoClipping, CL_GetLocalPlayer, pfnGetViewModel, @@ -4052,7 +4021,7 @@ static cl_enginefunc_t gEngfuncs = pfnGetPlayerForTrackerID, pfnServerCmdUnreliable, pfnGetMousePos, - pfnSetMousePos, + Platform_SetMousePos, pfnSetMouseEnable, Cvar_GetList, (void*)Cmd_GetFirstFunctionHandle, diff --git a/engine/client/in_touch.c b/engine/client/in_touch.c index 74f36120..4c219a63 100644 --- a/engine/client/in_touch.c +++ b/engine/client/in_touch.c @@ -1728,7 +1728,7 @@ void IN_TouchKeyEvent( int key, int down ) if( !touch.clientonly ) return; - CL_GetMousePosition( &xi, &yi ); + Platform_GetMousePos( &xi, &yi ); x = xi/SCR_W; y = yi/SCR_H; diff --git a/engine/client/input.c b/engine/client/input.c index 03a5dfd9..cade8019 100644 --- a/engine/client/input.c +++ b/engine/client/input.c @@ -101,10 +101,8 @@ void IN_MouseSavePos( void ) if( !in_mouseactive ) return; -#ifdef XASH_SDL - SDL_GetMouseState( &in_lastvalidpos.x, &in_lastvalidpos.y ); + Platform_GetMousePos( &in_lastvalidpos.x, &in_lastvalidpos.y ); in_mouse_savedpos = true; -#endif } /* @@ -119,9 +117,7 @@ void IN_MouseRestorePos( void ) if( !in_mouse_savedpos ) return; -#ifdef XASH_SDL - SDL_WarpMouseInWindow( host.hWnd, in_lastvalidpos.x, in_lastvalidpos.y ); -#endif + Platform_SetMousePos( in_lastvalidpos.x, in_lastvalidpos.y ); in_mouse_savedpos = false; } @@ -152,7 +148,7 @@ void IN_ToggleClientMouse( int newstate, int oldstate ) } else { - SDL_WarpMouseInWindow( host.hWnd, host.window_center_x, host.window_center_y ); + Platform_SetMousePos( host.window_center_x, host.window_center_y ); SDL_SetWindowGrab( host.hWnd, SDL_TRUE ); if( clgame.dllFuncs.pfnLookEvent ) SDL_SetRelativeMouseMode( SDL_TRUE ); @@ -282,9 +278,7 @@ void IN_MouseMove( void ) return; // find mouse movement -#ifdef XASH_SDL - SDL_GetMouseState( ¤t_pos.x, ¤t_pos.y ); -#endif + Platform_GetMousePos( ¤t_pos.x, ¤t_pos.y ); VGui_MouseMove( current_pos.x, current_pos.y ); @@ -321,7 +315,7 @@ void IN_MouseEvent( void ) #if defined( XASH_SDL ) static qboolean ignore; // igonre mouse warp event int x, y; - SDL_GetMouseState(&x, &y); + Platform_GetMousePos(&x, &y); if( host.mouse_visible ) SDL_ShowCursor( SDL_TRUE ); else @@ -332,7 +326,7 @@ void IN_MouseEvent( void ) x > host.window_center_x + host.window_center_x / 2 || y > host.window_center_y + host.window_center_y / 2 ) { - SDL_WarpMouseInWindow(host.hWnd, host.window_center_x, host.window_center_y); + Platform_SetMousePos( host.window_center_x, host.window_center_y ); ignore = 1; // next mouse event will be mouse warp return; } diff --git a/engine/client/vgui/vgui_draw.c b/engine/client/vgui/vgui_draw.c index a70dacb0..88ee44bf 100644 --- a/engine/client/vgui/vgui_draw.c +++ b/engine/client/vgui/vgui_draw.c @@ -81,7 +81,7 @@ void GAME_EXPORT VGUI_GetMousePos( int *_x, int *_y ) float yscale = (float)glState.height / (float)clgame.scrInfo.iHeight; int x, y; - CL_GetMousePosition( &x, &y ); + Platform_GetMousePos( &x, &y ); *_x = x / xscale, *_y = y / yscale; } diff --git a/engine/platform/platform.h b/engine/platform/platform.h index d0cdff30..69362bd4 100644 --- a/engine/platform/platform.h +++ b/engine/platform/platform.h @@ -40,6 +40,9 @@ int Platform_JoyInit( int numjoy ); // returns number of connected gamepads, neg void Platform_EnableTextInput( qboolean enable ); // System events void Platform_RunEvents( void ); +// Mouse +void Platform_GetMousePos( int *x, int *y ); +void Platform_SetMousePos( int x, int y ); /* ============================================================================== diff --git a/engine/platform/sdl/events.c b/engine/platform/sdl/events.c index 2d070dc1..491d7d50 100644 --- a/engine/platform/sdl/events.c +++ b/engine/platform/sdl/events.c @@ -470,7 +470,7 @@ void Platform_RunEvents( void ) SDLash_EventFilter( &event ); } -void* Platform_GetNativeObject( void ) +void* Platform_GetNativeObject( const char *name ) { return NULL; // SDL don't have it } diff --git a/engine/platform/sdl/in_sdl.c b/engine/platform/sdl/in_sdl.c index 78ed366b..ad075838 100644 --- a/engine/platform/sdl/in_sdl.c +++ b/engine/platform/sdl/in_sdl.c @@ -28,6 +28,28 @@ GNU General Public License for more details. static SDL_Joystick *joy; static SDL_GameController *gamecontroller; +/* +============= +Platform_GetMousePos + +============= +*/ +void Platform_GetMousePos( int *x, int *y ) +{ + SDL_GetMouseState( x, y ); +} + +/* +============= +Platform_SetMousePos + +============ +*/ +void Platform_SetMousePos( int x, int y ) +{ + SDL_WarpMouseInWindow( host.hWnd, x, y ); +} + /* ============= Platform_Vibrate