Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

cm_test.c File Reference

#include "cm_local.h"

Include dependency graph for cm_test.c:

Include dependency graph

Go to the source code of this file.

Functions

void CM_AdjustAreaPortalState (int area1, int area2, qboolean open)
qboolean CM_AreasConnected (int area1, int area2)
int CM_BoxBrushes (const vec3_t mins, const vec3_t maxs, cbrush_t **list, int listsize)
int CM_BoxLeafnums (const vec3_t mins, const vec3_t maxs, int *list, int listsize, int *lastLeaf)
void CM_BoxLeafnums_r (leafList_t *ll, int nodenum)
byteCM_ClusterPVS (int cluster)
void CM_FloodArea_r (int areaNum, int floodnum)
void CM_FloodAreaConnections (void)
int CM_PointContents (const vec3_t p, clipHandle_t model)
int CM_PointLeafnum (const vec3_t p)
int CM_PointLeafnum_r (const vec3_t p, int num)
void CM_StoreBrushes (leafList_t *ll, int nodenum)
void CM_StoreLeafs (leafList_t *ll, int nodenum)
int CM_TransformedPointContents (const vec3_t p, clipHandle_t model, const vec3_t origin, const vec3_t angles)
int CM_WriteAreaBits (byte *buffer, int area)


Function Documentation

void CM_AdjustAreaPortalState int  area1,
int  area2,
qboolean  open
 

Definition at line 385 of file cm_test.c.

References clipMap_t::areaPortals, cm, CM_FloodAreaConnections(), Com_Error(), ERR_DROP, and clipMap_t::numAreas.

Referenced by SV_AdjustAreaPortalState().

00385                                                                         {
00386     if ( area1 < 0 || area2 < 0 ) {
00387         return;
00388     }
00389 
00390     if ( area1 >= cm.numAreas || area2 >= cm.numAreas ) {
00391         Com_Error (ERR_DROP, "CM_ChangeAreaPortalState: bad area number");
00392     }
00393 
00394     if ( open ) {
00395         cm.areaPortals[ area1 * cm.numAreas + area2 ]++;
00396         cm.areaPortals[ area2 * cm.numAreas + area1 ]++;
00397     } else {
00398         cm.areaPortals[ area1 * cm.numAreas + area2 ]--;
00399         cm.areaPortals[ area2 * cm.numAreas + area1 ]--;
00400         if ( cm.areaPortals[ area2 * cm.numAreas + area1 ] < 0 ) {
00401             Com_Error (ERR_DROP, "CM_AdjustAreaPortalState: negative reference count");
00402         }
00403     }
00404 
00405     CM_FloodAreaConnections ();
00406 }

Here is the call graph for this function:

qboolean CM_AreasConnected int  area1,
int  area2
 

Definition at line 414 of file cm_test.c.

References clipMap_t::areas, cm, cm_noAreas, Com_Error(), ERR_DROP, cArea_t::floodnum, cvar_s::integer, clipMap_t::numAreas, and qboolean.

Referenced by SV_AddEntitiesVisibleFromPoint(), SV_GameSystemCalls(), and SV_inPVS().

00414                                                       {
00415 #ifndef BSPC
00416     if ( cm_noAreas->integer ) {
00417         return qtrue;
00418     }
00419 #endif
00420 
00421     if ( area1 < 0 || area2 < 0 ) {
00422         return qfalse;
00423     }
00424 
00425     if (area1 >= cm.numAreas || area2 >= cm.numAreas) {
00426         Com_Error (ERR_DROP, "area >= cm.numAreas");
00427     }
00428 
00429     if (cm.areas[area1].floodnum == cm.areas[area2].floodnum) {
00430         return qtrue;
00431     }
00432     return qfalse;
00433 }

Here is the call graph for this function:

int CM_BoxBrushes const vec3_t  mins,
const vec3_t  maxs,
cbrush_t **  list,
int  listsize
 

Definition at line 197 of file cm_test.c.

References leafList_s::bounds, clipMap_t::checkcount, cm, CM_BoxLeafnums_r(), leafList_s::count, leafList_s::lastLeaf, leafList_t, leafList_s::list, leafList_s::maxcount, leafList_s::overflowed, leafList_s::storeLeafs, and VectorCopy.

00197                                                                                          {
00198     leafList_t  ll;
00199 
00200     cm.checkcount++;
00201 
00202     VectorCopy( mins, ll.bounds[0] );
00203     VectorCopy( maxs, ll.bounds[1] );
00204     ll.count = 0;
00205     ll.maxcount = listsize;
00206     ll.list = (void *)list;
00207     ll.storeLeafs = CM_StoreBrushes;
00208     ll.lastLeaf = 0;
00209     ll.overflowed = qfalse;
00210     
00211     CM_BoxLeafnums_r( &ll, 0 );
00212 
00213     return ll.count;
00214 }

Here is the call graph for this function:

int CM_BoxLeafnums const vec3_t  mins,
const vec3_t  maxs,
int *  list,
int  listsize,
int *  lastLeaf
 

Definition at line 172 of file cm_test.c.

References leafList_s::bounds, clipMap_t::checkcount, cm, CM_BoxLeafnums_r(), leafList_s::count, leafList_s::lastLeaf, leafList_t, leafList_s::list, leafList_s::maxcount, leafList_s::overflowed, leafList_s::storeLeafs, and VectorCopy.

Referenced by SV_LinkEntity().

00172                                                                                                   {
00173     leafList_t  ll;
00174 
00175     cm.checkcount++;
00176 
00177     VectorCopy( mins, ll.bounds[0] );
00178     VectorCopy( maxs, ll.bounds[1] );
00179     ll.count = 0;
00180     ll.maxcount = listsize;
00181     ll.list = list;
00182     ll.storeLeafs = CM_StoreLeafs;
00183     ll.lastLeaf = 0;
00184     ll.overflowed = qfalse;
00185 
00186     CM_BoxLeafnums_r( &ll, 0 );
00187 
00188     *lastLeaf = ll.lastLeaf;
00189     return ll.count;
00190 }

Here is the call graph for this function:

void CM_BoxLeafnums_r leafList_t ll,
int  nodenum
 

Definition at line 140 of file cm_test.c.

References leafList_s::bounds, BoxOnPlaneSide(), cNode_t::children, cm, cplane_t, leafList_t, clipMap_t::nodes, cNode_t::plane, s, and leafList_s::storeLeafs.

Referenced by CM_BoxBrushes(), CM_BoxLeafnums(), and CM_PositionTest().

00140                                                      {
00141     cplane_t    *plane;
00142     cNode_t     *node;
00143     int         s;
00144 
00145     while (1) {
00146         if (nodenum < 0) {
00147             ll->storeLeafs( ll, nodenum );
00148             return;
00149         }
00150     
00151         node = &cm.nodes[nodenum];
00152         plane = node->plane;
00153         s = BoxOnPlaneSide( ll->bounds[0], ll->bounds[1], plane );
00154         if (s == 1) {
00155             nodenum = node->children[0];
00156         } else if (s == 2) {
00157             nodenum = node->children[1];
00158         } else {
00159             // go down both
00160             CM_BoxLeafnums_r( ll, node->children[0] );
00161             nodenum = node->children[1];
00162         }
00163 
00164     }
00165 }

Here is the call graph for this function:

byte* CM_ClusterPVS int  cluster  ) 
 

Definition at line 312 of file cm_test.c.

References byte, clipMap_t::clusterBytes, cm, clipMap_t::numClusters, clipMap_t::vised, and clipMap_t::visibility.

Referenced by R_inPVS(), SV_AddEntitiesVisibleFromPoint(), SV_inPVS(), and SV_inPVSIgnorePortals().

00312                                      {
00313     if (cluster < 0 || cluster >= cm.numClusters || !cm.vised ) {
00314         return cm.visibility;
00315     }
00316 
00317     return cm.visibility + cluster * cm.clusterBytes;
00318 }

void CM_FloodArea_r int  areaNum,
int  floodnum
 

Definition at line 330 of file cm_test.c.

References clipMap_t::areaPortals, clipMap_t::areas, cm, Com_Error(), con, ERR_DROP, cArea_t::floodnum, clipMap_t::floodvalid, cArea_t::floodvalid, i, and clipMap_t::numAreas.

Referenced by CM_FloodAreaConnections().

00330                                                 {
00331     int     i;
00332     cArea_t *area;
00333     int     *con;
00334 
00335     area = &cm.areas[ areaNum ];
00336 
00337     if ( area->floodvalid == cm.floodvalid ) {
00338         if (area->floodnum == floodnum)
00339             return;
00340         Com_Error (ERR_DROP, "FloodArea_r: reflooded");
00341     }
00342 
00343     area->floodnum = floodnum;
00344     area->floodvalid = cm.floodvalid;
00345     con = cm.areaPortals + areaNum * cm.numAreas;
00346     for ( i=0 ; i < cm.numAreas  ; i++ ) {
00347         if ( con[i] > 0 ) {
00348             CM_FloodArea_r( i, floodnum );
00349         }
00350     }
00351 }

Here is the call graph for this function:

void CM_FloodAreaConnections void   ) 
 

Definition at line 359 of file cm_test.c.

References clipMap_t::areas, cm, CM_FloodArea_r(), cArea_t::floodvalid, clipMap_t::floodvalid, i, and clipMap_t::numAreas.

Referenced by CM_AdjustAreaPortalState(), and CM_LoadMap().

00359                                         {
00360     int     i;
00361     cArea_t *area;
00362     int     floodnum;
00363 
00364     // all current floods are now invalid
00365     cm.floodvalid++;
00366     floodnum = 0;
00367 
00368     for (i = 0 ; i < cm.numAreas ; i++) {
00369         area = &cm.areas[i];
00370         if (area->floodvalid == cm.floodvalid) {
00371             continue;       // already flooded into
00372         }
00373         floodnum++;
00374         CM_FloodArea_r (i, floodnum);
00375     }
00376 
00377 }

Here is the call graph for this function:

int CM_PointContents const vec3_t  p,
clipHandle_t  model
 

Definition at line 226 of file cm_test.c.

References b, clipMap_t::brushes, cm, CM_ClipHandleToModel(), CM_PointLeafnum_r(), cmodel_t, cbrush_t::contents, d, cplane_s::dist, DotProduct, cLeaf_t::firstLeafBrush, i, k, cmodel_s::leaf, clipMap_t::leafbrushes, clipMap_t::leafs, cplane_s::normal, cLeaf_t::numLeafBrushes, clipMap_t::numNodes, cbrush_t::numsides, p, cbrushside_t::plane, and cbrush_t::sides.

Referenced by BotImport_PointContents(), CL_CgameSystemCalls(), CM_TransformedPointContents(), and SV_PointContents().

00226                                                            {
00227     int         leafnum;
00228     int         i, k;
00229     int         brushnum;
00230     cLeaf_t     *leaf;
00231     cbrush_t    *b;
00232     int         contents;
00233     float       d;
00234     cmodel_t    *clipm;
00235 
00236     if (!cm.numNodes) { // map not loaded
00237         return 0;
00238     }
00239 
00240     if ( model ) {
00241         clipm = CM_ClipHandleToModel( model );
00242         leaf = &clipm->leaf;
00243     } else {
00244         leafnum = CM_PointLeafnum_r (p, 0);
00245         leaf = &cm.leafs[leafnum];
00246     }
00247 
00248     contents = 0;
00249     for (k=0 ; k<leaf->numLeafBrushes ; k++) {
00250         brushnum = cm.leafbrushes[leaf->firstLeafBrush+k];
00251         b = &cm.brushes[brushnum];
00252 
00253         // see if the point is in the brush
00254         for ( i = 0 ; i < b->numsides ; i++ ) {
00255             d = DotProduct( p, b->sides[i].plane->normal );
00256 // FIXME test for Cash
00257 //          if ( d >= b->sides[i].plane->dist ) {
00258             if ( d > b->sides[i].plane->dist ) {
00259                 break;
00260             }
00261         }
00262 
00263         if ( i == b->numsides ) {
00264             contents |= b->contents;
00265         }
00266     }
00267 
00268     return contents;
00269 }

Here is the call graph for this function:

int CM_PointLeafnum const vec3_t  p  ) 
 

Definition at line 56 of file cm_test.c.

References cm, CM_PointLeafnum_r(), clipMap_t::numNodes, and p.

Referenced by SV_AddEntitiesVisibleFromPoint(), SV_inPVS(), and SV_inPVSIgnorePortals().

00056                                       {
00057     if ( !cm.numNodes ) {   // map not loaded
00058         return 0;
00059     }
00060     return CM_PointLeafnum_r (p, 0);
00061 }

Here is the call graph for this function:

int CM_PointLeafnum_r const vec3_t  p,
int  num
 

Definition at line 31 of file cm_test.c.

References c_pointcontents, cNode_t::children, cm, cplane_t, d, cplane_s::dist, DotProduct, clipMap_t::nodes, cplane_s::normal, p, cNode_t::plane, and cplane_s::type.

Referenced by CM_PointContents(), and CM_PointLeafnum().

00031                                                  {
00032     float       d;
00033     cNode_t     *node;
00034     cplane_t    *plane;
00035 
00036     while (num >= 0)
00037     {
00038         node = cm.nodes + num;
00039         plane = node->plane;
00040         
00041         if (plane->type < 3)
00042             d = p[plane->type] - plane->dist;
00043         else
00044             d = DotProduct (plane->normal, p) - plane->dist;
00045         if (d < 0)
00046             num = node->children[1];
00047         else
00048             num = node->children[0];
00049     }
00050 
00051     c_pointcontents++;      // optimize counter
00052 
00053     return -1 - num;
00054 }

void CM_StoreBrushes leafList_t ll,
int  nodenum
 

Definition at line 90 of file cm_test.c.

References b, leafList_s::bounds, cbrush_t::bounds, clipMap_t::brushes, clipMap_t::checkcount, cbrush_t::checkcount, cm, leafList_s::count, cLeaf_t::firstLeafBrush, i, k, clipMap_t::leafbrushes, leafList_t, clipMap_t::leafs, clipMap_t::leafsurfaces, leafList_s::list, leafList_s::maxcount, cLeaf_t::numLeafBrushes, cLeaf_t::numLeafSurfaces, leafList_s::overflowed, and clipMap_t::surfaces.

00090                                                     {
00091     int         i, k;
00092     int         leafnum;
00093     int         brushnum;
00094     cLeaf_t     *leaf;
00095     cbrush_t    *b;
00096 
00097     leafnum = -1 - nodenum;
00098 
00099     leaf = &cm.leafs[leafnum];
00100 
00101     for ( k = 0 ; k < leaf->numLeafBrushes ; k++ ) {
00102         brushnum = cm.leafbrushes[leaf->firstLeafBrush+k];
00103         b = &cm.brushes[brushnum];
00104         if ( b->checkcount == cm.checkcount ) {
00105             continue;   // already checked this brush in another leaf
00106         }
00107         b->checkcount = cm.checkcount;
00108         for ( i = 0 ; i < 3 ; i++ ) {
00109             if ( b->bounds[0][i] >= ll->bounds[1][i] || b->bounds[1][i] <= ll->bounds[0][i] ) {
00110                 break;
00111             }
00112         }
00113         if ( i != 3 ) {
00114             continue;
00115         }
00116         if ( ll->count >= ll->maxcount) {
00117             ll->overflowed = qtrue;
00118             return;
00119         }
00120         ((cbrush_t **)ll->list)[ ll->count++ ] = b;
00121     }
00122 #if 0
00123     // store patches?
00124     for ( k = 0 ; k < leaf->numLeafSurfaces ; k++ ) {
00125         patch = cm.surfaces[ cm.leafsurfaces[ leaf->firstleafsurface + k ] ];
00126         if ( !patch ) {
00127             continue;
00128         }
00129     }
00130 #endif
00131 }

void CM_StoreLeafs leafList_t ll,
int  nodenum
 

Definition at line 73 of file cm_test.c.

References cLeaf_t::cluster, cm, leafList_s::count, leafList_s::lastLeaf, leafList_t, clipMap_t::leafs, leafList_s::list, leafList_s::maxcount, and leafList_s::overflowed.

00073                                                   {
00074     int     leafNum;
00075 
00076     leafNum = -1 - nodenum;
00077 
00078     // store the lastLeaf even if the list is overflowed
00079     if ( cm.leafs[ leafNum ].cluster != -1 ) {
00080         ll->lastLeaf = leafNum;
00081     }
00082 
00083     if ( ll->count >= ll->maxcount) {
00084         ll->overflowed = qtrue;
00085         return;
00086     }
00087     ll->list[ ll->count++ ] = leafNum;
00088 }

int CM_TransformedPointContents const vec3_t  p,
clipHandle_t  model,
const vec3_t  origin,
const vec3_t  angles
 

Definition at line 279 of file cm_test.c.

References AngleVectors(), BOX_MODEL_HANDLE, CM_PointContents(), DotProduct, p, right, up, vec3_t, VectorCopy, and VectorSubtract.

Referenced by CL_CgameSystemCalls(), and SV_PointContents().

00279                                                                                                                {
00280     vec3_t      p_l;
00281     vec3_t      temp;
00282     vec3_t      forward, right, up;
00283 
00284     // subtract origin offset
00285     VectorSubtract (p, origin, p_l);
00286 
00287     // rotate start and end into the models frame of reference
00288     if ( model != BOX_MODEL_HANDLE && 
00289     (angles[0] || angles[1] || angles[2]) )
00290     {
00291         AngleVectors (angles, forward, right, up);
00292 
00293         VectorCopy (p_l, temp);
00294         p_l[0] = DotProduct (temp, forward);
00295         p_l[1] = -DotProduct (temp, right);
00296         p_l[2] = DotProduct (temp, up);
00297     }
00298 
00299     return CM_PointContents( p_l, model );
00300 }

Here is the call graph for this function:

int CM_WriteAreaBits byte buffer,
int  area
 

Definition at line 450 of file cm_test.c.

References clipMap_t::areas, buffer, byte, cm, cm_noAreas, Com_Memset(), cArea_t::floodnum, i, cvar_s::integer, and clipMap_t::numAreas.

Referenced by SV_AddEntitiesVisibleFromPoint().

00451 {
00452     int     i;
00453     int     floodnum;
00454     int     bytes;
00455 
00456     bytes = (cm.numAreas+7)>>3;
00457 
00458 #ifndef BSPC
00459     if (cm_noAreas->integer || area == -1)
00460 #else
00461     if ( area == -1)
00462 #endif
00463     {   // for debugging, send everything
00464         Com_Memset (buffer, 255, bytes);
00465     }
00466     else
00467     {
00468         floodnum = cm.areas[area].floodnum;
00469         for (i=0 ; i<cm.numAreas ; i++)
00470         {
00471             if (cm.areas[i].floodnum == floodnum || area == -1)
00472                 buffer[i>>3] |= 1<<(i&7);
00473         }
00474     }
00475 
00476     return bytes;
00477 }

Here is the call graph for this function:


Generated on Thu Aug 25 14:37:03 2005 for Quake III Arena by  doxygen 1.3.9.1