Browse Source

engine: input: fix incorrect client notifying about mouse button states

pull/2/head
Alibek Omarov 3 years ago
parent
commit
abbd0f92a4
  1. 46
      engine/client/input.c
  2. 2
      engine/client/input.h
  3. 12
      engine/platform/sdl/events.c

46
engine/client/input.c

@ -30,8 +30,7 @@ qboolean in_mouseinitialized;
qboolean in_mouse_suspended; qboolean in_mouse_suspended;
POINT in_lastvalidpos; POINT in_lastvalidpos;
qboolean in_mouse_savedpos; qboolean in_mouse_savedpos;
static uint in_mouse_oldbuttonstate; static int in_mstate = 0;
static int in_mouse_buttons = 5; // SDL maximum
static struct inputstate_s static struct inputstate_s
{ {
float lastpitch, lastyaw; float lastpitch, lastyaw;
@ -337,50 +336,33 @@ void IN_MouseMove( void )
IN_MouseEvent IN_MouseEvent
=========== ===========
*/ */
void IN_MouseEvent( uint mstate ) void IN_MouseEvent( int key, int down )
{ {
int i; int i;
if( !in_mouseinitialized ) if( !in_mouseinitialized )
return; return;
if( down )
SetBits( in_mstate, BIT( key ));
else ClearBits( in_mstate, BIT( key ));
if( cls.key_dest == key_game ) if( cls.key_dest == key_game )
{ {
// perform button actions // perform button actions
for( i = 0; i < in_mouse_buttons; i++ ) VGui_KeyEvent( K_MOUSE1 + key, down );
{
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 );
}
}
// don't do Key_Event here
// client may override IN_MouseEvent
// but by default it calls back to Key_Event anyway
if( in_mouseactive ) if( in_mouseactive )
clgame.dllFuncs.IN_MouseEvent( mstate ); clgame.dllFuncs.IN_MouseEvent( in_mstate );
in_mouse_oldbuttonstate = mstate;
return;
} }
else
// perform button actions
for( i = 0; i < in_mouse_buttons; i++ )
{ {
if( FBitSet( mstate, BIT( i )) && !FBitSet( in_mouse_oldbuttonstate, BIT( i ))) // perform button actions
{ Key_Event( K_MOUSE1 + key, down );
Key_Event( K_MOUSE1 + i, true );
}
if( !FBitSet( mstate, BIT( i )) && FBitSet( in_mouse_oldbuttonstate, BIT( i )))
{
Key_Event( K_MOUSE1 + i, false );
}
} }
in_mouse_oldbuttonstate = mstate;
} }
/* /*

2
engine/client/input.h

@ -33,7 +33,7 @@ extern qboolean in_mouseinitialized;
void IN_Init( void ); void IN_Init( void );
void Host_InputFrame( void ); void Host_InputFrame( void );
void IN_Shutdown( void ); void IN_Shutdown( void );
void IN_MouseEvent( uint mstate ); void IN_MouseEvent( int key, int down );
void IN_ActivateMouse( void ); void IN_ActivateMouse( void );
void IN_DeactivateMouse( void ); void IN_DeactivateMouse( void );
void IN_MouseSavePos( void ); void IN_MouseSavePos( void );

12
engine/platform/sdl/events.c

@ -281,19 +281,19 @@ static void SDLash_MouseEvent( SDL_MouseButtonEvent button )
switch( button.button ) switch( button.button )
{ {
case SDL_BUTTON_LEFT: case SDL_BUTTON_LEFT:
if( down ) SetBits( mstate, BIT( 0 )); IN_MouseEvent( 0, down );
break; break;
case SDL_BUTTON_MIDDLE: case SDL_BUTTON_MIDDLE:
if( down ) SetBits( mstate, BIT( 1 )); IN_MouseEvent( 1, down );
break; break;
case SDL_BUTTON_RIGHT: case SDL_BUTTON_RIGHT:
if( down ) SetBits( mstate, BIT( 2 )); IN_MouseEvent( 2, down );
break; break;
case SDL_BUTTON_X1: case SDL_BUTTON_X1:
if( down ) SetBits( mstate, BIT( 3 )); IN_MouseEvent( 3, down );
break; break;
case SDL_BUTTON_X2: case SDL_BUTTON_X2:
if( down ) SetBits( mstate, BIT( 4 )); IN_MouseEvent( 4, down );
break; break;
#if ! SDL_VERSION_ATLEAST( 2, 0, 0 ) #if ! SDL_VERSION_ATLEAST( 2, 0, 0 )
case SDL_BUTTON_WHEELUP: case SDL_BUTTON_WHEELUP:
@ -306,8 +306,6 @@ static void SDLash_MouseEvent( SDL_MouseButtonEvent button )
default: default:
Con_Printf( "Unknown mouse button ID: %d\n", button.button ); Con_Printf( "Unknown mouse button ID: %d\n", button.button );
} }
IN_MouseEvent( mstate );
} }
/* /*

Loading…
Cancel
Save