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

vis.c File Reference

#include "vis.h"
#include "threads.h"
#include "stdlib.h"

Include dependency graph for vis.c:

Include dependency graph

Go to the source code of this file.

Defines

#define CONTINUOUS_EPSILON   0.005
#define VIS_HEADER_SIZE   8
#define WCONVEX_EPSILON   0.2

Functions

void CalcFastVis (void)
void CalcPassagePortalVis (void)
void CalcPassageVis (void)
void CalcPHS (void)
void CalcPortalVis (void)
void CalcVis (void)
void ClusterMerge (int leafnum)
int CountActivePortals (void)
int LeafVectorFromPortalVector (byte *portalbits, byte *leafbits)
void LoadPortals (char *name)
void MergeLeafPortals (void)
void MergeLeaves (void)
winding_tNewWinding (int points)
void PassageMemory (void)
int PComp (const void *a, const void *b)
void PlaneFromWinding (winding_t *w, plane_t *plane)
void prl (leaf_t *l)
void SetPortalSphere (vportal_t *p)
void SortPortals (void)
int TryMergeLeaves (int l1num, int l2num)
winding_tTryMergeWinding (winding_t *f1, winding_t *f2, vec3_t planenormal)
void UpdatePortals (void)
int VisMain (int argc, char **argv)
int Winding_PlanesConcave (winding_t *w1, winding_t *w2, vec3_t normal1, vec3_t normal2, float dist1, float dist2)
void WriteFloat (FILE *f, vec_t v)
void WritePortals (char *filename)

Variables

int c_portalcheck
int c_portalpass
int c_portaltest
leaf_tfaceleafs
vportal_tfaces
qboolean fastvis
char inbase [32]
int leafbytes
int leaflongs
leaf_tleafs
qboolean mergevis
qboolean noPassageVis
qboolean nosort
int numfaces
int numportals
char outbase [32]
qboolean passageVisOnly
int portalbytes
int portalclusters
int portallongs
vportal_tportals
qboolean saveprt
vportal_tsorted_portals [MAX_MAP_PORTALS *2]
int testlevel = 2
int totalvis


Define Documentation

#define CONTINUOUS_EPSILON   0.005
 

Definition at line 584 of file vis.c.

#define VIS_HEADER_SIZE   8
 

Definition at line 32 of file vis.c.

Referenced by ClusterMerge(), and LoadPortals().

#define WCONVEX_EPSILON   0.2
 

Definition at line 407 of file vis.c.


Function Documentation

void CalcFastVis void   ) 
 

Definition at line 318 of file vis.c.

References i, numportals, and portals.

Referenced by CalcVis().

00319 {
00320     int     i;
00321 
00322     // fastvis just uses mightsee for a very loose bound
00323     for (i=0 ; i<numportals*2 ; i++)
00324     {
00325         portals[i].portalvis = portals[i].portalflood;
00326         portals[i].status = stat_done;
00327     }
00328 }

void CalcPassagePortalVis void   ) 
 

Definition at line 296 of file vis.c.

References _printf(), CreatePassages(), numportals, PassageMemory(), PassagePortalFlow(), qfalse, qtrue, and RunThreadsOnIndividual().

Referenced by CalcVis().

00297 {
00298     PassageMemory();
00299 
00300 #ifdef MREDEBUG
00301     _printf("%6d portals out of %d", 0, numportals*2);
00302     RunThreadsOnIndividual (numportals*2, qfalse, CreatePassages);
00303     _printf("\n");
00304     _printf("%6d portals out of %d", 0, numportals*2);
00305     RunThreadsOnIndividual (numportals*2, qfalse, PassagePortalFlow);
00306     _printf("\n");
00307 #else
00308     RunThreadsOnIndividual (numportals*2, qtrue, CreatePassages);
00309     RunThreadsOnIndividual (numportals*2, qtrue, PassagePortalFlow);
00310 #endif
00311 }

Here is the call graph for this function:

void CalcPassageVis void   ) 
 

Definition at line 274 of file vis.c.

References _printf(), CreatePassages(), numportals, PassageFlow(), PassageMemory(), qfalse, qtrue, and RunThreadsOnIndividual().

Referenced by CalcVis().

00275 {
00276     PassageMemory();
00277 
00278 #ifdef MREDEBUG
00279     _printf("%6d portals out of %d", 0, numportals*2);
00280     RunThreadsOnIndividual (numportals*2, qfalse, CreatePassages);
00281     _printf("\n");
00282     _printf("%6d portals out of %d", 0, numportals*2);
00283     RunThreadsOnIndividual (numportals*2, qfalse, PassageFlow);
00284     _printf("\n");
00285 #else
00286     RunThreadsOnIndividual (numportals*2, qtrue, CreatePassages);
00287     RunThreadsOnIndividual (numportals*2, qtrue, PassageFlow);
00288 #endif
00289 }

Here is the call graph for this function:

void CalcPHS void   ) 
 

Definition at line 1030 of file vis.c.

References _printf(), byte, count, Error(), i, j, k, l, leafbytes, MAX_MAP_LEAFS, memcpy(), portalclusters, src, uncompressed, and visBytes.

01031 {
01032     int     i, j, k, l, index;
01033     int     bitbyte;
01034     long    *dest, *src;
01035     byte    *scan;
01036     int     count;
01037     byte    uncompressed[MAX_MAP_LEAFS/8];
01038 
01039     _printf ("Building PHS...\n");
01040 
01041     count = 0;
01042     for (i=0 ; i<portalclusters ; i++)
01043     {
01044         scan = visBytes + i*leafbytes;
01045         memcpy (uncompressed, scan, leafbytes);
01046         for (j=0 ; j<leafbytes ; j++)
01047         {
01048             bitbyte = scan[j];
01049             if (!bitbyte)
01050                 continue;
01051             for (k=0 ; k<8 ; k++)
01052             {
01053                 if (! (bitbyte & (1<<k)) )
01054                     continue;
01055                 // OR this pvs row into the phs
01056                 index = ((j<<3)+k);
01057                 if (index >= portalclusters)
01058                     Error ("Bad bit in PVS");   // pad bits should be 0
01059                 src = (long *)(visBytes + index*leafbytes);
01060                 dest = (long *)uncompressed;
01061                 for (l=0 ; l<leaflongs ; l++)
01062                     ((long *)uncompressed)[l] |= src[l];
01063             }
01064         }
01065         for (j=0 ; j<portalclusters ; j++)
01066             if (uncompressed[j>>3] & (1<<(j&7)) )
01067                 count++;
01068 
01069         // FIXME: copy it off
01070     }
01071 
01072     _printf ("Average clusters hearable: %i\n", count/portalclusters);
01073 }

Here is the call graph for this function:

void CalcPortalVis void   ) 
 

Definition at line 257 of file vis.c.

References _printf(), numportals, PortalFlow(), qfalse, qtrue, and RunThreadsOnIndividual().

Referenced by CalcVis().

00258 {
00259 #ifdef MREDEBUG
00260     _printf("%6d portals out of %d", 0, numportals*2);
00261     //get rid of the counter
00262     RunThreadsOnIndividual (numportals*2, qfalse, PortalFlow);
00263 #else
00264     RunThreadsOnIndividual (numportals*2, qtrue, PortalFlow);
00265 #endif
00266 
00267 }

Here is the call graph for this function:

void CalcVis void   ) 
 

Definition at line 335 of file vis.c.

References _printf(), BasePortalVis(), CalcFastVis(), CalcPassagePortalVis(), CalcPassageVis(), CalcPortalVis(), ClusterMerge(), i, numportals, portalclusters, qtrue, RunThreadsOnIndividual(), SortPortals(), and totalvis.

Referenced by VisMain().

00336 {
00337     int     i;
00338 
00339     RunThreadsOnIndividual (numportals*2, qtrue, BasePortalVis);
00340 
00341 //  RunThreadsOnIndividual (numportals*2, qtrue, BetterPortalVis);
00342 
00343     SortPortals ();
00344 
00345     if (fastvis) {
00346         CalcFastVis();
00347     }
00348     else if ( noPassageVis ) {
00349         CalcPortalVis();
00350     }
00351     else if ( passageVisOnly ) {
00352         CalcPassageVis();
00353     }
00354     else {
00355         CalcPassagePortalVis();
00356     }
00357     //
00358     // assemble the leaf vis lists by oring and compressing the portal lists
00359     //
00360     _printf("creating leaf vis...\n");
00361     for (i=0 ; i<portalclusters ; i++)
00362         ClusterMerge (i);
00363 
00364     _printf( "Total visible clusters: %i\n", totalvis );
00365     _printf( "Average clusters visible: %i\n", totalvis / portalclusters );
00366 }

Here is the call graph for this function:

void ClusterMerge int  leafnum  ) 
 

Definition at line 200 of file vis.c.

References byte, Error(), i, j, leaf_t, leafbytes, leafs, LeafVectorFromPortalVector(), MAX_MAP_LEAFS, MAX_PORTALS, memcpy(), memset(), leaf_s::numportals, p, portalbytes, leaf_s::portals, vportal_t::portalvis, qprintf(), vportal_t::removed, vportal_t::status, totalvis, uncompressed, VIS_HEADER_SIZE, and visBytes.

Referenced by CalcVis().

00201 {
00202     leaf_t      *leaf;
00203     byte        portalvector[MAX_PORTALS/8];
00204     byte        uncompressed[MAX_MAP_LEAFS/8];
00205     int         i, j;
00206     int         numvis, mergedleafnum;
00207     vportal_t   *p;
00208     int         pnum;
00209 
00210     // OR together all the portalvis bits
00211 
00212     mergedleafnum = leafnum;
00213     while(leafs[mergedleafnum].merged >= 0)
00214         mergedleafnum = leafs[mergedleafnum].merged;
00215 
00216     memset (portalvector, 0, portalbytes);
00217     leaf = &leafs[mergedleafnum];
00218     for (i = 0; i < leaf->numportals; i++)
00219     {
00220         p = leaf->portals[i];
00221         if (p->removed)
00222             continue;
00223 
00224         if (p->status != stat_done)
00225             Error ("portal not done");
00226         for (j=0 ; j<portallongs ; j++)
00227             ((long *)portalvector)[j] |= ((long *)p->portalvis)[j];
00228         pnum = p - portals;
00229         portalvector[pnum>>3] |= 1<<(pnum&7);
00230     }
00231 
00232     memset (uncompressed, 0, leafbytes);
00233 
00234     uncompressed[mergedleafnum>>3] |= (1<<(mergedleafnum&7));
00235     // convert portal bits to leaf bits
00236     numvis = LeafVectorFromPortalVector (portalvector, uncompressed);
00237 
00238 //  if (uncompressed[leafnum>>3] & (1<<(leafnum&7)))
00239 //      _printf ("WARNING: Leaf portals saw into leaf\n");
00240         
00241 //  uncompressed[leafnum>>3] |= (1<<(leafnum&7));
00242 
00243     numvis++;       // count the leaf itself
00244 
00245     totalvis += numvis;
00246 
00247     qprintf ("cluster %4i : %4i visible\n", leafnum, numvis);
00248 
00249     memcpy (visBytes + VIS_HEADER_SIZE + leafnum*leafbytes, uncompressed, leafbytes);
00250 }

Here is the call graph for this function:

int CountActivePortals void   ) 
 

Definition at line 742 of file vis.c.

References _printf(), vportal_t::hint, j, numportals, p, portals, and vportal_t::removed.

Referenced by VisMain().

00743 {
00744     int num, hints, j;
00745     vportal_t *p;
00746 
00747     num = 0;
00748     hints = 0;
00749     for (j = 0; j < numportals * 2; j++)
00750     {
00751         p = portals + j;
00752         if (p->removed)
00753             continue;
00754         if (p->hint)
00755             hints++;
00756         num++;
00757     }
00758     _printf("%6d active portals\n", num);
00759     _printf("%6d hint portals\n", hints);
00760     return num;
00761 }

Here is the call graph for this function:

int LeafVectorFromPortalVector byte portalbits,
byte leafbits
 

Definition at line 159 of file vis.c.

References byte, CountBits(), i, j, vportal_t::leaf, leafs, numportals, p, portalclusters, and portals.

Referenced by ClusterMerge().

00160 {
00161     int         i, j, leafnum;
00162     vportal_t   *p;
00163     int         c_leafs;
00164 
00165 
00166     for (i=0 ; i<numportals*2 ; i++)
00167     {
00168         if (portalbits[i>>3] & (1<<(i&7)) )
00169         {
00170             p = portals+i;
00171             leafbits[p->leaf>>3] |= (1<<(p->leaf&7));
00172         }
00173     }
00174 
00175     for (j = 0; j < portalclusters; j++)
00176     {
00177         leafnum = j;
00178         while (leafs[leafnum].merged >= 0)
00179             leafnum = leafs[leafnum].merged;
00180         //if the merged leaf is visible then the original leaf is visible
00181         if (leafbits[leafnum>>3] & (1<<(leafnum&7)))
00182         {
00183             leafbits[j>>3] |= (1<<(j&7));
00184         }
00185     }
00186 
00187     c_leafs = CountBits (leafbits, portalclusters);
00188 
00189     return c_leafs;
00190 }

Here is the call graph for this function:

void LoadPortals char *  name  ) 
 

Definition at line 845 of file vis.c.

References _printf(), plane_t::dist, Error(), f, faceleafs, faces, fclose(), fopen(), fscanf(), vportal_t::hint, i, j, k, l, vportal_t::leaf, leaf_t, leafbytes, leaflongs, leafs, malloc(), memset(), leaf_s::merged, name, NewWinding(), plane_t::normal, vportal_t::num, numfaces, winding_t::numpoints, leaf_s::numportals, numportals, numVisBytes, p, vportal_t::plane, PlaneFromWinding(), winding_t::points, portalbytes, portalclusters, PORTALFILE, portallongs, leaf_s::portals, portals, SetPortalSphere(), strcmp(), v, vec3_origin, VectorCopy, VectorSubtract, VIS_HEADER_SIZE, w, and vportal_t::winding.

Referenced by VisMain().

00846 {
00847     int         i, j, hint;
00848     vportal_t   *p;
00849     leaf_t      *l;
00850     char        magic[80];
00851     FILE        *f;
00852     int         numpoints;
00853     winding_t   *w;
00854     int         leafnums[2];
00855     plane_t     plane;
00856     
00857     if (!strcmp(name,"-"))
00858         f = stdin;
00859     else
00860     {
00861         f = fopen(name, "r");
00862         if (!f)
00863             Error ("LoadPortals: couldn't read %s\n",name);
00864     }
00865 
00866     if (fscanf (f,"%79s\n%i\n%i\n%i\n",magic, &portalclusters, &numportals, &numfaces) != 4)
00867         Error ("LoadPortals: failed to read header");
00868     if (strcmp(magic,PORTALFILE))
00869         Error ("LoadPortals: not a portal file");
00870 
00871     _printf ("%6i portalclusters\n", portalclusters);
00872     _printf ("%6i numportals\n", numportals);
00873     _printf ("%6i numfaces\n", numfaces);
00874 
00875     // these counts should take advantage of 64 bit systems automatically
00876     leafbytes = ((portalclusters+63)&~63)>>3;
00877     leaflongs = leafbytes/sizeof(long);
00878     
00879     portalbytes = ((numportals*2+63)&~63)>>3;
00880     portallongs = portalbytes/sizeof(long);
00881 
00882     // each file portal is split into two memory portals
00883     portals = malloc(2*numportals*sizeof(vportal_t));
00884     memset (portals, 0, 2*numportals*sizeof(vportal_t));
00885     
00886     leafs = malloc(portalclusters*sizeof(leaf_t));
00887     memset (leafs, 0, portalclusters*sizeof(leaf_t));
00888 
00889     for (i = 0; i < portalclusters; i++)
00890         leafs[i].merged = -1;
00891 
00892     numVisBytes = VIS_HEADER_SIZE + portalclusters*leafbytes;
00893 
00894     ((int *)visBytes)[0] = portalclusters;
00895     ((int *)visBytes)[1] = leafbytes;
00896         
00897     for (i=0, p=portals ; i<numportals ; i++)
00898     {
00899         if (fscanf (f, "%i %i %i ", &numpoints, &leafnums[0], &leafnums[1]) != 3)
00900             Error ("LoadPortals: reading portal %i", i);
00901         if (numpoints > MAX_POINTS_ON_WINDING)
00902             Error ("LoadPortals: portal %i has too many points", i);
00903         if ( (unsigned)leafnums[0] > portalclusters
00904         || (unsigned)leafnums[1] > portalclusters)
00905             Error ("LoadPortals: reading portal %i", i);
00906         if (fscanf (f, "%i ", &hint) != 1)
00907             Error ("LoadPortals: reading hint state");
00908         
00909         w = p->winding = NewWinding (numpoints);
00910         w->numpoints = numpoints;
00911         
00912         for (j=0 ; j<numpoints ; j++)
00913         {
00914             double  v[3];
00915             int     k;
00916 
00917             // scanf into double, then assign to vec_t
00918             // so we don't care what size vec_t is
00919             if (fscanf (f, "(%lf %lf %lf ) "
00920             , &v[0], &v[1], &v[2]) != 3)
00921                 Error ("LoadPortals: reading portal %i", i);
00922             for (k=0 ; k<3 ; k++)
00923                 w->points[j][k] = v[k];
00924         }
00925         fscanf (f, "\n");
00926         
00927         // calc plane
00928         PlaneFromWinding (w, &plane);
00929 
00930         // create forward portal
00931         l = &leafs[leafnums[0]];
00932         if (l->numportals == MAX_PORTALS_ON_LEAF)
00933             Error ("Leaf with too many portals");
00934         l->portals[l->numportals] = p;
00935         l->numportals++;
00936         
00937         p->num = i+1;
00938         p->hint = hint;
00939         p->winding = w;
00940         VectorSubtract (vec3_origin, plane.normal, p->plane.normal);
00941         p->plane.dist = -plane.dist;
00942         p->leaf = leafnums[1];
00943         SetPortalSphere (p);
00944         p++;
00945         
00946         // create backwards portal
00947         l = &leafs[leafnums[1]];
00948         if (l->numportals == MAX_PORTALS_ON_LEAF)
00949             Error ("Leaf with too many portals");
00950         l->portals[l->numportals] = p;
00951         l->numportals++;
00952         
00953         p->num = i+1;
00954         p->hint = hint;
00955         p->winding = NewWinding(w->numpoints);
00956         p->winding->numpoints = w->numpoints;
00957         for (j=0 ; j<w->numpoints ; j++)
00958         {
00959             VectorCopy (w->points[w->numpoints-1-j], p->winding->points[j]);
00960         }
00961 
00962         p->plane = plane;
00963         p->leaf = leafnums[0];
00964         SetPortalSphere (p);
00965         p++;
00966 
00967     }
00968 
00969     faces = malloc(2*numfaces*sizeof(vportal_t));
00970     memset (faces, 0, 2*numfaces*sizeof(vportal_t));
00971 
00972     faceleafs = malloc(portalclusters*sizeof(leaf_t));
00973     memset(faceleafs, 0, portalclusters*sizeof(leaf_t));
00974 
00975     for (i = 0, p = faces; i < numfaces; i++)
00976     {
00977         if (fscanf (f, "%i %i ", &numpoints, &leafnums[0]) != 2)
00978             Error ("LoadPortals: reading portal %i", i);
00979 
00980         w = p->winding = NewWinding (numpoints);
00981         w->numpoints = numpoints;
00982         
00983         for (j=0 ; j<numpoints ; j++)
00984         {
00985             double  v[3];
00986             int     k;
00987 
00988             // scanf into double, then assign to vec_t
00989             // so we don't care what size vec_t is
00990             if (fscanf (f, "(%lf %lf %lf ) "
00991             , &v[0], &v[1], &v[2]) != 3)
00992                 Error ("LoadPortals: reading portal %i", i);
00993             for (k=0 ; k<3 ; k++)
00994                 w->points[j][k] = v[k];
00995         }
00996         fscanf (f, "\n");
00997         
00998         // calc plane
00999         PlaneFromWinding (w, &plane);
01000 
01001         l = &faceleafs[leafnums[0]];
01002         l->merged = -1;
01003         if (l->numportals == MAX_PORTALS_ON_LEAF)
01004             Error ("Leaf with too many faces");
01005         l->portals[l->numportals] = p;
01006         l->numportals++;
01007         
01008         p->num = i+1;
01009         p->winding = w;
01010         // normal pointing out of the leaf
01011         VectorSubtract (vec3_origin, plane.normal, p->plane.normal);
01012         p->plane.dist = -plane.dist;
01013         p->leaf = -1;
01014         SetPortalSphere (p);
01015         p++;
01016     }
01017     
01018     fclose (f);
01019 }

Here is the call graph for this function:

void MergeLeafPortals void   ) 
 

Definition at line 687 of file vis.c.

References _printf(), FreeWinding(), vportal_t::hint, i, j, k, vportal_t::leaf, leaf_t, leafs, leaf_s::merged, plane_t::normal, leaf_s::numportals, p2, vportal_t::plane, leaf_s::portals, vportal_t::removed, SetPortalSphere(), TryMergeWinding(), w, and vportal_t::winding.

Referenced by VisMain().

00688 {
00689     int i, j, k, nummerges, hintsmerged;
00690     leaf_t *leaf;
00691     vportal_t *p1, *p2;
00692     winding_t *w;
00693 
00694     nummerges = 0;
00695     hintsmerged = 0;
00696     for (i = 0; i < portalclusters; i++)
00697     {
00698         leaf = &leafs[i];
00699         if (leaf->merged >= 0) continue;
00700         for (j = 0; j < leaf->numportals; j++)
00701         {
00702             p1 = leaf->portals[j];
00703             if (p1->removed)
00704                 continue;
00705             for (k = j+1; k < leaf->numportals; k++)
00706             {
00707                 p2 = leaf->portals[k];
00708                 if (p2->removed)
00709                     continue;
00710                 if (p1->leaf == p2->leaf)
00711                 {
00712                     w = TryMergeWinding(p1->winding, p2->winding, p1->plane.normal);
00713                     if (w)
00714                     {
00715                         FreeWinding(p1->winding);
00716                         p1->winding = w;
00717                         if (p1->hint && p2->hint)
00718                             hintsmerged++;
00719                         p1->hint |= p2->hint;
00720                         SetPortalSphere(p1);
00721                         p2->removed = qtrue;
00722                         nummerges++;
00723                         i--;
00724                         break;
00725                     }
00726                 }
00727             }
00728             if (k < leaf->numportals)
00729                 break;
00730         }
00731     }
00732     _printf("%6d portals merged\n", nummerges);
00733     _printf("%6d hint portals merged\n", hintsmerged);
00734 }

Here is the call graph for this function:

void MergeLeaves void   ) 
 

Definition at line 540 of file vis.c.

References _printf(), vportal_t::hint, i, j, vportal_t::leaf, leaf_t, leafs, leaf_s::merged, leaf_s::numportals, p, leaf_s::portals, vportal_t::removed, TryMergeLeaves(), and UpdatePortals().

Referenced by VisMain().

00541 {
00542     int i, j, nummerges, totalnummerges;
00543     leaf_t *leaf;
00544     vportal_t *p;
00545 
00546     totalnummerges = 0;
00547     do
00548     {
00549         nummerges = 0;
00550         for (i = 0; i < portalclusters; i++)
00551         {
00552             leaf = &leafs[i];
00553             //if this leaf is merged already
00554             if (leaf->merged >= 0)
00555                 continue;
00556             //
00557             for (j = 0; j < leaf->numportals; j++)
00558             {
00559                 p = leaf->portals[j];
00560                 //
00561                 if (p->removed)
00562                     continue;
00563                 //never merge through hint portals
00564                 if (p->hint)
00565                     continue;
00566                 if (TryMergeLeaves(i, p->leaf))
00567                 {
00568                     UpdatePortals();
00569                     nummerges++;
00570                     break;
00571                 }
00572             }
00573         }
00574         totalnummerges += nummerges;
00575     } while (nummerges);
00576     _printf("%6d leaves merged\n", totalnummerges);
00577 }

Here is the call graph for this function:

winding_t* NewWinding int  points  ) 
 

Definition at line 91 of file vis.c.

References Error(), malloc(), memset(), points, winding_t::points, and w.

Referenced by LoadPortals(), and TryMergeWinding().

00092 {
00093     winding_t   *w;
00094     int         size;
00095     
00096     if (points > MAX_POINTS_ON_WINDING)
00097         Error ("NewWinding: %i points", points);
00098     
00099     size = (int)((winding_t *)0)->points[points];
00100     w = malloc (size);
00101     memset (w, 0, size);
00102     
00103     return w;
00104 }

Here is the call graph for this function:

void PassageMemory void   ) 
 

Definition at line 1395 of file visflow.c.

References _printf(), i, j, vportal_t::leaf, leaf_t, leafs, leaf_s::numportals, numportals, passage_t, leaf_s::portals, vportal_t::removed, and sorted_portals.

Referenced by CalcPassagePortalVis(), and CalcPassageVis().

01396 {
01397     int i, j, totalmem, totalportals;
01398     vportal_t *portal, *target;
01399     leaf_t *leaf;
01400 
01401     totalmem = 0;
01402     totalportals = 0;
01403     for (i = 0; i < numportals; i++)
01404     {
01405         portal = sorted_portals[i];
01406         if (portal->removed)
01407             continue;
01408         leaf = &leafs[portal->leaf];
01409         for (j = 0; j < leaf->numportals; j++)
01410         {
01411             target = leaf->portals[j];
01412             if (target->removed)
01413                 continue;
01414             totalmem += sizeof(passage_t) + portalbytes;
01415             totalportals++;
01416         }
01417     }
01418     _printf("%7i average number of passages per leaf\n", totalportals / numportals);
01419     _printf("%7i MB required passage memory\n", totalmem >> 10 >> 10);
01420 }

Here is the call graph for this function:

int PComp const void *  a,
const void *  b
 

Definition at line 133 of file vis.c.

Referenced by SortPortals().

00134 {
00135     if ( (*(vportal_t **)a)->nummightsee == (*(vportal_t **)b)->nummightsee)
00136         return 0;
00137     if ( (*(vportal_t **)a)->nummightsee < (*(vportal_t **)b)->nummightsee)
00138         return -1;
00139     return 1;
00140 }

void PlaneFromWinding winding_t w,
plane_t plane
 

Definition at line 73 of file vis.c.

References CrossProduct(), plane_t::dist, DotProduct, plane_t::normal, winding_t::points, v1, v2, vec3_t, VectorNormalize(), VectorSubtract, and w.

Referenced by LoadPortals().

00074 {
00075     vec3_t      v1, v2;
00076 
00077 // calc plane
00078     VectorSubtract (w->points[2], w->points[1], v1);
00079     VectorSubtract (w->points[0], w->points[1], v2);
00080     CrossProduct (v2, v1, plane->normal);
00081     VectorNormalize (plane->normal, plane->normal);
00082     plane->dist = DotProduct (w->points[0], plane->normal);
00083 }

Here is the call graph for this function:

void prl leaf_t l  ) 
 

Definition at line 108 of file vis.c.

References _printf(), plane_t::dist, i, l, vportal_t::leaf, leaf_t, plane_t::normal, leaf_s::numportals, p, vportal_t::plane, portals, and leaf_s::portals.

00109 {
00110     int         i;
00111     vportal_t   *p;
00112     plane_t     pl;
00113     
00114     for (i=0 ; i<l->numportals ; i++)
00115     {
00116         p = l->portals[i];
00117         pl = p->plane;
00118         _printf ("portal %4i to leaf %4i : %7.1f : (%4.1f, %4.1f, %4.1f)\n",(int)(p-portals),p->leaf,pl.dist, pl.normal[0], pl.normal[1], pl.normal[2]);
00119     }
00120 }

Here is the call graph for this function:

void SetPortalSphere vportal_t p  ) 
 

Definition at line 373 of file vis.c.

References i, winding_t::numpoints, vportal_t::origin, p, winding_t::points, r, vportal_t::radius, vec3_origin, vec3_t, VectorAdd, VectorCopy, VectorLength(), VectorSubtract, w, and vportal_t::winding.

Referenced by LoadPortals(), and MergeLeafPortals().

00374 {
00375     int     i;
00376     vec3_t  total, dist;
00377     winding_t   *w;
00378     float   r, bestr;
00379 
00380     w = p->winding;
00381     VectorCopy (vec3_origin, total);
00382     for (i=0 ; i<w->numpoints ; i++)
00383     {
00384         VectorAdd (total, w->points[i], total);
00385     }
00386     
00387     for (i=0 ; i<3 ; i++)
00388         total[i] /= w->numpoints;
00389 
00390     bestr = 0;      
00391     for (i=0 ; i<w->numpoints ; i++)
00392     {
00393         VectorSubtract (w->points[i], total, dist);
00394         r = VectorLength (dist);
00395         if (r > bestr)
00396             bestr = r;
00397     }
00398     VectorCopy (total, p->origin);
00399     p->radius = bestr;
00400 }

Here is the call graph for this function:

void SortPortals void   )