From 6deee3ec9b63c3f7e35eb96ba68f5fc4d9e65037 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 3 Aug 2020 22:33:43 +1000 Subject: [PATCH] Apply stair smoothing to other players too --- qcsrc/client/csqcmodel_hooks.qc | 2 ++ qcsrc/lib/csqcmodel/cl_player.qc | 29 ++++++++++++++++------------- qcsrc/lib/csqcmodel/cl_player.qh | 1 + 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/qcsrc/client/csqcmodel_hooks.qc b/qcsrc/client/csqcmodel_hooks.qc index 82b045801..fa7b2ae0e 100644 --- a/qcsrc/client/csqcmodel_hooks.qc +++ b/qcsrc/client/csqcmodel_hooks.qc @@ -677,6 +677,8 @@ void CSQCModel_Hook_PreDraw(entity this, bool isplayer) tracebox(this.origin + '0 0 1', this.mins, this.maxs, this.origin - '0 0 4', MOVE_NORMAL, this); if(trace_startsolid || trace_fraction < 1) onground = 1; + // predicted clients handle smoothing in the prediction code + this.origin = CSQCModel_ApplyStairSmoothing(this, onground, this.origin); } animdecide_load_if_needed(this); animdecide_setimplicitstate(this, onground); diff --git a/qcsrc/lib/csqcmodel/cl_player.qc b/qcsrc/lib/csqcmodel/cl_player.qc index 46beffa68..247f94100 100644 --- a/qcsrc/lib/csqcmodel/cl_player.qc +++ b/qcsrc/lib/csqcmodel/cl_player.qc @@ -239,24 +239,26 @@ vector CSQCPlayer_ApplySmoothing(entity this, vector v) } // simplified copy of CSQCPlayer_ApplySmoothing for use on player models -float mdl_stairsmoothz; -float mdl_smooth_prevtime; -vector CSQCModel_ApplyStairSmoothing(entity this, vector v) +.float stairsmooth_offset; +.float stairsmooth_prevtime; +.float stairsmooth_drawtime; // holds the previous draw time +vector CSQCModel_ApplyStairSmoothing(entity this, bool isonground, vector v) { - float smoothtime = bound(0, time - mdl_smooth_prevtime, 0.1); - mdl_smooth_prevtime = max(mdl_smooth_prevtime, drawtime); // drawtime is the previous frame's time at this point + float smoothtime = bound(0, time - this.stairsmooth_prevtime, 0.1); + this.stairsmooth_prevtime = max(this.stairsmooth_prevtime, this.stairsmooth_drawtime); // stairsmooth_drawtime is the previous frame's time at this point - if(this.csqcmodel_teleported || !(this.pmove_flags & PMF_ONGROUND) || autocvar_cl_stairsmoothspeed <= 0 || this.ground_networkentity) - mdl_stairsmoothz = v.z; + if(this.csqcmodel_teleported || !isonground || autocvar_cl_stairsmoothspeed <= 0 || this.ground_networkentity) + this.stairsmooth_offset = v.z; else { - if(mdl_stairsmoothz < v.z) - v.z = mdl_stairsmoothz = bound(v.z - PHYS_STEPHEIGHT(this), mdl_stairsmoothz + smoothtime * autocvar_cl_stairsmoothspeed, v.z); - else if(mdl_stairsmoothz > v.z) - v.z = mdl_stairsmoothz = bound(v.z, mdl_stairsmoothz - smoothtime * autocvar_cl_stairsmoothspeed, v.z + PHYS_STEPHEIGHT(this)); + if(this.stairsmooth_offset < v.z) + v.z = this.stairsmooth_offset = bound(v.z - PHYS_STEPHEIGHT(this), this.stairsmooth_offset + smoothtime * autocvar_cl_stairsmoothspeed, v.z); + else if(this.stairsmooth_offset > v.z) + v.z = this.stairsmooth_offset = bound(v.z, this.stairsmooth_offset - smoothtime * autocvar_cl_stairsmoothspeed, v.z + PHYS_STEPHEIGHT(this)); } - mdl_smooth_prevtime = time; + this.stairsmooth_prevtime = time; + this.stairsmooth_drawtime = drawtime; return v; } @@ -597,7 +599,8 @@ void CSQCPlayer_SetCamera() } // relink - e.origin = CSQCModel_ApplyStairSmoothing(e, e.origin); + e.stairsmooth_drawtime = drawtime; // since drawtime is a frame old at this point, copy it now to avoid using a drawtime 2 frames old! + e.origin = CSQCModel_ApplyStairSmoothing(e, (e.pmove_flags & PMF_ONGROUND), e.origin); setorigin(e, e.origin); } diff --git a/qcsrc/lib/csqcmodel/cl_player.qh b/qcsrc/lib/csqcmodel/cl_player.qh index af708da25..925c9bd07 100644 --- a/qcsrc/lib/csqcmodel/cl_player.qh +++ b/qcsrc/lib/csqcmodel/cl_player.qh @@ -39,3 +39,4 @@ void CSQCPlayer_SetCamera(); float CSQCPlayer_PreUpdate(entity this); float CSQCPlayer_PostUpdate(entity this); float CSQCPlayer_IsLocalPlayer(entity this); +vector CSQCModel_ApplyStairSmoothing(entity this, bool isonground, vector v); -- 2.39.2