]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'master' into Mario/model_stair_smoothing
authorMario <mario.mario@y7mail.com>
Mon, 19 Oct 2020 10:08:47 +0000 (20:08 +1000)
committerMario <mario.mario@y7mail.com>
Mon, 19 Oct 2020 10:08:47 +0000 (20:08 +1000)
qcsrc/client/csqcmodel_hooks.qc
qcsrc/lib/csqcmodel/cl_player.qc
qcsrc/lib/csqcmodel/cl_player.qh

index 3adef84a4b5c72299ba8f8c5889013c0bd145833..6fea1efc04f2eb104864b3ed06db740b382dff38 100644 (file)
@@ -675,6 +675,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);
index d8ea2a070c4cb26031d99965d3a6d018c39ff4a9..247f941002ede58abcf97f1998e5f6ee33b99b1c 100644 (file)
@@ -238,6 +238,31 @@ vector CSQCPlayer_ApplySmoothing(entity this, vector v)
        return v;
 }
 
+// simplified copy of CSQCPlayer_ApplySmoothing for use on player models
+.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 - 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 || !isonground || autocvar_cl_stairsmoothspeed <= 0 || this.ground_networkentity)
+               this.stairsmooth_offset = v.z;
+       else
+       {
+               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));
+       }
+
+       this.stairsmooth_prevtime = time;
+       this.stairsmooth_drawtime = drawtime;
+
+       return v;
+}
+
 bool autocvar_v_deathtilt;
 float autocvar_v_deathtiltangle;
 void CSQCPlayer_ApplyDeathTilt(entity this)
@@ -574,6 +599,8 @@ void CSQCPlayer_SetCamera()
                }
 
                // relink
+               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);
        }
 
index af708da25170f30287fb59507dc3c17c75034dca..925c9bd07f6988024728a82a2a289fbee707fdfd 100644 (file)
@@ -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);