Browse Source

input: merge touch support again. Fix m_ignore, fix EngineAppendMove

pull/2/head
mittorn 5 years ago
parent
commit
7f3ee9ca71
  1. 3
      engine/client/cl_main.c
  2. 16
      engine/client/cl_mobile.c
  3. 2
      engine/client/cl_view.c
  4. 1911
      engine/client/in_touch.c
  5. 44
      engine/client/input.c
  6. 28
      engine/client/input.h
  7. 1
      engine/client/keys.c
  8. 5
      engine/client/vgui/vgui_draw.c
  9. 1
      engine/platform/platform.h
  10. 43
      engine/platform/sdl/events.c

3
engine/client/cl_main.c

@ -652,7 +652,9 @@ void CL_CreateCmd( void )
} }
active = (( cls.signon == SIGNONS ) && !cl.paused && !cls.demoplayback ); active = (( cls.signon == SIGNONS ) && !cl.paused && !cls.demoplayback );
Platform_PreCreateMove();
clgame.dllFuncs.CL_CreateMove( host.frametime, &pcmd->cmd, active ); clgame.dllFuncs.CL_CreateMove( host.frametime, &pcmd->cmd, active );
IN_EngineAppendMove( host.frametime, &pcmd->cmd, active );
CL_PopPMStates(); CL_PopPMStates();
@ -3103,6 +3105,7 @@ void CL_Shutdown( void )
{ {
Host_WriteOpenGLConfig (); Host_WriteOpenGLConfig ();
Host_WriteVideoConfig (); Host_WriteVideoConfig ();
Touch_WriteConfig();
} }
// IN_TouchShutdown (); // IN_TouchShutdown ();

16
engine/client/cl_mobile.c

@ -95,22 +95,18 @@ static void *pfnGetNativeObject( const char *obj )
return Platform_GetNativeObject( obj ); return Platform_GetNativeObject( obj );
} }
void IN_TouchHideButtons( const char *str, unsigned char hide )
{
}
static mobile_engfuncs_t gpMobileEngfuncs = static mobile_engfuncs_t gpMobileEngfuncs =
{ {
MOBILITY_API_VERSION, MOBILITY_API_VERSION,
pfnVibrate, pfnVibrate,
pfnEnableTextInput, pfnEnableTextInput,
NULL, // IN_TouchAddClientButton, Touch_AddClientButton,
NULL, // IN_TouchAddDefaultButton, Touch_AddDefaultButton,
IN_TouchHideButtons, Touch_HideButtons,
NULL, // IN_TouchRemoveButton, Touch_RemoveButton,
NULL, // (void*)IN_TouchSetClientOnly, (void*)Touch_SetClientOnly,
NULL, // IN_TouchResetDefaultButtons, Touch_ResetDefaultButtons,
pfnDrawScaledCharacter, pfnDrawScaledCharacter,
Sys_Warn, Sys_Warn,
pfnGetNativeObject, pfnGetNativeObject,

2
engine/client/cl_view.c

@ -19,6 +19,7 @@ GNU General Public License for more details.
#include "entity_types.h" #include "entity_types.h"
#include "vgui_draw.h" #include "vgui_draw.h"
#include "sound.h" #include "sound.h"
#include "input.h" // touch
#include "platform/platform.h" // GL_UpdateSwapInterval #include "platform/platform.h" // GL_UpdateSwapInterval
/* /*
@ -484,6 +485,7 @@ void V_PostRender( void )
UI_UpdateMenu( host.realtime ); UI_UpdateMenu( host.realtime );
Con_DrawVersion(); Con_DrawVersion();
Con_DrawDebug(); // must be last Con_DrawDebug(); // must be last
Touch_Draw();
S_ExtraUpdate(); S_ExtraUpdate();
} }

1911
engine/client/in_touch.c

File diff suppressed because it is too large Load Diff

44
engine/client/input.c

@ -61,10 +61,8 @@ uint IN_CollectInputDevices( void )
if( !m_ignore->value ) // no way to check is mouse connected, so use cvar only if( !m_ignore->value ) // no way to check is mouse connected, so use cvar only
ret |= INPUT_DEVICE_MOUSE; ret |= INPUT_DEVICE_MOUSE;
#if 0 // TOUCHTODO if( CVAR_TO_BOOL(touch_enable) )
if( touch_enable->value )
ret |= INPUT_DEVICE_TOUCH; ret |= INPUT_DEVICE_TOUCH;
#endif
if( Joy_IsActive() ) // connected or enabled if( Joy_IsActive() ) // connected or enabled
ret |= INPUT_DEVICE_JOYSTICK; ret |= INPUT_DEVICE_JOYSTICK;
@ -94,13 +92,13 @@ void IN_LockInputDevices( qboolean lock )
{ {
SetBits( m_ignore->flags, FCVAR_READ_ONLY ); SetBits( m_ignore->flags, FCVAR_READ_ONLY );
SetBits( joy_enable->flags, FCVAR_READ_ONLY ); SetBits( joy_enable->flags, FCVAR_READ_ONLY );
// TOUCHTODO SetBits( touch_enable->flags, FCVAR_READ_ONLY );
} }
else else
{ {
ClearBits( m_ignore->flags, FCVAR_READ_ONLY ); ClearBits( m_ignore->flags, FCVAR_READ_ONLY );
ClearBits( joy_enable->flags, FCVAR_READ_ONLY ); ClearBits( joy_enable->flags, FCVAR_READ_ONLY );
// TOUCHTODO ClearBits( touch_enable->flags, FCVAR_READ_ONLY );
} }
} }
@ -197,7 +195,7 @@ void IN_ToggleClientMouse( int newstate, int oldstate )
{ {
// reset mouse pos, so cancel effect in game // reset mouse pos, so cancel effect in game
#ifdef XASH_SDL #ifdef XASH_SDL
if( 0 ) // touch_enable->value ) if( CVAR_TO_BOOL(touch_enable) )
{ {
SDL_SetRelativeMouseMode( SDL_FALSE ); SDL_SetRelativeMouseMode( SDL_FALSE );
SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
@ -268,7 +266,9 @@ void IN_ActivateMouse( qboolean force )
if( in_mouse_suspended ) if( in_mouse_suspended )
{ {
#ifdef XASH_SDL #ifdef XASH_SDL
SDL_ShowCursor( false ); /// TODO: Platform_ShowCursor
if( !touch_emulate )
SDL_ShowCursor( SDL_FALSE );
#endif #endif
UI_ShowCursor( false ); UI_ShowCursor( false );
} }
@ -360,9 +360,14 @@ void IN_MouseEvent( void )
{ {
int i; int i;
// touch emu: handle motion
if( CVAR_TO_BOOL( touch_emulate ))
Touch_KeyEvent( K_MOUSE1, 2 );
if( !in_mouseinitialized || !in_mouseactive ) if( !in_mouseinitialized || !in_mouseactive )
return; return;
if( m_ignore->value ) if( m_ignore->value )
return; return;
@ -374,7 +379,7 @@ void IN_MouseEvent( void )
Platform_GetMousePos(&x, &y); Platform_GetMousePos(&x, &y);
if( host.mouse_visible ) if( host.mouse_visible )
SDL_ShowCursor( SDL_TRUE ); SDL_ShowCursor( SDL_TRUE );
else else if( !CVAR_TO_BOOL( touch_emulate ) )
SDL_ShowCursor( SDL_FALSE ); SDL_ShowCursor( SDL_FALSE );
if( x < host.window_center_x / 2 || if( x < host.window_center_x / 2 ||
@ -426,6 +431,8 @@ void IN_Shutdown( void )
#ifdef XASH_USE_EVDEV #ifdef XASH_USE_EVDEV
Evdev_Shutdown(); Evdev_Shutdown();
#endif #endif
Touch_Shutdown();
} }
@ -446,6 +453,8 @@ void IN_Init( void )
Joy_Init(); // common joystick support init Joy_Init(); // common joystick support init
Touch_Init();
#ifdef XASH_USE_EVDEV #ifdef XASH_USE_EVDEV
Evdev_Init(); Evdev_Init();
#endif #endif
@ -469,7 +478,7 @@ Common function for engine joystick movement
#define R (1U << 3) // Right #define R (1U << 3) // Right
#define T (1U << 4) // Forward stop #define T (1U << 4) // Forward stop
#define S (1U << 5) // Side stop #define S (1U << 5) // Side stop
void IN_JoyAppendMove( usercmd_t *cmd, float forwardmove, float sidemove ) static void IN_JoyAppendMove( usercmd_t *cmd, float forwardmove, float sidemove )
{ {
static uint moveflags = T | S; static uint moveflags = T | S;
@ -545,7 +554,7 @@ void IN_JoyAppendMove( usercmd_t *cmd, float forwardmove, float sidemove )
void IN_CollectInput( float *forward, float *side, float *pitch, float *yaw, qboolean includeMouse, qboolean includeSdlMouse ) void IN_CollectInput( float *forward, float *side, float *pitch, float *yaw, qboolean includeMouse, qboolean includeSdlMouse )
{ {
if( !m_ignore->value || includeMouse ) if( includeMouse )
{ {
#if XASH_INPUT == INPUT_SDL #if XASH_INPUT == INPUT_SDL
if( includeSdlMouse ) if( includeSdlMouse )
@ -572,7 +581,7 @@ void IN_CollectInput( float *forward, float *side, float *pitch, float *yaw, qbo
} }
Joy_FinalizeMove( forward, side, yaw, pitch ); Joy_FinalizeMove( forward, side, yaw, pitch );
// IN_TouchMove( forward, side, yaw, pitch ); Touch_GetMove( forward, side, yaw, pitch );
if( look_filter->value ) if( look_filter->value )
{ {
@ -591,9 +600,10 @@ IN_EngineAppendMove
Called from cl_main.c after generating command in client Called from cl_main.c after generating command in client
================ ================
*/ */
void IN_EngineAppendMove( float frametime, usercmd_t *cmd, qboolean active ) void IN_EngineAppendMove( float frametime, void *cmd1, qboolean active )
{ {
float forward, side, pitch, yaw; float forward, side, pitch, yaw;
usercmd_t *cmd = cmd1;
if( clgame.dllFuncs.pfnLookEvent ) if( clgame.dllFuncs.pfnLookEvent )
return; return;
@ -605,15 +615,19 @@ void IN_EngineAppendMove( float frametime, usercmd_t *cmd, qboolean active )
if( active ) if( active )
{ {
float sensitivity = ( (float)cl.local.scr_fov / (float)90.0f ); float sensitivity = 1;//( (float)cl.local.scr_fov / (float)90.0f );
IN_CollectInput( &forward, &side, &pitch, &yaw, in_mouseinitialized, m_enginemouse->value ); IN_CollectInput( &forward, &side, &pitch, &yaw, in_mouseinitialized && !CVAR_TO_BOOL( m_ignore ), m_enginemouse->value );
IN_JoyAppendMove( cmd, forward, side ); IN_JoyAppendMove( cmd, forward, side );
if( pitch || yaw )
{
cmd->viewangles[YAW] += yaw * sensitivity; cmd->viewangles[YAW] += yaw * sensitivity;
cmd->viewangles[PITCH] += pitch * sensitivity; cmd->viewangles[PITCH] += pitch * sensitivity;
cmd->viewangles[PITCH] = bound( -90, cmd->viewangles[PITCH], 90 ); cmd->viewangles[PITCH] = bound( -90, cmd->viewangles[PITCH], 90 );
VectorCopy(cmd->viewangles, cl.viewangles);
}
} }
} }
@ -637,7 +651,7 @@ void Host_InputFrame( void )
if( clgame.dllFuncs.pfnLookEvent ) if( clgame.dllFuncs.pfnLookEvent )
{ {
IN_CollectInput( &forward, &side, &pitch, &yaw, in_mouseinitialized, true ); IN_CollectInput( &forward, &side, &pitch, &yaw, in_mouseinitialized && !CVAR_TO_BOOL( m_ignore ), true );
if( cls.key_dest == key_game ) if( cls.key_dest == key_game )
{ {

28
engine/client/input.h

@ -43,6 +43,7 @@ void IN_SetCursor( void *hCursor );
uint IN_CollectInputDevices( void ); uint IN_CollectInputDevices( void );
void IN_LockInputDevices( qboolean lock ); void IN_LockInputDevices( qboolean lock );
void IN_EngineAppendMove( float frametime, void *cmd, qboolean active );
// //
// in_touch.c // in_touch.c
@ -55,25 +56,24 @@ typedef enum
} touchEventType; } touchEventType;
extern convar_t *touch_enable; extern convar_t *touch_enable;
extern convar_t *touch_emulate;
void IN_TouchDraw( void ); void Touch_Draw( void );
void IN_TouchEditClear( void ); void Touch_SetClientOnly( qboolean state );
void IN_TouchSetClientOnly( qboolean state ); void Touch_RemoveButton( const char *name );
void IN_TouchRemoveButton( const char *name ); void Touch_HideButtons( const char *name, unsigned char hide );
void IN_TouchHideButtons( const char *name, unsigned char hide );
//void IN_TouchSetCommand( const char *name, const char *command ); //void IN_TouchSetCommand( const char *name, const char *command );
//void IN_TouchSetTexture( const char *name, const char *texture ); //void IN_TouchSetTexture( const char *name, const char *texture );
//void IN_TouchSetColor( const char *name, byte *color ); //void IN_TouchSetColor( const char *name, byte *color );
void IN_TouchAddClientButton( const char *name, const char *texture, const char *command, float x1, float y1, float x2, float y2, byte *color, int round, float aspect, int flags ); void Touch_AddClientButton( const char *name, const char *texture, const char *command, float x1, float y1, float x2, float y2, byte *color, int round, float aspect, int flags );
void IN_TouchAddDefaultButton( const char *name, const char *texturefile, const char *command, float x1, float y1, float x2, float y2, byte *color, int round, float aspect, int flags ); void Touch_AddDefaultButton( const char *name, const char *texturefile, const char *command, float x1, float y1, float x2, float y2, byte *color, int round, float aspect, int flags );
void IN_TouchInitConfig( void ); void Touch_WriteConfig( void );
void IN_TouchWriteConfig( void ); void Touch_Init( void );
void IN_TouchInit( void ); void Touch_Shutdown( void );
void IN_TouchShutdown( void ); void Touch_GetMove( float * forward, float *side, float *yaw, float *pitch );
void IN_TouchMove( float * forward, float *side, float *yaw, float *pitch ); void Touch_ResetDefaultButtons( void );
void IN_TouchResetDefaultButtons( 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 IN_TouchKeyEvent( int key, int down ); void Touch_KeyEvent( int key, int down );
// //
// in_joy.c // in_joy.c

1
engine/client/keys.c

@ -652,6 +652,7 @@ void Key_Event( int key, int down )
} }
VGui_KeyEvent( key, down ); VGui_KeyEvent( key, down );
Touch_KeyEvent( key, down );
// console key is hardcoded, so the user can never unbind it // console key is hardcoded, so the user can never unbind it
if( key == '`' || key == '~' ) if( key == '`' || key == '~' )

5
engine/client/vgui/vgui_draw.c

@ -23,6 +23,7 @@ GNU General Public License for more details.
#include "library.h" #include "library.h"
#include "keydefs.h" #include "keydefs.h"
#include "ref_common.h" #include "ref_common.h"
#include "input.h"
#ifdef XASH_SDL #ifdef XASH_SDL
#include <SDL_events.h> #include <SDL_events.h>
static SDL_Cursor* s_pDefaultCursor[20]; static SDL_Cursor* s_pDefaultCursor[20];
@ -108,6 +109,10 @@ void GAME_EXPORT VGUI_CursorSelect(enum VGUI_DefaultCursor cursor )
} }
#ifdef XASH_SDL #ifdef XASH_SDL
/// TODO: platform cursors
if( CVAR_TO_BOOL( touch_emulate ) )
return;
if( host.mouse_visible ) if( host.mouse_visible )
{ {
SDL_SetRelativeMouseMode( SDL_FALSE ); SDL_SetRelativeMouseMode( SDL_FALSE );

1
engine/platform/platform.h

@ -68,6 +68,7 @@ void Platform_RunEvents( void );
// Mouse // Mouse
void Platform_GetMousePos( int *x, int *y ); void Platform_GetMousePos( int *x, int *y );
void Platform_SetMousePos( int x, int y ); void Platform_SetMousePos( int x, int y );
void Platform_PreCreateMove( void );
// Clipboard // Clipboard
void Platform_GetClipboardText( char *buffer, size_t size ); void Platform_GetClipboardText( char *buffer, size_t size );
void Platform_SetClipboardText( const char *buffer, size_t size ); void Platform_SetClipboardText( const char *buffer, size_t size );

43
engine/platform/sdl/events.c

@ -157,7 +157,12 @@ SDLash_MouseEvent
static void SDLash_MouseEvent( SDL_MouseButtonEvent button ) static void SDLash_MouseEvent( SDL_MouseButtonEvent button )
{ {
int down = button.state != SDL_RELEASED; int down = button.state != SDL_RELEASED;
if( in_mouseinitialized && !m_ignore->value && button.which != SDL_TOUCH_MOUSEID )
if( CVAR_TO_BOOL( touch_emulate ) )
{
Touch_KeyEvent( K_MOUSE1 - 1 + button.button, down );
}
else if( in_mouseinitialized && !m_ignore->value && button.which != SDL_TOUCH_MOUSEID )
{ {
Key_Event( K_MOUSE1 - 1 + button.button, down ); Key_Event( K_MOUSE1 - 1 + button.button, down );
} }
@ -210,27 +215,12 @@ static void SDLash_EventFilter( SDL_Event *event )
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
if( !host.mouse_visible && event->motion.which != SDL_TOUCH_MOUSEID ) if( !host.mouse_visible && event->motion.which != SDL_TOUCH_MOUSEID )
IN_MouseEvent(); IN_MouseEvent();
#ifdef TOUCHEMU
if( mdown )
IN_TouchEvent( event_motion, 0,
event->motion.x/(float)refState.width,
event->motion.y/(float)refState.height,
event->motion.xrel/(float)refState.width,
event->motion.yrel/(float)refState.height );
SDL_ShowCursor( true );
#endif
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
#ifdef TOUCHEMU
mdown = event->button.state != SDL_RELEASED;
IN_TouchEvent( event_down, 0,
event->button.x/(float)refState.width,
event->button.y/(float)refState.height, 0, 0);
#else
SDLash_MouseEvent( event->button ); SDLash_MouseEvent( event->button );
#endif
break; break;
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
@ -294,7 +284,7 @@ static void SDLash_EventFilter( SDL_Event *event )
dy /= (float)refState.height; dy /= (float)refState.height;
} }
// IN_TouchEvent( type, event->tfinger.fingerId, x, y, dx, dy ); IN_TouchEvent( type, event->tfinger.fingerId, x, y, dx, dy );
break; break;
} }
@ -469,4 +459,21 @@ void* Platform_GetNativeObject( const char *name )
return NULL; // SDL don't have it return NULL; // SDL don't have it
} }
/*
========================
Platform_PreCreateMove
this should disable mouse look on client when m_ignore enabled
TODO: kill mouse in win32 clients too
========================
*/
void Platform_PreCreateMove( void )
{
if( CVAR_TO_BOOL( m_ignore ) )
{
SDL_GetRelativeMouseState( NULL, NULL );
SDL_ShowCursor( SDL_TRUE );
}
}
#endif // defined( XASH_SDL ) && !defined( XASH_DEDICATED ) #endif // defined( XASH_SDL ) && !defined( XASH_DEDICATED )

Loading…
Cancel
Save