Browse Source

input: provide a common function for collecting input from different sources

pull/2/head
Alibek Omarov 6 years ago
parent
commit
da094fa04e
  1. 116
      engine/client/input.c

116
engine/client/input.c

@ -493,6 +493,47 @@ void IN_JoyAppendMove( usercmd_t *cmd, float forwardmove, float sidemove ) @@ -493,6 +493,47 @@ void IN_JoyAppendMove( usercmd_t *cmd, float forwardmove, float sidemove )
}
}
void IN_CollectInput( float *forward, float *side, float *pitch, float *yaw, qboolean includeSdlMouse )
{
if( !m_ignore->value )
{
#if XASH_INPUT == INPUT_SDL
if( includeSdlMouse )
{
int x, y;
SDL_GetMouseState( &x, &y );
*pitch += y * m_pitch->value;
*yaw -= x * m_yaw->value;
}
#endif // INPUT_SDL
#ifdef __ANDROID__
{
float x, y;
Android_MouseMove( &x, &y );
*pitch += y * m_pitch->value;
*yaw -= x * m_yaw->value;
}
#endif // ANDROID
}
Joy_FinalizeMove( forward, side, yaw, pitch );
IN_TouchMove( forward, side, yaw, pitch );
#ifdef USE_EVDEV
IN_EvdevMove( yaw, pitch );
#endif
if( look_filter->value )
{
*pitch = ( inputstate.lastpitch + *pitch ) / 2;
*yaw = ( inputstate.lastyaw + *yaw ) / 2;
inputstate.lastpitch = *pitch;
inputstate.lastyaw = *yaw;
}
}
/*
================
IN_EngineAppendMove
@ -502,7 +543,7 @@ Called from cl_main.c after generating command in client @@ -502,7 +543,7 @@ Called from cl_main.c after generating command in client
*/
void IN_EngineAppendMove( float frametime, usercmd_t *cmd, qboolean active )
{
float forward, side, dpitch, dyaw;
float forward, side, pitch, yaw;
if( clgame.dllFuncs.pfnLookEvent )
return;
@ -510,45 +551,18 @@ void IN_EngineAppendMove( float frametime, usercmd_t *cmd, qboolean active ) @@ -510,45 +551,18 @@ void IN_EngineAppendMove( float frametime, usercmd_t *cmd, qboolean active )
if( cls.key_dest != key_game || cl.paused || cl.intermission )
return;
forward = side = dpitch = dyaw = 0;
forward = side = pitch = yaw = 0;
if(active)
if( active )
{
float sensitivity = ( (float)RI.fov_x / (float)90.0f );
#if XASH_INPUT == INPUT_SDL
if( m_enginemouse->value && !m_ignore->value )
{
int mouse_x, mouse_y;
SDL_GetRelativeMouseState( &mouse_x, &mouse_y );
RI.viewangles[PITCH] += mouse_y * m_pitch->value * sensitivity;
RI.viewangles[YAW] -= mouse_x * m_yaw->value * sensitivity;
}
#endif
#ifdef __ANDROID__
if( !m_ignore->value )
{
float mouse_x, mouse_y;
Android_MouseMove( &mouse_x, &mouse_y );
RI.viewangles[PITCH] += mouse_y * m_pitch->value * sensitivity;
RI.viewangles[YAW] -= mouse_x * m_yaw->value * sensitivity;
}
#endif
Joy_FinalizeMove( &forward, &side, &dyaw, &dpitch );
IN_TouchMove( &forward, &side, &dyaw, &dpitch );
IN_CollectInput( &forward, &side, &yaw, &pitch, m_enginemouse->value );
IN_JoyAppendMove( cmd, forward, side );
#ifdef USE_EVDEV
IN_EvdevMove( &dyaw, &dpitch );
#endif
if( look_filter->value )
{
dpitch = ( inputstate.lastpitch + dpitch ) / 2;
dyaw = ( inputstate.lastyaw + dyaw ) / 2;
inputstate.lastpitch = dpitch;
inputstate.lastyaw = dyaw;
}
RI.viewangles[YAW] += dyaw * sensitivity;
RI.viewangles[PITCH] += dpitch * sensitivity;
RI.viewangles[YAW] += yaw * sensitivity;
RI.viewangles[PITCH] += pitch * sensitivity;
RI.viewangles[PITCH] = bound( -90, RI.viewangles[PITCH], 90 );
}
}
@ -573,37 +587,7 @@ void Host_InputFrame( void ) @@ -573,37 +587,7 @@ void Host_InputFrame( void )
if( clgame.dllFuncs.pfnLookEvent )
{
int dx, dy;
#ifndef __ANDROID__
if( in_mouseinitialized && !m_ignore->value )
{
SDL_GetRelativeMouseState( &dx, &dy );
pitch += dy * m_pitch->value, yaw -= dx * m_yaw->value; //mouse speed
}
#endif
#ifdef __ANDROID__
if( !m_ignore->value )
{
float mouse_x, mouse_y;
Android_MouseMove( &mouse_x, &mouse_y );
pitch += mouse_y * m_pitch->value, yaw -= mouse_x * m_yaw->value; //mouse speed
}
#endif
Joy_FinalizeMove( &forward, &side, &yaw, &pitch );
IN_TouchMove( &forward, &side, &yaw, &pitch );
#ifdef USE_EVDEV
IN_EvdevMove( &yaw, &pitch );
#endif
if( look_filter->value )
{
pitch = ( inputstate.lastpitch + pitch ) / 2;
yaw = ( inputstate.lastyaw + yaw ) / 2;
inputstate.lastpitch = pitch;
inputstate.lastyaw = yaw;
}
IN_CollectInput( &forward, &side, &yaw, &pitch, in_mouseinitialized );
if( cls.key_dest == key_game )
{

Loading…
Cancel
Save