From 801605f9f6d61a742c4415c9abba69e411968398 Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Wed, 31 Jul 2024 21:11:42 +1000 Subject: [PATCH] physics: fix a subtle prediction regression In 3d8f1ca7b142c0a9fd8c3b4a494b62dcce39ab71 a horizontal player speed calculation was changed to include the vertical velocity and to no longer be the speed, by use of the wrong macro. This patch reverts those changes and adds a macro for this calculation. Signed-off-by: bones_was_here --- cl_input.c | 2 +- mathlib.h | 1 + sv_user.c | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cl_input.c b/cl_input.c index 21c2ad64..5468a4e2 100644 --- a/cl_input.c +++ b/cl_input.c @@ -1367,7 +1367,7 @@ static void CL_ClientMovement_Physics_Walk(cl_clientmovement_state_t *s) wishspeed *= 0.5; // apply edge friction - speed = VectorLength2(s->velocity); + speed = Vector2Length(s->velocity); if (speed > 0) { friction = cl.movevars_friction; diff --git a/mathlib.h b/mathlib.h index 2fa93a1c..eee0373a 100644 --- a/mathlib.h +++ b/mathlib.h @@ -76,6 +76,7 @@ unsigned int CeilPowerOf2(unsigned int value); #define Vector2Set(a,b,c) ((a)[0]=(b),(a)[1]=(c)) #define Vector2Scale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale)) #define Vector2Normalize2(v,dest) {float ilength = (float)DotProduct2((v),(v));if (ilength) ilength = 1.0f / sqrt(ilength);dest[0] = (v)[0] * ilength;dest[1] = (v)[1] * ilength;} +#define Vector2Length(a) (sqrt(DotProduct2(a, a))) #define DotProduct4(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2]+(a)[3]*(b)[3]) #define Vector4Clear(a) ((a)[0]=(a)[1]=(a)[2]=(a)[3]=0) diff --git a/sv_user.c b/sv_user.c index 58bef9bf..1192e586 100644 --- a/sv_user.c +++ b/sv_user.c @@ -320,7 +320,7 @@ static void SV_UserFriction (void) vec3_t start, stop; trace_t trace; - speed = sqrt(PRVM_serveredictvector(host_client->edict, velocity)[0]*PRVM_serveredictvector(host_client->edict, velocity)[0]+PRVM_serveredictvector(host_client->edict, velocity)[1]*PRVM_serveredictvector(host_client->edict, velocity)[1]); + speed = Vector2Length(PRVM_serveredictvector(host_client->edict, velocity)); if (!speed) return; -- 2.39.2