]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_collision.c
add apparently not yet working optimization flags to Mem_ExpandableArray function...
[xonotic/darkplaces.git] / cl_collision.c
index 527acecc4cb08298721dd2a833b7179df022c30c..1aedfe74bc3a281e4251ef6974963136396c1daf 100644 (file)
@@ -87,7 +87,7 @@ void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius)
                cl.worldmodel->brush.FindNonSolidLocation(cl.worldmodel, in, out, radius);
 }
 
-model_t *CL_GetModelByIndex(int modelindex)
+dp_model_t *CL_GetModelByIndex(int modelindex)
 {
        if(!modelindex)
                return NULL;
@@ -105,7 +105,7 @@ model_t *CL_GetModelByIndex(int modelindex)
        return NULL;
 }
 
-model_t *CL_GetModelFromEdict(prvm_edict_t *ed)
+dp_model_t *CL_GetModelFromEdict(prvm_edict_t *ed)
 {
        if (!ed || ed->priv.server->free)
                return NULL;
@@ -114,14 +114,62 @@ model_t *CL_GetModelFromEdict(prvm_edict_t *ed)
 
 void CL_LinkEdict(prvm_edict_t *ent)
 {
+       vec3_t mins, maxs;
+
        if (ent == prog->edicts)
                return;         // don't add the world
 
        if (ent->priv.server->free)
                return;
 
-       VectorAdd(ent->fields.client->origin, ent->fields.client->mins, ent->fields.client->absmin);
-       VectorAdd(ent->fields.client->origin, ent->fields.client->maxs, ent->fields.client->absmax);
+       // set the abs box
+
+       if (ent->fields.client->solid == SOLID_BSP)
+       {
+               dp_model_t *model = CL_GetModelByIndex( (int)ent->fields.client->modelindex );
+               if (model == NULL)
+               {
+                       Con_Printf("edict %i: SOLID_BSP with invalid modelindex!\n", PRVM_NUM_FOR_EDICT(ent));
+
+                       model = CL_GetModelByIndex( 0 );
+               }
+
+               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 (ent->fields.client->angles[0] || ent->fields.client->angles[2] || ent->fields.client->avelocity[0] || ent->fields.client->avelocity[2])
+                       {
+                               VectorAdd(ent->fields.client->origin, model->rotatedmins, mins);
+                               VectorAdd(ent->fields.client->origin, model->rotatedmaxs, maxs);
+                       }
+                       else if (ent->fields.client->angles[1] || ent->fields.client->avelocity[1])
+                       {
+                               VectorAdd(ent->fields.client->origin, model->yawmins, mins);
+                               VectorAdd(ent->fields.client->origin, model->yawmaxs, maxs);
+                       }
+                       else
+                       {
+                               VectorAdd(ent->fields.client->origin, model->normalmins, mins);
+                               VectorAdd(ent->fields.client->origin, model->normalmaxs, maxs);
+                       }
+               }
+               else
+               {
+                       // SOLID_BSP with no model is valid, mainly because some QC setup code does so temporarily
+                       VectorAdd(ent->fields.client->origin, ent->fields.client->mins, mins);
+                       VectorAdd(ent->fields.client->origin, ent->fields.client->maxs, maxs);
+               }
+       }
+       else
+       {
+               VectorAdd(ent->fields.client->origin, ent->fields.client->mins, mins);
+               VectorAdd(ent->fields.client->origin, ent->fields.client->maxs, maxs);
+       }
+
+       VectorCopy(mins, ent->fields.client->absmin);
+       VectorCopy(maxs, ent->fields.client->absmax);
 
        World_LinkEdict(&cl.world, ent, ent->fields.client->absmin, ent->fields.client->absmax);
 }
@@ -178,7 +226,7 @@ trace_t CL_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const
        // matrices to transform into/out of other entity's space
        matrix4x4_t matrix, imatrix;
        // model of other entity
-       model_t *model;
+       dp_model_t *model;
        // list of entities to test for collisions
        int numtouchedicts;
        prvm_edict_t *touchedicts[MAX_EDICTS];
@@ -247,7 +295,7 @@ trace_t CL_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const
        // figure out whether this is a point trace for comparisons
        pointtrace = VectorCompare(clipmins, clipmaxs);
        // precalculate passedict's owner edict pointer for comparisons
-       traceowner = passedict ? PRVM_PROG_TO_EDICT(passedict->fields.client->owner) : 0;
+       traceowner = passedict ? PRVM_PROG_TO_EDICT(passedict->fields.client->owner) : NULL;
 
        // collide against network entities
        if (hitnetworkbrushmodels)