diff options
author | Andrey Nazarov <skuller@skuller.net> | 2007-11-28 16:10:24 +0000 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2007-11-28 16:10:24 +0000 |
commit | a377c011febdb961837261ec4e5484d94467942c (patch) | |
tree | 3e1771079d78db5181510d6cdf65a16a7ceaf369 | |
parent | d67917510d5795c9ff8364ceb8d6389369809f54 (diff) |
Set headnode number on edicts as game DLL expects.
Avoid crash on NULL headnode.
-rw-r--r-- | source/cmodel.c | 13 | ||||
-rw-r--r-- | source/com_local.h | 2 | ||||
-rw-r--r-- | source/sv_world.c | 6 |
3 files changed, 10 insertions, 11 deletions
diff --git a/source/cmodel.c b/source/cmodel.c index f44ccbd..51611f9 100644 --- a/source/cmodel.c +++ b/source/cmodel.c @@ -900,6 +900,9 @@ cnode_t *CM_NodeNum( cm_t *cm, int number ) { if( !cm->cache ) { Com_Error( ERR_DROP, "CM_NodeNum: NULL cache" ); } + if( number == -1 ) { + return ( cnode_t * )cm->cache->leafs; // special case for solid leaf + } if( number < 0 || number >= cm->cache->numnodes ) { Com_Error( ERR_DROP, "CM_NodeNum: bad number: %d", number ); } @@ -1021,14 +1024,9 @@ CM_PointLeaf_r */ static cleaf_t *CM_PointLeaf_r( vec3_t p, cnode_t *node ) { float d; - cplane_t *plane; while( node->plane ) { - plane = node->plane; - if( plane->type < 3 ) - d = p[plane->type] - plane->dist; - else - d = DotProduct( plane->normal, p ) - plane->dist; + d = PlaneDiffFast( p, node->plane ); if( d < 0 ) node = node->children[1]; else @@ -1574,7 +1572,6 @@ void CM_BoxTrace( trace_t *trace, vec3_t start, vec3_t end, cleaf_t *leafs[1024]; int i, numleafs; vec3_t c1, c2; - cnode_t *topnode; VectorAdd (start, mins, c1); VectorAdd (start, maxs, c2); @@ -1584,7 +1581,7 @@ void CM_BoxTrace( trace_t *trace, vec3_t start, vec3_t end, c2[i] += 1; } - numleafs = CM_BoxLeafs_headnode (c1, c2, leafs, 1024, headnode, &topnode); + numleafs = CM_BoxLeafs_headnode (c1, c2, leafs, 1024, headnode, NULL); for (i=0 ; i<numleafs ; i++) { CM_TestInLeaf (leafs[i]); diff --git a/source/com_local.h b/source/com_local.h index e783c36..5903d13 100644 --- a/source/com_local.h +++ b/source/com_local.h @@ -708,6 +708,8 @@ char *CM_EntityString( cm_t *cm ); cnode_t *CM_NodeNum( cm_t *cm, int number ); cleaf_t *CM_LeafNum( cm_t *cm, int number ); +#define CM_NumNode( cm, node ) ( (node) ? ( (node) - (cm)->cache->nodes ) : -1 ) + // creates a clipping hull for an arbitrary box cnode_t *CM_HeadnodeForBox( vec3_t mins, vec3_t maxs ); diff --git a/source/sv_world.c b/source/sv_world.c index f802abc..9f5b71d 100644 --- a/source/sv_world.c +++ b/source/sv_world.c @@ -209,7 +209,7 @@ void SV_LinkEdict( cm_t *cm, edict_t *ent ) { if (num_leafs >= MAX_TOTAL_ENT_LEAFS) { // assume we missed some leafs, and mark by headnode ent->num_clusters = -1; - ent->headnode = topnode - cm->cache->nodes; + ent->headnode = CM_NumNode( cm, topnode ); } else { @@ -226,7 +226,7 @@ void SV_LinkEdict( cm_t *cm, edict_t *ent ) { if (ent->num_clusters == MAX_ENT_CLUSTERS) { // assume we missed some leafs, and mark by headnode ent->num_clusters = -1; - ent->headnode = topnode - cm->cache->nodes; + ent->headnode = CM_NumNode( cm, topnode ); break; } @@ -409,7 +409,7 @@ static cnode_t *SV_HullForEntity( edict_t *ent ) { if( ent->solid == SOLID_BSP ) { // explicit hulls in the BSP model - if( ent->s.modelindex < 1 || ent->s.modelindex > sv.cm.cache->numcmodels ) { + if( ent->s.modelindex < 2 || ent->s.modelindex > sv.cm.cache->numcmodels ) { Com_Error( ERR_DROP, "SV_HullForEntity: inline model index %d out of range", ent->s.modelindex ); } |