]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_user.c
reworked predicted player physics to call PlayerPreThink before the move and PlayerPo...
[xonotic/darkplaces.git] / sv_user.c
index f4ea2cff108f05307edf58b408924779411d699f..8dbd05c0e818dc1067061fc7b04ac4501835688e 100644 (file)
--- a/sv_user.c
+++ b/sv_user.c
@@ -379,10 +379,25 @@ the move fields specify an intended velocity in pix/sec
 the angle fields specify an exact angular motion in degrees
 ===================
 */
+extern cvar_t sv_playerphysicsqc;
 void SV_ClientThink (void)
 {
        vec3_t v_angle;
 
+       SV_ApplyClientMove();
+       // make sure the velocity is sane (not a NaN)
+       SV_CheckVelocity(host_client->edict);
+
+       // LordHavoc: QuakeC replacement for SV_ClientThink (player movement)
+       if (prog->funcoffsets.SV_PlayerPhysics && sv_playerphysicsqc.integer)
+       {
+               prog->globals.server->time = sv.time;
+               prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
+               PRVM_ExecuteProgram (prog->funcoffsets.SV_PlayerPhysics, "QC function SV_PlayerPhysics is missing");
+               SV_CheckVelocity(host_client->edict);
+               return;
+       }
+
        if (host_client->edict->fields.server->movetype == MOVETYPE_NONE)
                return;
 
@@ -409,6 +424,7 @@ void SV_ClientThink (void)
        if ( (int)host_client->edict->fields.server->flags & FL_WATERJUMP )
        {
                SV_WaterJump ();
+               SV_CheckVelocity(host_client->edict);
                return;
        }
 
@@ -426,10 +442,12 @@ void SV_ClientThink (void)
        if ((host_client->edict->fields.server->waterlevel >= 2) && (host_client->edict->fields.server->movetype != MOVETYPE_NOCLIP))
        {
                SV_WaterMove ();
+               SV_CheckVelocity(host_client->edict);
                return;
        }
 
        SV_AirMove ();
+       SV_CheckVelocity(host_client->edict);
 }
 
 /*
@@ -456,6 +474,9 @@ void SV_ReadClientMove (void)
        if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__);
        move->receivetime = (float)sv.time;
 
+#if DEBUGMOVES
+       Con_Printf("%s move%i #%i %ims (%ims) %i %i '%i %i %i' '%i %i %i'\n", move->time > move->receivetime ? "^3read future" : "^4read normal", sv_numreadmoves + 1, move->sequence, (int)floor((move->time - host_client->cmd.time) * 1000.0 + 0.5), (int)floor(move->time * 1000.0 + 0.5), move->impulse, move->buttons, (int)move->viewangles[0], (int)move->viewangles[1], (int)move->viewangles[2], (int)move->forwardmove, (int)move->sidemove, (int)move->upmove);
+#endif
        // limit reported time to current time
        // (incase the client is trying to cheat)
        move->time = min(move->time, move->receivetime + sv.frametime);
@@ -527,12 +548,6 @@ void SV_ReadClientMove (void)
                move->buttons |= host_client->cmd.buttons;
        }
 
-       // disable clientside movement prediction in some cases
-       if (ceil((move->receivetime - move->time) * 1000.0) < sv_clmovement_minping.integer)
-               host_client->clmovement_disabletimeout = realtime + sv_clmovement_minping_disabletime.value / 1000.0;
-       if (!sv_clmovement_enable.integer || host_client->clmovement_disabletimeout > realtime)
-               move->sequence = 0;
-
        // now store this move for later execution
        // (we have to buffer the moves because of old ones being repeated)
        if (sv_numreadmoves < CL_MAX_USERCMDS)
@@ -548,12 +563,20 @@ void SV_ExecuteClientMoves(void)
 #ifdef NUM_PING_TIMES
        double total;
 #endif
+       prvm_eval_t *val;
        if (sv_numreadmoves < 1)
                return;
        // only start accepting input once the player is spawned
        if (!host_client->spawned)
                return;
-       if (sv_readmoves[sv_numreadmoves-1].sequence && sv_clmovement_enable.integer && sv_clmovement_waitforinput.integer > 0)
+#if DEBUGMOVES
+       Con_Printf("SV_ExecuteClientMoves: read %i moves at sv.time %f\n", sv_numreadmoves, (float)sv.time);
+#endif
+       // disable clientside movement prediction in some cases
+       if (ceil(max(sv_readmoves[sv_numreadmoves-1].receivetime - sv_readmoves[sv_numreadmoves-1].time, 0) * 1000.0) < sv_clmovement_minping.integer)
+               host_client->clmovement_disabletimeout = realtime + sv_clmovement_minping_disabletime.value / 1000.0;
+       // several conditions govern whether clientside movement prediction is allowed
+       if (sv_readmoves[sv_numreadmoves-1].sequence && sv_clmovement_enable.integer && sv_clmovement_waitforinput.integer > 0 && host_client->clmovement_disabletimeout <= realtime && host_client->edict->fields.server->movetype == MOVETYPE_WALK && (!(val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.disableclientprediction)) || !val->_float))
        {
                // process the moves in order and ignore old ones
                // but always trust the latest move
@@ -563,8 +586,11 @@ void SV_ExecuteClientMoves(void)
                for (moveindex = 0;moveindex < sv_numreadmoves;moveindex++)
                {
                        usercmd_t *move = sv_readmoves + moveindex;
-                       if (host_client->cmd.sequence < move->sequence || moveindex == sv_numreadmoves - 1)
+                       if (host_client->movesequence < move->sequence || moveindex == sv_numreadmoves - 1)
                        {
+#if DEBUGMOVES
+                               Con_Printf("%smove #%i %ims (%ims) %i %i '%i %i %i' '%i %i %i'\n", (move->time - host_client->cmd.time) > sv.frametime ? "^1" : "^2", move->sequence, (int)floor((move->time - host_client->cmd.time) * 1000.0 + 0.5), (int)floor(move->time * 1000.0 + 0.5), move->impulse, move->buttons, (int)move->viewangles[0], (int)move->viewangles[1], (int)move->viewangles[2], (int)move->forwardmove, (int)move->sidemove, (int)move->upmove);
+#endif
                                // this is a new move
                                moveframetime = bound(0, move->time - host_client->cmd.time, 0.1);
                                //Con_Printf("movesequence = %i (%i lost), moveframetime = %f\n", move->sequence, move->sequence ? move->sequence - host_client->movesequence - 1 : 0, moveframetime);
@@ -584,9 +610,14 @@ void SV_ExecuteClientMoves(void)
                                // update ping time for qc to see while executing this move
                                host_client->ping = host_client->cmd.receivetime - host_client->cmd.time;
                                // the server and qc frametime values must be changed temporarily
-                               sv.frametime = moveframetime;
-                               prog->globals.server->frametime = moveframetime;
-                               SV_Physics_ClientEntity(host_client->edict);
+                               prog->globals.server->frametime = sv.frametime = moveframetime;
+                               // if move is more than 50ms, split it into two moves (this matches QWSV behavior and the client prediction)
+                               if (sv.frametime > 0.05)
+                               {
+                                       prog->globals.server->frametime = sv.frametime = moveframetime * 0.5f;
+                                       SV_Physics_ClientMove();
+                               }
+                               SV_Physics_ClientMove();
                                sv.frametime = oldframetime2;
                                prog->globals.server->frametime = oldframetime;
                                host_client->clmovement_skipphysicsframes = sv_clmovement_waitforinput.integer;
@@ -609,8 +640,10 @@ void SV_ExecuteClientMoves(void)
                }
                // now copy the new move
                host_client->cmd = sv_readmoves[sv_numreadmoves-1];
+               host_client->movesequence = 0;
+               // make sure that normal physics takes over immediately
+               host_client->clmovement_skipphysicsframes = 0;
        }
-       host_client->movesequence = host_client->cmd.sequence;
 
        // calculate average ping time
        host_client->ping = host_client->cmd.receivetime - host_client->cmd.time;