From 5e81772eba5b0a6e8c55efff6c9e44d57becc286 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 9 Feb 2016 21:18:19 -0800 Subject: [PATCH] Split IN_Move into 2 functions --- quakespasm/Quake/in_sdl.c | 62 +++++++++++++++++++++++++++++++++------ quakespasm/Quake/input.h | 2 +- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/quakespasm/Quake/in_sdl.c b/quakespasm/Quake/in_sdl.c index 2b5e358f..77ea6efc 100644 --- a/quakespasm/Quake/in_sdl.c +++ b/quakespasm/Quake/in_sdl.c @@ -449,7 +449,7 @@ extern cvar_t cl_maxpitch; /* johnfitz -- variable pitch clamping */ extern cvar_t cl_minpitch; /* johnfitz -- variable pitch clamping */ -void IN_MouseMove(int dx, int dy) +void IN_MouseMotion(int dx, int dy) { total_dx += dx; total_dy += dy; @@ -541,11 +541,14 @@ void IN_ControllerAxis(SDL_JoystickID instanceid, SDL_GameControllerAxis axis, S } #endif -void IN_Move (usercmd_t *cmd) +void IN_JoyMove (usercmd_t *cmd) { int dmx, dmy; float joy_dx = 0.0f, joy_dy = 0.0f; + if (!joy_enabled.value) + return; + #if defined(USE_SDL2) // jeremiah sypult -- BEGIN joystick // @@ -603,11 +606,8 @@ void IN_Move (usercmd_t *cmd) // // jeremiah sypult -- ENDjoystick - dmx = (total_dx * sensitivity.value) + joy_dx; - dmy = (total_dy * sensitivity.value) + joy_dy; - - total_dx = 0; - total_dy = 0; + dmx = joy_dx; + dmy = joy_dy; if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) )) cmd->sidemove += m_side.value * dmx; @@ -638,6 +638,51 @@ void IN_Move (usercmd_t *cmd) } } +void IN_MouseMove(usercmd_t *cmd) +{ + int dmx, dmy; + + dmx = total_dx * sensitivity.value; + dmy = total_dy * sensitivity.value; + + total_dx = 0; + total_dy = 0; + + if ((in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1))) + cmd->sidemove += m_side.value * dmx; + else + cl.viewangles[YAW] -= m_yaw.value * dmx; + + if (in_mlook.state & 1) + { + if (dmx || dmy) + V_StopPitchDrift(); + } + + if ((in_mlook.state & 1) && !(in_strafe.state & 1)) + { + cl.viewangles[PITCH] += m_pitch.value * dmy; + /* johnfitz -- variable pitch clamping */ + if (cl.viewangles[PITCH] > cl_maxpitch.value) + cl.viewangles[PITCH] = cl_maxpitch.value; + if (cl.viewangles[PITCH] < cl_minpitch.value) + cl.viewangles[PITCH] = cl_minpitch.value; + } + else + { + if ((in_strafe.state & 1) && noclip_anglehack) + cmd->upmove -= m_forward.value * dmy; + else + cmd->forwardmove -= m_forward.value * dmy; + } +} + +void IN_Move(usercmd_t *cmd) +{ + IN_JoyMove(cmd); + IN_MouseMove(cmd); +} + void IN_ClearStates (void) { } @@ -975,7 +1020,7 @@ void IN_SendKeyEvents (void) #endif case SDL_MOUSEMOTION: - IN_MouseMove(event.motion.xrel, event.motion.yrel); + IN_MouseMotion(event.motion.xrel, event.motion.yrel); break; #if defined(USE_SDL2) @@ -1027,4 +1072,3 @@ void IN_SendKeyEvents (void) } } } - diff --git a/quakespasm/Quake/input.h b/quakespasm/Quake/input.h index ed7877fa..fe551fb0 100644 --- a/quakespasm/Quake/input.h +++ b/quakespasm/Quake/input.h @@ -32,7 +32,7 @@ void IN_Commands (void); // oportunity for devices to stick commands on the script buffer // mouse moved by dx and dy pixels -void IN_MouseMove(int dx, int dy); +void IN_MouseMotion(int dx, int dy); void IN_SendKeyEvents (void);