}
/*
- =================
- WritePortalFile_r
- =================
- */
- void WritePortalFile_r (node_t *node)
- {
- int i, s, flags;
- portal_t *p;
- winding_t *w;
- vec3_t normal;
- vec_t dist;
+ =================
+ WritePortalFile_r
+ =================
+ */
+ void WritePortalFile_r( node_t *node ){
- int i, s;
++ int i, s, flags;
+ portal_t *p;
+ winding_t *w;
+ vec3_t normal;
+ vec_t dist;
// decision node
- if (node->planenum != PLANENUM_LEAF) {
- WritePortalFile_r (node->children[0]);
- WritePortalFile_r (node->children[1]);
+ if ( node->planenum != PLANENUM_LEAF ) {
+ WritePortalFile_r( node->children[0] );
+ WritePortalFile_r( node->children[1] );
return;
}
-
- if (node->opaque) {
+
+ if ( node->opaque ) {
return;
}
// the changeover point between different axis. interpret the
// plane the same way vis will, and flip the side orders if needed
// FIXME: is this still relevent?
- WindingPlane (w, normal, &dist);
+ WindingPlane( w, normal, &dist );
- if ( DotProduct (p->plane.normal, normal) < 0.99 )
- { // backwards...
- fprintf (pf,"%i %i %i ",w->numpoints, p->nodes[1]->cluster, p->nodes[0]->cluster);
+ if ( DotProduct( p->plane.normal, normal ) < 0.99 ) { // backwards...
+ fprintf( pf,"%i %i %i ",w->numpoints, p->nodes[1]->cluster, p->nodes[0]->cluster );
+ }
+ else{
+ fprintf( pf,"%i %i %i ",w->numpoints, p->nodes[0]->cluster, p->nodes[1]->cluster );
}
- else
- fprintf (pf,"%i %i %i ",w->numpoints, p->nodes[0]->cluster, p->nodes[1]->cluster);
-
+ flags = 0;
++
/* ydnar: added this change to make antiportals work */
- if( p->compileFlags & C_HINT )
- if ( p->compileFlags & C_HINT ) {
- fprintf( pf, "1 " );
++ if( p->compileFlags & C_HINT ) {
+ flags |= 1;
+ }
- else{
- fprintf( pf, "0 " );
+
+ /* divVerent: I want farplanedist to not kill skybox. So... */
- if( p->compileFlags & C_SKY )
++ if( p->compileFlags & C_SKY ) {
+ flags |= 2;
+ }
-
+ fprintf( pf, "%d ", flags );
++
/* write the winding */
- for (i=0 ; i<w->numpoints ; i++)
+ for ( i = 0 ; i < w->numpoints ; i++ )
{
- fprintf (pf,"(");
- WriteFloat (pf, w->p[i][0]);
- WriteFloat (pf, w->p[i][1]);
- WriteFloat (pf, w->p[i][2]);
- fprintf (pf,") ");
+ fprintf( pf,"(" );
+ WriteFloat( pf, w->p[i][0] );
+ WriteFloat( pf, w->p[i][1] );
+ WriteFloat( pf, w->p[i][2] );
+ fprintf( pf,") " );
}
- fprintf (pf,"\n");
+ fprintf( pf,"\n" );
}
}
typedef struct
{
- int num;
- qboolean hint; /* true if this portal was created from a hint splitter */
- qboolean sky; /* true if this portal belongs to a sky leaf */
- qboolean removed;
- visPlane_t plane; /* normal pointing into neighbor */
- int leaf; /* neighbor */
-
- vec3_t origin; /* for fast clip testing */
- float radius;
-
- fixedWinding_t *winding;
- vstatus_t status;
- byte *portalfront; /* [portals], preliminary */
- byte *portalflood; /* [portals], intermediate */
- byte *portalvis; /* [portals], final */
-
- int nummightsee; /* bit count on portalflood for sort */
- passage_t *passages; /* there are just as many passages as there */
- /* are portals in the leaf this portal leads */
+ int num;
+ qboolean hint; /* true if this portal was created from a hint splitter */
++ qboolean sky; /* true if this portal belongs to a sky leaf */
+ qboolean removed;
+ visPlane_t plane; /* normal pointing into neighbor */
+ int leaf; /* neighbor */
+
+ vec3_t origin; /* for fast clip testing */
+ float radius;
+
+ fixedWinding_t *winding;
+ vstatus_t status;
+ byte *portalfront; /* [portals], preliminary */
+ byte *portalflood; /* [portals], intermediate */
+ byte *portalvis; /* [portals], final */
+
+ int nummightsee; /* bit count on portalflood for sort */
+ passage_t *passages; /* there are just as many passages as there */
+ /* are portals in the leaf this portal leads */
}
vportal_t;
}
/*
- ============
- LoadPortals
- ============
- */
- void LoadPortals (char *name)
- {
- int i, j, flags;
- vportal_t *p;
- leaf_t *l;
- char magic[80];
- FILE *f;
- int numpoints;
- fixedWinding_t *w;
- int leafnums[2];
- visPlane_t plane;
-
- if (!strcmp(name,"-"))
+ ============
+ LoadPortals
+ ============
+ */
+ void LoadPortals( char *name ){
- int i, j, hint;
++ int i, j, flags;
+ vportal_t *p;
+ leaf_t *l;
+ char magic[80];
+ FILE *f;
+ int numpoints;
+ fixedWinding_t *w;
+ int leafnums[2];
+ visPlane_t plane;
+
+ if ( !strcmp( name,"-" ) ) {
f = stdin;
+ }
else
{
- f = fopen(name, "r");
- if (!f)
- Error ("LoadPortals: couldn't read %s\n",name);
+ f = fopen( name, "r" );
+ if ( !f ) {
+ Error( "LoadPortals: couldn't read %s\n",name );
+ }
}
- if (fscanf (f,"%79s\n%i\n%i\n%i\n",magic, &portalclusters, &numportals, &numfaces) != 4)
- Error ("LoadPortals: failed to read header");
- if (strcmp(magic,PORTALFILE))
- Error ("LoadPortals: not a portal file");
+ if ( fscanf( f,"%79s\n%i\n%i\n%i\n",magic, &portalclusters, &numportals, &numfaces ) != 4 ) {
+ Error( "LoadPortals: failed to read header" );
+ }
+ if ( strcmp( magic,PORTALFILE ) ) {
+ Error( "LoadPortals: not a portal file" );
+ }
+
+ Sys_Printf( "%6i portalclusters\n", portalclusters );
+ Sys_Printf( "%6i numportals\n", numportals );
+ Sys_Printf( "%6i numfaces\n", numfaces );
- Sys_Printf ("%6i portalclusters\n", portalclusters);
- Sys_Printf ("%6i numportals\n", numportals);
- Sys_Printf ("%6i numfaces\n", numfaces);
+ if ( numportals > MAX_PORTALS ) {
+ Error( "MAX_PORTALS" );
+ }
- if(numportals > MAX_PORTALS)
- Error("MAX_PORTALS");
-
// these counts should take advantage of 64 bit systems automatically
- leafbytes = ((portalclusters+63)&~63)>>3;
- leaflongs = leafbytes/sizeof(long);
-
- portalbytes = ((numportals*2+63)&~63)>>3;
- portallongs = portalbytes/sizeof(long);
+ leafbytes = ( ( portalclusters + 63 ) & ~63 ) >> 3;
+ leaflongs = leafbytes / sizeof( long );
+
+ portalbytes = ( ( numportals * 2 + 63 ) & ~63 ) >> 3;
+ portallongs = portalbytes / sizeof( long );
// each file portal is split into two memory portals
- portals = safe_malloc(2*numportals*sizeof(vportal_t));
- memset (portals, 0, 2*numportals*sizeof(vportal_t));
-
- leafs = safe_malloc(portalclusters*sizeof(leaf_t));
- memset (leafs, 0, portalclusters*sizeof(leaf_t));
+ portals = safe_malloc( 2 * numportals * sizeof( vportal_t ) );
+ memset( portals, 0, 2 * numportals * sizeof( vportal_t ) );
+
+ leafs = safe_malloc( portalclusters * sizeof( leaf_t ) );
+ memset( leafs, 0, portalclusters * sizeof( leaf_t ) );
- for (i = 0; i < portalclusters; i++)
+ for ( i = 0; i < portalclusters; i++ )
leafs[i].merged = -1;
- numBSPVisBytes = VIS_HEADER_SIZE + portalclusters*leafbytes;
+ numBSPVisBytes = VIS_HEADER_SIZE + portalclusters * leafbytes;
- if (numBSPVisBytes > MAX_MAP_VISIBILITY)
- Error("MAX_MAP_VISIBILITY exceeded");
+ if ( numBSPVisBytes > MAX_MAP_VISIBILITY ) {
+ Error( "MAX_MAP_VISIBILITY exceeded" );
+ }
+
+ ( (int *)bspVisBytes )[0] = portalclusters;
+ ( (int *)bspVisBytes )[1] = leafbytes;
- ((int *)bspVisBytes)[0] = portalclusters;
- ((int *)bspVisBytes)[1] = leafbytes;
-
- for (i=0, p=portals ; i<numportals ; i++)
+ for ( i = 0, p = portals ; i < numportals ; i++ )
{
- if (fscanf (f, "%i %i %i ", &numpoints, &leafnums[0], &leafnums[1]) != 3)
- Error ("LoadPortals: reading portal %i", i);
- if (numpoints > MAX_POINTS_ON_WINDING)
- Error ("LoadPortals: portal %i has too many points", i);
- if (leafnums[0] > portalclusters
- || leafnums[1] > portalclusters)
- Error ("LoadPortals: reading portal %i", i);
- if (fscanf (f, "%i ", &flags) != 1)
- Error ("LoadPortals: reading flags");
-
- w = p->winding = NewFixedWinding (numpoints);
+ if ( fscanf( f, "%i %i %i ", &numpoints, &leafnums[0], &leafnums[1] ) != 3 ) {
+ Error( "LoadPortals: reading portal %i", i );
+ }
+ if ( numpoints > MAX_POINTS_ON_WINDING ) {
+ Error( "LoadPortals: portal %i has too many points", i );
+ }
+ if ( leafnums[0] > portalclusters
+ || leafnums[1] > portalclusters ) {
+ Error( "LoadPortals: reading portal %i", i );
+ }
- if ( fscanf( f, "%i ", &hint ) != 1 ) {
- Error( "LoadPortals: reading hint state" );
++ if ( fscanf( f, "%i ", &flags ) != 1 ) {
++ Error( "LoadPortals: reading flags" );
+ }
+
+ w = p->winding = NewFixedWinding( numpoints );
w->numpoints = numpoints;
-
- for (j=0 ; j<numpoints ; j++)
+
+ for ( j = 0 ; j < numpoints ; j++ )
{
- double v[3];
- int k;
+ double v[3];
+ int k;
// scanf into double, then assign to vec_t
// so we don't care what size vec_t is
// create forward portal
l = &leafs[leafnums[0]];
- if (l->numportals == MAX_PORTALS_ON_LEAF)
- Error ("Leaf with too many portals");
+ if ( l->numportals == MAX_PORTALS_ON_LEAF ) {
+ Error( "Leaf with too many portals" );
+ }
l->portals[l->numportals] = p;
l->numportals++;
-
- p->num = i+1;
+
+ p->num = i + 1;
- p->hint = hint;
+ p->hint = ((flags & 1) != 0);
+ p->sky = ((flags & 2) != 0);
p->winding = w;
- VectorSubtract (vec3_origin, plane.normal, p->plane.normal);
+ VectorSubtract( vec3_origin, plane.normal, p->plane.normal );
p->plane.dist = -plane.dist;
p->leaf = leafnums[1];
- SetPortalSphere (p);
+ SetPortalSphere( p );
p++;
-
+
// create backwards portal
l = &leafs[leafnums[1]];
- if (l->numportals == MAX_PORTALS_ON_LEAF)
- Error ("Leaf with too many portals");
+ if ( l->numportals == MAX_PORTALS_ON_LEAF ) {
+ Error( "Leaf with too many portals" );
+ }
l->portals[l->numportals] = p;
l->numportals++;
-
- p->num = i+1;
+
+ p->num = i + 1;
p->hint = hint;
- p->winding = NewFixedWinding(w->numpoints);
+ p->winding = NewFixedWinding( w->numpoints );
p->winding->numpoints = w->numpoints;
- for (j=0 ; j<w->numpoints ; j++)
+ for ( j = 0 ; j < w->numpoints ; j++ )
{
- VectorCopy (w->points[w->numpoints-1-j], p->winding->points[j]);
+ VectorCopy( w->points[w->numpoints - 1 - j], p->winding->points[j] );
}
p->plane = plane;
/* ydnar: this is old farplane vis code from mre */
/*
- if (farplanedist >= 0)
- {
- vec3_t dir;
- VectorSubtract(p->origin, tp->origin, dir);
- if (VectorLength(dir) > farplanedist - p->radius - tp->radius)
- continue;
- }
- */
-
+ if (farplanedist >= 0)
+ {
+ vec3_t dir;
+ VectorSubtract(p->origin, tp->origin, dir);
+ if (VectorLength(dir) > farplanedist - p->radius - tp->radius)
+ continue;
+ }
+ */
+
/* ydnar: this is known-to-be-working farplane code */
- if( !p->sky && !tp->sky )
- if( farPlaneDist > 0.0f )
- {
- if ( farPlaneDist > 0.0f ) {
++ if ( !p->sky && !tp->sky && farPlaneDist > 0.0f ) {
VectorSubtract( p->origin, tp->origin, dir );
- if( VectorLength( dir ) - p->radius - tp->radius > farPlaneDist )
+ if ( VectorLength( dir ) - p->radius - tp->radius > farPlaneDist ) {
continue;
+ }
}
-
-
+
+
w = tp->winding;
- for (k=0 ; k<w->numpoints ; k++)
+ for ( k = 0 ; k < w->numpoints ; k++ )
{
- d = DotProduct (w->points[k], p->plane.normal)
+ d = DotProduct( w->points[k], p->plane.normal )
- p->plane.dist;
- if (d > ON_EPSILON)
+ if ( d > ON_EPSILON ) {
break;
+ }
}
- if (k == w->numpoints)
- continue; // no points on front
+ if ( k == w->numpoints ) {
+ continue; // no points on front
+ }
w = p->winding;
- for (k=0 ; k<w->numpoints ; k++)
+ for ( k = 0 ; k < w->numpoints ; k++ )
{
- d = DotProduct (w->points[k], tp->plane.normal)
+ d = DotProduct( w->points[k], tp->plane.normal )
- tp->plane.dist;
- if (d < -ON_EPSILON)
+ if ( d < -ON_EPSILON ) {
break;
+ }
}
- if (k == w->numpoints)
- continue; // no points on front
+ if ( k == w->numpoints ) {
+ continue; // no points on front
- p->portalfront[j>>3] |= (1<<(j&7));
+ }
+ p->portalfront[j >> 3] |= ( 1 << ( j & 7 ) );
}
-
- SimpleFlood (p, p->leaf);
- p->nummightsee = CountBits (p->portalflood, numportals*2);
+ SimpleFlood( p, p->leaf );
+
+ p->nummightsee = CountBits( p->portalflood, numportals * 2 );
// Sys_Printf ("portal %i: %i mightsee\n", portalnum, p->nummightsee);
c_flood += p->nummightsee;
}