cm_test.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. #include "cm_local.h"
  2. #pragma warning (push, 3) //go back down to 3 for the stl include
  3. #pragma warning (pop)
  4. using namespace std;
  5. #ifdef _XBOX
  6. #include "../renderer/tr_local.h"
  7. #endif
  8. class CPoint
  9. {
  10. public:
  11. float x,y,z;
  12. CPoint(float _x,float _y,float _z):
  13. x(_x),
  14. y(_y),
  15. z(_z)
  16. {
  17. }
  18. bool operator== (const CPoint& _P) const {return((x==_P.x)&&(y==_P.y)&&(z==_P.z));}
  19. };
  20. /*
  21. class CPointComparator
  22. {
  23. public:
  24. bool operator()(const CPoint& _A,const CPoint& _B) const {return((_A.x==_B.x)&&(_A.y==_B.y)&&(_A.z==_B.z));}
  25. };
  26. */
  27. // Fixed memory version of pointToLeaf that doesn't use STL
  28. // cuts down on memory fragmentation
  29. struct PointAndLeaf
  30. {
  31. // Default constructor for array construction below
  32. PointAndLeaf() : point(0, 0, 0), leaf(0) { }
  33. CPoint point;
  34. int leaf;
  35. };
  36. // I think it is a patholoically bad idea to do a 64 item linear search for a cache,
  37. // so I reduced this to something more manageable.
  38. // hopefully getting rid of water checks on maps with no water will leave us less
  39. // reliant on this cache. -gwg
  40. #define MAX_POINTS_TO_LEAVES 16
  41. static PointAndLeaf pointToLeaf[MAX_POINTS_TO_LEAVES];
  42. static int oldestPointToLeaf = 0, sizePointToLeaf = 0;
  43. //static hlist<pair<CPoint,int> > pointToLeaf;
  44. //static hlist<pair<CPoint,int> > pointToContents;
  45. void CM_CleanLeafCache(void)
  46. {
  47. oldestPointToLeaf = sizePointToLeaf = 0;
  48. // pointToLeaf.clear();
  49. #if 0 // VVFIXME
  50. hlist<pair<CPoint,int> >::iterator l;
  51. for(l=pointToLeaf.begin();l!=pointToLeaf.end();l++)
  52. {
  53. pointToLeaf.erase(l);
  54. }
  55. #endif
  56. /*
  57. for(l=pointToContents.begin();l!=pointToContents.end();l++)
  58. {
  59. pointToContents.erase(l);
  60. }
  61. */
  62. }
  63. /*
  64. ==================
  65. CM_PointLeafnum_r
  66. ==================
  67. */
  68. int CM_PointLeafnum_r( const vec3_t p, int num, clipMap_t *local ) {
  69. float d;
  70. cNode_t *node;
  71. cplane_t *plane;
  72. #ifdef _XBOX
  73. if(!tr.world) {
  74. return 0;
  75. }
  76. #endif
  77. while (num >= 0)
  78. {
  79. node = local->nodes + num;
  80. #ifdef _XBOX
  81. plane = cmg.planes + tr.world->nodes[num].planeNum;
  82. #else
  83. plane = node->plane;
  84. #endif
  85. if (plane->type < 3)
  86. d = p[plane->type] - plane->dist;
  87. else
  88. d = DotProduct (plane->normal, p) - plane->dist;
  89. if (d < 0)
  90. num = node->children[1];
  91. else
  92. num = node->children[0];
  93. }
  94. c_pointcontents++; // optimize counter
  95. return -1 - num;
  96. }
  97. int CM_PointLeafnum( const vec3_t p ) {
  98. if ( !cmg.numNodes ) { // map not loaded
  99. return 0;
  100. }
  101. return CM_PointLeafnum_r (p, 0, &cmg);
  102. }
  103. /*
  104. ======================================================================
  105. LEAF LISTING
  106. ======================================================================
  107. */
  108. void CM_StoreLeafs( leafList_t *ll, int nodenum ) {
  109. int leafNum;
  110. leafNum = -1 - nodenum;
  111. // store the lastLeaf even if the list is overflowed
  112. if ( cmg.leafs[ leafNum ].cluster != -1 ) {
  113. ll->lastLeaf = leafNum;
  114. }
  115. if ( ll->count >= ll->maxcount) {
  116. ll->overflowed = qtrue;
  117. return;
  118. }
  119. ll->list[ ll->count++ ] = leafNum;
  120. }
  121. void CM_StoreBrushes( leafList_t *ll, int nodenum ) {
  122. int i, k;
  123. int leafnum;
  124. int brushnum;
  125. cLeaf_t *leaf;
  126. cbrush_t *b;
  127. leafnum = -1 - nodenum;
  128. leaf = &cmg.leafs[leafnum];
  129. for ( k = 0 ; k < leaf->numLeafBrushes ; k++ ) {
  130. brushnum = cmg.leafbrushes[leaf->firstLeafBrush+k];
  131. b = &cmg.brushes[brushnum];
  132. if ( b->checkcount == cmg.checkcount ) {
  133. continue; // already checked this brush in another leaf
  134. }
  135. b->checkcount = cmg.checkcount;
  136. for ( i = 0 ; i < 3 ; i++ ) {
  137. if ( b->bounds[0][i] >= ll->bounds[1][i] || b->bounds[1][i] <= ll->bounds[0][i] ) {
  138. break;
  139. }
  140. }
  141. if ( i != 3 ) {
  142. continue;
  143. }
  144. if ( ll->count >= ll->maxcount) {
  145. ll->overflowed = qtrue;
  146. return;
  147. }
  148. ((cbrush_t **)ll->list)[ ll->count++ ] = b;
  149. }
  150. #if 0
  151. // store patches?
  152. for ( k = 0 ; k < leaf->numLeafSurfaces ; k++ ) {
  153. patch = cmg.surfaces[ cmg.leafsurfaces[ leaf->firstleafsurface + k ] ];
  154. if ( !patch ) {
  155. continue;
  156. }
  157. }
  158. #endif
  159. }
  160. /*
  161. =============
  162. CM_BoxLeafnums
  163. Fills in a list of all the leafs touched
  164. =============
  165. */
  166. void CM_BoxLeafnums_r( leafList_t *ll, int nodenum ) {
  167. cplane_t *plane;
  168. cNode_t *node;
  169. int s;
  170. #ifdef _XBOX
  171. if(!tr.world) {
  172. return;
  173. }
  174. #endif
  175. while (1) {
  176. if (nodenum < 0) {
  177. ll->storeLeafs( ll, nodenum );
  178. return;
  179. }
  180. node = &cmg.nodes[nodenum];
  181. #ifdef _XBOX
  182. plane = cmg.planes + tr.world->nodes[nodenum].planeNum;
  183. #else
  184. plane = node->plane;
  185. #endif
  186. s = BoxOnPlaneSide( ll->bounds[0], ll->bounds[1], plane );
  187. if (s == 1) {
  188. nodenum = node->children[0];
  189. } else if (s == 2) {
  190. nodenum = node->children[1];
  191. } else {
  192. // go down both
  193. CM_BoxLeafnums_r( ll, node->children[0] );
  194. nodenum = node->children[1];
  195. }
  196. }
  197. }
  198. /*
  199. ==================
  200. CM_BoxLeafnums
  201. ==================
  202. */
  203. int CM_BoxLeafnums( const vec3_t mins, const vec3_t maxs, int *boxList, int listsize, int *lastLeaf) {
  204. leafList_t ll;
  205. cmg.checkcount++;
  206. VectorCopy( mins, ll.bounds[0] );
  207. VectorCopy( maxs, ll.bounds[1] );
  208. ll.count = 0;
  209. ll.maxcount = listsize;
  210. ll.list = boxList;
  211. ll.storeLeafs = CM_StoreLeafs;
  212. ll.lastLeaf = 0;
  213. ll.overflowed = qfalse;
  214. CM_BoxLeafnums_r( &ll, 0 );
  215. *lastLeaf = ll.lastLeaf;
  216. return ll.count;
  217. }
  218. /*
  219. ==================
  220. CM_BoxBrushes
  221. ==================
  222. */
  223. int CM_BoxBrushes( const vec3_t mins, const vec3_t maxs, cbrush_t **boxlist, int listsize ) {
  224. leafList_t ll;
  225. cmg.checkcount++;
  226. VectorCopy( mins, ll.bounds[0] );
  227. VectorCopy( maxs, ll.bounds[1] );
  228. ll.count = 0;
  229. ll.maxcount = listsize;
  230. ll.list = (int *)boxlist;
  231. ll.storeLeafs = CM_StoreBrushes;
  232. ll.lastLeaf = 0;
  233. ll.overflowed = qfalse;
  234. CM_BoxLeafnums_r( &ll, 0 );
  235. return ll.count;
  236. }
  237. //====================================================================
  238. /*
  239. ==================
  240. CM_PointContents
  241. ==================
  242. */
  243. #if 1
  244. int CM_PointContents( const vec3_t p, clipHandle_t model ) {
  245. int leafnum=0;
  246. int i, k;
  247. int brushnum;
  248. cLeaf_t *leaf;
  249. cbrush_t *b;
  250. int contents;
  251. float d;
  252. cmodel_t *clipm;
  253. clipMap_t *local;
  254. if (!cmg.numNodes) { // map not loaded
  255. return 0;
  256. }
  257. if ( model ) {
  258. clipm = CM_ClipHandleToModel( model, &local );
  259. leaf = &clipm->leaf;
  260. }
  261. else
  262. {
  263. local = &cmg;
  264. CPoint pt(p[0],p[1],p[2]);
  265. /* map<CPoint,int,CPointComparator>::iterator l=pointToLeaf.find(pt);
  266. if(l!=pointToLeaf.end())
  267. {
  268. leafnum=(*l).second;
  269. }
  270. else
  271. {
  272. if(pointToLeaf.size()>=64)
  273. {
  274. pointToLeaf.clear();
  275. Com_Printf("Cleared cache\n");
  276. }
  277. leafnum=CM_PointLeafnum_r(p, 0);
  278. pointToLeaf[pt]=leafnum;
  279. }*/
  280. int l = 0;
  281. for ( ; l < sizePointToLeaf; ++l)
  282. {
  283. if (pointToLeaf[l].point == pt)
  284. {
  285. leafnum = pointToLeaf[l].leaf;
  286. break;
  287. }
  288. }
  289. if (l == sizePointToLeaf)
  290. { // Didn't find it
  291. if (sizePointToLeaf < MAX_POINTS_TO_LEAVES)
  292. { // We're adding a new one, rather than replacing
  293. sizePointToLeaf++;
  294. }
  295. else
  296. { // Put it in the "oldest" slot
  297. l = oldestPointToLeaf++;
  298. oldestPointToLeaf &= (MAX_POINTS_TO_LEAVES-1);
  299. }
  300. leafnum = CM_PointLeafnum_r(p, 0, local);
  301. pointToLeaf[l].leaf = leafnum;
  302. pointToLeaf[l].point = pt;
  303. }
  304. /*
  305. hlist<pair<CPoint,int> >::iterator l;
  306. for(l=pointToLeaf.begin();l!=pointToLeaf.end();l++)
  307. {
  308. if((*l).first==pt)
  309. {
  310. leafnum=(*l).second;
  311. break;
  312. }
  313. }
  314. if(l==pointToLeaf.end())
  315. {
  316. if(pointToLeaf.size()>=64)
  317. {
  318. pointToLeaf.pop_back();
  319. }
  320. leafnum=CM_PointLeafnum_r(p, 0, local);
  321. pointToLeaf.push_front(pair<CPoint,int>(pt,leafnum));
  322. }
  323. */
  324. leaf = &local->leafs[leafnum];
  325. }
  326. contents = 0;
  327. for (k=0 ; k<leaf->numLeafBrushes ; k++) {
  328. brushnum = local->leafbrushes[leaf->firstLeafBrush+k];
  329. b = &local->brushes[brushnum];
  330. // see if the point is in the brush
  331. for ( i = 0 ; i < b->numsides ; i++ ) {
  332. #ifdef _XBOX
  333. d = DotProduct( p,
  334. cmg.planes[b->sides[i].planeNum.GetValue()].normal );
  335. #else
  336. d = DotProduct( p, b->sides[i].plane->normal );
  337. #endif
  338. // FIXME test for Cash
  339. // if ( d >= b->sides[i].plane->dist ) {
  340. #ifdef _XBOX
  341. if ( d > cmg.planes[b->sides[i].planeNum.GetValue()].dist ) {
  342. #else
  343. if ( d > b->sides[i].plane->dist ) {
  344. #endif
  345. break;
  346. }
  347. }
  348. if ( i == b->numsides ) {
  349. contents |= b->contents;
  350. #ifndef _XBOX // Removing terrain from Xbox
  351. if(cmg.landScape && (contents & CONTENTS_TERRAIN) )
  352. {
  353. if(p[2] < cmg.landScape->GetWaterHeight())
  354. {
  355. contents |= cmg.landScape->GetWaterContents();
  356. }
  357. }
  358. #endif
  359. }
  360. }
  361. return contents;
  362. }
  363. #else
  364. int CM_PointContents( const vec3_t p, clipHandle_t model ) {
  365. int leafnum=0;
  366. int i, k;
  367. int brushnum;
  368. cLeaf_t *leaf;
  369. cbrush_t *b;
  370. int contents;
  371. float d;
  372. cmodel_t *clipm;
  373. if (!cmg.numNodes) { // map not loaded
  374. return 0;
  375. }
  376. CPoint pt(p[0],p[1],p[2]);
  377. if ( model )
  378. {
  379. clipm = CM_ClipHandleToModel( model );
  380. leaf = &clipm->leaf;
  381. }
  382. else
  383. {
  384. hlist<pair<CPoint,int> >::iterator l;
  385. for(l=pointToContents.begin();l!=pointToContents.end();l++)
  386. {
  387. if((*l).first==pt)
  388. {
  389. // Breakout early.
  390. return((*l).second);
  391. }
  392. }
  393. leafnum=CM_PointLeafnum_r(p, 0);
  394. leaf = &cmg.leafs[leafnum];
  395. }
  396. contents = 0;
  397. for (k=0 ; k<leaf->numLeafBrushes ; k++)
  398. {
  399. brushnum = cmg.leafbrushes[leaf->firstLeafBrush+k];
  400. b = &cmg.brushes[brushnum];
  401. // see if the point is in the brush
  402. for ( i = 0 ; i < b->numsides ; i++ )
  403. {
  404. d = DotProduct( p, b->sides[i].plane->normal );
  405. // FIXME test for Cash
  406. // if ( d >= b->sides[i].plane->dist ) {
  407. if ( d > b->sides[i].plane->dist )
  408. {
  409. break;
  410. }
  411. }
  412. if ( i == b->numsides )
  413. {
  414. contents |= b->contents;
  415. }
  416. }
  417. // Cache the result for next time.
  418. if(!model)
  419. {
  420. if(pointToContents.size()>=64)
  421. {
  422. pointToContents.pop_back();
  423. }
  424. pointToContents.push_front(pair<CPoint,int>(pt,contents));
  425. }
  426. return contents;
  427. }
  428. #endif
  429. /*
  430. ==================
  431. CM_TransformedPointContents
  432. Handles offseting and rotation of the end points for moving and
  433. rotating entities
  434. ==================
  435. */
  436. int CM_TransformedPointContents( const vec3_t p, clipHandle_t model, const vec3_t origin, const vec3_t angles) {
  437. vec3_t p_l;
  438. vec3_t temp;
  439. vec3_t forward, right, up;
  440. // subtract origin offset
  441. VectorSubtract (p, origin, p_l);
  442. // rotate start and end into the models frame of reference
  443. if ( model != BOX_MODEL_HANDLE &&
  444. (angles[0] || angles[1] || angles[2]) )
  445. {
  446. AngleVectors (angles, forward, right, up);
  447. VectorCopy (p_l, temp);
  448. p_l[0] = DotProduct (temp, forward);
  449. p_l[1] = -DotProduct (temp, right);
  450. p_l[2] = DotProduct (temp, up);
  451. }
  452. return CM_PointContents( p_l, model );
  453. }
  454. /*
  455. ===============================================================================
  456. PVS
  457. ===============================================================================
  458. */
  459. #ifdef _XBOX
  460. extern trGlobals_t tr;
  461. const byte *CM_ClusterPVS (int cluster) {
  462. if (cluster < 0 || cluster >= cmg.numClusters || !cmg.vised ) {
  463. return NULL;
  464. }
  465. return cmg.visibility->Decompress(cluster * cmg.clusterBytes,
  466. cmg.numClusters);
  467. }
  468. #else
  469. byte *CM_ClusterPVS (int cluster) {
  470. if (cluster < 0 || cluster >= cmg.numClusters || !cmg.vised ) {
  471. return cmg.visibility;
  472. }
  473. return cmg.visibility + cluster * cmg.clusterBytes;
  474. }
  475. #endif
  476. /*
  477. ===============================================================================
  478. AREAPORTALS
  479. ===============================================================================
  480. */
  481. #ifdef _XBOX
  482. void CM_FloodArea_r( int areaNum, int floodnum) {
  483. int i;
  484. cArea_t *area;
  485. int *con;
  486. area = &cmg.areas[ areaNum ];
  487. if ( area->floodvalid == cmg.floodvalid ) {
  488. if (area->floodnum == floodnum)
  489. return;
  490. Com_Error (ERR_DROP, "FloodArea_r: reflooded");
  491. }
  492. area->floodnum = floodnum;
  493. area->floodvalid = cmg.floodvalid;
  494. con = cmg.areaPortals + areaNum * cmg.numAreas;
  495. for ( i=0 ; i < cmg.numAreas ; i++ ) {
  496. if ( con[i] > 0 ) {
  497. CM_FloodArea_r( i, floodnum );
  498. }
  499. }
  500. }
  501. #else // _XBOX
  502. void CM_FloodArea_r( int areaNum, int floodnum, clipMap_t &cm) {
  503. int i;
  504. cArea_t *area;
  505. int *con;
  506. area = &cmg.areas[ areaNum ];
  507. if ( area->floodvalid == cmg.floodvalid ) {
  508. if (area->floodnum == floodnum)
  509. return;
  510. Com_Error (ERR_DROP, "FloodArea_r: reflooded");
  511. }
  512. area->floodnum = floodnum;
  513. area->floodvalid = cmg.floodvalid;
  514. con = cmg.areaPortals + areaNum * cmg.numAreas;
  515. for ( i=0 ; i < cmg.numAreas ; i++ ) {
  516. if ( con[i] > 0 ) {
  517. CM_FloodArea_r( i, floodnum, cm );
  518. }
  519. }
  520. }
  521. #endif // XBOX
  522. /*
  523. ====================
  524. CM_FloodAreaConnections
  525. ====================
  526. */
  527. #ifdef _XBOX
  528. void CM_FloodAreaConnections( void ) {
  529. int i;
  530. cArea_t *area;
  531. int floodnum;
  532. // all current floods are now invalid
  533. cmg.floodvalid++;
  534. floodnum = 0;
  535. for (i = 0 ; i < cmg.numAreas ; i++) {
  536. area = &cmg.areas[i];
  537. if (area->floodvalid == cmg.floodvalid) {
  538. continue; // already flooded into
  539. }
  540. floodnum++;
  541. CM_FloodArea_r (i, floodnum);
  542. }
  543. }
  544. #else // _XBOX
  545. void CM_FloodAreaConnections( clipMap_t &cm ) {
  546. int i;
  547. cArea_t *area;
  548. int floodnum;
  549. // all current floods are now invalid
  550. cmg.floodvalid++;
  551. floodnum = 0;
  552. for (i = 0 ; i < cmg.numAreas ; i++) {
  553. area = &cmg.areas[i];
  554. if (area->floodvalid == cmg.floodvalid) {
  555. continue; // already flooded into
  556. }
  557. floodnum++;
  558. CM_FloodArea_r (i, floodnum, cm);
  559. }
  560. }
  561. #endif // _XBOX
  562. /*
  563. ====================
  564. CM_AdjustAreaPortalState
  565. ====================
  566. */
  567. void CM_AdjustAreaPortalState( int area1, int area2, qboolean open ) {
  568. if ( area1 < 0 || area2 < 0 ) {
  569. return;
  570. }
  571. if ( area1 >= cmg.numAreas || area2 >= cmg.numAreas ) {
  572. Com_Error (ERR_DROP, "CM_ChangeAreaPortalState: bad area number");
  573. }
  574. if ( open ) {
  575. cmg.areaPortals[ area1 * cmg.numAreas + area2 ]++;
  576. cmg.areaPortals[ area2 * cmg.numAreas + area1 ]++;
  577. } else {
  578. cmg.areaPortals[ area1 * cmg.numAreas + area2 ]--;
  579. cmg.areaPortals[ area2 * cmg.numAreas + area1 ]--;
  580. if ( cmg.areaPortals[ area2 * cmg.numAreas + area1 ] < 0 ) {
  581. Com_Error (ERR_DROP, "CM_AdjustAreaPortalState: negative reference count");
  582. }
  583. }
  584. #ifdef _XBOX
  585. CM_FloodAreaConnections ();
  586. #else
  587. CM_FloodAreaConnections (cmg);
  588. #endif
  589. }
  590. /*
  591. ====================
  592. CM_AreasConnected
  593. ====================
  594. */
  595. qboolean CM_AreasConnected( int area1, int area2 ) {
  596. #ifndef BSPC
  597. if ( cm_noAreas->integer ) {
  598. return qtrue;
  599. }
  600. #endif
  601. if ( area1 < 0 || area2 < 0 ) {
  602. return qfalse;
  603. }
  604. if (area1 >= cmg.numAreas || area2 >= cmg.numAreas) {
  605. Com_Error (ERR_DROP, "area >= cmg.numAreas");
  606. }
  607. if (cmg.areas[area1].floodnum == cmg.areas[area2].floodnum) {
  608. return qtrue;
  609. }
  610. return qfalse;
  611. }
  612. /*
  613. =================
  614. CM_WriteAreaBits
  615. Writes a bit vector of all the areas
  616. that are in the same flood as the area parameter
  617. Returns the number of bytes needed to hold all the bits.
  618. The bits are OR'd in, so you can CM_WriteAreaBits from multiple
  619. viewpoints and get the union of all visible areas.
  620. This is used to cull non-visible entities from snapshots
  621. =================
  622. */
  623. int CM_WriteAreaBits (byte *buffer, int area)
  624. {
  625. int i;
  626. int floodnum;
  627. int bytes;
  628. bytes = (cmg.numAreas+7)>>3;
  629. #ifndef BSPC
  630. if (cm_noAreas->integer || area == -1)
  631. #else
  632. if ( area == -1)
  633. #endif
  634. { // for debugging, send everything
  635. memset (buffer, 255, bytes);
  636. }
  637. else
  638. {
  639. floodnum = cmg.areas[area].floodnum;
  640. for (i=0 ; i<cmg.numAreas ; i++)
  641. {
  642. if (cmg.areas[i].floodnum == floodnum || area == -1)
  643. buffer[i>>3] |= 1<<(i&7);
  644. }
  645. }
  646. return bytes;
  647. }
  648. void CM_SnapPVS(vec3_t origin,byte *buffer)
  649. {
  650. int clientarea;
  651. int leafnum;
  652. int i;
  653. leafnum = CM_PointLeafnum (origin);
  654. clientarea = CM_LeafArea (leafnum);
  655. // calculate the visible areas
  656. memset(buffer,0,MAX_MAP_AREA_BYTES);
  657. CM_WriteAreaBits(buffer,clientarea);
  658. for ( i = 0 ; i < MAX_MAP_AREA_BYTES/4 ; i++ ) {
  659. ((int *)buffer)[i] = ((int *)buffer)[i] ^ -1;
  660. }
  661. }