]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_phys.c
added clearstencil parameter to R_Shadow_RenderMode_StencilShadowVolumes
[xonotic/darkplaces.git] / sv_phys.c
index 6ce4f9e11c0c418eaff7ba952aada09ccc1fe0ff..08e8aea87c51fee46e55efb034e4b8fb78276669 100644 (file)
--- a/sv_phys.c
+++ b/sv_phys.c
@@ -1999,20 +1999,75 @@ static void SV_Physics_Entity (prvm_edict_t *ent)
        }
 }
 
-void SV_Physics_ClientEntity (prvm_edict_t *ent)
+void SV_Physics_ClientMove(void)
 {
-       SV_ApplyClientMove();
+       prvm_edict_t *ent;
+       ent = host_client->edict;
+
+       // call player physics, this needs the proper frametime
+       prog->globals.server->frametime = sv.frametime;
+       SV_ClientThink();
+
+       // call standard client pre-think, with frametime = 0
+       prog->globals.server->time = sv.time;
+       prog->globals.server->frametime = 0;
+       prog->globals.server->self = PRVM_EDICT_TO_PROG(ent);
+       PRVM_ExecuteProgram (prog->globals.server->PlayerPreThink, "QC function PlayerPreThink is missing");
+       prog->globals.server->frametime = sv.frametime;
+
        // make sure the velocity is sane (not a NaN)
        SV_CheckVelocity(ent);
-       // LordHavoc: QuakeC replacement for SV_ClientThink (player movement)
-       if (prog->funcoffsets.SV_PlayerPhysics && sv_playerphysicsqc.integer)
+       // LordHavoc: a hack to ensure that the (rather silly) id1 quakec
+       // player_run/player_stand1 does not horribly malfunction if the
+       // velocity becomes a number that is both == 0 and != 0
+       // (sounds to me like NaN but to be absolutely safe...)
+       if (DotProduct(ent->fields.server->velocity, ent->fields.server->velocity) < 0.0001)
+               VectorClear(ent->fields.server->velocity);
+
+       // perform MOVETYPE_WALK behavior
+       if (!SV_CheckWater (ent) && ! ((int)ent->fields.server->flags & FL_WATERJUMP) )
+               SV_AddGravity (ent);
+       SV_CheckStuck (ent);
+       SV_WalkMove (ent);
+
+       SV_CheckVelocity (ent);
+
+       SV_LinkEdict (ent, true);
+
+       SV_CheckVelocity (ent);
+
+       // call standard player post-think, with frametime = 0
+       prog->globals.server->time = sv.time;
+       prog->globals.server->frametime = 0;
+       prog->globals.server->self = PRVM_EDICT_TO_PROG(ent);
+       PRVM_ExecuteProgram (prog->globals.server->PlayerPostThink, "QC function PlayerPostThink is missing");
+       prog->globals.server->frametime = sv.frametime;
+
+       if(ent->fields.server->fixangle)
        {
-               prog->globals.server->time = sv.time;
-               prog->globals.server->self = PRVM_EDICT_TO_PROG(ent);
-               PRVM_ExecuteProgram (prog->funcoffsets.SV_PlayerPhysics, "QC function SV_PlayerPhysics is missing");
+               // angle fixing was requested by physics code...
+               // so store the current angles for later use
+               memcpy(host_client->fixangle_angles, ent->fields.server->angles, sizeof(host_client->fixangle_angles));
+               host_client->fixangle_angles_set = TRUE;
+
+               // and clear fixangle for the next frame
+               ent->fields.server->fixangle = 0;
        }
-       else
-               SV_ClientThink ();
+}
+
+void SV_Physics_ClientEntity(prvm_edict_t *ent)
+{
+       // don't do physics on disconnected clients, FrikBot relies on this
+       if (!host_client->spawned)
+       {
+               memset(&host_client->cmd, 0, sizeof(host_client->cmd));
+               return;
+       }
+
+       // don't run physics here if running asynchronously
+       if (host_client->clmovement_skipphysicsframes <= 0)
+               SV_ClientThink();
+
        // make sure the velocity is sane (not a NaN)
        SV_CheckVelocity(ent);
        // LordHavoc: a hack to ensure that the (rather silly) id1 quakec
@@ -2021,6 +2076,7 @@ void SV_Physics_ClientEntity (prvm_edict_t *ent)
        // (sounds to me like NaN but to be absolutely safe...)
        if (DotProduct(ent->fields.server->velocity, ent->fields.server->velocity) < 0.0001)
                VectorClear(ent->fields.server->velocity);
+
        // call standard client pre-think
        prog->globals.server->time = sv.time;
        prog->globals.server->self = PRVM_EDICT_TO_PROG(ent);
@@ -2042,18 +2098,18 @@ void SV_Physics_ClientEntity (prvm_edict_t *ent)
                SV_Physics_Follow (ent);
                break;
        case MOVETYPE_NOCLIP:
-               if (SV_RunThink(ent))
-               {
-                       SV_CheckWater(ent);
-                       VectorMA(ent->fields.server->origin, sv.frametime, ent->fields.server->velocity, ent->fields.server->origin);
-                       VectorMA(ent->fields.server->angles, sv.frametime, ent->fields.server->avelocity, ent->fields.server->angles);
-               }
+               SV_RunThink(ent);
+               SV_CheckWater(ent);
+               VectorMA(ent->fields.server->origin, sv.frametime, ent->fields.server->velocity, ent->fields.server->origin);
+               VectorMA(ent->fields.server->angles, sv.frametime, ent->fields.server->avelocity, ent->fields.server->angles);
                break;
        case MOVETYPE_STEP:
                SV_Physics_Step (ent);
                break;
        case MOVETYPE_WALK:
-               if (SV_RunThink (ent))
+               SV_RunThink (ent);
+               // don't run physics here if running asynchronously
+               if (host_client->clmovement_skipphysicsframes <= 0)
                {
                        if (!SV_CheckWater (ent) && ! ((int)ent->fields.server->flags & FL_WATERJUMP) )
                                SV_AddGravity (ent);
@@ -2066,28 +2122,31 @@ void SV_Physics_ClientEntity (prvm_edict_t *ent)
        case MOVETYPE_BOUNCEMISSILE:
        case MOVETYPE_FLYMISSILE:
                // regular thinking
-               if (SV_RunThink (ent))
-                       SV_Physics_Toss (ent);
+               SV_RunThink (ent);
+               SV_Physics_Toss (ent);
                break;
        case MOVETYPE_FLY:
-               if (SV_RunThink (ent))
-               {
-                       SV_CheckWater (ent);
-                       SV_WalkMove (ent);
-               }
+               SV_RunThink (ent);
+               SV_CheckWater (ent);
+               SV_WalkMove (ent);
                break;
        default:
                Con_Printf ("SV_Physics_ClientEntity: bad movetype %i\n", (int)ent->fields.server->movetype);
                break;
        }
 
+       // decrement the countdown variable used to decide when to go back to
+       // synchronous physics
+       if (host_client->clmovement_skipphysicsframes > 0)
+               host_client->clmovement_skipphysicsframes--;
+
        SV_CheckVelocity (ent);
 
-       // call standard player post-think
        SV_LinkEdict (ent, true);
 
        SV_CheckVelocity (ent);
 
+       // call standard player post-think
        prog->globals.server->time = sv.time;
        prog->globals.server->self = PRVM_EDICT_TO_PROG(ent);
        PRVM_ExecuteProgram (prog->globals.server->PlayerPostThink, "QC function PlayerPostThink is missing");
@@ -2134,19 +2193,8 @@ void SV_Physics (void)
 
        // run physics on the client entities
        for (i = 1, ent = PRVM_EDICT_NUM(i), host_client = svs.clients;i <= svs.maxclients;i++, ent = PRVM_NEXT_EDICT(ent), host_client++)
-       {
                if (!ent->priv.server->free)
-               {
-                       // don't do physics on disconnected clients, FrikBot relies on this
-                       if (!host_client->spawned)
-                               memset(&host_client->cmd, 0, sizeof(host_client->cmd));
-                       // don't run physics here if running asynchronously
-                       else if (host_client->clmovement_skipphysicsframes > 0)
-                               host_client->clmovement_skipphysicsframes--;
-                       else
                                SV_Physics_ClientEntity(ent);
-               }
-       }
 
        // run physics on all the non-client entities
        if (!sv_freezenonclients.integer)