]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_phys.c
fix for lift blocking due to imprecision at very low frame times (slowmo)
[xonotic/darkplaces.git] / sv_phys.c
index 76b12e25f27b8d8b176f4392bce15be6b24cd263..99605cc26c05258af59b2a2ae6867d200b9178c0 100644 (file)
--- a/sv_phys.c
+++ b/sv_phys.c
@@ -623,38 +623,48 @@ void SV_PushMove (edict_t *pusher, float movetime)
                // if it is still inside the pusher, block
                if (SV_TestEntityPosition (check))
                {
-                       // fail the move
-                       if (check->v.mins[0] == check->v.maxs[0])
-                               continue;
-                       if (check->v.solid == SOLID_NOT || check->v.solid == SOLID_TRIGGER)
+                       // try moving the contacted entity a tiny bit further to account for precision errors
+                       pusher->v.solid = SOLID_NOT;
+                       VectorScale(move, 0.1, move);
+                       trace = SV_PushEntity (check, move, vec3_origin);
+                       pusher->v.solid = savesolid;
+                       if (SV_TestEntityPosition (check))
                        {
-                               // corpse
-                               check->v.mins[0] = check->v.mins[1] = 0;
-                               VectorCopy (check->v.mins, check->v.maxs);
-                               continue;
-                       }
+                               // still inside pusher, so it's really blocked
 
-                       VectorCopy (pushorig, pusher->v.origin);
-                       VectorCopy (pushang, pusher->v.angles);
-                       pusher->v.ltime = pushltime;
-                       SV_LinkEdict (pusher, false);
+                               // fail the move
+                               if (check->v.mins[0] == check->v.maxs[0])
+                                       continue;
+                               if (check->v.solid == SOLID_NOT || check->v.solid == SOLID_TRIGGER)
+                               {
+                                       // corpse
+                                       check->v.mins[0] = check->v.mins[1] = 0;
+                                       VectorCopy (check->v.mins, check->v.maxs);
+                                       continue;
+                               }
 
-                       // move back any entities we already moved
-                       for (i=0 ; i<num_moved ; i++)
-                       {
-                               VectorCopy (moved_from[i], moved_edict[i]->v.origin);
-                               VectorCopy (moved_fromangles[i], moved_edict[i]->v.angles);
-                               SV_LinkEdict (moved_edict[i], false);
-                       }
+                               VectorCopy (pushorig, pusher->v.origin);
+                               VectorCopy (pushang, pusher->v.angles);
+                               pusher->v.ltime = pushltime;
+                               SV_LinkEdict (pusher, false);
 
-                       // if the pusher has a "blocked" function, call it, otherwise just stay in place until the obstacle is gone
-                       if (pusher->v.blocked)
-                       {
-                               pr_global_struct->self = EDICT_TO_PROG(pusher);
-                               pr_global_struct->other = EDICT_TO_PROG(check);
-                               PR_ExecuteProgram (pusher->v.blocked, "");
+                               // move back any entities we already moved
+                               for (i=0 ; i<num_moved ; i++)
+                               {
+                                       VectorCopy (moved_from[i], moved_edict[i]->v.origin);
+                                       VectorCopy (moved_fromangles[i], moved_edict[i]->v.angles);
+                                       SV_LinkEdict (moved_edict[i], false);
+                               }
+
+                               // if the pusher has a "blocked" function, call it, otherwise just stay in place until the obstacle is gone
+                               if (pusher->v.blocked)
+                               {
+                                       pr_global_struct->self = EDICT_TO_PROG(pusher);
+                                       pr_global_struct->other = EDICT_TO_PROG(check);
+                                       PR_ExecuteProgram (pusher->v.blocked, "");
+                               }
+                               return;
                        }
-                       return;
                }
        }
 }
@@ -771,18 +781,18 @@ qboolean SV_CheckWater (edict_t *ent)
 
        ent->v.waterlevel = 0;
        ent->v.watertype = CONTENTS_EMPTY;
-       cont = Mod_PointInLeaf(point, sv.worldmodel)->contents;
+       cont = Mod_PointContents(point, sv.worldmodel);
        if (cont <= CONTENTS_WATER)
        {
                ent->v.watertype = cont;
                ent->v.waterlevel = 1;
                point[2] = ent->v.origin[2] + (ent->v.mins[2] + ent->v.maxs[2])*0.5;
-               cont = Mod_PointInLeaf(point, sv.worldmodel)->contents;
+               cont = Mod_PointContents(point, sv.worldmodel);
                if (cont <= CONTENTS_WATER)
                {
                        ent->v.waterlevel = 2;
                        point[2] = ent->v.origin[2] + ent->v.view_ofs[2];
-                       cont = Mod_PointInLeaf(point, sv.worldmodel)->contents;
+                       cont = Mod_PointContents(point, sv.worldmodel);
                        if (cont <= CONTENTS_WATER)
                                ent->v.waterlevel = 3;
                }
@@ -943,13 +953,11 @@ void SV_WalkMove (edict_t *ent)
 
        // check for stuckness, possibly due to the limited precision of floats
        // in the clipping hulls
-       /*
        if (clip
         && fabs(oldorg[1] - ent->v.origin[1]) < 0.03125
         && fabs(oldorg[0] - ent->v.origin[0]) < 0.03125)
                // stepping up didn't make any progress
                clip = SV_TryUnstick (ent, oldvel);
-       */
 
        // extra friction based on view angle
        if (clip & 2 && sv_wallfriction.integer)
@@ -961,7 +969,8 @@ void SV_WalkMove (edict_t *ent)
 
        if (downtrace.plane.normal[2] > 0.7)
        {
-               if (ent->v.solid == SOLID_BSP)
+               // LordHavoc: disabled this so you can walk on monsters/players
+               //if (ent->v.solid == SOLID_BSP)
                {
                        ent->v.flags =  (int)ent->v.flags | FL_ONGROUND;
                        ent->v.groundentity = EDICT_TO_PROG(downtrace.ent);
@@ -985,26 +994,20 @@ SV_Physics_Client
 Player character actions
 ================
 */
-void SV_Physics_Client (edict_t        *ent, int num)
+void SV_Physics_Client (edict_t *ent, int num)
 {
-       if ( ! svs.clients[num-1].active )
+       if (!svs.clients[num-1].active)
                return;         // unconnected slot
 
-//
-// call standard client pre-think
-//
+       // call standard client pre-think
        pr_global_struct->time = sv.time;
        pr_global_struct->self = EDICT_TO_PROG(ent);
        PR_ExecuteProgram (pr_global_struct->PlayerPreThink, "QC function PlayerPreThink is missing");
 
-//
-// do a move
-//
+       // do a move
        SV_CheckVelocity (ent);
 
-//
-// decide which move function to call
-//
+       // decide which move function to call
        switch ((int)ent->v.movetype)
        {
        case MOVETYPE_NONE:
@@ -1046,9 +1049,7 @@ void SV_Physics_Client (edict_t   *ent, int num)
                Host_Error ("SV_Physics_client: bad movetype %i", (int)ent->v.movetype);
        }
 
-//
-// call standard player post-think
-//
+       // call standard player post-think
        SV_LinkEdict (ent, true);
 
        pr_global_struct->time = sv.time;
@@ -1137,8 +1138,8 @@ SV_CheckWaterTransition
 */
 void SV_CheckWaterTransition (edict_t *ent)
 {
-       int             cont;
-       cont = Mod_PointInLeaf(ent->v.origin, sv.worldmodel)->contents;
+       int cont;
+       cont = Mod_PointContents(ent->v.origin, sv.worldmodel);
        if (!ent->v.watertype)
        {
                // just spawned here
@@ -1149,7 +1150,7 @@ void SV_CheckWaterTransition (edict_t *ent)
 
        if (cont <= CONTENTS_WATER)
        {
-               if (ent->v.watertype == CONTENTS_EMPTY)
+               if (ent->v.watertype == CONTENTS_EMPTY && cont != CONTENTS_LAVA)
                        // just crossed into water
                        SV_StartSound (ent, 0, "misc/h2ohit1.wav", 255, 1);
 
@@ -1158,7 +1159,7 @@ void SV_CheckWaterTransition (edict_t *ent)
        }
        else
        {
-               if (ent->v.watertype != CONTENTS_EMPTY)
+               if (ent->v.watertype != CONTENTS_EMPTY && ent->v.watertype != CONTENTS_LAVA)
                        // just crossed into water
                        SV_StartSound (ent, 0, "misc/h2ohit1.wav", 255, 1);
 
@@ -1293,7 +1294,7 @@ void SV_Physics_Step (edict_t *ent)
        {
                if (flags & FL_FLY)
                        fall = false;
-               else if ((flags & FL_SWIM) && Mod_PointInLeaf(ent->v.origin, sv.worldmodel)->contents != CONTENTS_EMPTY)
+               else if ((flags & FL_SWIM) && Mod_PointContents(ent->v.origin, sv.worldmodel) != CONTENTS_EMPTY)
                        fall = false;
        }
        if (fall && (flags & FL_ONGROUND) && ent->v.groundentity == 0)