From abbd0f92a48b6b8bdda0b57157e223b39a18b589 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 13 Jan 2022 15:52:59 +0300 Subject: [PATCH] engine: input: fix incorrect client notifying about mouse button states --- engine/client/input.c | 46 +++++++++++------------------------- engine/client/input.h | 2 +- engine/platform/sdl/events.c | 12 ++++------ 3 files changed, 20 insertions(+), 40 deletions(-) diff --git a/engine/client/input.c b/engine/client/input.c index e90a5848..09d01033 100644 --- a/engine/client/input.c +++ b/engine/client/input.c @@ -30,8 +30,7 @@ qboolean in_mouseinitialized; qboolean in_mouse_suspended; POINT in_lastvalidpos; qboolean in_mouse_savedpos; -static uint in_mouse_oldbuttonstate; -static int in_mouse_buttons = 5; // SDL maximum +static int in_mstate = 0; static struct inputstate_s { float lastpitch, lastyaw; @@ -337,50 +336,33 @@ void IN_MouseMove( void ) IN_MouseEvent =========== */ -void IN_MouseEvent( uint mstate ) +void IN_MouseEvent( int key, int down ) { int i; if( !in_mouseinitialized ) return; + if( down ) + SetBits( in_mstate, BIT( key )); + else ClearBits( in_mstate, BIT( key )); + if( cls.key_dest == key_game ) { // perform button actions - for( i = 0; i < in_mouse_buttons; i++ ) - { - if( FBitSet( mstate, BIT( i )) && !FBitSet( in_mouse_oldbuttonstate, BIT( i ))) - { - VGui_KeyEvent( K_MOUSE1 + i, true ); - } - - if( !FBitSet( mstate, BIT( i )) && FBitSet( in_mouse_oldbuttonstate, BIT( i ))) - { - VGui_KeyEvent( K_MOUSE1 + i, false ); - } - } + VGui_KeyEvent( K_MOUSE1 + key, down ); + // don't do Key_Event here + // client may override IN_MouseEvent + // but by default it calls back to Key_Event anyway if( in_mouseactive ) - clgame.dllFuncs.IN_MouseEvent( mstate ); - - in_mouse_oldbuttonstate = mstate; - return; + clgame.dllFuncs.IN_MouseEvent( in_mstate ); } - - // perform button actions - for( i = 0; i < in_mouse_buttons; i++ ) + else { - if( FBitSet( mstate, BIT( i )) && !FBitSet( in_mouse_oldbuttonstate, BIT( i ))) - { - Key_Event( K_MOUSE1 + i, true ); - } - - if( !FBitSet( mstate, BIT( i )) && FBitSet( in_mouse_oldbuttonstate, BIT( i ))) - { - Key_Event( K_MOUSE1 + i, false ); - } + // perform button actions + Key_Event( K_MOUSE1 + key, down ); } - in_mouse_oldbuttonstate = mstate; } /* diff --git a/engine/client/input.h b/engine/client/input.h index 4c647dfe..32ad2b6b 100644 --- a/engine/client/input.h +++ b/engine/client/input.h @@ -33,7 +33,7 @@ extern qboolean in_mouseinitialized; void IN_Init( void ); void Host_InputFrame( void ); void IN_Shutdown( void ); -void IN_MouseEvent( uint mstate ); +void IN_MouseEvent( int key, int down ); void IN_ActivateMouse( void ); void IN_DeactivateMouse( void ); void IN_MouseSavePos( void ); diff --git a/engine/platform/sdl/events.c b/engine/platform/sdl/events.c index 54e36e87..e2530909 100644 --- a/engine/platform/sdl/events.c +++ b/engine/platform/sdl/events.c @@ -281,19 +281,19 @@ static void SDLash_MouseEvent( SDL_MouseButtonEvent button ) switch( button.button ) { case SDL_BUTTON_LEFT: - if( down ) SetBits( mstate, BIT( 0 )); + IN_MouseEvent( 0, down ); break; case SDL_BUTTON_MIDDLE: - if( down ) SetBits( mstate, BIT( 1 )); + IN_MouseEvent( 1, down ); break; case SDL_BUTTON_RIGHT: - if( down ) SetBits( mstate, BIT( 2 )); + IN_MouseEvent( 2, down ); break; case SDL_BUTTON_X1: - if( down ) SetBits( mstate, BIT( 3 )); + IN_MouseEvent( 3, down ); break; case SDL_BUTTON_X2: - if( down ) SetBits( mstate, BIT( 4 )); + IN_MouseEvent( 4, down ); break; #if ! SDL_VERSION_ATLEAST( 2, 0, 0 ) case SDL_BUTTON_WHEELUP: @@ -306,8 +306,6 @@ static void SDLash_MouseEvent( SDL_MouseButtonEvent button ) default: Con_Printf( "Unknown mouse button ID: %d\n", button.button ); } - - IN_MouseEvent( mstate ); } /*