Browse Source

engine: minimize SetCursorType calls count

pull/2/head
Alibek Omarov 2 years ago
parent
commit
1a09d297ee
  1. 2
      3rdparty/mainui
  2. 8
      engine/client/cl_parse.c
  3. 4
      engine/client/cl_qparse.c
  4. 7
      engine/client/in_touch.c
  5. 46
      engine/client/input.c
  6. 1
      engine/client/input.h
  7. 7
      engine/client/vgui/vgui_draw.c
  8. 2
      engine/common/common.h
  9. 9
      engine/common/host.c
  10. 6
      engine/common/system.c
  11. 2
      engine/platform/sdl/events.c

2
3rdparty/mainui vendored

@ -1 +1 @@
Subproject commit 7ba2010e8dffa60ca1bc166db005c13c7b75aeb9 Subproject commit 0f31c646d623d75b46a9b16f887ac29a167319a3

8
engine/client/cl_parse.c

@ -914,11 +914,7 @@ void CL_ParseServerData( sizebuf_t *msg )
// set the background state // set the background state
if( cls.demoplayback && ( cls.demonum != -1 )) if( cls.demoplayback && ( cls.demonum != -1 ))
{
// re-init mouse
host.mouse_visible = false;
cl.background = true; cl.background = true;
}
else cl.background = background; else cl.background = background;
if( cl.background ) // tell the game parts about background state if( cl.background ) // tell the game parts about background state
@ -2502,11 +2498,7 @@ void CL_ParseLegacyServerData( sizebuf_t *msg )
// set the background state // set the background state
if( cls.demoplayback && ( cls.demonum != -1 )) if( cls.demoplayback && ( cls.demonum != -1 ))
{
// re-init mouse
host.mouse_visible = false;
cl.background = true; cl.background = true;
}
else cl.background = background; else cl.background = background;
if( cl.background ) // tell the game parts about background state if( cl.background ) // tell the game parts about background state

4
engine/client/cl_qparse.c

@ -237,10 +237,6 @@ static void CL_ParseQuakeServerInfo( sizebuf_t *msg )
} }
else Cvar_Reset( "r_decals" ); else Cvar_Reset( "r_decals" );
// re-init mouse
if( cl.background )
host.mouse_visible = false;
if( cl.background ) // tell the game parts about background state if( cl.background ) // tell the game parts about background state
Cvar_FullSet( "cl_background", "1", FCVAR_READ_ONLY ); Cvar_FullSet( "cl_background", "1", FCVAR_READ_ONLY );
else Cvar_FullSet( "cl_background", "0", FCVAR_READ_ONLY ); else Cvar_FullSet( "cl_background", "0", FCVAR_READ_ONLY );

7
engine/client/in_touch.c

@ -469,8 +469,8 @@ static touch_button_t *Touch_FindFirst( touchbuttonlist_t *list, const char *nam
void Touch_SetClientOnly( byte state ) void Touch_SetClientOnly( byte state )
{ {
// TODO: fix clash with vgui cursors
touch.clientonly = state; touch.clientonly = state;
host.mouse_visible = state;
touch.move_finger = touch.look_finger = -1; touch.move_finger = touch.look_finger = -1;
touch.forward = touch.side = 0; touch.forward = touch.side = 0;
@ -2070,6 +2070,11 @@ void Touch_KeyEvent( int key, int down )
ly = y; ly = y;
} }
qboolean Touch_WantVisibleCursor( void )
{
return ( touch_enable.value && touch_emulate.value ) || touch.clientonly;
}
void Touch_Shutdown( void ) void Touch_Shutdown( void )
{ {
if( !touch.initialized ) if( !touch.initialized )

46
engine/client/input.c

@ -47,8 +47,6 @@ convar_t *cl_backspeed;
convar_t *look_filter; convar_t *look_filter;
convar_t *m_rawinput; convar_t *m_rawinput;
static qboolean s_bRawInput, s_bMouseGrab;
/* /*
================ ================
IN_CollectInputDevices IN_CollectInputDevices
@ -173,19 +171,16 @@ Called when key_dest is changed
*/ */
void IN_ToggleClientMouse( int newstate, int oldstate ) void IN_ToggleClientMouse( int newstate, int oldstate )
{ {
if( newstate == oldstate ) return; if( newstate == oldstate )
return;
if( oldstate == key_game ) // since SetCursorType controls cursor visibility
{ // execute it first, and then check mouse grab state
IN_DeactivateMouse(); if(( newstate == key_menu || newstate == key_console || newstate == key_message ) &&
} ( !CL_IsBackgroundMap() || CL_IsBackgroundDemo( )))
else if( newstate == key_game )
{ {
IN_ActivateMouse(); Platform_SetCursorType( dc_arrow );
}
if( ( newstate == key_menu || newstate == key_console || newstate == key_message ) && ( !CL_IsBackgroundMap() || CL_IsBackgroundDemo( )))
{
#if XASH_ANDROID #if XASH_ANDROID
Android_ShowMouse( true ); Android_ShowMouse( true );
#endif #endif
@ -195,6 +190,8 @@ void IN_ToggleClientMouse( int newstate, int oldstate )
} }
else else
{ {
Platform_SetCursorType( dc_none );
#if XASH_ANDROID #if XASH_ANDROID
Android_ShowMouse( false ); Android_ShowMouse( false );
#endif #endif
@ -202,10 +199,21 @@ void IN_ToggleClientMouse( int newstate, int oldstate )
Evdev_SetGrab( true ); Evdev_SetGrab( true );
#endif #endif
} }
if( oldstate == key_game )
{
IN_DeactivateMouse();
}
else if( newstate == key_game )
{
IN_ActivateMouse();
}
} }
void IN_CheckMouseState( qboolean active ) void IN_CheckMouseState( qboolean active )
{ {
static qboolean s_bRawInput, s_bMouseGrab;
#if XASH_WIN32 #if XASH_WIN32
qboolean useRawInput = CVAR_TO_BOOL( m_rawinput ) && clgame.client_dll_uses_sdl || clgame.dllFuncs.pfnLookEvent; qboolean useRawInput = CVAR_TO_BOOL( m_rawinput ) && clgame.client_dll_uses_sdl || clgame.dllFuncs.pfnLookEvent;
#else #else
@ -313,15 +321,6 @@ void IN_MouseMove( void )
if( !in_mouseinitialized ) if( !in_mouseinitialized )
return; return;
if( FBitSet( touch_emulate.flags, FCVAR_CHANGED ))
{
// FIXME: do not hide cursor if it was requested by GUI
if( !touch_emulate.value )
Platform_SetCursorType( dc_none );
ClearBits( touch_emulate.flags, FCVAR_CHANGED );
}
if( touch_emulate.value ) if( touch_emulate.value )
{ {
// touch emulation overrides all input // touch emulation overrides all input
@ -334,11 +333,6 @@ void IN_MouseMove( void )
VGui_MouseMove( x, y ); VGui_MouseMove( x, y );
// HACKHACK: show cursor in UI, as mainui doesn't call
// platform-dependent SetCursor anymore
if( UI_IsVisible( ))
Platform_SetCursorType( dc_arrow );
// if the menu is visible, move the menu cursor // if the menu is visible, move the menu cursor
UI_MouseMove( x, y ); UI_MouseMove( x, y );
} }

1
engine/client/input.h

@ -74,6 +74,7 @@ void Touch_GetMove( float * forward, float *side, float *yaw, float *pitch );
void Touch_ResetDefaultButtons( void ); void Touch_ResetDefaultButtons( void );
int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx, float dy ); int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx, float dy );
void Touch_KeyEvent( int key, int down ); void Touch_KeyEvent( int key, int down );
qboolean Touch_WantVisibleCursor( void );
// //
// in_joy.c // in_joy.c

7
engine/client/vgui/vgui_draw.c

@ -24,7 +24,7 @@ GNU General Public License for more details.
#include "platform/platform.h" #include "platform/platform.h"
static enum VGUI_KeyCode s_pVirtualKeyTrans[256]; static enum VGUI_KeyCode s_pVirtualKeyTrans[256];
static VGUI_DefaultCursor s_currentCursor; static VGUI_DefaultCursor s_currentCursor = -1;
static HINSTANCE s_pVGuiSupport; // vgui_support library static HINSTANCE s_pVGuiSupport; // vgui_support library
static convar_t *vgui_utf8 = NULL; static convar_t *vgui_utf8 = NULL;
@ -50,8 +50,12 @@ void GAME_EXPORT VGUI_GetMousePos( int *_x, int *_y )
void GAME_EXPORT VGUI_CursorSelect( VGUI_DefaultCursor cursor ) void GAME_EXPORT VGUI_CursorSelect( VGUI_DefaultCursor cursor )
{ {
if( s_currentCursor != cursor )
{
Platform_SetCursorType( cursor ); Platform_SetCursorType( cursor );
s_currentCursor = cursor; s_currentCursor = cursor;
}
} }
byte GAME_EXPORT VGUI_GetColor( int i, int j) byte GAME_EXPORT VGUI_GetColor( int i, int j)
@ -250,7 +254,6 @@ void VGui_Startup( const char *clientlib, int width, int height )
if( vgui.initialized ) if( vgui.initialized )
{ {
//host.mouse_visible = true;
vgui.Startup( width, height ); vgui.Startup( width, height );
} }
else if ( COM_CheckString( clientlib ) ) else if ( COM_CheckString( clientlib ) )

2
engine/common/common.h

@ -358,7 +358,7 @@ typedef struct host_parm_s
qboolean allow_cheats; // this host will allow cheating qboolean allow_cheats; // this host will allow cheating
qboolean con_showalways; // show console always (developer and dedicated) qboolean con_showalways; // show console always (developer and dedicated)
qboolean change_game; // initialize when game is changed qboolean change_game; // initialize when game is changed
qboolean mouse_visible; // vgui override cursor control qboolean mouse_visible; // vgui override cursor control (never change outside Platform_SetCursorType!)
qboolean shutdown_issued; // engine is shutting down qboolean shutdown_issued; // engine is shutting down
qboolean force_draw_version; // used when fraps is loaded qboolean force_draw_version; // used when fraps is loaded
float force_draw_version_time; float force_draw_version_time;

9
engine/common/host.c

@ -703,15 +703,6 @@ void GAME_EXPORT Host_Error( const char *error, ... )
static qboolean recursive = false; static qboolean recursive = false;
va_list argptr; va_list argptr;
if( host.mouse_visible && !CL_IsInMenu( ))
{
// hide VGUI mouse
#ifdef XASH_SDL
SDL_ShowCursor( 0 );
#endif
host.mouse_visible = false;
}
va_start( argptr, error ); va_start( argptr, error );
Q_vsprintf( hosterror1, error, argptr ); Q_vsprintf( hosterror1, error, argptr );
va_end( argptr ); va_end( argptr );

6
engine/common/system.c

@ -400,12 +400,16 @@ void Sys_Error( const char *error, ... )
va_list argptr; va_list argptr;
char text[MAX_PRINT_MSG]; char text[MAX_PRINT_MSG];
// enable cursor before debugger call
if( !Host_IsDedicated( ))
Platform_SetCursorType( dc_arrow );
DEBUG_BREAK; DEBUG_BREAK;
if( host.status == HOST_ERR_FATAL ) if( host.status == HOST_ERR_FATAL )
return; // don't multiple executes return; // don't multiple executes
// make sure what console received last message // make sure that console received last message
if( host.change_game ) Sys_Sleep( 200 ); if( host.change_game ) Sys_Sleep( 200 );
error_on_exit = true; error_on_exit = true;

2
engine/platform/sdl/events.c

@ -668,7 +668,7 @@ TODO: kill mouse in win32 clients too
*/ */
void Platform_PreCreateMove( void ) void Platform_PreCreateMove( void )
{ {
if( CVAR_TO_BOOL( m_ignore ) ) if( CVAR_TO_BOOL( m_ignore ))
{ {
SDL_GetRelativeMouseState( NULL, NULL ); SDL_GetRelativeMouseState( NULL, NULL );
SDL_ShowCursor( SDL_TRUE ); SDL_ShowCursor( SDL_TRUE );

Loading…
Cancel
Save