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

2
3rdparty/mainui vendored

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

8
engine/client/cl_parse.c

@ -914,11 +914,7 @@ void CL_ParseServerData( sizebuf_t *msg ) @@ -914,11 +914,7 @@ void CL_ParseServerData( sizebuf_t *msg )
// set the background state
if( cls.demoplayback && ( cls.demonum != -1 ))
{
// re-init mouse
host.mouse_visible = false;
cl.background = true;
}
else cl.background = background;
if( cl.background ) // tell the game parts about background state
@ -2502,11 +2498,7 @@ void CL_ParseLegacyServerData( sizebuf_t *msg ) @@ -2502,11 +2498,7 @@ void CL_ParseLegacyServerData( sizebuf_t *msg )
// set the background state
if( cls.demoplayback && ( cls.demonum != -1 ))
{
// re-init mouse
host.mouse_visible = false;
cl.background = true;
}
else cl.background = background;
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 ) @@ -237,10 +237,6 @@ static void CL_ParseQuakeServerInfo( sizebuf_t *msg )
}
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
Cvar_FullSet( "cl_background", "1", 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 @@ -469,8 +469,8 @@ static touch_button_t *Touch_FindFirst( touchbuttonlist_t *list, const char *nam
void Touch_SetClientOnly( byte state )
{
// TODO: fix clash with vgui cursors
touch.clientonly = state;
host.mouse_visible = state;
touch.move_finger = touch.look_finger = -1;
touch.forward = touch.side = 0;
@ -2070,6 +2070,11 @@ void Touch_KeyEvent( int key, int down ) @@ -2070,6 +2070,11 @@ void Touch_KeyEvent( int key, int down )
ly = y;
}
qboolean Touch_WantVisibleCursor( void )
{
return ( touch_enable.value && touch_emulate.value ) || touch.clientonly;
}
void Touch_Shutdown( void )
{
if( !touch.initialized )

46
engine/client/input.c

@ -47,8 +47,6 @@ convar_t *cl_backspeed; @@ -47,8 +47,6 @@ convar_t *cl_backspeed;
convar_t *look_filter;
convar_t *m_rawinput;
static qboolean s_bRawInput, s_bMouseGrab;
/*
================
IN_CollectInputDevices
@ -173,19 +171,16 @@ Called when key_dest is changed @@ -173,19 +171,16 @@ Called when key_dest is changed
*/
void IN_ToggleClientMouse( int newstate, int oldstate )
{
if( newstate == oldstate ) return;
if( newstate == oldstate )
return;
if( oldstate == key_game )
{
IN_DeactivateMouse();
}
else if( newstate == key_game )
// since SetCursorType controls cursor visibility
// execute it first, and then check mouse grab state
if(( newstate == key_menu || newstate == key_console || newstate == key_message ) &&
( !CL_IsBackgroundMap() || CL_IsBackgroundDemo( )))
{
IN_ActivateMouse();
}
Platform_SetCursorType( dc_arrow );
if( ( newstate == key_menu || newstate == key_console || newstate == key_message ) && ( !CL_IsBackgroundMap() || CL_IsBackgroundDemo( )))
{
#if XASH_ANDROID
Android_ShowMouse( true );
#endif
@ -195,6 +190,8 @@ void IN_ToggleClientMouse( int newstate, int oldstate ) @@ -195,6 +190,8 @@ void IN_ToggleClientMouse( int newstate, int oldstate )
}
else
{
Platform_SetCursorType( dc_none );
#if XASH_ANDROID
Android_ShowMouse( false );
#endif
@ -202,10 +199,21 @@ void IN_ToggleClientMouse( int newstate, int oldstate ) @@ -202,10 +199,21 @@ void IN_ToggleClientMouse( int newstate, int oldstate )
Evdev_SetGrab( true );
#endif
}
if( oldstate == key_game )
{
IN_DeactivateMouse();
}
else if( newstate == key_game )
{
IN_ActivateMouse();
}
}
void IN_CheckMouseState( qboolean active )
{
static qboolean s_bRawInput, s_bMouseGrab;
#if XASH_WIN32
qboolean useRawInput = CVAR_TO_BOOL( m_rawinput ) && clgame.client_dll_uses_sdl || clgame.dllFuncs.pfnLookEvent;
#else
@ -313,15 +321,6 @@ void IN_MouseMove( void ) @@ -313,15 +321,6 @@ void IN_MouseMove( void )
if( !in_mouseinitialized )
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 )
{
// touch emulation overrides all input
@ -334,11 +333,6 @@ void IN_MouseMove( void ) @@ -334,11 +333,6 @@ void IN_MouseMove( void )
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
UI_MouseMove( x, y );
}

1
engine/client/input.h

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

7
engine/client/vgui/vgui_draw.c

@ -24,7 +24,7 @@ GNU General Public License for more details. @@ -24,7 +24,7 @@ GNU General Public License for more details.
#include "platform/platform.h"
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 convar_t *vgui_utf8 = NULL;
@ -49,10 +49,14 @@ void GAME_EXPORT VGUI_GetMousePos( int *_x, int *_y ) @@ -49,10 +49,14 @@ void GAME_EXPORT VGUI_GetMousePos( int *_x, int *_y )
}
void GAME_EXPORT VGUI_CursorSelect( VGUI_DefaultCursor cursor )
{
if( s_currentCursor != cursor )
{
Platform_SetCursorType( cursor );
s_currentCursor = cursor;
}
}
byte GAME_EXPORT VGUI_GetColor( int i, int j)
{
@ -250,7 +254,6 @@ void VGui_Startup( const char *clientlib, int width, int height ) @@ -250,7 +254,6 @@ void VGui_Startup( const char *clientlib, int width, int height )
if( vgui.initialized )
{
//host.mouse_visible = true;
vgui.Startup( width, height );
}
else if ( COM_CheckString( clientlib ) )

2
engine/common/common.h

@ -358,7 +358,7 @@ typedef struct host_parm_s @@ -358,7 +358,7 @@ typedef struct host_parm_s
qboolean allow_cheats; // this host will allow cheating
qboolean con_showalways; // show console always (developer and dedicated)
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 force_draw_version; // used when fraps is loaded
float force_draw_version_time;

9
engine/common/host.c

@ -703,15 +703,6 @@ void GAME_EXPORT Host_Error( const char *error, ... ) @@ -703,15 +703,6 @@ void GAME_EXPORT Host_Error( const char *error, ... )
static qboolean recursive = false;
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 );
Q_vsprintf( hosterror1, error, argptr );
va_end( argptr );

6
engine/common/system.c

@ -400,12 +400,16 @@ void Sys_Error( const char *error, ... ) @@ -400,12 +400,16 @@ void Sys_Error( const char *error, ... )
va_list argptr;
char text[MAX_PRINT_MSG];
// enable cursor before debugger call
if( !Host_IsDedicated( ))
Platform_SetCursorType( dc_arrow );
DEBUG_BREAK;
if( host.status == HOST_ERR_FATAL )
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 );
error_on_exit = true;

Loading…
Cancel
Save