]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Fix the bmodel collision bug in csqc.
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 10 Jan 2008 13:40:57 +0000 (13:40 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 10 Jan 2008 13:40:57 +0000 (13:40 +0000)
clvm's setmodel and setmodelindex also update the min, max and size now (just like they do in sqc).

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7948 d7cf8633-e32d-0410-b094-e92efae38249

cl_collision.c
clvm_cmds.c
svvm_cmds.c

index 527acecc4cb08298721dd2a833b7179df022c30c..45acfefa13cc5a42fb1d415d80e0cf99a855e596 100644 (file)
@@ -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)
+       {
+               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);
 }
index 290ad287373c89b1dcc7460f5a4969a3fae839ae..2f589274cfdd423740d68bb50352e28148e6fc0d 100644 (file)
@@ -56,12 +56,28 @@ void VM_CL_setorigin (void)
        CL_LinkEdict(e);
 }
 
+static void SetMinMaxSize (prvm_edict_t *e, float *min, float *max)
+{
+       int             i;
+
+       for (i=0 ; i<3 ; i++)
+               if (min[i] > max[i])
+                       PRVM_ERROR("SetMinMaxSize: backwards mins/maxs");
+
+       // set derived values
+       VectorCopy (min, e->fields.client->mins);
+       VectorCopy (max, e->fields.client->maxs);
+       VectorSubtract (max, min, e->fields.client->size);
+
+       CL_LinkEdict (e);
+}
+
 // #3 void(entity e, string m) setmodel
 void VM_CL_setmodel (void)
 {
        prvm_edict_t    *e;
        const char              *m;
-       struct model_s  *mod;
+       model_t *mod;
        int                             i;
 
        VM_SAFEPARMCOUNT(2, VM_CL_setmodel);
@@ -92,6 +108,14 @@ void VM_CL_setmodel (void)
        e->fields.client->modelindex = 0;
        e->fields.client->model = 0;
        VM_Warning ("setmodel: model '%s' not precached\n", m);
+
+       // TODO: check if this breaks needed consistency and maybe add a cvar for it too?? [1/10/2008 Black]
+       if (mod)
+       {
+               SetMinMaxSize (e, mod->normalmins, mod->normalmaxs);
+       }
+       else
+               SetMinMaxSize (e, vec3_origin, vec3_origin);
 }
 
 // #4 void(entity e, vector min, vector max) setsize
@@ -115,9 +139,7 @@ static void VM_CL_setsize (void)
        min = PRVM_G_VECTOR(OFS_PARM1);
        max = PRVM_G_VECTOR(OFS_PARM2);
 
-       VectorCopy (min, e->fields.client->mins);
-       VectorCopy (max, e->fields.client->maxs);
-       VectorSubtract (max, min, e->fields.client->size);
+       SetMinMaxSize( e, min, max );
 
        CL_LinkEdict(e);
 }
@@ -196,8 +218,6 @@ static void VM_CL_spawn (void)
 {
        prvm_edict_t *ed;
        ed = PRVM_ED_Alloc();
-       // FIXME: WTF.. this should be removed imo.. entnum points to the server.. [12/17/2007 Black]
-       ed->fields.client->entnum = PRVM_NUM_FOR_EDICT(ed);     //[515]: not needed any more ?
        VM_RETURN_EDICT(ed);
 }
 
@@ -978,6 +998,14 @@ static void VM_CL_setmodelindex (void)
        }
        t->fields.client->model = PRVM_SetEngineString(model->name);
        t->fields.client->modelindex = i;
+
+       // TODO: check if this breaks needed consistency and maybe add a cvar for it too?? [1/10/2008 Black]
+       if (model)
+       {
+               SetMinMaxSize (t, model->normalmins, model->normalmaxs);
+       }
+       else
+               SetMinMaxSize (t, vec3_origin, vec3_origin);
 }
 
 //#334 string(float mdlindex) modelnameforindex (EXT_CSQC)
index a48dda5d35e9cc6d8f3af14e28c25c48b567d052..57eaab8029d21b5bd087e1286a1fee0da5e0de20 100644 (file)
@@ -181,8 +181,8 @@ static void VM_SV_setorigin (void)
        SV_LinkEdict (e, false);
 }
 
-
-void SetMinMaxSize (prvm_edict_t *e, float *min, float *max, qboolean rotate)
+// TODO: rotate param isnt used.. could be a bug. please check this and remove it if possible [1/10/2008 Black]
+static void SetMinMaxSize (prvm_edict_t *e, float *min, float *max, qboolean rotate)
 {
        int             i;