]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_input.c
input: limit cl_netrepeatinput to 3
[xonotic/darkplaces.git] / cl_input.c
index a9da42ccf43cbc494461347617dbf084c3e82e96..be77aaafe42de23ea79d83fc2e2df28059a6a58e 100644 (file)
@@ -301,6 +301,7 @@ void IN_BestWeapon (void)
        // if we couldn't find any of the weapons, there's nothing more we can do...
 }
 
+#if 0
 void IN_CycleWeapon (void)
 {
        int i, n;
@@ -347,6 +348,7 @@ void IN_CycleWeapon (void)
        }
        // if we couldn't find any of the weapons, there's nothing more we can do...
 }
+#endif
 
 /*
 ===============
@@ -413,6 +415,7 @@ cvar_t cl_backspeed = {CVAR_SAVE, "cl_backspeed","400","backward movement speed"
 cvar_t cl_sidespeed = {CVAR_SAVE, "cl_sidespeed","350","strafe movement speed"};
 
 cvar_t cl_movespeedkey = {CVAR_SAVE, "cl_movespeedkey","2.0","how much +speed multiplies keyboard movement speed"};
+cvar_t cl_movecliptokeyboard = {0, "cl_movecliptokeyboard", "0", "if set to 1, any move is clipped to the nine keyboard states; if set to 2, only the direction is clipped, not the amount"};
 
 cvar_t cl_yawspeed = {CVAR_SAVE, "cl_yawspeed","140","keyboard yaw turning speed"};
 cvar_t cl_pitchspeed = {CVAR_SAVE, "cl_pitchspeed","150","keyboard pitch turning speed"};
@@ -441,6 +444,10 @@ cvar_t in_pitch_min = {0, "in_pitch_min", "-90", "how far downward you can aim (
 cvar_t in_pitch_max = {0, "in_pitch_max", "90", "how far upward you can aim (quake used 80"};
 
 cvar_t m_filter = {CVAR_SAVE, "m_filter","0", "smoothes mouse movement, less responsive but smoother aiming"};
+cvar_t m_accelerate = {CVAR_SAVE, "m_accelerate","1", "mouse acceleration factor (try 2)"};
+cvar_t m_accelerate_minspeed = {CVAR_SAVE, "m_accelerate_minspeed","5000", "below this speed, no acceleration is done"};
+cvar_t m_accelerate_maxspeed = {CVAR_SAVE, "m_accelerate_maxspeed","10000", "above this speed, full acceleration is done"};
+cvar_t m_accelerate_filter = {CVAR_SAVE, "m_accelerate_filter","0.1", "mouse acceleration factor filtering"};
 
 cvar_t cl_netfps = {CVAR_SAVE, "cl_netfps","20", "how many input packets to send to server each second"};
 cvar_t cl_netrepeatinput = {CVAR_SAVE, "cl_netrepeatinput", "1", "how many packets in a row can be lost without movement issues when using cl_movement (technically how many input messages to repeat in each packet that have not yet been acknowledged by the server), only affects DP7 and later servers (Quake uses 0, QuakeWorld uses 2, and just for comparison Quake3 uses 1)"};
@@ -553,6 +560,47 @@ void CL_Input (void)
        // allow mice or other external controllers to add to the move
        IN_Move ();
 
+       // apply m_accelerate if it is on
+       if(m_accelerate.value > 1)
+       {
+               static float averagespeed = 0;
+               float speed, f, mi, ma;
+
+               speed = sqrt(in_mouse_x * in_mouse_x + in_mouse_y * in_mouse_y) / cl.realframetime;
+               if(m_accelerate_filter.value > 0)
+                       f = bound(0, cl.realframetime / m_accelerate_filter.value, 1);
+               else
+                       f = 1;
+               averagespeed = speed * f + averagespeed * (1 - f);
+
+               mi = max(1, m_accelerate_minspeed.value);
+               ma = max(m_accelerate_minspeed.value + 1, m_accelerate_maxspeed.value);
+
+               if(averagespeed <= mi)
+               {
+                       f = 1;
+               }
+               else if(averagespeed >= ma)
+               {
+                       f = m_accelerate.value;
+               }
+               else
+               {
+                       /*
+                       f = log(averagespeed);
+                       mi = log(mi);
+                       ma = log(ma);
+                       */
+                       f = averagespeed;
+                       mi = mi;
+                       ma = ma;
+                       f = (f - mi) / (ma - mi) * (m_accelerate.value - 1) + 1;
+               }
+
+               in_mouse_x *= f;
+               in_mouse_y *= f;
+       }
+
        // apply m_filter if it is on
        mx = in_mouse_x;
        my = in_mouse_y;
@@ -621,6 +669,71 @@ void CL_Input (void)
 
        // clamp after the move to prevent rendering with bad angles
        CL_AdjustAngles ();
+
+       if(cl_movecliptokeyboard.integer)
+       {
+               vec_t f = 1;
+               if (in_speed.state & 1)
+                       f *= cl_movespeedkey.value;
+               if(cl_movecliptokeyboard.integer == 2)
+               {
+                       // digital direction, analog amount
+                       vec_t wishvel_x, wishvel_y;
+                       f *= max(cl_sidespeed.value, max(cl_forwardspeed.value, cl_backspeed.value));
+                       wishvel_x = fabs(cl.cmd.forwardmove);
+                       wishvel_y = fabs(cl.cmd.sidemove);
+                       if(wishvel_x != 0 && wishvel_y != 0 && wishvel_x != wishvel_y)
+                       {
+                               vec_t wishspeed = sqrt(wishvel_x * wishvel_x + wishvel_y * wishvel_y);
+                               if(wishvel_x >= 2 * wishvel_y)
+                               {
+                                       // pure X motion
+                                       if(cl.cmd.forwardmove > 0)
+                                               cl.cmd.forwardmove = wishspeed;
+                                       else
+                                               cl.cmd.forwardmove = -wishspeed;
+                                       cl.cmd.sidemove = 0;
+                               }
+                               else if(wishvel_y >= 2 * wishvel_x)
+                               {
+                                       // pure Y motion
+                                       cl.cmd.forwardmove = 0;
+                                       if(cl.cmd.sidemove > 0)
+                                               cl.cmd.sidemove = wishspeed;
+                                       else
+                                               cl.cmd.sidemove = -wishspeed;
+                               }
+                               else
+                               {
+                                       // diagonal
+                                       if(cl.cmd.forwardmove > 0)
+                                               cl.cmd.forwardmove = 0.70710678118654752440 * wishspeed;
+                                       else
+                                               cl.cmd.forwardmove = -0.70710678118654752440 * wishspeed;
+                                       if(cl.cmd.sidemove > 0)
+                                               cl.cmd.sidemove = 0.70710678118654752440 * wishspeed;
+                                       else
+                                               cl.cmd.sidemove = -0.70710678118654752440 * wishspeed;
+                               }
+                       }
+               }
+               else if(cl_movecliptokeyboard.integer)
+               {
+                       // digital direction, digital amount
+                       if(cl.cmd.sidemove >= cl_sidespeed.value * f * 0.5)
+                               cl.cmd.sidemove = cl_sidespeed.value * f;
+                       else if(cl.cmd.sidemove <= -cl_sidespeed.value * f * 0.5)
+                               cl.cmd.sidemove = -cl_sidespeed.value * f;
+                       else
+                               cl.cmd.sidemove = 0;
+                       if(cl.cmd.forwardmove >= cl_forwardspeed.value * f * 0.5)
+                               cl.cmd.forwardmove = cl_forwardspeed.value * f;
+                       else if(cl.cmd.forwardmove <= -cl_backspeed.value * f * 0.5)
+                               cl.cmd.forwardmove = -cl_backspeed.value * f;
+                       else
+                               cl.cmd.forwardmove = 0;
+               }
+       }
 }
 
 #include "cl_collision.h"
@@ -781,7 +894,7 @@ void CL_ClientMovement_UpdateStatus(cl_clientmovement_state_t *s)
 
        // set onground
        VectorSet(origin1, s->origin[0], s->origin[1], s->origin[2] + 1);
-       VectorSet(origin2, s->origin[0], s->origin[1], s->origin[2] - 2);
+       VectorSet(origin2, s->origin[0], s->origin[1], s->origin[2] - 1); // -2 causes clientside doublejump bug at above 150fps, raising that to 300fps :)
        trace = CL_Move(origin1, s->mins, s->maxs, origin2, MOVE_NORMAL, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_PLAYERCLIP, true, true, NULL, false);
        s->onground = trace.fraction < 1 && trace.plane.normal[2] > 0.7;
 
@@ -988,6 +1101,79 @@ void CL_ClientMovement_Physics_CPM_PM_Aircontrol(cl_clientmovement_state_t *s, v
        s->velocity[2] = zspeed;
 }
 
+void CL_ClientMovement_Physics_PM_Accelerate(cl_clientmovement_state_t *s, vec3_t wishdir, vec_t wishspeed, vec_t accel, vec_t accelqw, vec_t sidefric)
+{
+       vec_t vel_straight, vel_z;
+       vec3_t vel_perpend;
+       vec_t addspeed;
+
+       vel_straight = DotProduct(s->velocity, wishdir);
+       vel_z = s->velocity[2];
+       VectorMA(s->velocity, -vel_straight, wishdir, vel_perpend); vel_perpend[2] -= vel_z;
+
+       addspeed = wishspeed - vel_straight;
+       if(addspeed > 0)
+               vel_straight = vel_straight + min(addspeed, accel * s->cmd.frametime * wishspeed) * accelqw;
+       if(wishspeed > 0)
+               vel_straight = vel_straight + min(wishspeed, accel * s->cmd.frametime * wishspeed) * (1 - accelqw);
+       
+       VectorScale(vel_perpend, 1 - s->cmd.frametime * wishspeed * sidefric, vel_perpend);
+
+       VectorMA(vel_perpend, vel_straight, wishdir, s->velocity);
+       s->velocity[2] += vel_z;
+}
+
+void CL_ClientMovement_Physics_PM_AirAccelerate(cl_clientmovement_state_t *s, vec3_t wishdir, vec_t wishspeed)
+{
+    vec3_t curvel, wishvel, acceldir, curdir;
+    float addspeed, accelspeed, curspeed;
+    float dot;
+
+    float airforwardaccel = cl.movevars_warsowbunny_airforwardaccel;
+    float bunnyaccel = cl.movevars_warsowbunny_accel;
+    float bunnytopspeed = cl.movevars_warsowbunny_topspeed;
+    float turnaccel = cl.movevars_warsowbunny_turnaccel;
+    float backtosideratio = cl.movevars_warsowbunny_backtosideratio;
+
+    if( !wishspeed )
+        return;
+
+    VectorCopy( s->velocity, curvel );
+    curvel[2] = 0;
+    curspeed = VectorLength( curvel );
+
+    if( wishspeed > curspeed * 1.01f )
+    {
+        float accelspeed = curspeed + airforwardaccel * cl.movevars_maxairspeed * s->cmd.frametime;
+        if( accelspeed < wishspeed )
+            wishspeed = accelspeed;
+    }
+    else
+    {
+        float f = ( bunnytopspeed - curspeed ) / ( bunnytopspeed - cl.movevars_maxairspeed );
+        if( f < 0 )
+            f = 0;
+        wishspeed = max( curspeed, cl.movevars_maxairspeed ) + bunnyaccel * f * cl.movevars_maxairspeed * s->cmd.frametime;
+    }
+    VectorScale( wishdir, wishspeed, wishvel );
+    VectorSubtract( wishvel, curvel, acceldir );
+    addspeed = VectorNormalizeLength( acceldir );
+
+    accelspeed = turnaccel * cl.movevars_maxairspeed /* wishspeed */ * s->cmd.frametime;
+    if( accelspeed > addspeed )
+        accelspeed = addspeed;
+
+    if( backtosideratio < 1.0f )
+    {
+        VectorNormalize2( curvel, curdir );
+        dot = DotProduct( acceldir, curdir );
+        if( dot < 0 )
+            VectorMA( acceldir, -( 1.0f - backtosideratio ) * dot, curdir, acceldir );
+    }
+
+    VectorMA( s->velocity, accelspeed, acceldir, s->velocity );
+}
+
 void CL_ClientMovement_Physics_Walk(cl_clientmovement_state_t *s)
 {
        vec_t friction;
@@ -1028,13 +1214,13 @@ void CL_ClientMovement_Physics_Walk(cl_clientmovement_state_t *s)
                VectorScale(wishvel, 1 / wishspeed, wishdir);
        else
                VectorSet( wishdir, 0.0, 0.0, 0.0 );
-       wishspeed = min(wishspeed, cl.movevars_maxspeed);
-       if (s->crouched)
-               wishspeed *= 0.5;
-
        // check if onground
        if (s->onground)
        {
+               wishspeed = min(wishspeed, cl.movevars_maxspeed);
+               if (s->crouched)
+                       wishspeed *= 0.5;
+
                // apply edge friction
                f = sqrt(s->velocity[0] * s->velocity[0] + s->velocity[1] * s->velocity[1]);
                if (f > 0)
@@ -1077,55 +1263,51 @@ void CL_ClientMovement_Physics_Walk(cl_clientmovement_state_t *s)
        {
                if (s->waterjumptime <= 0)
                {
-                       vec_t f;
-                       vec_t vel_straight;
-                       vec_t vel_z;
-                       vec3_t vel_perpend;
-                       float wishspeed2, accel;
-
                        // apply air speed limit
+                       vec_t accel, wishspeed2, accelqw;
+                       qboolean accelerating;
+
+                       accelqw = cl.movevars_airaccel_qw;
                        wishspeed = min(wishspeed, cl.movevars_maxairspeed);
+                       if (s->crouched)
+                               wishspeed *= 0.5;
                        accel = cl.movevars_airaccelerate;
-                       
-                       // CPM: air control
+
+                       accelerating = (DotProduct(s->velocity, wishdir) > 0);
                        wishspeed2 = wishspeed;
+
+                       // CPM: air control
                        if(cl.movevars_airstopaccelerate != 0)
                                if(DotProduct(s->velocity, wishdir) < 0)
                                        accel = cl.movevars_airstopaccelerate;
                        if(s->cmd.forwardmove == 0 && s->cmd.sidemove != 0)
                        {
                                if(cl.movevars_maxairstrafespeed)
+                               {
                                        if(wishspeed > cl.movevars_maxairstrafespeed)
                                                wishspeed = cl.movevars_maxairstrafespeed;
+                                       if(cl.movevars_maxairstrafespeed < cl.movevars_maxairspeed)
+                                               accelqw = 1;
+                                               // otherwise, CPMA-style air acceleration misbehaves a lot
+                                               // if partially non-QW acceleration is used (as in, strafing
+                                               // would get faster than moving forward straight)
+                               }
                                if(cl.movevars_airstrafeaccelerate)
+                               {
                                        accel = cl.movevars_airstrafeaccelerate;
+                                       if(cl.movevars_airstrafeaccelerate > cl.movevars_airaccelerate)
+                                               accelqw = 1;
+                                               // otherwise, CPMA-style air acceleration misbehaves a lot
+                                               // if partially non-QW acceleration is used (as in, strafing
+                                               // would get faster than moving forward straight)
+                               }
                        }
                        // !CPM
 
-                       /*
-                       addspeed = wishspeed - DotProduct(s->velocity, wishdir);
-                       if (addspeed > 0)
-                       {
-                               accelspeed = min(cl.movevars_accelerate * s->q.frametime * wishspeed, addspeed);
-                               VectorMA(s->velocity, accelspeed, wishdir, s->velocity);
-                       }
-                       */
-
-                       vel_straight = DotProduct(s->velocity, wishdir);
-                       vel_z = s->velocity[2];
-                       VectorMA(s->velocity, -vel_straight, wishdir, vel_perpend);
-                       vel_perpend[2] -= vel_z;
-
-                       f = wishspeed - vel_straight;
-                       if(f > 0)
-                               vel_straight += min(f, accel * s->cmd.frametime * wishspeed) * cl.movevars_airaccel_qw;
-                       if(wishspeed > 0)
-                               vel_straight += min(wishspeed, accel * s->cmd.frametime * wishspeed) * (1 - cl.movevars_airaccel_qw);
-
-                       VectorM(1 - (s->cmd.frametime * (wishspeed / cl.movevars_maxairspeed) * cl.movevars_airaccel_sideways_friction), vel_perpend, vel_perpend);
-
-                       VectorMA(vel_perpend, vel_straight, wishdir, s->velocity);
-                       s->velocity[2] += vel_z;
+                       if(cl.movevars_warsowbunny_turnaccel && accelerating && s->cmd.sidemove == 0 && s->cmd.forwardmove != 0)
+                               CL_ClientMovement_Physics_PM_AirAccelerate(s, wishdir, wishspeed2);
+                       else
+                               CL_ClientMovement_Physics_PM_Accelerate(s, wishdir, wishspeed, accel, accelqw, cl.movevars_airaccel_sideways_friction / cl.movevars_maxairspeed);
 
                        if(cl.movevars_aircontrol)
                                CL_ClientMovement_Physics_CPM_PM_Aircontrol(s, wishdir, wishspeed2);
@@ -1178,6 +1360,11 @@ void CL_UpdateMoveVars(void)
                cl.movevars_airstrafeaccelerate = cl.statsf[STAT_MOVEVARS_AIRSTRAFEACCELERATE];
                cl.movevars_maxairstrafespeed = cl.statsf[STAT_MOVEVARS_MAXAIRSTRAFESPEED];
                cl.movevars_aircontrol = cl.statsf[STAT_MOVEVARS_AIRCONTROL];
+               cl.movevars_warsowbunny_airforwardaccel = cl.statsf[STAT_MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL];
+               cl.movevars_warsowbunny_accel = cl.statsf[STAT_MOVEVARS_WARSOWBUNNY_ACCEL];
+               cl.movevars_warsowbunny_topspeed = cl.statsf[STAT_MOVEVARS_WARSOWBUNNY_TOPSPEED];
+               cl.movevars_warsowbunny_turnaccel = cl.statsf[STAT_MOVEVARS_WARSOWBUNNY_TURNACCEL];
+               cl.movevars_warsowbunny_backtosideratio = cl.statsf[STAT_MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO];
        }
        else
        {
@@ -1203,6 +1390,11 @@ void CL_UpdateMoveVars(void)
                cl.movevars_airstrafeaccelerate = 0;
                cl.movevars_maxairstrafespeed = 0;
                cl.movevars_aircontrol = 0;
+               cl.movevars_warsowbunny_airforwardaccel = 0;
+               cl.movevars_warsowbunny_accel = 0;
+               cl.movevars_warsowbunny_topspeed = 0;
+               cl.movevars_warsowbunny_turnaccel = 0;
+               cl.movevars_warsowbunny_backtosideratio = 0;
        }
 }
 
@@ -1593,7 +1785,7 @@ void CL_SendMove(void)
                case PROTOCOL_DARKPLACES6:
                case PROTOCOL_DARKPLACES7:
                        // set the maxusercmds variable to limit how many should be sent
-                       maxusercmds = bound(1, cl_netrepeatinput.integer + 1, CL_MAX_USERCMDS);
+                       maxusercmds = bound(1, cl_netrepeatinput.integer + 1, min(3, CL_MAX_USERCMDS));
                        // when movement prediction is off, there's not much point in repeating old input as it will just be ignored
                        if (!cl.cmd.predicted)
                                maxusercmds = 1;
@@ -1788,9 +1980,12 @@ void CL_InitInput (void)
 
        // LordHavoc: added bestweapon command
        Cmd_AddCommand ("bestweapon", IN_BestWeapon, "send an impulse number to server to select the first usable weapon out of several (example: 8 7 6 5 4 3 2 1)");
+#if 0
        Cmd_AddCommand ("cycleweapon", IN_CycleWeapon, "send an impulse number to server to select the next usable weapon out of several (example: 9 4 8) if you are holding one of these, and choose the first one if you are holding none of these");
+#endif
        Cmd_AddCommand ("register_bestweapon", IN_BestWeapon_Register_f, "(for QC usage only) change weapon parameters to be used by bestweapon; stuffcmd this in ClientConnect");
 
+       Cvar_RegisterVariable(&cl_movecliptokeyboard);
        Cvar_RegisterVariable(&cl_movement);
        Cvar_RegisterVariable(&cl_movement_minping);
        Cvar_RegisterVariable(&cl_movement_track_canjump);
@@ -1812,6 +2007,10 @@ void CL_InitInput (void)
        Cvar_RegisterVariable(&in_pitch_min);
        Cvar_RegisterVariable(&in_pitch_max);
        Cvar_RegisterVariable(&m_filter);
+       Cvar_RegisterVariable(&m_accelerate);
+       Cvar_RegisterVariable(&m_accelerate_minspeed);
+       Cvar_RegisterVariable(&m_accelerate_maxspeed);
+       Cvar_RegisterVariable(&m_accelerate_filter);
 
        Cvar_RegisterVariable(&cl_netfps);
        Cvar_RegisterVariable(&cl_netrepeatinput);