]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_collision.c
added pmove_onground to get this value from the engine prediction
[xonotic/darkplaces.git] / cl_collision.c
index f4744885794fd2a0a141d7cff21d3c0f83605766..79989532a39727173a44ff71218a44b180f30ec3 100644 (file)
@@ -18,12 +18,12 @@ float CL_SelectTraceLine(const vec3_t start, const vec3_t end, vec3_t impact, ve
        vec3_t end;
        vec_t len = 0;
 
-       if(!VectorCompare(start, pEnd))
+       if(!VectorCompare(start, pEnd) && collision_endposnudge.value > 0)
        {
                // TRICK: make the trace 1 qu longer!
                VectorSubtract(pEnd, start, end);
                len = VectorNormalizeLength(end);
-               VectorAdd(pEnd, end, end);
+               VectorMA(pEnd, collision_endposnudge.value, end, end);
        }
        else
                VectorCopy(pEnd, end);
@@ -72,8 +72,8 @@ float CL_SelectTraceLine(const vec3_t start, const vec3_t end, vec3_t impact, ve
                Matrix4x4_Transform(&ent->inversematrix, end, endtransformed);
                Collision_ClipTrace_Box(&trace, ent->model->normalmins, ent->model->normalmaxs, starttransformed, vec3_origin, vec3_origin, endtransformed, SUPERCONTENTS_SOLID, SUPERCONTENTS_SOLID, 0, NULL);
 #ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
-               if(!VectorCompare(start, pEnd))
-                       Collision_ShortenTrace(&trace, len / (len + 1), pEnd);
+               if(!VectorCompare(start, pEnd) && collision_endposnudge.value > 0)
+                       Collision_ShortenTrace(&trace, len / (len + collision_endposnudge.value), pEnd);
 #endif
                if (maxrealfrac < trace.realfraction)
                        continue;
@@ -157,8 +157,8 @@ void CL_LinkEdict(prvm_edict_t *ent)
 
                if( model != NULL )
                {
-                       if (!model->TraceBox && developer.integer >= 1)
-                               Con_Printf("edict %i: SOLID_BSP with non-collidable model\n", PRVM_NUM_FOR_EDICT(ent));
+                       if (!model->TraceBox)
+                               Con_DPrintf("edict %i: SOLID_BSP with non-collidable model\n", PRVM_NUM_FOR_EDICT(ent));
 
                        if (ent->fields.client->angles[0] || ent->fields.client->angles[2] || ent->fields.client->avelocity[0] || ent->fields.client->avelocity[2])
                        {
@@ -197,12 +197,11 @@ void CL_LinkEdict(prvm_edict_t *ent)
 
 int CL_GenericHitSuperContentsMask(const prvm_edict_t *passedict)
 {
-       prvm_eval_t *val;
        if (passedict)
        {
-               val = PRVM_EDICTFIELDVALUE(passedict, prog->fieldoffsets.dphitcontentsmask);
-               if (val && val->_float)
-                       return (int)val->_float;
+               int dphitcontentsmask = (int)PRVM_EDICTFIELDFLOAT(passedict, prog->fieldoffsets.dphitcontentsmask);
+               if (dphitcontentsmask)
+                       return dphitcontentsmask;
                else if (passedict->fields.client->solid == SOLID_SLIDEBOX)
                {
                        if ((int)passedict->fields.client->flags & FL_MONSTER)
@@ -246,7 +245,7 @@ trace_t CL_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int
        dp_model_t *model;
        // list of entities to test for collisions
        int numtouchedicts;
-       prvm_edict_t *touchedicts[MAX_EDICTS];
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
 
        if (hitnetworkentity)
                *hitnetworkentity = 0;
@@ -321,7 +320,7 @@ trace_t CL_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int
                vec3_t origin, entmins, entmaxs;
                matrix4x4_t entmatrix, entinversematrix;
 
-               if(gamemode == GAME_NEXUIZ)
+               if(gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC)
                {
                        // don't hit network players, if we are a nonsolid player
                        if(cl.scores[cl.playerentity-1].frags == -666 || cl.scores[cl.playerentity-1].frags == -616)
@@ -340,7 +339,7 @@ trace_t CL_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int
                        if (!cl.scores[i-1].name[0])
                                continue;
 
-                       if(gamemode == GAME_NEXUIZ)
+                       if(gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC)
                        {
                                // don't hit spectators or nonsolid players
                                if(cl.scores[i-1].frags == -666 || cl.scores[i-1].frags == -616)
@@ -435,9 +434,9 @@ CL_TraceLine
 ==================
 */
 #ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
-trace_t CL_TraceLine(const vec3_t start, const vec3_t pEnd, int type, prvm_edict_t *passedict, int hitsupercontentsmask, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities)
+trace_t CL_TraceLine(const vec3_t start, const vec3_t pEnd, int type, prvm_edict_t *passedict, int hitsupercontentsmask, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities, qboolean hitsurfaces)
 #else
-trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities)
+trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities, qboolean hitsurfaces)
 #endif
 {
        int i, bodysupercontents;
@@ -458,24 +457,27 @@ trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_
        dp_model_t *model;
        // list of entities to test for collisions
        int numtouchedicts;
-       prvm_edict_t *touchedicts[MAX_EDICTS];
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
 #ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
        vec3_t end;
        vec_t len = 0;
 
-       if(!VectorCompare(start, pEnd))
+       if (VectorCompare(start, pEnd))
+               return CL_TracePoint(start, type, passedict, hitsupercontentsmask, hitnetworkbrushmodels, hitnetworkplayers, hitnetworkentity, hitcsqcentities);
+
+       if(collision_endposnudge.value > 0)
        {
                // TRICK: make the trace 1 qu longer!
                VectorSubtract(pEnd, start, end);
                len = VectorNormalizeLength(end);
-               VectorAdd(pEnd, end, end);
+               VectorMA(pEnd, collision_endposnudge.value, end, end);
        }
        else
                VectorCopy(pEnd, end);
-#endif
-
+#else
        if (VectorCompare(start, end))
                return CL_TracePoint(start, type, passedict, hitsupercontentsmask, hitnetworkbrushmodels, hitnetworkplayers, hitnetworkentity, hitcsqcentities);
+#endif
 
        if (hitnetworkentity)
                *hitnetworkentity = 0;
@@ -489,7 +491,7 @@ trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_
 #endif
 
        // clip to world
-       Collision_ClipLineToWorld(&cliptrace, cl.worldmodel, clipstart, clipend, hitsupercontentsmask);
+       Collision_ClipLineToWorld(&cliptrace, cl.worldmodel, clipstart, clipend, hitsupercontentsmask, hitsurfaces);
        cliptrace.bmodelstartsolid = cliptrace.startsolid;
        if (cliptrace.startsolid || cliptrace.fraction < 1)
                cliptrace.ent = prog ? prog->edicts : NULL;
@@ -538,7 +540,7 @@ trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_
                        entity_render_t *ent = &cl.entities[cl.brushmodel_entities[i]].render;
                        if (!BoxesOverlap(clipboxmins, clipboxmaxs, ent->mins, ent->maxs))
                                continue;
-                       Collision_ClipLineToGenericEntity(&trace, ent->model, ent->frameblend, ent->skeleton, vec3_origin, vec3_origin, 0, &ent->matrix, &ent->inversematrix, start, end, hitsupercontentsmask);
+                       Collision_ClipLineToGenericEntity(&trace, ent->model, ent->frameblend, ent->skeleton, vec3_origin, vec3_origin, 0, &ent->matrix, &ent->inversematrix, start, end, hitsupercontentsmask, hitsurfaces);
                        if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
                                *hitnetworkentity = cl.brushmodel_entities[i];
                        Collision_CombineTraces(&cliptrace, &trace, NULL, true);
@@ -551,7 +553,7 @@ trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_
                vec3_t origin, entmins, entmaxs;
                matrix4x4_t entmatrix, entinversematrix;
 
-               if(gamemode == GAME_NEXUIZ)
+               if(gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC)
                {
                        // don't hit network players, if we are a nonsolid player
                        if(cl.scores[cl.playerentity-1].frags == -666 || cl.scores[cl.playerentity-1].frags == -616)
@@ -570,7 +572,7 @@ trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_
                        if (!cl.scores[i-1].name[0])
                                continue;
 
-                       if(gamemode == GAME_NEXUIZ)
+                       if(gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC)
                        {
                                // don't hit spectators or nonsolid players
                                if(cl.scores[i-1].frags == -666 || cl.scores[i-1].frags == -616)
@@ -584,7 +586,7 @@ trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_
                                continue;
                        Matrix4x4_CreateTranslate(&entmatrix, origin[0], origin[1], origin[2]);
                        Matrix4x4_CreateTranslate(&entinversematrix, -origin[0], -origin[1], -origin[2]);
-                       Collision_ClipLineToGenericEntity(&trace, NULL, NULL, NULL, cl.playerstandmins, cl.playerstandmaxs, SUPERCONTENTS_BODY, &entmatrix, &entinversematrix, start, end, hitsupercontentsmask);
+                       Collision_ClipLineToGenericEntity(&trace, NULL, NULL, NULL, cl.playerstandmins, cl.playerstandmaxs, SUPERCONTENTS_BODY, &entmatrix, &entinversematrix, start, end, hitsupercontentsmask, hitsurfaces);
                        if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
                                *hitnetworkentity = i;
                        Collision_CombineTraces(&cliptrace, &trace, NULL, false);
@@ -648,7 +650,7 @@ skipnetworkplayers:
                if (type == MOVE_MISSILE && (int)touch->fields.client->flags & FL_MONSTER)
                        Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touch->fields.client->mins, touch->fields.client->maxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask);
                else
-                       Collision_ClipLineToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touch->fields.client->mins, touch->fields.client->maxs, bodysupercontents, &matrix, &imatrix, clipstart, clipend, hitsupercontentsmask);
+                       Collision_ClipLineToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touch->fields.client->mins, touch->fields.client->maxs, bodysupercontents, &matrix, &imatrix, clipstart, clipend, hitsupercontentsmask, hitsurfaces);
 
                if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
                        *hitnetworkentity = 0;
@@ -657,8 +659,8 @@ skipnetworkplayers:
 
 finished:
 #ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
-       if(!VectorCompare(start, pEnd))
-               Collision_ShortenTrace(&cliptrace, len / (len + 1), pEnd);
+       if(!VectorCompare(start, pEnd) && collision_endposnudge.value > 0)
+               Collision_ShortenTrace(&cliptrace, len / (len + collision_endposnudge.value), pEnd);
 #endif
        return cliptrace;
 }
@@ -696,22 +698,34 @@ trace_t CL_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, co
        dp_model_t *model;
        // list of entities to test for collisions
        int numtouchedicts;
-       prvm_edict_t *touchedicts[MAX_EDICTS];
+       static prvm_edict_t *touchedicts[MAX_EDICTS];
 #ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
        vec3_t end;
        vec_t len = 0;
 
-       if(!VectorCompare(start, pEnd))
+       if (VectorCompare(mins, maxs))
+       {
+               vec3_t shiftstart, shiftend;
+               VectorAdd(start, mins, shiftstart);
+               VectorAdd(pEnd, mins, shiftend);
+               if (VectorCompare(start, pEnd))
+                       trace = CL_TracePoint(shiftstart, type, passedict, hitsupercontentsmask, hitnetworkbrushmodels, hitnetworkplayers, hitnetworkentity, hitcsqcentities);
+               else
+                       trace = CL_TraceLine(shiftstart, shiftend, type, passedict, hitsupercontentsmask, hitnetworkbrushmodels, hitnetworkplayers, hitnetworkentity, hitcsqcentities, false);
+               VectorSubtract(trace.endpos, mins, trace.endpos);
+               return trace;
+       }
+
+       if(!VectorCompare(start, pEnd) && collision_endposnudge.value > 0)
        {
                // TRICK: make the trace 1 qu longer!
                VectorSubtract(pEnd, start, end);
                len = VectorNormalizeLength(end);
-               VectorAdd(pEnd, end, end);
+               VectorMA(pEnd, collision_endposnudge.value, end, end);
        }
        else
                VectorCopy(pEnd, end);
-#endif
-
+#else
        if (VectorCompare(mins, maxs))
        {
                vec3_t shiftstart, shiftend;
@@ -720,10 +734,11 @@ trace_t CL_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, co
                if (VectorCompare(start, end))
                        trace = CL_TracePoint(shiftstart, type, passedict, hitsupercontentsmask, hitnetworkbrushmodels, hitnetworkplayers, hitnetworkentity, hitcsqcentities);
                else
-                       trace = CL_TraceLine(shiftstart, shiftend, type, passedict, hitsupercontentsmask, hitnetworkbrushmodels, hitnetworkplayers, hitnetworkentity, hitcsqcentities);
+                       trace = CL_TraceLine(shiftstart, shiftend, type, passedict, hitsupercontentsmask, hitnetworkbrushmodels, hitnetworkplayers, hitnetworkentity, hitcsqcentities, false);
                VectorSubtract(trace.endpos, mins, trace.endpos);
                return trace;
        }
+#endif
 
        if (hitnetworkentity)
                *hitnetworkentity = 0;
@@ -812,7 +827,7 @@ trace_t CL_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, co
                vec3_t origin, entmins, entmaxs;
                matrix4x4_t entmatrix, entinversematrix;
 
-               if(gamemode == GAME_NEXUIZ)
+               if(gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC)
                {
                        // don't hit network players, if we are a nonsolid player
                        if(cl.scores[cl.playerentity-1].frags == -666 || cl.scores[cl.playerentity-1].frags == -616)
@@ -831,7 +846,7 @@ trace_t CL_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, co
                        if (!cl.scores[i-1].name[0])
                                continue;
 
-                       if(gamemode == GAME_NEXUIZ)
+                       if(gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC)
                        {
                                // don't hit spectators or nonsolid players
                                if(cl.scores[i-1].frags == -666 || cl.scores[i-1].frags == -616)
@@ -918,8 +933,8 @@ skipnetworkplayers:
 
 finished:
 #ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
-       if(!VectorCompare(start, pEnd))
-               Collision_ShortenTrace(&cliptrace, len / (len + 1), pEnd);
+       if(!VectorCompare(start, pEnd) && collision_endposnudge.value > 0)
+               Collision_ShortenTrace(&cliptrace, len / (len + collision_endposnudge.value), pEnd);
 #endif
        return cliptrace;
 }