From 68b9ca890671794845c8f682ce3fd219345fa73c Mon Sep 17 00:00:00 2001 From: Chris Cowan Date: Sun, 5 Mar 2023 04:53:13 -0800 Subject: [PATCH] Fix joystick movement threshold and run behavior Fixes issue where holding the movement joystick at a 45 degree angle would instead make you move at a 41 degree angle if you had "Always Run" set to "Vanilla" or at a 60 degree angle. Fixes issue where holding the movement joystick all the way while not running would make you move at speed 283 instead of 200. Fixes issue where while running you reach the maximum speed while holding the joystick at only 83% (when joy_exponent_move is at its default value of 3, and when joy_exponent_move is 2, 75%, and when joy_exponent_move is 1, 57%). --- Quake/in_sdl.c | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/Quake/in_sdl.c b/Quake/in_sdl.c index 6e482f6f..7c63899b 100644 --- a/Quake/in_sdl.c +++ b/Quake/in_sdl.c @@ -475,29 +475,6 @@ static joyaxis_t IN_ApplyEasing(joyaxis_t axis, float exponent) return result; } -/* -================ -IN_ApplyMoveEasing - -same as IN_ApplyEasing, but scales the output by sqrt(2). -this gives diagonal stick inputs coordinates of (+/-1,+/-1). - -forward/back/left/right will return +/- 1.41; this shouldn't be a problem because -you can pull back on the stick to go slower (and the final speed is clamped -by sv_maxspeed). -================ -*/ -static joyaxis_t IN_ApplyMoveEasing(joyaxis_t axis, float exponent) -{ - joyaxis_t result = IN_ApplyEasing(axis, exponent); - const float v = sqrtf(2.0f); - - result.x *= v; - result.y *= v; - - return result; -} - /* ================ IN_ApplyDeadzone @@ -668,6 +645,7 @@ void IN_JoyMove (usercmd_t *cmd) float speed; joyaxis_t moveRaw, moveDeadzone, moveEased; joyaxis_t lookRaw, lookDeadzone, lookEased; + extern cvar_t sv_maxspeed; if (!joy_enable.value) return; @@ -693,16 +671,21 @@ void IN_JoyMove (usercmd_t *cmd) moveDeadzone = IN_ApplyDeadzone(moveRaw, joy_deadzone_move.value, joy_outer_threshold_move.value); lookDeadzone = IN_ApplyDeadzone(lookRaw, joy_deadzone_look.value, joy_outer_threshold_look.value); - moveEased = IN_ApplyMoveEasing(moveDeadzone, joy_exponent_move.value); + moveEased = IN_ApplyEasing(moveDeadzone, joy_exponent_move.value); lookEased = IN_ApplyEasing(lookDeadzone, joy_exponent.value); - - if ((in_speed.state & 1) ^ (cl_alwaysrun.value != 0.0)) - speed = cl_movespeedkey.value; - else - speed = 1; - cmd->sidemove += (cl_sidespeed.value * speed * moveEased.x); - cmd->forwardmove -= (cl_forwardspeed.value * speed * moveEased.y); + if ((in_speed.state & 1) ^ (cl_alwaysrun.value != 0.0 || cl_forwardspeed.value >= sv_maxspeed.value)) + // running + speed = sv_maxspeed.value; + else if (cl_forwardspeed.value >= sv_maxspeed.value) + // not running, with always run = vanilla + speed = q_min(sv_maxspeed.value, cl_forwardspeed.value / cl_movespeedkey.value); + else + // not running, with always run = off or quakespasm + speed = cl_forwardspeed.value; + + cmd->sidemove += speed * moveEased.x; + cmd->forwardmove -= speed * moveEased.y; cl.viewangles[YAW] -= lookEased.x * joy_sensitivity_yaw.value * host_frametime; cl.viewangles[PITCH] += lookEased.y * joy_sensitivity_pitch.value * (joy_invert.value ? -1.0 : 1.0) * host_frametime;