]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
make whitespace match master better divVerent/colormod
authorRudolf Polzer <divverent@alientrap.org>
Mon, 14 May 2012 18:57:25 +0000 (20:57 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Mon, 14 May 2012 18:57:25 +0000 (20:57 +0200)
tools/quake3/q3map2/map.c
tools/quake3/q3map2/model.c
tools/quake3/q3map2/q3map2.h
tools/quake3/q3map2/surface.c
tools/quake3/q3map2/surface_foliage.c

index 36b45e04b923375790eff27d932663e72952b7be..22a85b2bfc33c0b685676a2d5d90a18e3dd5d305 100644 (file)
 /* FIXME: remove these vars */
 
 /* undefine to make plane finding use linear sort (note: really slow) */
-#define        USE_HASHING
-#define        PLANE_HASHES    8192
+#define USE_HASHING
+#define PLANE_HASHES    8192
 
-int                                            planehash[ PLANE_HASHES ];
+int planehash[ PLANE_HASHES ];
 
-int                                            c_boxbevels;
-int                                            c_edgebevels;
-int                                            c_areaportals;
-int                                            c_detail;
-int                                            c_structural;
+int c_boxbevels;
+int c_edgebevels;
+int c_areaportals;
+int c_detail;
+int c_structural;
 
 
 
@@ -60,13 +60,13 @@ int                                         c_structural;
  */
 
 qboolean PlaneEqual( plane_t *p, vec3_t normal, vec_t dist ){
-       float   ne, de;
-       
-       
+       float ne, de;
+
+
        /* get local copies */
        ne = normalEpsilon;
        de = distanceEpsilon;
-       
+
        /* compare */
        // We check equality of each component since we're using '<', not '<='
        // (the epsilons may be zero).  We want to use '<' intead of '<=' to be
@@ -78,7 +78,7 @@ qboolean PlaneEqual( plane_t *p, vec3_t normal, vec_t dist ){
                 ( p->normal[2] == normal[2] || fabs( p->normal[2] - normal[2] ) < ne ) ) {
                return qtrue;
        }
-       
+
        /* different */
        return qfalse;
 }
@@ -90,9 +90,9 @@ qboolean PlaneEqual( plane_t *p, vec3_t normal, vec_t dist ){
  */
 
 void AddPlaneToHash( plane_t *p ){
-       int             hash;
+       int hash;
+
 
-       
        hash = ( PLANE_HASHES - 1 ) & (int) fabs( p->dist );
 
        p->hash_chain = planehash[hash];
@@ -105,7 +105,7 @@ void AddPlaneToHash( plane_t *p ){
    ================
  */
 int CreateNewFloatPlane( vec3_t normal, vec_t dist ){
-       plane_t *p, temp;
+       plane_t *p, temp;
 
        if ( VectorLength( normal ) < 0.5 ) {
                Sys_Printf( "FloatPlane: bad normal\n" );
@@ -154,8 +154,8 @@ int CreateNewFloatPlane( vec3_t normal, vec_t dist ){
 
 qboolean SnapNormal( vec3_t normal ){
 #if Q3MAP2_EXPERIMENTAL_SNAP_NORMAL_FIX
-       int             i;
-       qboolean        adjusted = qfalse;
+       int i;
+       qboolean adjusted = qfalse;
 
        // A change from the original SnapNormal() is that we snap each
        // component that's close to 0.  So for example if a normal is
@@ -165,7 +165,7 @@ qboolean SnapNormal( vec3_t normal ){
        // only snapped vectors that were near a perfect axis.
 
        for ( i = 0; i < 3; i++ )
-               {
+       {
                if ( normal[i] != 0.0 && -normalEpsilon < normal[i] && normal[i] < normalEpsilon ) {
                        normal[i] = 0.0;
                        adjusted = qtrue;
@@ -178,25 +178,25 @@ qboolean SnapNormal( vec3_t normal ){
        }
        return qfalse;
 #else
-       int             i;
+       int i;
 
        // I would suggest that you uncomment the following code and look at the
        // results:
 
        /*
-       Sys_Printf("normalEpsilon is %f\n", normalEpsilon);
-       for (i = 0;; i++)
-       {
-               normal[0] = 1.0;
-               normal[1] = 0.0;
-               normal[2] = i * 0.000001;
-               VectorNormalize(normal, normal);
-               if (1.0 - normal[0] >= normalEpsilon) {
-                       Sys_Printf("(%f %f %f)\n", normal[0], normal[1], normal[2]);
-                       Error("SnapNormal: test completed");
-               }
-       }
-       */
+          Sys_Printf("normalEpsilon is %f\n", normalEpsilon);
+          for (i = 0;; i++)
+          {
+           normal[0] = 1.0;
+           normal[1] = 0.0;
+           normal[2] = i * 0.000001;
+           VectorNormalize(normal, normal);
+           if (1.0 - normal[0] >= normalEpsilon) {
+               Sys_Printf("(%f %f %f)\n", normal[0], normal[1], normal[2]);
+               Error("SnapNormal: test completed");
+           }
+          }
+        */
 
        // When the normalEpsilon is 0.00001, the loop will break out when normal is
        // (0.999990 0.000000 0.004469).  In other words, this is the vector closest
@@ -214,7 +214,7 @@ qboolean SnapNormal( vec3_t normal ){
        // code fix.
 
        for ( i = 0; i < 3; i++ )
-               {
+       {
                if ( fabs( normal[ i ] - 1 ) < normalEpsilon ) {
                        VectorClear( normal );
                        normal[ i ] = 1;
@@ -242,8 +242,8 @@ void SnapPlane( vec3_t normal, vec_t *dist, vec3_t center ){
 // brushes made from triangles of embedded models, and it has little effect
 // on anything else (axial planes are usually derived from snapped points)
 /*
-  SnapPlane reenabled by namespace because of multiple reports of
-  q3map2-crashes which were triggered by this patch.
+   SnapPlane reenabled by namespace because of multiple reports of
+   q3map2-crashes which were triggered by this patch.
  */
        SnapNormal( normal );
 
@@ -278,9 +278,9 @@ void SnapPlane( vec3_t normal, vec_t *dist, vec3_t center ){
    snaps a plane to normal/distance epsilons, improved code
  */
 void SnapPlaneImproved( vec3_t normal, vec_t *dist, int numPoints, const vec3_t *points ){
-       int     i;
-       vec3_t  center;
-       vec_t   distNearestInt;
+       int i;
+       vec3_t center;
+       vec_t distNearestInt;
 
        if ( SnapNormal( normal ) ) {
                if ( numPoints > 0 ) {
@@ -318,10 +318,10 @@ int FindFloatPlane( vec3_t innormal, vec_t dist, int numPoints, vec3_t *points )
 #ifdef USE_HASHING
 
 {
-       int             i, j, hash, h;
+       int i, j, hash, h;
        int pidx;
-       plane_t *p;
-       vec_t   d;
+       plane_t *p;
+       vec_t d;
        vec3_t normal;
 
        VectorCopy( innormal, normal );
@@ -332,7 +332,7 @@ int FindFloatPlane( vec3_t innormal, vec_t dist, int numPoints, vec3_t *points )
 #endif
        /* hash the plane */
        hash = ( PLANE_HASHES - 1 ) & (int) fabs( dist );
-       
+
        /* search the border bins as well */
        for ( i = -1; i <= 1; i++ )
        {
@@ -345,10 +345,10 @@ int FindFloatPlane( vec3_t innormal, vec_t dist, int numPoints, vec3_t *points )
                        if ( !PlaneEqual( p, normal, dist ) ) {
                                continue;
                        }
-                       
+
                        /* ydnar: uncomment the following line for old-style plane finding */
                        //%     return p - mapplanes;
-                       
+
                        /* ydnar: test supplied points against this plane */
                        for ( j = 0; j < numPoints; j++ )
                        {
@@ -361,16 +361,16 @@ int FindFloatPlane( vec3_t innormal, vec_t dist, int numPoints, vec3_t *points )
                                d = fabs( d );
                                if ( d != 0.0 && d >= distanceEpsilon ) {
                                        break; // Point is too far from plane.
+                               }
                        }
-                       }
-                       
+
                        /* found a matching plane */
                        if ( j >= numPoints ) {
                                return p - mapplanes;
+                       }
                }
        }
-       }
-       
+
        /* none found, so create a new one */
        return CreateNewFloatPlane( normal, dist );
 }
@@ -378,15 +378,15 @@ int FindFloatPlane( vec3_t innormal, vec_t dist, int numPoints, vec3_t *points )
 #else
 
 {
-       int             i;
-       plane_t *p;
+       int i;
+       plane_t *p;
        vec3_t normal;
-       
+
        VectorCopy( innormal, normal );
 #if Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX
        SnapPlaneImproved( normal, &dist, numPoints, (const vec3_t *) points );
 #else
-       SnapPlane( normal, &dist );
+       SnapPlane( normal, &dist );
 #endif
        for ( i = 0, p = mapplanes; i < nummapplanes; i++, p++ )
        {
@@ -396,16 +396,16 @@ int FindFloatPlane( vec3_t innormal, vec_t dist, int numPoints, vec3_t *points )
 
                /* ydnar: uncomment the following line for old-style plane finding */
                //%     return i;
-                       
+
                /* ydnar: test supplied points against this plane */
                for ( j = 0; j < numPoints; j++ )
                {
                        d = DotProduct( points[ j ], p->normal ) - p->dist;
                        if ( fabs( d ) > distanceEpsilon ) {
                                break;
+                       }
                }
-               }
-               
+
                /* found a matching plane */
                if ( j >= numPoints ) {
                        return i;
@@ -414,7 +414,7 @@ int FindFloatPlane( vec3_t innormal, vec_t dist, int numPoints, vec3_t *points )
                // for the provided points.  It should do that.  I think this code
                // is unmaintained because nobody sets USE_HASHING to off.
        }
-       
+
        return CreateNewFloatPlane( normal, dist );
 }
 
@@ -429,10 +429,10 @@ int FindFloatPlane( vec3_t innormal, vec_t dist, int numPoints, vec3_t *points )
 
 int MapPlaneFromPoints( vec3_t *p ){
 #if Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES
-       vec3_accu_t     paccu[3];
-       vec3_accu_t     t1, t2, normalAccu;
-       vec3_t          normal;
-       vec_t           dist;
+       vec3_accu_t paccu[3];
+       vec3_accu_t t1, t2, normalAccu;
+       vec3_t normal;
+       vec_t dist;
 
        VectorCopyRegularToAccu( p[0], paccu[0] );
        VectorCopyRegularToAccu( p[1], paccu[1] );
@@ -450,19 +450,19 @@ int MapPlaneFromPoints( vec3_t *p ){
 
        return FindFloatPlane( normal, dist, 3, p );
 #else
-       vec3_t  t1, t2, normal;
-       vec_t   dist;
-       
-       
+       vec3_t t1, t2, normal;
+       vec_t dist;
+
+
        /* calc plane normal */
        VectorSubtract( p[ 0 ], p[ 1 ], t1 );
        VectorSubtract( p[ 2 ], p[ 1 ], t2 );
        CrossProduct( t1, t2, normal );
        VectorNormalize( normal, normal );
-       
+
        /* calc plane distance */
        dist = DotProduct( p[ 0 ], normal );
-       
+
        /* store the plane */
        return FindFloatPlane( normal, dist, 3, p );
 #endif
@@ -476,19 +476,19 @@ int MapPlaneFromPoints( vec3_t *p ){
  */
 
 void SetBrushContents( brush_t *b ){
-       int                     contentFlags, compileFlags;
-       side_t          *s;
-       int                     i;
+       int contentFlags, compileFlags;
+       side_t      *s;
+       int i;
        //%     qboolean        mixed;
-       
-       
+
+
        /* get initial compile flags from first side */
        s = &b->sides[ 0 ];
        contentFlags = s->contentFlags;
        compileFlags = s->compileFlags;
        b->contentShader = s->shaderInfo;
        //%     mixed = qfalse;
-       
+
        /* get the content/compile flags for every side in the brush */
        for ( i = 1; i < b->numsides; i++, s++ )
        {
@@ -502,7 +502,7 @@ void SetBrushContents( brush_t *b ){
                contentFlags |= s->contentFlags;
                compileFlags |= s->compileFlags;
        }
-       
+
        /* ydnar: getting rid of this stupid warning */
        //%     if( mixed )
        //%             Sys_FPrintf( SYS_VRB,"Entity %i, Brush %i: mixed face contentFlags\n", b->entitynum, b->brushnum );
@@ -512,17 +512,17 @@ void SetBrushContents( brush_t *b ){
                xml_Select( "Mixed detail and structural (defaulting to structural)", mapEnt->mapEntityNum, entitySourceBrushes, qfalse );
                compileFlags &= ~C_DETAIL;
        }
-       
+
        /* the fulldetail flag will cause detail brushes to be treated like normal brushes */
        if ( fulldetail ) {
                compileFlags &= ~C_DETAIL;
        }
-       
+
        /* all translucent brushes that aren't specifically made structural will be detail */
        if ( ( compileFlags & C_TRANSLUCENT ) && !( compileFlags & C_STRUCTURAL ) ) {
                compileFlags |= C_DETAIL;
        }
-       
+
        /* detail? */
        if ( compileFlags & C_DETAIL ) {
                c_detail++;
@@ -533,7 +533,7 @@ void SetBrushContents( brush_t *b ){
                c_structural++;
                b->detail = qfalse;
        }
-       
+
        /* opaque? */
        if ( compileFlags & C_TRANSLUCENT ) {
                b->opaque = qfalse;
@@ -541,12 +541,12 @@ void SetBrushContents( brush_t *b ){
        else{
                b->opaque = qtrue;
        }
-       
+
        /* areaportal? */
        if ( compileFlags & C_AREAPORTAL ) {
                c_areaportals++;
        }
-       
+
        /* set brush flags */
        b->contentFlags = contentFlags;
        b->compileFlags = compileFlags;
@@ -562,15 +562,15 @@ void SetBrushContents( brush_t *b ){
  */
 
 void AddBrushBevels( void ){
-       int                     axis, dir;
-       int                     i, j, k, l, order;
-       side_t          sidetemp;
-       side_t          *s, *s2;
-       winding_t       *w, *w2;
-       vec3_t          normal;
-       float           dist;
-       vec3_t          vec, vec2;
-       float           d, minBack;
+       int axis, dir;
+       int i, j, k, l, order;
+       side_t sidetemp;
+       side_t      *s, *s2;
+       winding_t   *w, *w2;
+       vec3_t normal;
+       float dist;
+       vec3_t vec, vec2;
+       float d, minBack;
 
        //
        // add the axial planes
@@ -583,20 +583,20 @@ void AddBrushBevels( void ){
                        {
                                /* ydnar: testing disabling of mre code */
                                #if 0
-                                       if ( dir > 0 ) {
-                                               if ( mapplanes[s->planenum].normal[axis] >= 0.9999f ) {
-                                                       break;
-                                               }
+                               if ( dir > 0 ) {
+                                       if ( mapplanes[s->planenum].normal[axis] >= 0.9999f ) {
+                                               break;
                                        }
-                                       else {
-                                               if ( mapplanes[s->planenum].normal[axis] <= -0.9999f ) {
-                                                       break;
-                                               }
+                               }
+                               else {
+                                       if ( mapplanes[s->planenum].normal[axis] <= -0.9999f ) {
+                                               break;
                                        }
+                               }
                                #else
                                if ( ( dir > 0 && mapplanes[ s->planenum ].normal[ axis ] == 1.0f ) ||
                                         ( dir < 0 && mapplanes[ s->planenum ].normal[ axis ] == -1.0f ) ) {
-                                               break;
+                                       break;
                                }
                                #endif
                        }
@@ -618,7 +618,7 @@ void AddBrushBevels( void ){
                                        }
                                        else{
                                                dist = buildBrush->maxs[ axis ];
-                               }
+                                       }
                                }
                                else
                                {
@@ -628,7 +628,7 @@ void AddBrushBevels( void ){
                                        }
                                        else{
                                                dist = -buildBrush->mins[ axis ];
-                               }
+                                       }
                                }
 
                                s->planenum = FindFloatPlane( normal, dist, 0, NULL );
@@ -650,7 +650,7 @@ void AddBrushBevels( void ){
        // add the edge bevels
        //
        if ( buildBrush->numsides == 6 ) {
-               return;         // pure axial
+               return;     // pure axial
        }
 
        // test the non-axial plane edges
@@ -669,11 +669,11 @@ void AddBrushBevels( void ){
                        SnapNormal( vec );
                        for ( k = 0; k < 3; k++ ) {
                                if ( vec[k] == -1.0f || vec[k] == 1.0f || ( vec[k] == 0.0f && vec[( k + 1 ) % 3] == 0.0f ) ) {
-                                       break;  // axial
+                                       break;  // axial
                                }
                        }
                        if ( k != 3 ) {
-                               continue;       // only test non-axial edges
+                               continue;   // only test non-axial edges
                        }
 
                        /* debug code */
@@ -690,7 +690,7 @@ void AddBrushBevels( void ){
                                                continue;
                                        }
                                        dist = DotProduct( w->p[j], normal );
-                                       
+
                                        // if all the points on all the sides are
                                        // behind this plane, it is a proper edge bevel
                                        for ( k = 0; k < buildBrush->numsides; k++ ) {
@@ -708,7 +708,7 @@ void AddBrushBevels( void ){
                                                for ( l = 0; l < w2->numpoints; l++ ) {
                                                        d = DotProduct( w2->p[l], normal ) - dist;
                                                        if ( d > 0.1f ) {
-                                                               break;  // point in front
+                                                               break;  // point in front
                                                        }
                                                        if ( d < minBack ) {
                                                                minBack = d;
@@ -727,12 +727,12 @@ void AddBrushBevels( void ){
                                        }
 
                                        if ( k != buildBrush->numsides ) {
-                                               continue;       // wasn't part of the outer hull
+                                               continue;   // wasn't part of the outer hull
                                        }
-                                       
+
                                        /* debug code */
                                        //%     Sys_Printf( "n = %f %f %f\n", normal[ 0 ], normal[ 1 ], normal[ 2 ] );
-                                       
+
                                        // add this plane
                                        if ( buildBrush->numsides == MAX_BUILD_SIDES ) {
                                                xml_Select( "MAX_BUILD_SIDES", buildBrush->entityNum, buildBrush->brushNum, qtrue );
@@ -775,9 +775,9 @@ static void MergeOrigin( entity_t *ent, vec3_t origin ){
 }
 
 brush_t *FinishBrush( qboolean noCollapseGroups ){
-       brush_t         *b;
-       
-       
+       brush_t     *b;
+
+
        /* create windings for sides and bounds for brush */
        if ( !CreateBrushWindings( buildBrush ) ) {
                return NULL;
@@ -786,17 +786,17 @@ brush_t *FinishBrush( qboolean noCollapseGroups ){
        /* origin brushes are removed, but they set the rotation origin for the rest of the brushes in the entity.
           after the entire entity is parsed, the planenums and texinfos will be adjusted for the origin brush */
        if ( buildBrush->compileFlags & C_ORIGIN ) {
-               vec3_t  origin;
+               vec3_t origin;
 
-               Sys_Printf( "Entity %i, Brush %i: origin brush detected\n", 
-                               mapEnt->mapEntityNum, entitySourceBrushes );
+               Sys_Printf( "Entity %i, Brush %i: origin brush detected\n",
+                                       mapEnt->mapEntityNum, entitySourceBrushes );
 
                if ( numEntities == 1 ) {
-                       Sys_Printf( "Entity %i, Brush %i: origin brushes not allowed in world\n", 
-                               mapEnt->mapEntityNum, entitySourceBrushes );
+                       Sys_Printf( "Entity %i, Brush %i: origin brushes not allowed in world\n",
+                                               mapEnt->mapEntityNum, entitySourceBrushes );
                        return NULL;
                }
-               
+
                VectorAdd( buildBrush->mins, buildBrush->maxs, origin );
                VectorScale( origin, 0.5, origin );
 
@@ -805,7 +805,7 @@ brush_t *FinishBrush( qboolean noCollapseGroups ){
                /* don't keep this brush */
                return NULL;
        }
-       
+
        /* determine if the brush is an area portal */
        if ( buildBrush->compileFlags & C_AREAPORTAL ) {
                if ( numEntities != 1 ) {
@@ -813,29 +813,29 @@ brush_t *FinishBrush( qboolean noCollapseGroups ){
                        return NULL;
                }
        }
-       
+
        /* add bevel planes */
        if ( !noCollapseGroups ) {
                AddBrushBevels();
        }
-       
+
        /* keep it */
        b = CopyBrush( buildBrush );
-       
+
        /* set map entity and brush numbering */
        b->entityNum = mapEnt->mapEntityNum;
        b->brushNum = entitySourceBrushes;
-       
+
        /* set original */
        b->original = b;
-       
+
        /* link opaque brushes to head of list, translucent brushes to end */
        if ( b->opaque || mapEnt->lastBrush == NULL ) {
                b->next = mapEnt->brushes;
                mapEnt->brushes = b;
                if ( mapEnt->lastBrush == NULL ) {
                        mapEnt->lastBrush = b;
-       }
+               }
        }
        else
        {
@@ -843,15 +843,15 @@ brush_t *FinishBrush( qboolean noCollapseGroups ){
                mapEnt->lastBrush->next = b;
                mapEnt->lastBrush = b;
        }
-       
+
        /* link colorMod volume brushes to the entity directly */
        if ( b->contentShader != NULL &&
-               b->contentShader->colorMod != NULL &&
+                b->contentShader->colorMod != NULL &&
                 b->contentShader->colorMod->type == CM_VOLUME ) {
                b->nextColorModBrush = mapEnt->colorModBrushes;
                mapEnt->colorModBrushes = b;
        }
-       
+
        /* return to sender */
        return b;
 }
@@ -864,33 +864,33 @@ brush_t *FinishBrush( qboolean noCollapseGroups ){
    (must be identical in radiant!)
  */
 
-vec3_t baseaxis[18] =
+vec3_t baseaxis[18] =
 {
-       {0,0,1}, {1,0,0}, {0,-1,0},                     // floor
-       {0,0,-1}, {1,0,0}, {0,-1,0},            // ceiling
-       {1,0,0}, {0,1,0}, {0,0,-1},                     // west wall
-       {-1,0,0}, {0,1,0}, {0,0,-1},            // east wall
-       {0,1,0}, {1,0,0}, {0,0,-1},                     // south wall
-       {0,-1,0}, {1,0,0}, {0,0,-1}                     // north wall
+       {0,0,1}, {1,0,0}, {0,-1,0},         // floor
+       {0,0,-1}, {1,0,0}, {0,-1,0},        // ceiling
+       {1,0,0}, {0,1,0}, {0,0,-1},         // west wall
+       {-1,0,0}, {0,1,0}, {0,0,-1},        // east wall
+       {0,1,0}, {1,0,0}, {0,0,-1},         // south wall
+       {0,-1,0}, {1,0,0}, {0,0,-1}         // north wall
 };
 
 void TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv ){
-       int             bestaxis;
-       vec_t   dot,best;
-       int             i;
-       
+       int bestaxis;
+       vec_t dot,best;
+       int i;
+
        best = 0;
        bestaxis = 0;
-       
+
        for ( i = 0 ; i < 6 ; i++ )
-               {
+       {
                dot = DotProduct( pln->normal, baseaxis[i * 3] );
                if ( dot > best + 0.0001f ) { /* ydnar: bug 637 fix, suggested by jmonroe */
                        best = dot;
                        bestaxis = i;
                }
        }
-       
+
        VectorCopy( baseaxis[bestaxis * 3 + 1], xv );
        VectorCopy( baseaxis[bestaxis * 3 + 2], yv );
 }
@@ -903,15 +903,15 @@ void TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv ){
  */
 
 void QuakeTextureVecs( plane_t *plane, vec_t shift[ 2 ], vec_t rotate, vec_t scale[ 2 ], vec_t mappingVecs[ 2 ][ 4 ] ){
-       vec3_t  vecs[2];
-       int             sv, tv;
-       vec_t   ang, sinv, cosv;
-       vec_t   ns, nt;
-       int             i, j;
-       
-       
+       vec3_t vecs[2];
+       int sv, tv;
+       vec_t ang, sinv, cosv;
+       vec_t ns, nt;
+       int i, j;
+
+
        TextureAxisFromPlane( plane, vecs[0], vecs[1] );
-       
+
        if ( !scale[0] ) {
                scale[0] = 1;
        }
@@ -933,7 +933,7 @@ void QuakeTextureVecs( plane_t *plane, vec_t shift[ 2 ], vec_t rotate, vec_t sca
                sinv = -1 ; cosv = 0;
        }
        else
-       {       
+       {
                ang = rotate / 180 * Q_PI;
                sinv = sin( ang );
                cosv = cos( ang );
@@ -948,7 +948,7 @@ void QuakeTextureVecs( plane_t *plane, vec_t shift[ 2 ], vec_t rotate, vec_t sca
        else{
                sv = 2;
        }
-                               
+
        if ( vecs[1][0] ) {
                tv = 0;
        }
@@ -958,7 +958,7 @@ void QuakeTextureVecs( plane_t *plane, vec_t shift[ 2 ], vec_t rotate, vec_t sca
        else{
                tv = 2;
        }
-                                       
+
        for ( i = 0 ; i < 2 ; i++ ) {
                ns = cosv * vecs[i][sv] - sinv * vecs[i][tv];
                nt = sinv * vecs[i][sv] +  cosv * vecs[i][tv];
@@ -991,27 +991,27 @@ void QuakeTextureVecs( plane_t *plane, vec_t shift[ 2 ], vec_t rotate, vec_t sca
  */
 
 static void ParseRawBrush( qboolean onlyLights ){
-       side_t                  *side;
-       vec3_t                  planePoints[ 3 ];
-       int                             planenum;
-       shaderInfo_t    *si;
-       vec_t                   shift[ 2 ];
-       vec_t                   rotate = 0;
-       vec_t                   scale[ 2 ];
-       char                    name[ MAX_QPATH ];
-       char                    shader[ MAX_QPATH ];
-       int                             flags;
-       
-       
+       side_t          *side;
+       vec3_t planePoints[ 3 ];
+       int planenum;
+       shaderInfo_t    *si;
+       vec_t shift[ 2 ];
+       vec_t rotate = 0;
+       vec_t scale[ 2 ];
+       char name[ MAX_QPATH ];
+       char shader[ MAX_QPATH ];
+       int flags;
+
+
        /* initial setup */
        buildBrush->numsides = 0;
        buildBrush->detail = qfalse;
-       
+
        /* bp */
        if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
                MatchToken( "{" );
        }
-       
+
        /* parse sides */
        while ( 1 )
        {
@@ -1021,7 +1021,7 @@ static void ParseRawBrush( qboolean onlyLights ){
                if ( !strcmp( token, "}" ) ) {
                        break;
                }
-                
+
                /* ttimo : bp: here we may have to jump over brush epairs (only used in editor) */
                if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
                        while ( 1 )
@@ -1036,31 +1036,31 @@ static void ParseRawBrush( qboolean onlyLights ){
                        }
                }
                UnGetToken();
-               
+
                /* test side count */
                if ( buildBrush->numsides >= MAX_BUILD_SIDES ) {
                        xml_Select( "MAX_BUILD_SIDES", buildBrush->entityNum, buildBrush->brushNum, qtrue );
                }
-               
+
                /* add side */
                side = &buildBrush->sides[ buildBrush->numsides ];
                memset( side, 0, sizeof( *side ) );
                buildBrush->numsides++;
-               
+
                /* read the three point plane definition */
                Parse1DMatrix( 3, planePoints[ 0 ] );
                Parse1DMatrix( 3, planePoints[ 1 ] );
                Parse1DMatrix( 3, planePoints[ 2 ] );
-               
+
                /* bp: read the texture matrix */
                if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
                        Parse2DMatrix( 2, 3, (float*) side->texMat );
                }
-               
+
                /* read shader name */
                GetToken( qfalse );
                strcpy( name, token );
-               
+
                /* bp */
                if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) {
                        GetToken( qfalse );
@@ -1068,13 +1068,13 @@ static void ParseRawBrush( qboolean onlyLights ){
                        GetToken( qfalse );
                        shift[ 1 ] = atof( token );
                        GetToken( qfalse );
-                       rotate = atof( token ); 
+                       rotate = atof( token );
                        GetToken( qfalse );
                        scale[ 0 ] = atof( token );
                        GetToken( qfalse );
                        scale[ 1 ] = atof( token );
                }
-               
+
                /* set default flags and values */
                sprintf( shader, "textures/%s", name );
                if ( onlyLights ) {
@@ -1088,24 +1088,24 @@ static void ParseRawBrush( qboolean onlyLights ){
                side->contentFlags = si->contentFlags;
                side->compileFlags = si->compileFlags;
                side->value = si->value;
-               
+
                /* ydnar: gs mods: bias texture shift */
                if ( si->globalTexture == qfalse ) {
                        shift[ 0 ] -= ( floor( shift[ 0 ] / si->shaderWidth ) * si->shaderWidth );
                        shift[ 1 ] -= ( floor( shift[ 1 ] / si->shaderHeight ) * si->shaderHeight );
                }
-               
+
                /*
-                       historically, there are 3 integer values at the end of a brushside line in a .map file.
-                       in quake 3, the only thing that mattered was the first of these three values, which
-                       was previously the content flags. and only then did a single bit matter, the detail
-                       bit. because every game has its own special flags for specifying detail, the
-                       traditionally game-specified CONTENTS_DETAIL flag was overridden for Q3Map 2.3.0
-                       by C_DETAIL, defined in q3map2.h. the value is exactly as it was before, but
-                       is stored in compileFlags, as opposed to contentFlags, for multiple-game
-                       portability. :sigh:
-               */
-               
+                   historically, there are 3 integer values at the end of a brushside line in a .map file.
+                   in quake 3, the only thing that mattered was the first of these three values, which
+                   was previously the content flags. and only then did a single bit matter, the detail
+                   bit. because every game has its own special flags for specifying detail, the
+                   traditionally game-specified CONTENTS_DETAIL flag was overridden for Q3Map 2.3.0
+                   by C_DETAIL, defined in q3map2.h. the value is exactly as it was before, but
+                   is stored in compileFlags, as opposed to contentFlags, for multiple-game
+                   portability. :sigh:
+                */
+
                if ( TokenAvailable() ) {
                        /* get detail bit from map content flags */
                        GetToken( qfalse );
@@ -1113,24 +1113,24 @@ static void ParseRawBrush( qboolean onlyLights ){
                        if ( flags & C_DETAIL ) {
                                side->compileFlags |= C_DETAIL;
                        }
-                       
+
                        /* historical */
                        GetToken( qfalse );
                        //% td.flags = atoi( token );
                        GetToken( qfalse );
                        //% td.value = atoi( token );
                }
-               
+
                /* find the plane number */
                planenum = MapPlaneFromPoints( planePoints );
                side->planenum = planenum;
-               
+
                /* bp: get the texture mapping for this texturedef / plane combination */
                if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) {
                        QuakeTextureVecs( &mapplanes[ planenum ], shift, rotate, scale, side->vecs );
+               }
        }
-       }
-       
+
        /* bp */
        if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
                UnGetToken();
@@ -1149,8 +1149,8 @@ static void ParseRawBrush( qboolean onlyLights ){
  */
 
 qboolean RemoveDuplicateBrushPlanes( brush_t *b ){
-       int                     i, j, k;
-       side_t          *sides;
+       int i, j, k;
+       side_t      *sides;
 
        sides = b->sides;
 
@@ -1158,7 +1158,7 @@ qboolean RemoveDuplicateBrushPlanes( brush_t *b ){
 
                // check for a degenerate plane
                if ( sides[i].planenum == -1 ) {
-                 xml_Select( "degenerate plane", b->entityNum, b->brushNum, qfalse );
+                       xml_Select( "degenerate plane", b->entityNum, b->brushNum, qfalse );
                        // remove it
                        for ( k = i + 1 ; k < b->numsides ; k++ ) {
                                sides[k - 1] = sides[k];
@@ -1171,7 +1171,7 @@ qboolean RemoveDuplicateBrushPlanes( brush_t *b ){
                // check for duplication and mirroring
                for ( j = 0 ; j < i ; j++ ) {
                        if ( sides[i].planenum == sides[j].planenum ) {
-                         xml_Select( "duplicate plane", b->entityNum, b->brushNum, qfalse );
+                               xml_Select( "duplicate plane", b->entityNum, b->brushNum, qfalse );
                                // remove the second duplicate
                                for ( k = i + 1 ; k < b->numsides ; k++ ) {
                                        sides[k - 1] = sides[k];
@@ -1183,7 +1183,7 @@ qboolean RemoveDuplicateBrushPlanes( brush_t *b ){
 
                        if ( sides[i].planenum == ( sides[j].planenum ^ 1 ) ) {
                                // mirror plane, brush is invalid
-                         xml_Select( "mirrored plane", b->entityNum, b->brushNum, qfalse );
+                               xml_Select( "mirrored plane", b->entityNum, b->brushNum, qfalse );
                                return qfalse;
                        }
                }
@@ -1201,44 +1201,44 @@ qboolean RemoveDuplicateBrushPlanes( brush_t *b ){
 static void ParseBrush( qboolean onlyLights, qboolean noCollapseGroups ){
        /* parse the brush out of the map */
        ParseRawBrush( onlyLights );
-       
+
        /* only go this far? */
        if ( onlyLights ) {
                return;
        }
-       
+
        /* set some defaults */
        buildBrush->portalareas[ 0 ] = -1;
        buildBrush->portalareas[ 1 ] = -1;
        buildBrush->entityNum = numMapEntities - 1;
        buildBrush->brushNum = entitySourceBrushes;
-       
+
        /* if there are mirrored planes, the entire brush is invalid */
        if ( !RemoveDuplicateBrushPlanes( buildBrush ) ) {
                return;
        }
-       
+
        /* get the content for the entire brush */
        SetBrushContents( buildBrush );
-       
+
        /* allow detail brushes to be removed */
        if ( nodetail && ( buildBrush->compileFlags & C_DETAIL ) ) {
                //%     FreeBrush( buildBrush );
                return;
        }
-       
+
        /* allow liquid brushes to be removed */
        if ( nowater && ( buildBrush->compileFlags & C_LIQUID ) ) {
                //%     FreeBrush( buildBrush );
                return;
        }
-       
+
        /* ydnar: allow hint brushes to be removed */
        if ( noHint && ( buildBrush->compileFlags & C_HINT ) ) {
                //%     FreeBrush( buildBrush );
                return;
        }
-       
+
        /* finish the brush */
        FinishBrush( noCollapseGroups );
 }
@@ -1254,27 +1254,27 @@ static void ParseBrush( qboolean onlyLights, qboolean noCollapseGroups ){
 
 void AdjustBrushesForOrigin( entity_t *ent );
 void MoveBrushesToWorld( entity_t *ent ){
-       brush_t         *b, *next;
-       parseMesh_t     *pm;
+       brush_t     *b, *next;
+       parseMesh_t *pm;
 
        /* we need to undo the common/origin adjustment, and instead shift them by the entity key origin */
        VectorScale( ent->origin, -1, ent->originbrush_origin );
        AdjustBrushesForOrigin( ent );
        VectorClear( ent->originbrush_origin );
-       
+
        /* move brushes */
        for ( b = ent->brushes; b != NULL; b = next )
        {
                /* get next brush */
                next = b->next;
-               
+
                /* link opaque brushes to head of list, translucent brushes to end */
                if ( b->opaque || entities[ 0 ].lastBrush == NULL ) {
                        b->next = entities[ 0 ].brushes;
                        entities[ 0 ].brushes = b;
                        if ( entities[ 0 ].lastBrush == NULL ) {
                                entities[ 0 ].lastBrush = b;
-               }
+                       }
                }
                else
                {
@@ -1284,24 +1284,24 @@ void MoveBrushesToWorld( entity_t *ent ){
                }
        }
        ent->brushes = NULL;
-       
+
        /* ydnar: move colormod brushes */
        if ( ent->colorModBrushes != NULL ) {
                for ( b = ent->colorModBrushes; b->nextColorModBrush != NULL; b = b->nextColorModBrush ) ;
-               
+
                b->nextColorModBrush = entities[ 0 ].colorModBrushes;
                entities[ 0 ].colorModBrushes = ent->colorModBrushes;
-               
+
                ent->colorModBrushes = NULL;
        }
-       
+
        /* move patches */
        if ( ent->patches != NULL ) {
                for ( pm = ent->patches; pm->next != NULL; pm = pm->next ) ;
-               
+
                pm->next = entities[ 0 ].patches;
                entities[ 0 ].patches = ent->patches;
-               
+
                ent->patches = NULL;
        }
 }
@@ -1313,13 +1313,13 @@ void MoveBrushesToWorld( entity_t *ent ){
  */
 
 void AdjustBrushesForOrigin( entity_t *ent ){
-       
-       int                     i;
-       side_t          *s;
-       vec_t           newdist;
-       brush_t         *b;
-       parseMesh_t     *p;
-       
+
+       int i;
+       side_t      *s;
+       vec_t newdist;
+       brush_t     *b;
+       parseMesh_t *p;
+
        /* walk brush list */
        for ( b = ent->brushes; b != NULL; b = b->next )
        {
@@ -1328,18 +1328,18 @@ void AdjustBrushesForOrigin( entity_t *ent ){
                {
                        /* get brush side */
                        s = &b->sides[ i ];
-                       
+
                        /* offset side plane */
                        newdist = mapplanes[ s->planenum ].dist - DotProduct( mapplanes[ s->planenum ].normal, ent->originbrush_origin );
-                       
+
                        /* find a new plane */
                        s->planenum = FindFloatPlane( mapplanes[ s->planenum ].normal, newdist, 0, NULL );
                }
-               
+
                /* rebuild brush windings (ydnar: just offsetting the winding above should be fine) */
                CreateBrushWindings( b );
        }
-       
+
        /* walk patch list */
        for ( p = ent->patches; p != NULL; p = p->next )
        {
@@ -1356,14 +1356,14 @@ void AdjustBrushesForOrigin( entity_t *ent ){
  */
 
 void SetEntityBounds( entity_t *e ){
-       int                     i;
-       brush_t *b;
-       parseMesh_t     *p;
-       vec3_t          mins, maxs;
-       const char      *value;
+       int i;
+       brush_t *b;
+       parseMesh_t *p;
+       vec3_t mins, maxs;
+       const char  *value;
+
+
 
-       
-       
 
        /* walk the entity's brushes/patches and determine bounds */
        ClearBounds( mins, maxs );
@@ -1377,17 +1377,17 @@ void SetEntityBounds( entity_t *e ){
                for ( i = 0; i < ( p->mesh.width * p->mesh.height ); i++ )
                        AddPointToBounds( p->mesh.verts[ i ].xyz, mins, maxs );
        }
-       
+
        /* try to find explicit min/max key */
-       value = ValueForKey( e, "min" ); 
+       value = ValueForKey( e, "min" );
        if ( value[ 0 ] != '\0' ) {
                GetVectorForKey( e, "min", mins );
        }
-       value = ValueForKey( e, "max" ); 
+       value = ValueForKey( e, "max" );
        if ( value[ 0 ] != '\0' ) {
                GetVectorForKey( e, "max", maxs );
        }
-       
+
        /* store the bounds */
        for ( b = e->brushes; b; b = b->next )
        {
@@ -1409,21 +1409,21 @@ void SetEntityBounds( entity_t *e ){
  */
 
 void LoadEntityIndexMap( entity_t *e ){
-       int                             i, size, numLayers, w, h;
-       const char              *value, *indexMapFilename, *shader;
-       char                    ext[ MAX_QPATH ], offset[ 4096 ], *search, *space;
-       byte                    *pixels;
-       unsigned int    *pixels32;
-       indexMap_t              *im;
-       brush_t                 *b;
-       parseMesh_t             *p;
-       
-       
+       int i, size, numLayers, w, h;
+       const char      *value, *indexMapFilename, *shader;
+       char ext[ MAX_QPATH ], offset[ 4096 ], *search, *space;
+       byte            *pixels;
+       unsigned int    *pixels32;
+       indexMap_t      *im;
+       brush_t         *b;
+       parseMesh_t     *p;
+
+
        /* this only works with bmodel ents */
        if ( e->brushes == NULL && e->patches == NULL ) {
                return;
        }
-       
+
        /* determine if there is an index map (support legacy "alphamap" key as well) */
        value = ValueForKey( e, "_indexmap" );
        if ( value[ 0 ] == '\0' ) {
@@ -1433,7 +1433,7 @@ void LoadEntityIndexMap( entity_t *e ){
                return;
        }
        indexMapFilename = value;
-       
+
        /* get number of layers (support legacy "layers" key as well) */
        value = ValueForKey( e, "_layers" );
        if ( value[ 0 ] == '\0' ) {
@@ -1450,7 +1450,7 @@ void LoadEntityIndexMap( entity_t *e ){
                Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
                return;
        }
-       
+
        /* get base shader name (support legacy "shader" key as well) */
        value = ValueForKey( mapEnt, "_shader" );
        if ( value[ 0 ] == '\0' ) {
@@ -1462,18 +1462,18 @@ void LoadEntityIndexMap( entity_t *e ){
                return;
        }
        shader = value;
-       
+
        /* note it */
        Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n",  mapEnt->mapEntityNum, ValueForKey( e, "classname" ), indexMapFilename );
-       
+
        /* get index map file extension */
        ExtractFileExtension( indexMapFilename, ext );
-       
+
        /* handle tga image */
        if ( !Q_stricmp( ext, "tga" ) ) {
                /* load it */
                Load32BitImage( indexMapFilename, &pixels32, &w, &h );
-               
+
                /* convert to bytes */
                size = w * h;
                pixels = safe_malloc( size );
@@ -1482,9 +1482,9 @@ void LoadEntityIndexMap( entity_t *e ){
                        pixels[ i ] = ( ( pixels32[ i ] & 0xFF ) * numLayers ) / 256;
                        if ( pixels[ i ] >= numLayers ) {
                                pixels[ i ] = numLayers - 1;
+                       }
                }
-               }
-               
+
                /* free the 32 bit image */
                free( pixels32 );
        }
@@ -1492,10 +1492,10 @@ void LoadEntityIndexMap( entity_t *e ){
        {
                /* load it */
                Load256Image( indexMapFilename, &pixels, NULL, &w, &h );
-               
+
                /* debug code */
                //%     Sys_Printf( "-------------------------------" );
-               
+
                /* fix up out-of-range values */
                size = w * h;
                for ( i = 0; i < size; i++ )
@@ -1503,17 +1503,17 @@ void LoadEntityIndexMap( entity_t *e ){
                        if ( pixels[ i ] >= numLayers ) {
                                pixels[ i ] = numLayers - 1;
                        }
-                       
+
                        /* debug code */
                        //%     if( (i % w) == 0 )
                        //%             Sys_Printf( "\n" );
                        //%     Sys_Printf( "%c", pixels[ i ] + '0' );
                }
-               
+
                /* debug code */
                //%     Sys_Printf( "\n-------------------------------\n" );
        }
-       
+
        /* the index map must be at least 2x2 pixels */
        if ( w < 2 || h < 2 ) {
                Sys_Printf( "WARNING: Entity with index/alpha map \"%s\" is smaller than 2x2 pixels\n", indexMapFilename );
@@ -1525,7 +1525,7 @@ void LoadEntityIndexMap( entity_t *e ){
        /* create a new index map */
        im = safe_malloc( sizeof( *im ) );
        memset( im, 0, sizeof( *im ) );
-       
+
        /* set it up */
        im->w = w;
        im->h = h;
@@ -1533,7 +1533,7 @@ void LoadEntityIndexMap( entity_t *e ){
        strcpy( im->name, indexMapFilename );
        strcpy( im->shader, shader );
        im->pixels = pixels;
-       
+
        /* get height offsets */
        value = ValueForKey( mapEnt, "_offsets" );
        if ( value[ 0 ] == '\0' ) {
@@ -1543,7 +1543,7 @@ void LoadEntityIndexMap( entity_t *e ){
                /* value is a space-seperated set of numbers */
                strcpy( offset, value );
                search = offset;
-               
+
                /* get each value */
                for ( i = 0; i < 256 && *search != '\0'; i++ )
                {
@@ -1558,7 +1558,7 @@ void LoadEntityIndexMap( entity_t *e ){
                        search = space + 1;
                }
        }
-       
+
        /* store the index map in every brush/patch in the entity */
        for ( b = e->brushes; b != NULL; b = b->next )
                b->im = im;
@@ -1578,65 +1578,65 @@ void LoadEntityIndexMap( entity_t *e ){
  */
 
 static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups ){
-       epair_t                 *ep;
-       const char              *classname, *value;
-       float                   lightmapScale, shadeAngle;
-       int                             lightmapSampleSize;
-       char                    shader[ MAX_QPATH ];
-       shaderInfo_t    *celShader = NULL;
-       brush_t                 *brush;
-       parseMesh_t             *patch;
-       qboolean                funcGroup;
-       int                             castShadows, recvShadows;
+       epair_t         *ep;
+       const char      *classname, *value;
+       float lightmapScale, shadeAngle;
+       int lightmapSampleSize;
+       char shader[ MAX_QPATH ];
+       shaderInfo_t    *celShader = NULL;
+       brush_t         *brush;
+       parseMesh_t     *patch;
+       qboolean funcGroup;
+       int castShadows, recvShadows;
        vec3_t                  colormod;
-       
-       
+
+
        /* eof check */
        if ( !GetToken( qtrue ) ) {
                return qfalse;
        }
-       
+
        /* conformance check */
        if ( strcmp( token, "{" ) ) {
                Sys_Printf( "WARNING: ParseEntity: { not found, found %s on line %d - last entity was at: <%4.2f, %4.2f, %4.2f>...\n"
-                       "Continuing to process map, but resulting BSP may be invalid.\n",
-                       token, scriptline, entities[ numEntities ].origin[ 0 ], entities[ numEntities ].origin[ 1 ], entities[ numEntities ].origin[ 2 ] );
+                                       "Continuing to process map, but resulting BSP may be invalid.\n",
+                                       token, scriptline, entities[ numEntities ].origin[ 0 ], entities[ numEntities ].origin[ 1 ], entities[ numEntities ].origin[ 2 ] );
                return qfalse;
        }
-       
+
        /* range check */
        AUTOEXPAND_BY_REALLOC( entities, numEntities, allocatedEntities, 32 );
-       
+
        /* setup */
        entitySourceBrushes = 0;
        mapEnt = &entities[ numEntities ];
        numEntities++;
        memset( mapEnt, 0, sizeof( *mapEnt ) );
-       
+
        /* ydnar: true entity numbering */
        mapEnt->mapEntityNum = numMapEntities;
        numMapEntities++;
-       
+
        /* loop */
        while ( 1 )
        {
                /* get initial token */
                if ( !GetToken( qtrue ) ) {
                        Sys_Printf( "WARNING: ParseEntity: EOF without closing brace\n"
-                               "Continuing to process map, but resulting BSP may be invalid.\n" );
+                                               "Continuing to process map, but resulting BSP may be invalid.\n" );
                        return qfalse;
                }
-               
+
                if ( !strcmp( token, "}" ) ) {
                        break;
                }
-               
+
                if ( !strcmp( token, "{" ) ) {
                        /* parse a brush or patch */
                        if ( !GetToken( qtrue ) ) {
                                break;
                        }
-                       
+
                        /* check */
                        if ( !strcmp( token, "patchDef2" ) ) {
                                numMapPatches++;
@@ -1644,14 +1644,14 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
                        }
                        else if ( !strcmp( token, "terrainDef" ) ) {
                                //% ParseTerrain();
-                               Sys_Printf( "WARNING: Terrain entity parsing not supported in this build.\n" ); /* ydnar */
+                               Sys_Printf( "WARNING: Terrain entity parsing not supported in this build.\n" ); /* ydnar */
                        }
                        else if ( !strcmp( token, "brushDef" ) ) {
                                if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) {
                                        Error( "Old brush format not allowed in new brush format map" );
                                }
                                g_bBrushPrimit = BPRIMIT_NEWBRUSHES;
-                               
+
                                /* parse brush primitive */
                                ParseBrush( onlyLights, noCollapseGroups );
                        }
@@ -1661,7 +1661,7 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
                                        Error( "New brush format not allowed in old brush format map" );
                                }
                                g_bBrushPrimit = BPRIMIT_OLDBRUSHES;
-                               
+
                                /* parse old brush format */
                                UnGetToken();
                                ParseBrush( onlyLights, noCollapseGroups );
@@ -1672,7 +1672,7 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
                {
                        /* parse a key / value pair */
                        ep = ParseEPair();
-                       
+
                        /* ydnar: 2002-07-06 fixed wolf bug with empty epairs */
                        if ( ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' ) {
                                ep->next = mapEnt->epairs;
@@ -1680,16 +1680,16 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
                        }
                }
        }
-       
+
        /* ydnar: get classname */
        classname = ValueForKey( mapEnt, "classname" );
-       
+
        /* ydnar: only lights? */
        if ( onlyLights && Q_strncasecmp( classname, "light", 5 ) ) {
                numEntities--;
                return qtrue;
        }
-       
+
        /* ydnar: determine if this is a func_group */
        if ( !Q_stricmp( "func_group", classname ) ) {
                funcGroup = qtrue;
@@ -1697,14 +1697,14 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
        else{
                funcGroup = qfalse;
        }
-       
+
        /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */
        if ( funcGroup || mapEnt->mapEntityNum == 0 ) {
                //%     Sys_Printf( "World:  %d\n", mapEnt->mapEntityNum );
                castShadows = WORLDSPAWN_CAST_SHADOWS;
                recvShadows = WORLDSPAWN_RECV_SHADOWS;
        }
-       
+
        /* other entities don't cast any shadows, but recv worldspawn shadows */
        else
        {
@@ -1712,15 +1712,15 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
                castShadows = ENTITY_CAST_SHADOWS;
                recvShadows = ENTITY_RECV_SHADOWS;
        }
-       
+
        /* get explicit shadow flags */
        GetEntityShadowFlags( mapEnt, NULL, &castShadows, &recvShadows );
-       
+
        /* vortex: added _ls key (short name of lightmapscale) */
        /* ydnar: get lightmap scaling value for this entity */
        lightmapScale = 0.0f;
        if ( strcmp( "", ValueForKey( mapEnt, "lightmapscale" ) ) ||
-               strcmp( "", ValueForKey( mapEnt, "_lightmapscale" ) ) || 
+                strcmp( "", ValueForKey( mapEnt, "_lightmapscale" ) ) ||
                 strcmp( "", ValueForKey( mapEnt, "_ls" ) ) ) {
                /* get lightmap scale from entity */
                lightmapScale = FloatForKey( mapEnt, "lightmapscale" );
@@ -1735,7 +1735,7 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
                }
                if ( lightmapScale > 0.0f ) {
                        Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt->mapEntityNum, classname, lightmapScale );
-       }
+               }
        }
 
        VectorClear(colormod);
@@ -1779,7 +1779,7 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
        else if ( strcmp( "", ValueForKey( mapEnt, "_smooth" ) ) ) {
                shadeAngle = FloatForKey( mapEnt, "_smooth" );
        }
-       
+
        if ( shadeAngle < 0.0f ) {
                shadeAngle = 0.0f;
        }
@@ -1787,7 +1787,7 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
        if ( shadeAngle > 0.0f ) {
                Sys_Printf( "Entity %d (%s) has shading angle of %.4f\n", mapEnt->mapEntityNum, classname, shadeAngle );
        }
-       
+
        /* jal : entity based _samplesize */
        lightmapSampleSize = 0;
        if ( strcmp( "", ValueForKey( mapEnt, "_lightmapsamplesize" ) ) ) {
@@ -1796,7 +1796,7 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
        else if ( strcmp( "", ValueForKey( mapEnt, "_samplesize" ) ) ) {
                lightmapSampleSize = IntForKey( mapEnt, "_samplesize" );
        }
-       
+
        if ( lightmapSampleSize < 0 ) {
                lightmapSampleSize = 0;
        }
@@ -1804,7 +1804,7 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
        if ( lightmapSampleSize > 0 ) {
                Sys_Printf( "Entity %d (%s) has lightmap sample size of %d\n", mapEnt->mapEntityNum, classname, lightmapSampleSize );
        }
-       
+
        /* attach stuff to everything in the entity */
        for ( brush = mapEnt->brushes; brush != NULL; brush = brush->next )
        {
@@ -1817,7 +1817,7 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
                brush->shadeAngleDegrees = shadeAngle;
                brush->colormod = colormod;
        }
-       
+
        for ( patch = mapEnt->patches; patch != NULL; patch = patch->next )
        {
                patch->entityNum = mapEnt->mapEntityNum;
@@ -1828,13 +1828,13 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
                patch->celShader = celShader;
                patch->colormod = colormod;
        }
-       
+
        /* ydnar: gs mods: set entity bounds */
        SetEntityBounds( mapEnt );
-       
+
        /* ydnar: gs mods: load shader index map (equivalent to old terrain alphamap) */
        LoadEntityIndexMap( mapEnt );
-       
+
        /* get entity origin and adjust brushes */
        GetVectorForKey( mapEnt, "origin", mapEnt->origin );
        if ( mapEnt->originbrush_origin[ 0 ] || mapEnt->originbrush_origin[ 1 ] || mapEnt->originbrush_origin[ 2 ] ) {
@@ -1846,14 +1846,14 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
                numEntities--;
                return qtrue;
        }
-       
+
        /* group entities are just for editor convenience, toss all brushes into worldspawn */
        if ( !noCollapseGroups && funcGroup ) {
                MoveBrushesToWorld( mapEnt );
                numEntities--;
                return qtrue;
        }
-       
+
        /* done */
        return qtrue;
 }
@@ -1866,22 +1866,22 @@ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
  */
 
 void LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups ){
-       FILE            *file;
-       brush_t         *b;
-       int                     oldNumEntities = 0, numMapBrushes;
-       
-       
+       FILE        *file;
+       brush_t     *b;
+       int oldNumEntities = 0, numMapBrushes;
+
+
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- LoadMapFile ---\n" );
        Sys_Printf( "Loading %s\n", filename );
-       
+
        /* hack */
        file = SafeOpenRead( filename );
        fclose( file );
-       
+
        /* load the map file */
        LoadScriptFile( filename, -1 );
-       
+
        /* setup */
        if ( onlyLights ) {
                oldNumEntities = numEntities;
@@ -1889,18 +1889,18 @@ void LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups
        else{
                numEntities = 0;
        }
-       
+
        /* initial setup */
        numMapDrawSurfs = 0;
        c_detail = 0;
        g_bBrushPrimit = BPRIMIT_UNDEFINED;
-       
+
        /* allocate a very large temporary brush for building the brushes as they are loaded */
        buildBrush = AllocBrush( MAX_BUILD_SIDES );
-       
+
        /* parse the map file */
        while ( ParseMapEntity( onlyLights, noCollapseGroups ) ) ;
-       
+
        /* light loading */
        if ( onlyLights ) {
                /* emit some statistics */
@@ -1915,13 +1915,13 @@ void LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups
                        AddPointToBounds( b->mins, mapMins, mapMaxs );
                        AddPointToBounds( b->maxs, mapMins, mapMaxs );
                }
-               
+
                /* get brush counts */
                numMapBrushes = CountBrushList( entities[ 0 ].brushes );
                if ( (float) c_detail / (float) numMapBrushes < 0.10f && numMapBrushes > 500 ) {
                        Sys_Printf( "WARNING: Over 90 percent structural map detected. Compile time may be adversely affected.\n" );
                }
-               
+
                /* emit some statistics */
                Sys_FPrintf( SYS_VRB, "%9d total world brushes\n", numMapBrushes );
                Sys_FPrintf( SYS_VRB, "%9d detail brushes\n", c_detail );
@@ -1932,12 +1932,12 @@ void LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups
                Sys_FPrintf( SYS_VRB, "%9d planes\n", nummapplanes );
                Sys_Printf( "%9d areaportals\n", c_areaportals );
                Sys_Printf( "Size: %5.0f, %5.0f, %5.0f to %5.0f, %5.0f, %5.0f\n",
-                       mapMins[ 0 ], mapMins[ 1 ], mapMins[ 2 ],
+                                       mapMins[ 0 ], mapMins[ 1 ], mapMins[ 2 ],
                                        mapMaxs[ 0 ], mapMaxs[ 1 ], mapMaxs[ 2 ] );
-               
+
                /* write bogus map */
                if ( fakemap ) {
                        WriteBSPBrushMap( "fakemap.map", entities[ 0 ].brushes );
-       }
+               }
        }
 }
index 7489bcf07a8b882423f4628ae97b5c9b0b5d175e..32f65d0891774ebd07e702505bab98e1a33e909b 100644 (file)
@@ -38,7 +38,7 @@
 
 
 
-/* 
+/*
    PicoPrintFunc()
    callback for picomodel.lib
  */
@@ -49,31 +49,31 @@ void PicoPrintFunc( int level, const char *str ){
        }
        switch ( level )
        {
-               case PICO_NORMAL:
-                       Sys_Printf( "%s\n", str );
-                       break;
-               
-               case PICO_VERBOSE:
-                       Sys_FPrintf( SYS_VRB, "%s\n", str );
-                       break;
-               
-               case PICO_WARNING:
-                       Sys_Printf( "WARNING: %s\n", str );
-                       break;
-               
-               case PICO_ERROR:
-                       Sys_Printf( "ERROR: %s\n", str );
-                       break;
-               
-               case PICO_FATAL:
-                       Error( "ERROR: %s\n", str );
-                       break;
+       case PICO_NORMAL:
+               Sys_Printf( "%s\n", str );
+               break;
+
+       case PICO_VERBOSE:
+               Sys_FPrintf( SYS_VRB, "%s\n", str );
+               break;
+
+       case PICO_WARNING:
+               Sys_Printf( "WARNING: %s\n", str );
+               break;
+
+       case PICO_ERROR:
+               Sys_Printf( "ERROR: %s\n", str );
+               break;
+
+       case PICO_FATAL:
+               Error( "ERROR: %s\n", str );
+               break;
        }
 }
 
 
 
-/* 
+/*
    PicoLoadFileFunc()
    callback for picomodel.lib
  */
@@ -90,29 +90,29 @@ void PicoLoadFileFunc( const char *name, byte **buffer, int *bufSize ){
  */
 
 picoModel_t *FindModel( const char *name, int frame ){
-       int                     i;
-       
-       
+       int i;
+
+
        /* init */
        if ( numPicoModels <= 0 ) {
                memset( picoModels, 0, sizeof( picoModels ) );
        }
-       
+
        /* dummy check */
        if ( name == NULL || name[ 0 ] == '\0' ) {
                return NULL;
        }
-       
+
        /* search list */
        for ( i = 0; i < MAX_MODELS; i++ )
        {
                if ( picoModels[ i ] != NULL &&
-                       !strcmp( PicoGetModelName( picoModels[ i ] ), name ) &&
+                        !strcmp( PicoGetModelName( picoModels[ i ] ), name ) &&
                         PicoGetModelFrameNum( picoModels[ i ] ) == frame ) {
                        return picoModels[ i ];
+               }
        }
-       }
-       
+
        /* no matching picoModel found */
        return NULL;
 }
@@ -125,44 +125,44 @@ picoModel_t *FindModel( const char *name, int frame ){
  */
 
 picoModel_t *LoadModel( const char *name, int frame ){
-       int                             i;
-       picoModel_t             *model, **pm;
-       
-       
+       int i;
+       picoModel_t     *model, **pm;
+
+
        /* init */
        if ( numPicoModels <= 0 ) {
                memset( picoModels, 0, sizeof( picoModels ) );
        }
-       
+
        /* dummy check */
        if ( name == NULL || name[ 0 ] == '\0' ) {
                return NULL;
        }
-       
+
        /* try to find existing picoModel */
        model = FindModel( name, frame );
        if ( model != NULL ) {
                return model;
        }
-       
+
        /* none found, so find first non-null picoModel */
        pm = NULL;
        for ( i = 0; i < MAX_MODELS; i++ )
-               {
+       {
                if ( picoModels[ i ] == NULL ) {
                        pm = &picoModels[ i ];
                        break;
                }
        }
-       
+
        /* too many picoModels? */
        if ( pm == NULL ) {
                Error( "MAX_MODELS (%d) exceeded, there are too many model files referenced by the map.", MAX_MODELS );
        }
-       
+
        /* attempt to parse model */
        *pm = PicoLoadModel( name, frame );
-       
+
        /* if loading failed, make a bogus model to silence the rest of the warnings */
        if ( *pm == NULL ) {
                /* allocate a new model */
@@ -170,19 +170,19 @@ picoModel_t *LoadModel( const char *name, int frame ){
                if ( *pm == NULL ) {
                        return NULL;
                }
-               
+
                /* set data */
                PicoSetModelName( *pm, name );
                PicoSetModelFrameNum( *pm, frame );
        }
-       
+
        /* debug code */
        #if 0
        {
-               int                             numSurfaces, numVertexes;
-               picoSurface_t   *ps;
-               
-               
+               int numSurfaces, numVertexes;
+               picoSurface_t   *ps;
+
+
                Sys_Printf( "Model %s\n", name );
                numSurfaces = PicoGetModelNumSurfaces( *pm );
                for ( i = 0; i < numSurfaces; i++ )
@@ -193,12 +193,12 @@ picoModel_t *LoadModel( const char *name, int frame ){
                }
        }
        #endif
-       
+
        /* set count */
        if ( *pm != NULL ) {
                numPicoModels++;
        }
-       
+
        /* return the picoModel */
        return *pm;
 }
@@ -211,29 +211,29 @@ picoModel_t *LoadModel( const char *name, int frame ){
  */
 
 void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle, vec3_t colormod ){
-       int                                     i, j, s, numSurfaces;
-       m4x4_t                          identity, nTransform;
-       picoModel_t                     *model;
-       picoShader_t            *shader;
-       picoSurface_t           *surface;
-       shaderInfo_t            *si;
-       mapDrawSurface_t        *ds;
-       bspDrawVert_t           *dv;
-       char                            *picoShaderName;
-       char                            shaderName[ MAX_QPATH ];
-       picoVec_t                       *xyz, *normal, *st;
-       byte                            *color;
-       picoIndex_t                     *indexes;
-       remap_t                         *rm, *glob;
-       skinfile_t                      *sf, *sf2;
-       double                          normalEpsilon_save;
-       double                          distanceEpsilon_save;
-       char                            skinfilename[ MAX_QPATH ];
-       char                            *skinfilecontent;
-       int                                     skinfilesize;
-       char                            *skinfileptr, *skinfilenextptr;
-       
-       
+       int i, j, s, numSurfaces;
+       m4x4_t identity, nTransform;
+       picoModel_t         *model;
+       picoShader_t        *shader;
+       picoSurface_t       *surface;
+       shaderInfo_t        *si;
+       mapDrawSurface_t    *ds;
+       bspDrawVert_t       *dv;
+       char                *picoShaderName;
+       char shaderName[ MAX_QPATH ];
+       picoVec_t           *xyz, *normal, *st;
+       byte                *color;
+       picoIndex_t         *indexes;
+       remap_t             *rm, *glob;
+       skinfile_t          *sf, *sf2;
+       double normalEpsilon_save;
+       double distanceEpsilon_save;
+       char skinfilename[ MAX_QPATH ];
+       char                *skinfilecontent;
+       int skinfilesize;
+       char                *skinfileptr, *skinfilenextptr;
+
+
        /* get model */
        model = LoadModel( name, frame );
        if ( model == NULL ) {
@@ -251,7 +251,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                skinfilesize = vfsLoadFile( skinfilename, (void**) &skinfilecontent, 0 );
                if ( skinfilesize >= 0 ) {
                        Sys_Printf( "Skin %d of %s does not exist, using 0 instead\n", skin, name );
-       }
+               }
        }
        sf = NULL;
        if ( skinfilesize >= 0 ) {
@@ -298,25 +298,25 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                }
                free( skinfilecontent );
        }
-       
+
        /* handle null matrix */
        if ( transform == NULL ) {
                m4x4_identity( identity );
                transform = identity;
        }
-       
+
        /* hack: Stable-1_2 and trunk have differing row/column major matrix order
           this transpose is necessary with Stable-1_2
           uncomment the following line with old m4x4_t (non 1.3/spog_branch) code */
        //%     m4x4_transpose( transform );
-       
+
        /* create transform matrix for normals */
        memcpy( nTransform, transform, sizeof( m4x4_t ) );
        if ( m4x4_invert( nTransform ) ) {
                Sys_FPrintf( SYS_VRB, "WARNING: Can't invert model transform matrix, using transpose instead\n" );
        }
        m4x4_transpose( nTransform );
-       
+
        /* fix bogus lightmap scale */
        if ( lightmapScale <= 0.0f ) {
                lightmapScale = 1.0f;
@@ -326,7 +326,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
        if ( shadeAngle <= 0.0f ) {
                shadeAngle = 0.0f;
        }
-       
+
        /* each surface on the model will become a new map drawsurface */
        numSurfaces = PicoGetModelNumSurfaces( model );
        //%     Sys_FPrintf( SYS_VRB, "Model %s has %d surfaces\n", name, numSurfaces );
@@ -337,14 +337,14 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                if ( surface == NULL ) {
                        continue;
                }
-               
+
                /* only handle triangle surfaces initially (fixme: support patches) */
                if ( PicoGetSurfaceType( surface ) != PICO_TRIANGLES ) {
                        continue;
                }
-               
+
                /* get shader name */
-        shader = PicoGetSurfaceShader( surface );
+               shader = PicoGetSurfaceShader( surface );
                if ( shader == NULL ) {
                        picoShaderName = "";
                }
@@ -356,7 +356,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                if ( sf ) {
                        picoShaderName = NULL;
                        for ( sf2 = sf; sf2 != NULL; sf2 = sf2->next )
-                               {
+                       {
                                if ( !Q_stricmp( surface->name, sf2->name ) ) {
                                        Sys_FPrintf( SYS_VRB, "Skin file: mapping %s to %s\n", surface->name, sf2->to );
                                        picoShaderName = sf2->to;
@@ -383,12 +383,12 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                                break;
                        }
                }
-               
+
                if ( glob != NULL ) {
                        Sys_FPrintf( SYS_VRB, "Globbing %s to %s\n", picoShaderName, glob->to );
                        picoShaderName = glob->to;
                }
-               
+
                /* shader renaming for sof2 */
                if ( renameModelShaders ) {
                        strcpy( shaderName, picoShaderName );
@@ -404,7 +404,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                else{
                        si = ShaderInfoForShader( picoShaderName );
                }
-               
+
                /* allocate a surface (ydnar: gs mods) */
                ds = AllocDrawSurface( SURFACE_TRIANGLES );
                ds->entityNum = eNum;
@@ -428,7 +428,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                if ( lightmapSampleSize > 0.0f ) {
                        ds->sampleSize = lightmapSampleSize;
                }
-               
+
                /* set lightmap scale */
                if ( lightmapScale > 0.0f ) {
                        ds->lightmapScale = lightmapScale;
@@ -441,27 +441,27 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                if ( shadeAngle > 0.0f ) {
                        ds->shadeAngleDegrees = shadeAngle;
                }
-               
+
                /* set particulars */
                ds->numVerts = PicoGetSurfaceNumVertexes( surface );
                ds->verts = safe_malloc( ds->numVerts * sizeof( ds->verts[ 0 ] ) );
                memset( ds->verts, 0, ds->numVerts * sizeof( ds->verts[ 0 ] ) );
-               
+
                ds->numIndexes = PicoGetSurfaceNumIndexes( surface );
                ds->indexes = safe_malloc( ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
                memset( ds->indexes, 0, ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
-               
+
                /* copy vertexes */
                for ( i = 0; i < ds->numVerts; i++ )
                {
                        /* get vertex */
                        dv = &ds->verts[ i ];
-                       
+
                        /* xyz and normal */
                        xyz = PicoGetSurfaceXYZ( surface, i );
                        VectorCopy( xyz, dv->xyz );
                        m4x4_transform_point( transform, dv->xyz );
-                       
+
                        normal = PicoGetSurfaceNormal( surface, i );
                        VectorCopy( normal, dv->normal );
                        m4x4_transform_normal( nTransform, dv->normal );
@@ -472,14 +472,14 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                                dv->st[ 0 ] = si->stFlat[ 0 ];
                                dv->st[ 1 ] = si->stFlat[ 1 ];
                        }
-                       
+
                        /* ydnar: gs mods: added support for explicit shader texcoord generation */
                        else if ( si->tcGen ) {
                                /* project the texture */
                                dv->st[ 0 ] = DotProduct( si->vecs[ 0 ], dv->xyz );
                                dv->st[ 1 ] = DotProduct( si->vecs[ 1 ], dv->xyz );
                        }
-                       
+
                        /* normal texture coordinates */
                        else
                        {
@@ -487,7 +487,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                                dv->st[ 0 ] = st[ 0 ];
                                dv->st[ 1 ] = st[ 1 ];
                        }
-                       
+
                        /* set lightmap/color bits */
                        color = PicoGetSurfaceColor( surface, 0, i );
                        for ( j = 0; j < MAX_LIGHTMAPS; j++ )
@@ -509,44 +509,44 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                                }
                        }
                }
-               
+
                /* copy indexes */
                indexes = PicoGetSurfaceIndexes( surface, 0 );
                for ( i = 0; i < ds->numIndexes; i++ )
                        ds->indexes[ i ] = indexes[ i ];
-               
+
                /* set cel shader */
                ds->celShader = celShader;
-               
+
                /* ydnar: giant hack land: generate clipping brushes for model triangles */
                if ( si->clipModel || ( spawnFlags & 2 ) ) { /* 2nd bit */
-                       vec3_t          points[ 4 ], backs[ 3 ];
-                       vec4_t          plane, reverse, pa, pb, pc;
-                       
-                       
+                       vec3_t points[ 4 ], backs[ 3 ];
+                       vec4_t plane, reverse, pa, pb, pc;
+
+
                        /* temp hack */
                        if ( !si->clipModel && !( si->compileFlags & C_SOLID ) ) {
                                continue;
                        }
-                       
+
                        /* walk triangle list */
                        for ( i = 0; i < ds->numIndexes; i += 3 )
                        {
                                /* overflow hack */
                                AUTOEXPAND_BY_REALLOC( mapplanes, ( nummapplanes + 64 ) << 1, allocatedmapplanes, 1024 );
-                               
+
                                /* make points and back points */
                                for ( j = 0; j < 3; j++ )
                                {
                                        /* get vertex */
                                        dv = &ds->verts[ ds->indexes[ i + j ] ];
-                                       
+
                                        /* copy xyz */
                                        VectorCopy( dv->xyz, points[ j ] );
                                }
 
                                VectorCopy( points[0], points[3] ); // for cyclic usage
-                               
+
                                /* make plane for triangle */
                                // div0: add some extra spawnflags:
                                //   0: snap normals to axial planes for extrusion
@@ -617,7 +617,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                                                }
                                                if ( distanceEpsilon > 0 ) {
                                                        distanceEpsilon = 0;
-                                       }
+                                               }
                                        }
                                        else{
                                                buildBrush->detail = qtrue;
@@ -642,13 +642,13 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                                        // that's at least sqrt(1/3) backPlaneDistance, unless in DOWN mode; in DOWN mode, we are screwed anyway if we encounter a plane that's perpendicular to the xy plane)
 
                                        if ( PlaneFromPoints( pa, points[ 2 ], points[ 1 ], backs[ 1 ] ) &&
-                                                       PlaneFromPoints( pb, points[ 1 ], points[ 0 ], backs[ 0 ] ) &&
+                                                PlaneFromPoints( pb, points[ 1 ], points[ 0 ], backs[ 0 ] ) &&
                                                 PlaneFromPoints( pc, points[ 0 ], points[ 2 ], backs[ 2 ] ) ) {
                                                /* set up brush sides */
                                                buildBrush->numsides = 5;
                                                buildBrush->sides[ 0 ].shaderInfo = si;
                                                for ( j = 1; j < buildBrush->numsides; j++ )
-                                                       buildBrush->sides[ j ].shaderInfo = NULL; // don't emit these faces as draw surfaces, should make smaller BSPs; hope this works
+                                                       buildBrush->sides[ j ].shaderInfo = NULL;  // don't emit these faces as draw surfaces, should make smaller BSPs; hope this works
 
                                                buildBrush->sides[ 0 ].planenum = FindFloatPlane( plane, plane[ 3 ], 3, points );
                                                buildBrush->sides[ 1 ].planenum = FindFloatPlane( pa, pa[ 3 ], 2, &points[ 1 ] ); // pa contains points[1] and points[2]
@@ -675,11 +675,11 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
                                        }
                                        else{
                                                free( buildBrush );
+                                       }
                                }
                        }
                }
        }
-       }
 }
 
 
@@ -690,25 +690,25 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
  */
 
 void AddTriangleModels( entity_t *e ){
-       int                             num, frame, skin, castShadows, recvShadows, spawnFlags;
-       entity_t                *e2;
-       const char              *targetName;
-       const char              *target, *model, *value;
-       char                    shader[ MAX_QPATH ];
-       shaderInfo_t    *celShader;
-       float                   temp, baseLightmapScale, lightmapScale;
-       float                   shadeAngle;
-       int                             lightmapSampleSize;
-       vec3_t                  origin, scale, angles;
-       m4x4_t                  transform;
-       epair_t                 *ep;
-       remap_t                 *remap, *remap2;
-       char                    *split;
-       
-       
+       int num, frame, skin, castShadows, recvShadows, spawnFlags;
+       entity_t        *e2;
+       const char      *targetName;
+       const char      *target, *model, *value;
+       char shader[ MAX_QPATH ];
+       shaderInfo_t    *celShader;
+       float temp, baseLightmapScale, lightmapScale;
+       float shadeAngle;
+       int lightmapSampleSize;
+       vec3_t origin, scale, angles;
+       m4x4_t transform;
+       epair_t         *ep;
+       remap_t         *remap, *remap2;
+       char            *split;
+
+
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- AddTriangleModels ---\n" );
-       
+
        /* get current brush entity targetname */
        if ( e == entities ) {
                targetName = "";
@@ -716,18 +716,18 @@ void AddTriangleModels( entity_t *e ){
        else
        {
                targetName = ValueForKey( e, "targetname" );
-       
+
                /* misc_model entities target non-worldspawn brush model entities */
                if ( targetName[ 0 ] == '\0' ) {
                        return;
+               }
        }
-       }
-       
+
        /* get lightmap scale */
        /* vortex: added _ls key (short name of lightmapscale) */
        baseLightmapScale = 0.0f;
        if ( strcmp( "", ValueForKey( e, "lightmapscale" ) ) ||
-               strcmp( "", ValueForKey( e, "_lightmapscale" ) ) || 
+                strcmp( "", ValueForKey( e, "_lightmapscale" ) ) ||
                 strcmp( "", ValueForKey( e, "_ls" ) ) ) {
                baseLightmapScale = FloatForKey( e, "lightmapscale" );
                if ( baseLightmapScale <= 0.0f ) {
@@ -741,16 +741,16 @@ void AddTriangleModels( entity_t *e ){
                }
                if ( baseLightmapScale > 0.0f ) {
                        Sys_Printf( "World Entity has lightmap scale of %.4f\n", baseLightmapScale );
+               }
        }
-       }
-       
-       
+
+
        /* walk the entity list */
        for ( num = 1; num < numEntities; num++ )
        {
                /* get e2 */
                e2 = &entities[ num ];
-               
+
                /* convert misc_models into raw geometry */
                if ( Q_stricmp( "misc_model", ValueForKey( e2, "classname" ) ) ) {
                        continue;
@@ -761,15 +761,15 @@ void AddTriangleModels( entity_t *e ){
                if ( strcmp( target, targetName ) ) {
                        continue;
                }
-               
+
                /* get model name */
                model = ValueForKey( e2, "model" );
                if ( model[ 0 ] == '\0' ) {
                        Sys_Printf( "WARNING: misc_model at %i %i %i without a model key\n",
-                               (int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] );
+                                               (int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] );
                        continue;
                }
-               
+
                /* get model frame */
                frame = 0;
                if ( strcmp( "", ValueForKey( e2, "_frame" ) ) ) {
@@ -778,30 +778,30 @@ void AddTriangleModels( entity_t *e ){
                else if ( strcmp( "", ValueForKey( e2, "frame" ) ) ) {
                        frame = IntForKey( e2, "frame" );
                }
-               
+
                /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */
                if ( e == entities ) {
                        castShadows = WORLDSPAWN_CAST_SHADOWS;
                        recvShadows = WORLDSPAWN_RECV_SHADOWS;
                }
-               
+
                /* other entities don't cast any shadows, but recv worldspawn shadows */
                else
                {
                        castShadows = ENTITY_CAST_SHADOWS;
                        recvShadows = ENTITY_RECV_SHADOWS;
                }
-               
+
                /* get explicit shadow flags */
                GetEntityShadowFlags( e2, e, &castShadows, &recvShadows );
-               
+
                /* get spawnflags */
                spawnFlags = IntForKey( e2, "spawnflags" );
-               
+
                /* get origin */
                GetVectorForKey( e2, "origin", origin );
-               VectorSubtract( origin, e->origin, origin );    /* offset by parent */
-               
+               VectorSubtract( origin, e->origin, origin );    /* offset by parent */
+
                /* get scale */
                scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = 1.0f;
                temp = FloatForKey( e2, "modelscale" );
@@ -812,7 +812,7 @@ void AddTriangleModels( entity_t *e ){
                if ( value[ 0 ] != '\0' ) {
                        sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] );
                }
-               
+
                /* get "angle" (yaw) or "angles" (pitch yaw roll) */
                angles[ 0 ] = angles[ 1 ] = angles[ 2 ] = 0.0f;
                angles[ 2 ] = FloatForKey( e2, "angle" );
@@ -820,25 +820,25 @@ void AddTriangleModels( entity_t *e ){
                if ( value[ 0 ] != '\0' ) {
                        sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] );
                }
-               
+
                /* set transform matrix (thanks spog) */
                m4x4_identity( transform );
                m4x4_pivoted_transform_by_vec3( transform, origin, angles, eXYZ, scale, vec3_origin );
-               
+
                /* get shader remappings */
                remap = NULL;
                for ( ep = e2->epairs; ep != NULL; ep = ep->next )
                {
                        /* look for keys prefixed with "_remap" */
                        if ( ep->key != NULL && ep->value != NULL &&
-                               ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' &&
+                                ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' &&
                                 !Q_strncasecmp( ep->key, "_remap", 6 ) ) {
                                /* create new remapping */
                                remap2 = remap;
                                remap = safe_malloc( sizeof( *remap ) );
                                remap->next = remap2;
                                strcpy( remap->from, ep->value );
-                               
+
                                /* split the string */
                                split = strchr( remap->from, ';' );
                                if ( split == NULL ) {
@@ -847,16 +847,16 @@ void AddTriangleModels( entity_t *e ){
                                        remap = remap2;
                                        continue;
                                }
-                               
+
                                /* store the split */
                                *split = '\0';
                                strcpy( remap->to, ( split + 1 ) );
-                               
+
                                /* note it */
                                //%     Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", remap->from, remap->to );
                        }
                }
-               
+
                /* ydnar: cel shader support */
                value = ValueForKey( e2, "_celshader" );
                if ( value[ 0 ] == '\0' ) {
@@ -891,7 +891,7 @@ void AddTriangleModels( entity_t *e ){
                /* vortex: added _ls key (short name of lightmapscale) */
                lightmapScale = 0.0f;
                if ( strcmp( "", ValueForKey( e2, "lightmapscale" ) ) ||
-                       strcmp( "", ValueForKey( e2, "_lightmapscale" ) ) || 
+                        strcmp( "", ValueForKey( e2, "_lightmapscale" ) ) ||
                         strcmp( "", ValueForKey( e2, "_ls" ) ) ) {
                        lightmapScale = FloatForKey( e2, "lightmapscale" );
                        if ( lightmapScale <= 0.0f ) {
@@ -905,7 +905,7 @@ void AddTriangleModels( entity_t *e ){
                        }
                        if ( lightmapScale > 0.0f ) {
                                Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale );
-               }
+                       }
                }
 
                /* jal : entity based _shadeangle */
@@ -942,7 +942,7 @@ void AddTriangleModels( entity_t *e ){
 
                /* insert the model */
                InsertModel( model, skin, frame, transform, remap, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale, lightmapSampleSize, shadeAngle, colormod );
-               
+
                /* free shader remappings */
                while ( remap != NULL )
                {
index 55e4b9d439fc67728ef240fccda0828397a0fe15..175672a5527aa489e7b5127b5e44f8ec1d7e3d3f 100644 (file)
@@ -38,7 +38,7 @@
 #ifndef Q3MAP_VERSION
 #error no Q3MAP_VERSION defined
 #endif
-#define Q3MAP_MOTD             "Your map saw the pretty lights from q3map2's BFG"
+#define Q3MAP_MOTD      "Your map saw the pretty lights from q3map2's BFG"
 
 
 
@@ -66,7 +66,7 @@
 
 
 /* general */
-#include "version.h"                   /* ttimo: might want to guard that if built outside of the GtkRadiant tree */
+#include "version.h"            /* ttimo: might want to guard that if built outside of the GtkRadiant tree */
 
 #include "cmdlib.h"
 #include "mathlib.h"
 
    ------------------------------------------------------------------------------- */
 
-#define MAC_STATIC_HACK                        0
-#if defined( __APPLE__ ) && MAC_STATIC_HACK 
-       #define MAC_STATIC                      static
+#define MAC_STATIC_HACK         0
+#if defined( __APPLE__ ) && MAC_STATIC_HACK
+       #define MAC_STATIC          static
 #else
-       #define MAC_STATIC                      
+       #define MAC_STATIC
 #endif
 
 #if 1
        #ifdef WIN32
-               #define Q_stricmp                       stricmp
-               #define Q_strncasecmp           strnicmp
+               #define Q_stricmp           stricmp
+               #define Q_strncasecmp       strnicmp
        #else
-               #define Q_stricmp                       strcasecmp
-               #define Q_strncasecmp           strncasecmp
+               #define Q_stricmp           strcasecmp
+               #define Q_strncasecmp       strncasecmp
        #endif
 #endif
 
 
 /* temporary hacks and tests (please keep off in SVN to prevent anyone's legacy map from screwing up) */
 /* 2011-01-10 TTimo says we should turn these on in SVN, so turning on now */
-#define Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES  1
-#define Q3MAP2_EXPERIMENTAL_SNAP_NORMAL_FIX            1
-#define Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX             1
+#define Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES   1
+#define Q3MAP2_EXPERIMENTAL_SNAP_NORMAL_FIX     1
+#define Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX      1
 
 /* general */
-#define MAX_QPATH                              64
+#define MAX_QPATH               64
 
-#define MAX_IMAGES                             512
-#define DEFAULT_IMAGE                  "*default"
+#define MAX_IMAGES              512
+#define DEFAULT_IMAGE           "*default"
 
-#define MAX_MODELS                             512
+#define MAX_MODELS              512
 
-#define        DEF_BACKSPLASH_FRACTION 0.05f   /* 5% backsplash by default */
-#define        DEF_BACKSPLASH_DISTANCE 23
+#define DEF_BACKSPLASH_FRACTION 0.05f   /* 5% backsplash by default */
+#define DEF_BACKSPLASH_DISTANCE 23
 
-#define DEF_RADIOSITY_BOUNCE   1.0f    /* ydnar: default to 100% re-emitted light */
+#define DEF_RADIOSITY_BOUNCE    1.0f    /* ydnar: default to 100% re-emitted light */
 
-#define        MAX_SHADER_INFO                 8192
+#define MAX_SHADER_INFO         8192
 #define MAX_CUST_SURFACEPARMS   256
 
-#define        SHADER_MAX_VERTEXES             1000
+#define SHADER_MAX_VERTEXES     1000
 #define SHADER_MAX_INDEXES      ( 6 * SHADER_MAX_VERTEXES )
 
-#define MAX_JITTERS                            256
+#define MAX_JITTERS             256
 
 
 /* epair parsing (note case-sensitivity directive) */
-#define CASE_INSENSITIVE_EPAIRS        1
+#define CASE_INSENSITIVE_EPAIRS 1
 
 #if CASE_INSENSITIVE_EPAIRS
-       #define EPAIR_STRCMP            Q_stricmp
+       #define EPAIR_STRCMP        Q_stricmp
 #else
-       #define EPAIR_STRCMP            strcmp
+       #define EPAIR_STRCMP        strcmp
 #endif
 
 
 /* ydnar: compiler flags, because games have widely varying content/surface flags */
-#define C_SOLID                                        0x00000001
-#define C_TRANSLUCENT                  0x00000002
-#define C_STRUCTURAL                   0x00000004
-#define C_HINT                                 0x00000008
-#define C_NODRAW                               0x00000010
-#define C_LIGHTGRID                            0x00000020
-#define C_ALPHASHADOW                  0x00000040
-#define C_LIGHTFILTER                  0x00000080
-#define C_VERTEXLIT                            0x00000100
-#define C_LIQUID                               0x00000200
-#define C_FOG                                  0x00000400
-#define C_SKY                                  0x00000800
-#define C_ORIGIN                               0x00001000
-#define C_AREAPORTAL                   0x00002000
-#define C_ANTIPORTAL                   0x00004000      /* like hint, but doesn't generate portals */
-#define C_SKIP                                 0x00008000      /* like hint, but skips this face (doesn't split bsp) */
-#define C_NOMARKS                              0x00010000      /* no decals */
-#define C_DETAIL                               0x08000000      /* THIS MUST BE THE SAME AS IN RADIANT! */
+#define C_SOLID                 0x00000001
+#define C_TRANSLUCENT           0x00000002
+#define C_STRUCTURAL            0x00000004
+#define C_HINT                  0x00000008
+#define C_NODRAW                0x00000010
+#define C_LIGHTGRID             0x00000020
+#define C_ALPHASHADOW           0x00000040
+#define C_LIGHTFILTER           0x00000080
+#define C_VERTEXLIT             0x00000100
+#define C_LIQUID                0x00000200
+#define C_FOG                   0x00000400
+#define C_SKY                   0x00000800
+#define C_ORIGIN                0x00001000
+#define C_AREAPORTAL            0x00002000
+#define C_ANTIPORTAL            0x00004000  /* like hint, but doesn't generate portals */
+#define C_SKIP                  0x00008000  /* like hint, but skips this face (doesn't split bsp) */
+#define C_NOMARKS               0x00010000  /* no decals */
+#define C_DETAIL                0x08000000  /* THIS MUST BE THE SAME AS IN RADIANT! */
 
 
 /* shadow flags */
-#define WORLDSPAWN_CAST_SHADOWS        1
-#define WORLDSPAWN_RECV_SHADOWS        1
-#define ENTITY_CAST_SHADOWS            0
-#define ENTITY_RECV_SHADOWS            1
+#define WORLDSPAWN_CAST_SHADOWS 1
+#define WORLDSPAWN_RECV_SHADOWS 1
+#define ENTITY_CAST_SHADOWS     0
+#define ENTITY_RECV_SHADOWS     1
 
 
 /* bsp */
-#define        MAX_PATCH_SIZE                  32
-#define        MAX_BRUSH_SIDES                 1024
-#define MAX_BUILD_SIDES                        1024
+#define MAX_PATCH_SIZE          32
+#define MAX_BRUSH_SIDES         1024
+#define MAX_BUILD_SIDES         1024
 
-#define        MAX_EXPANDED_AXIS               128
+#define MAX_EXPANDED_AXIS       128
 
-#define        CLIP_EPSILON                    0.1f
-#define        PLANESIDE_EPSILON               0.001f
-#define        PLANENUM_LEAF                   -1
+#define CLIP_EPSILON            0.1f
+#define PLANESIDE_EPSILON       0.001f
+#define PLANENUM_LEAF           -1
 
-#define        HINT_PRIORITY                   1000            /* ydnar: force hint splits first and antiportal/areaportal splits last */
-#define ANTIPORTAL_PRIORITY            -1000
-#define AREAPORTAL_PRIORITY            -1000
-#define DETAIL_PRIORITY                -3000
+#define HINT_PRIORITY           1000        /* ydnar: force hint splits first and antiportal/areaportal splits last */
+#define ANTIPORTAL_PRIORITY     -1000
+#define AREAPORTAL_PRIORITY     -1000
+#define DETAIL_PRIORITY     -3000
 
-#define        PSIDE_FRONT                             1
-#define        PSIDE_BACK                              2
+#define PSIDE_FRONT             1
+#define PSIDE_BACK              2
 #define PSIDE_BOTH              ( PSIDE_FRONT | PSIDE_BACK )
-#define        PSIDE_FACING                    4
+#define PSIDE_FACING            4
 
-#define BPRIMIT_UNDEFINED              0
-#define BPRIMIT_OLDBRUSHES             1
-#define BPRIMIT_NEWBRUSHES             2
+#define BPRIMIT_UNDEFINED       0
+#define BPRIMIT_OLDBRUSHES      1
+#define BPRIMIT_NEWBRUSHES      2
 
 
 /* vis */
-#define        VIS_HEADER_SIZE                 8
+#define VIS_HEADER_SIZE         8
 
-#define SEPERATORCACHE                 /* seperator caching helps a bit */
+#define SEPERATORCACHE          /* seperator caching helps a bit */
 
-#define        PORTALFILE                              "PRT1"
+#define PORTALFILE              "PRT1"
 
-#define        MAX_PORTALS                             0x20000 /* same as MAX_MAP_PORTALS */
-#define MAX_SEPERATORS                 MAX_POINTS_ON_WINDING
-#define        MAX_POINTS_ON_FIXED_WINDING     24      /* ydnar: increased this from 12 at the expense of more memory */
-#define        MAX_PORTALS_ON_LEAF             1024
+#define MAX_PORTALS             0x20000 /* same as MAX_MAP_PORTALS */
+#define MAX_SEPERATORS          MAX_POINTS_ON_WINDING
+#define MAX_POINTS_ON_FIXED_WINDING 24  /* ydnar: increased this from 12 at the expense of more memory */
+#define MAX_PORTALS_ON_LEAF     1024
 
 
 /* light */
-#define EMIT_POINT                             0
-#define EMIT_AREA                              1
-#define EMIT_SPOT                              2
-#define EMIT_SUN                               3
-
-#define LIGHT_ATTEN_LINEAR             1
-#define LIGHT_ATTEN_ANGLE              2
-#define LIGHT_ATTEN_DISTANCE   4
-#define LIGHT_TWOSIDED                 8
-#define LIGHT_GRID                             16
-#define LIGHT_SURFACES                 32
-#define LIGHT_DARK                             64              /* probably never use this */
-#define LIGHT_FAST                             256
-#define LIGHT_FAST_TEMP                        512
+#define EMIT_POINT              0
+#define EMIT_AREA               1
+#define EMIT_SPOT               2
+#define EMIT_SUN                3
+
+#define LIGHT_ATTEN_LINEAR      1
+#define LIGHT_ATTEN_ANGLE       2
+#define LIGHT_ATTEN_DISTANCE    4
+#define LIGHT_TWOSIDED          8
+#define LIGHT_GRID              16
+#define LIGHT_SURFACES          32
+#define LIGHT_DARK              64      /* probably never use this */
+#define LIGHT_FAST              256
+#define LIGHT_FAST_TEMP         512
 #define LIGHT_FAST_ACTUAL       ( LIGHT_FAST | LIGHT_FAST_TEMP )
-#define LIGHT_NEGATIVE                 1024
-#define LIGHT_UNNORMALIZED             2048    /* vortex: do not normalize _color */
+#define LIGHT_NEGATIVE          1024
+#define LIGHT_UNNORMALIZED      2048    /* vortex: do not normalize _color */
 
 #define LIGHT_SUN_DEFAULT       ( LIGHT_ATTEN_ANGLE | LIGHT_GRID | LIGHT_SURFACES )
 #define LIGHT_AREA_DEFAULT      ( LIGHT_ATTEN_ANGLE | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES )    /* q3a and wolf are the same */
 #define LIGHT_Q3A_DEFAULT       ( LIGHT_ATTEN_ANGLE | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES | LIGHT_FAST )
 #define LIGHT_WOLF_DEFAULT      ( LIGHT_ATTEN_LINEAR | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES | LIGHT_FAST )
 
-#define MAX_TRACE_TEST_NODES   256
-#define DEFAULT_INHIBIT_RADIUS 1.5f
+#define MAX_TRACE_TEST_NODES    256
+#define DEFAULT_INHIBIT_RADIUS  1.5f
 
-#define LUXEL_EPSILON                  0.125f
-#define VERTEX_EPSILON                 -0.125f
-#define GRID_EPSILON                   0.0f
+#define LUXEL_EPSILON           0.125f
+#define VERTEX_EPSILON          -0.125f
+#define GRID_EPSILON            0.0f
 
-#define DEFAULT_LIGHTMAP_SAMPLE_SIZE   16
-#define DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE       0
-#define DEFAULT_LIGHTMAP_SAMPLE_OFFSET 1.0f
-#define DEFAULT_SUBDIVIDE_THRESHOLD            1.0f
+#define DEFAULT_LIGHTMAP_SAMPLE_SIZE    16
+#define DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE    0
+#define DEFAULT_LIGHTMAP_SAMPLE_OFFSET  1.0f
+#define DEFAULT_SUBDIVIDE_THRESHOLD     1.0f
 
-#define        EXTRA_SCALE                             2       /* -extrawide = -super 2 */
-#define        EXTRAWIDE_SCALE                 2       /* -extrawide = -super 2 -filter */
+#define EXTRA_SCALE             2   /* -extrawide = -super 2 */
+#define EXTRAWIDE_SCALE         2   /* -extrawide = -super 2 -filter */
 
-#define CLUSTER_UNMAPPED               -1
-#define CLUSTER_OCCLUDED               -2
-#define CLUSTER_FLOODED                        -3
+#define CLUSTER_UNMAPPED        -1
+#define CLUSTER_OCCLUDED        -2
+#define CLUSTER_FLOODED         -3
 
-#define VERTEX_LUXEL_SIZE              3
-#define BSP_LUXEL_SIZE                 3
-#define RAD_LUXEL_SIZE                 3
-#define SUPER_LUXEL_SIZE               4
-#define SUPER_FLAG_SIZE                        4
+#define VERTEX_LUXEL_SIZE       3
+#define BSP_LUXEL_SIZE          3
+#define RAD_LUXEL_SIZE          3
+#define SUPER_LUXEL_SIZE        4
+#define SUPER_FLAG_SIZE         4
 #define FLAG_FORCE_SUBSAMPLING 1
 #define FLAG_ALREADY_SUBSAMPLED 2
-#define SUPER_ORIGIN_SIZE              3
-#define SUPER_NORMAL_SIZE              4
-#define SUPER_DELUXEL_SIZE             3
-#define BSP_DELUXEL_SIZE               3
-#define SUPER_FLOODLIGHT_SIZE  4
+#define SUPER_ORIGIN_SIZE       3
+#define SUPER_NORMAL_SIZE       4
+#define SUPER_DELUXEL_SIZE      3
+#define BSP_DELUXEL_SIZE        3
+#define SUPER_FLOODLIGHT_SIZE   4
 
 #define VERTEX_LUXEL( s, v )    ( vertexLuxels[ s ] + ( ( v ) * VERTEX_LUXEL_SIZE ) )
 #define RAD_VERTEX_LUXEL( s, v )( radVertexLuxels[ s ] + ( ( v ) * VERTEX_LUXEL_SIZE ) )
 
    ------------------------------------------------------------------------------- */
 
-#define EXTERNAL_LIGHTMAP              "lm_%04d.tga"
+#define EXTERNAL_LIGHTMAP       "lm_%04d.tga"
 
-#define MAX_LIGHTMAPS                  4                       /* RBSP */
-#define MAX_LIGHT_STYLES               64
-#define        MAX_SWITCHED_LIGHTS             32
-#define LS_NORMAL                              0x00
-#define LS_UNUSED                              0xFE
-#define        LS_NONE                                 0xFF
+#define MAX_LIGHTMAPS           4           /* RBSP */
+#define MAX_LIGHT_STYLES        64
+#define MAX_SWITCHED_LIGHTS     32
+#define LS_NORMAL               0x00
+#define LS_UNUSED               0xFE
+#define LS_NONE                 0xFF
 
-#define MAX_LIGHTMAP_SHADERS   256
+#define MAX_LIGHTMAP_SHADERS    256
 
 /* ok to increase these at the expense of more memory */
-#define        MAX_MAP_AREAS                   0x100           /* MAX_MAP_AREA_BYTES in q_shared must match! */
-#define        MAX_MAP_FOGS                    30                      //& 0x100       /* RBSP (32 - world fog - goggles) */
-#define        MAX_MAP_LEAFS                   0x20000
-#define        MAX_MAP_PORTALS                 0x20000
-#define        MAX_MAP_LIGHTING                0x800000
-#define        MAX_MAP_LIGHTGRID               0x100000        //%     0x800000 /* ydnar: set to points, not bytes */
+#define MAX_MAP_AREAS           0x100       /* MAX_MAP_AREA_BYTES in q_shared must match! */
+#define MAX_MAP_FOGS            30          //& 0x100  /* RBSP (32 - world fog - goggles) */
+#define MAX_MAP_LEAFS           0x20000
+#define MAX_MAP_PORTALS         0x20000
+#define MAX_MAP_LIGHTING        0x800000
+#define MAX_MAP_LIGHTGRID       0x100000    //%        0x800000 /* ydnar: set to points, not bytes */
 #define MAX_MAP_VISCLUSTERS     0x4000 // <= MAX_MAP_LEAFS
 #define MAX_MAP_VISIBILITY      ( VIS_HEADER_SIZE + MAX_MAP_VISCLUSTERS * ( ( ( MAX_MAP_VISCLUSTERS + 63 ) & ~63 ) >> 3 ) )
 
-#define        MAX_MAP_DRAW_SURFS              0x20000
+#define MAX_MAP_DRAW_SURFS      0x20000
 
-#define MAX_MAP_ADVERTISEMENTS 30
+#define MAX_MAP_ADVERTISEMENTS  30
 
 /* key / value pair sizes in the entities lump */
-#define        MAX_KEY                                 32
-#define        MAX_VALUE                               1024
+#define MAX_KEY                 32
+#define MAX_VALUE               1024
 
 /* the editor uses these predefined yaw angles to orient entities up or down */
-#define        ANGLE_UP                                -1
-#define        ANGLE_DOWN                              -2
+#define ANGLE_UP                -1
+#define ANGLE_DOWN              -2
 
-#define        LIGHTMAP_WIDTH                  128
-#define        LIGHTMAP_HEIGHT                 128
+#define LIGHTMAP_WIDTH          128
+#define LIGHTMAP_HEIGHT         128
 
 #define MIN_WORLD_COORD         ( -65536 )
 #define MAX_WORLD_COORD         ( 65536 )
@@ -352,35 +352,35 @@ typedef void ( *bspFunc )( const char * );
 
 typedef struct
 {
-       int                     offset, length;
+       int offset, length;
 }
 bspLump_t;
 
 
 typedef struct
 {
-       char            ident[ 4 ];
-       int                     version;
-       
-       bspLump_t       lumps[ 100 ];   /* theoretical maximum # of bsp lumps */
+       char ident[ 4 ];
+       int version;
+
+       bspLump_t lumps[ 100 ];     /* theoretical maximum # of bsp lumps */
 }
 bspHeader_t;
 
 
 typedef struct
 {
-       float           mins[ 3 ], maxs[ 3 ];
-       int                     firstBSPSurface, numBSPSurfaces;
-       int                     firstBSPBrush, numBSPBrushes;
+       float mins[ 3 ], maxs[ 3 ];
+       int firstBSPSurface, numBSPSurfaces;
+       int firstBSPBrush, numBSPBrushes;
 }
 bspModel_t;
 
 
 typedef struct
 {
-       char            shader[ MAX_QPATH ];
-       int                     surfaceFlags;
-       int                     contentFlags;
+       char shader[ MAX_QPATH ];
+       int surfaceFlags;
+       int contentFlags;
 }
 bspShader_t;
 
@@ -389,73 +389,73 @@ bspShader_t;
 
 typedef struct
 {
-       float           normal[ 3 ];
-       float           dist;
+       float normal[ 3 ];
+       float dist;
 }
 bspPlane_t;
 
 
 typedef struct
 {
-       int                     planeNum;
-       int                     children[ 2 ];          /* negative numbers are -(leafs+1), not nodes */
-       int                     mins[ 3 ];                      /* for frustom culling */
-       int                     maxs[ 3 ];
+       int planeNum;
+       int children[ 2 ];              /* negative numbers are -(leafs+1), not nodes */
+       int mins[ 3 ];                  /* for frustom culling */
+       int maxs[ 3 ];
 }
 bspNode_t;
 
 
 typedef struct
 {
-       int                     cluster;                        /* -1 = opaque cluster (do I still store these?) */
-       int                     area;
-       
-       int                     mins[ 3 ];                      /* for frustum culling */
-       int                     maxs[ 3 ];
-       
-       int                     firstBSPLeafSurface;
-       int                     numBSPLeafSurfaces;
-       
-       int                     firstBSPLeafBrush;
-       int                     numBSPLeafBrushes;
+       int cluster;                    /* -1 = opaque cluster (do I still store these?) */
+       int area;
+
+       int mins[ 3 ];                  /* for frustum culling */
+       int maxs[ 3 ];
+
+       int firstBSPLeafSurface;
+       int numBSPLeafSurfaces;
+
+       int firstBSPLeafBrush;
+       int numBSPLeafBrushes;
 }
 bspLeaf_t;
 
 
 typedef struct
 {
-       int                     planeNum;                       /* positive plane side faces out of the leaf */
-       int                     shaderNum;
-       int                     surfaceNum;                     /* RBSP */
+       int planeNum;                   /* positive plane side faces out of the leaf */
+       int shaderNum;
+       int surfaceNum;                 /* RBSP */
 }
 bspBrushSide_t;
 
 
 typedef struct
 {
-       int                     firstSide;
-       int                     numSides;
-       int                     shaderNum;                      /* the shader that determines the content flags */
+       int firstSide;
+       int numSides;
+       int shaderNum;                  /* the shader that determines the content flags */
 }
 bspBrush_t;
 
 
 typedef struct
 {
-       char            shader[ MAX_QPATH ];
-       int                     brushNum;
-       int                     visibleSide;            /* the brush side that ray tests need to clip against (-1 == none) */
+       char shader[ MAX_QPATH ];
+       int brushNum;
+       int visibleSide;                /* the brush side that ray tests need to clip against (-1 == none) */
 }
 bspFog_t;
 
 
 typedef struct
 {
-       vec3_t          xyz;
-       float           st[ 2 ];
-       float           lightmap[ MAX_LIGHTMAPS ][ 2 ]; /* RBSP */
-       vec3_t          normal;
-       byte            color[ MAX_LIGHTMAPS ][ 4 ];    /* RBSP */
+       vec3_t xyz;
+       float st[ 2 ];
+       float lightmap[ MAX_LIGHTMAPS ][ 2 ];       /* RBSP */
+       vec3_t normal;
+       byte color[ MAX_LIGHTMAPS ][ 4 ];           /* RBSP */
 }
 bspDrawVert_t;
 
@@ -474,47 +474,47 @@ bspSurfaceType_t;
 
 typedef struct bspGridPoint_s
 {
-       byte            ambient[ MAX_LIGHTMAPS ][ 3 ];
-       byte            directed[ MAX_LIGHTMAPS ][ 3 ];
-       byte            styles[ MAX_LIGHTMAPS ];
-       byte            latLong[ 2 ];
+       byte ambient[ MAX_LIGHTMAPS ][ 3 ];
+       byte directed[ MAX_LIGHTMAPS ][ 3 ];
+       byte styles[ MAX_LIGHTMAPS ];
+       byte latLong[ 2 ];
 }
 bspGridPoint_t;
 
 
 typedef struct
 {
-       int                     shaderNum;
-       int                     fogNum;
-       int                     surfaceType;
-       
-       int                     firstVert;
-       int                     numVerts;
-       
-       int                     firstIndex;
-       int                     numIndexes;
-       
-       byte            lightmapStyles[ MAX_LIGHTMAPS ];                                                /* RBSP */
-       byte            vertexStyles[ MAX_LIGHTMAPS ];                                                  /* RBSP */
-       int                     lightmapNum[ MAX_LIGHTMAPS ];                                                   /* RBSP */
-       int                     lightmapX[ MAX_LIGHTMAPS ], lightmapY[ MAX_LIGHTMAPS ]; /* RBSP */
-       int                     lightmapWidth, lightmapHeight;
-       
-       vec3_t          lightmapOrigin;
-       vec3_t          lightmapVecs[ 3 ];      /* on patches, [ 0 ] and [ 1 ] are lodbounds */
-       
-       int                     patchWidth;
-       int                     patchHeight;
+       int shaderNum;
+       int fogNum;
+       int surfaceType;
+
+       int firstVert;
+       int numVerts;
+
+       int firstIndex;
+       int numIndexes;
+
+       byte lightmapStyles[ MAX_LIGHTMAPS ];                               /* RBSP */
+       byte vertexStyles[ MAX_LIGHTMAPS ];                                 /* RBSP */
+       int lightmapNum[ MAX_LIGHTMAPS ];                                   /* RBSP */
+       int lightmapX[ MAX_LIGHTMAPS ], lightmapY[ MAX_LIGHTMAPS ];         /* RBSP */
+       int lightmapWidth, lightmapHeight;
+
+       vec3_t lightmapOrigin;
+       vec3_t lightmapVecs[ 3 ];       /* on patches, [ 0 ] and [ 1 ] are lodbounds */
+
+       int patchWidth;
+       int patchHeight;
 }
 bspDrawSurface_t;
 
 
 /* advertisements */
 typedef struct {
-       int                     cellId;
-       vec3_t          normal;
-       vec3_t          rect[4];
-       char            model[ MAX_QPATH ];
+       int cellId;
+       vec3_t normal;
+       vec3_t rect[4];
+       char model[ MAX_QPATH ];
 } bspAdvertisement_t;
 
 
@@ -525,20 +525,20 @@ typedef struct {
    ------------------------------------------------------------------------------- */
 
 /* ydnar: for smaller structs */
-typedef unsigned char  qb_t;
+typedef unsigned char qb_t;
 
 
 /* ydnar: for q3map_tcMod */
-typedef float  tcMod_t[ 3 ][ 3 ];
+typedef float tcMod_t[ 3 ][ 3 ];
 
 
 /* ydnar: for multiple game support */
 typedef struct surfaceParm_s
 {
-       char            *name;
-       int                     contentFlags, contentFlagsClear;
-       int                     surfaceFlags, surfaceFlagsClear;
-       int                     compileFlags, compileFlagsClear;
+       char        *name;
+       int contentFlags, contentFlagsClear;
+       int surfaceFlags, surfaceFlagsClear;
+       int compileFlags, compileFlagsClear;
 }
 surfaceParm_t;
 
@@ -552,110 +552,110 @@ miniMapMode_t;
 
 typedef struct game_s
 {
-       char                            *arg;                                                   /* -game matches this */
-       char                            *gamePath;                                              /* main game data dir */
-       char                            *homeBasePath;                                  /* home sub-dir on unix */
-       char                            *magic;                                                 /* magic word for figuring out base path */
-       char                            *shaderPath;                                    /* shader directory */
-       int                                     maxLMSurfaceVerts;                              /* default maximum meta surface verts */
-       int                                     maxSurfaceVerts;                                /* default maximum surface verts */
-       int                                     maxSurfaceIndexes;                              /* default maximum surface indexes (tris * 3) */
-       qboolean                        emitFlares;                                             /* when true, emit flare surfaces */
-       char                            *flareShader;                                   /* default flare shader (MUST BE SET) */
-       qboolean                        wolfLight;                                              /* when true, lights work like wolf q3map  */
-       int                                     lightmapSize;                                   /* bsp lightmap width/height */
-       float                           lightmapGamma;                                  /* default lightmap gamma */
+       char                *arg;                           /* -game matches this */
+       char                *gamePath;                      /* main game data dir */
+       char                *homeBasePath;                  /* home sub-dir on unix */
+       char                *magic;                         /* magic word for figuring out base path */
+       char                *shaderPath;                    /* shader directory */
+       int maxLMSurfaceVerts;                              /* default maximum meta surface verts */
+       int maxSurfaceVerts;                                /* default maximum surface verts */
+       int maxSurfaceIndexes;                              /* default maximum surface indexes (tris * 3) */
+       qboolean emitFlares;                                /* when true, emit flare surfaces */
+       char                *flareShader;                   /* default flare shader (MUST BE SET) */
+       qboolean wolfLight;                                 /* when true, lights work like wolf q3map  */
+       int lightmapSize;                                   /* bsp lightmap width/height */
+       float lightmapGamma;                                /* default lightmap gamma */
        qboolean lightmapsRGB;                              /* default lightmap sRGB mode */
        qboolean texturesRGB;                               /* default texture sRGB mode */
        qboolean colorsRGB;                             /* default color sRGB mode */
-       float                           lightmapExposure;                               /* default lightmap exposure */
-       float                           lightmapCompensate;                             /* default lightmap compensate value */
-       float                           gridScale;                                              /* vortex: default lightgrid scale (affects both directional and ambient spectres) */
-       float                           gridAmbientScale;                               /* vortex: default lightgrid ambient spectre scale */
-       qboolean                        lightAngleHL;                                   /* jal: use half-lambert curve for light angle attenuation */
-       qboolean                        noStyles;                                               /* use lightstyles hack or not */
-       qboolean                        keepLights;                                             /* keep light entities on bsp */
-       int                                     patchSubdivisions;                              /* default patch subdivisions tolerance */
-       qboolean                        patchShadows;                                   /* patch casting enabled */
-       qboolean                        deluxeMap;                                              /* compile deluxemaps */
-       int                                     deluxeMode;                                             /* deluxemap mode (0 - modelspace, 1 - tangentspace with renormalization, 2 - tangentspace without renormalization) */
-       int                 miniMapSize;                    /* minimap size */
-       float               miniMapSharpen;                 /* minimap sharpening coefficient */
-       float               miniMapBorder;                  /* minimap border amount */
-       qboolean            miniMapKeepAspect;              /* minimap keep aspect ratio by letterboxing */
-       miniMapMode_t       miniMapMode;                    /* minimap mode */
+       float lightmapExposure;                             /* default lightmap exposure */
+       float lightmapCompensate;                           /* default lightmap compensate value */
+       float gridScale;                                    /* vortex: default lightgrid scale (affects both directional and ambient spectres) */
+       float gridAmbientScale;                             /* vortex: default lightgrid ambient spectre scale */
+       qboolean lightAngleHL;                              /* jal: use half-lambert curve for light angle attenuation */
+       qboolean noStyles;                                  /* use lightstyles hack or not */
+       qboolean keepLights;                                /* keep light entities on bsp */
+       int patchSubdivisions;                              /* default patch subdivisions tolerance */
+       qboolean patchShadows;                              /* patch casting enabled */
+       qboolean deluxeMap;                                 /* compile deluxemaps */
+       int deluxeMode;                                     /* deluxemap mode (0 - modelspace, 1 - tangentspace with renormalization, 2 - tangentspace without renormalization) */
+       int miniMapSize;                                    /* minimap size */
+       float miniMapSharpen;                               /* minimap sharpening coefficient */
+       float miniMapBorder;                                /* minimap border amount */
+       qboolean miniMapKeepAspect;                         /* minimap keep aspect ratio by letterboxing */
+       miniMapMode_t miniMapMode;                          /* minimap mode */
        char                *miniMapNameFormat;             /* minimap name format */
-       char                            *bspIdent;                                              /* 4-letter bsp file prefix */
-       int                                     bspVersion;                                             /* bsp version to use */
-       qboolean                        lumpSwap;                                               /* cod-style len/ofs order */
-       bspFunc                         load, write;                                    /* load/write function pointers */
-       surfaceParm_t           surfaceParms[ 128 ];                    /* surfaceparm array */
+       char                *bspIdent;                      /* 4-letter bsp file prefix */
+       int bspVersion;                                     /* bsp version to use */
+       qboolean lumpSwap;                                  /* cod-style len/ofs order */
+       bspFunc load, write;                                /* load/write function pointers */
+       surfaceParm_t surfaceParms[ 128 ];                  /* surfaceparm array */
 }
 game_t;
 
 
 typedef struct image_s
 {
-       char                            *name, *filename;
-       int                                     refCount;
-       int                                     width, height;
-       byte                            *pixels;
+       char                *name, *filename;
+       int refCount;
+       int width, height;
+       byte                *pixels;
 }
 image_t;
 
 
 typedef struct sun_s
 {
-       struct sun_s            *next;
-       vec3_t                          direction, color;
-       float                           photons, deviance, filterRadius;
-       int                                     numSamples, style;
+       struct sun_s        *next;
+       vec3_t direction, color;
+       float photons, deviance, filterRadius;
+       int numSamples, style;
 }
 sun_t;
 
 
-typedef struct surfaceModel_s 
+typedef struct surfaceModel_s
 {
-       struct surfaceModel_s   *next;
-       char                            model[ MAX_QPATH ];
-       float                           density, odds;
-       float                           minScale, maxScale;
-       float                           minAngle, maxAngle;
-       qboolean                        oriented;
+       struct surfaceModel_s   *next;
+       char model[ MAX_QPATH ];
+       float density, odds;
+       float minScale, maxScale;
+       float minAngle, maxAngle;
+       qboolean oriented;
 }
 surfaceModel_t;
 
 
 /* ydnar/sd: foliage stuff for wolf et (engine-supported optimization of the above) */
-typedef struct foliage_s 
+typedef struct foliage_s
 {
-       struct foliage_s        *next;
-       char                            model[ MAX_QPATH ];
-       float                           scale, density, odds;
-       qboolean                        inverseAlpha;
+       struct foliage_s    *next;
+       char model[ MAX_QPATH ];
+       float scale, density, odds;
+       qboolean inverseAlpha;
 }
 foliage_t;
 
 typedef struct foliageInstance_s
 {
-       vec3_t                          xyz, normal;
+       vec3_t xyz, normal;
 }
 foliageInstance_t;
 
 
 typedef struct remap_s
 {
-       struct remap_s          *next;
-       char                            from[ 1024 ];
-       char                            to[ MAX_QPATH ];
+       struct remap_s      *next;
+       char from[ 1024 ];
+       char to[ MAX_QPATH ];
 }
 remap_t;
 
 typedef struct skinfile_s
 {
-       struct skinfile_s       *next;
-       char                            name[ 1024 ];
-       char                            to[ MAX_QPATH ];
+       struct skinfile_s   *next;
+       char name[ 1024 ];
+       char to[ MAX_QPATH ];
 }
 skinfile_t;
 
@@ -685,9 +685,9 @@ colorModType_t;
 
 typedef struct colorMod_s
 {
-       struct colorMod_s       *next;
-       colorModType_t          type;
-       vec_t                           data[ 16 ];
+       struct colorMod_s   *next;
+       colorModType_t type;
+       vec_t data[ 16 ];
 }
 colorMod_t;
 
@@ -704,115 +704,115 @@ implicitMap_t;
 
 typedef struct shaderInfo_s
 {
-       char                            shader[ MAX_QPATH ];
-       int                                     surfaceFlags;
-       int                                     contentFlags;
-       int                                     compileFlags;
-       float                           value;                                                  /* light value */
-       
-       char                            *flareShader;                                   /* for light flares */
-       char                            *damageShader;                                  /* ydnar: sof2 damage shader name */
-       char                            *backShader;                                    /* for surfaces that generate different front and back passes */
-       char                            *cloneShader;                                   /* ydnar: for cloning of a surface */
-       char                            *remapShader;                                   /* ydnar: remap a shader in final stage */
-       char                            *deprecateShader;                               /* vortex: shader is deprecated and replaced by this on use */
-
-       surfaceModel_t          *surfaceModel;                                  /* ydnar: for distribution of models */
-       foliage_t                       *foliage;                                               /* ydnar/splash damage: wolf et foliage */
-       
-       float                           subdivisions;                                   /* from a "tesssize xxx" */
-       float                           backsplashFraction;                             /* floating point value, usually 0.05 */
-       float                           backsplashDistance;                             /* default 16 */
-       float                           lightSubdivide;                                 /* default 999 */
-       float                           lightFilterRadius;                              /* ydnar: lightmap filtering/blurring radius for lights created by this shader (default: 0) */
-       
-       int                                     lightmapSampleSize;                             /* lightmap sample size */
-       float                           lightmapSampleOffset;                   /* ydnar: lightmap sample offset (default: 1.0) */
-       
-       float                           bounceScale;                                    /* ydnar: radiosity re-emission [0,1.0+] */
-       float                           offset;                                                 /* ydnar: offset in units */
-       float                           shadeAngleDegrees;                              /* ydnar: breaking angle for smooth shading (degrees) */
-       
-       vec3_t                          mins, maxs;                                             /* ydnar: for particle studio vertexDeform move support */
-       
-       qb_t                            legacyTerrain;                                  /* ydnar: enable legacy terrain crutches */
-       qb_t                            indexed;                                                /* ydnar: attempt to use indexmap (terrain alphamap style) */
-       qb_t                            forceMeta;                                              /* ydnar: force metasurface path */
-       qb_t                            noClip;                                                 /* ydnar: don't clip into bsp, preserve original face winding */
-       qb_t                            noFast;                                                 /* ydnar: supress fast lighting for surfaces with this shader */
-       qb_t                            invert;                                                 /* ydnar: reverse facing */
-       qb_t                            nonplanar;                                              /* ydnar: for nonplanar meta surface merging */
-       qb_t                            tcGen;                                                  /* ydnar: has explicit texcoord generation */
-       vec3_t                          vecs[ 2 ];                                              /* ydnar: explicit texture vectors for [0,1] texture space */
-       tcMod_t                         mod;                                                    /* ydnar: q3map_tcMod matrix for djbob :) */
-       vec3_t                          lightmapAxis;                                   /* ydnar: explicit lightmap axis projection */
-       colorMod_t                      *colorMod;                                              /* ydnar: q3map_rgb/color/alpha/Set/Mod support */
-       
-       int                                     furNumLayers;                                   /* ydnar: number of fur layers */
-       float                           furOffset;                                              /* ydnar: offset of each layer */
-       float                           furFade;                                                /* ydnar: alpha fade amount per layer */
-
-       qb_t                            splotchFix;                                             /* ydnar: filter splotches on lightmaps */
-       
-       qb_t                            hasPasses;                                              /* false if the shader doesn't define any rendering passes */
-       qb_t                            globalTexture;                                  /* don't normalize texture repeats */
-       qb_t                            twoSided;                                               /* cull none */
-       qb_t                            autosprite;                                             /* autosprite shaders will become point lights instead of area lights */
-       qb_t                            polygonOffset;                                  /* ydnar: don't face cull this or against this */
-       qb_t                            patchShadows;                                   /* have patches casting shadows when using -light for this surface */
-       qb_t                            vertexShadows;                                  /* shadows will be casted at this surface even when vertex lit */
-       qb_t                            forceSunlight;                                  /* force sun light at this surface even tho we might not calculate shadows in vertex lighting */
-       qb_t                            notjunc;                                                /* don't use this surface for tjunction fixing */
-       qb_t                            fogParms;                                               /* ydnar: has fogparms */
-       qb_t                            noFog;                                                  /* ydnar: supress fogging */
-       qb_t                            clipModel;                                              /* ydnar: solid model hack */
-       qb_t                            noVertexLight;                                  /* ydnar: leave vertex color alone */
-       qb_t                            noDirty;                                                /* jal: do not apply the dirty pass to this surface */
-
-       byte                            styleMarker;                                    /* ydnar: light styles hack */
-       
-       float                           vertexScale;                                    /* vertex light scale */
-       
-       char                            skyParmsImageBase[ MAX_QPATH ]; /* ydnar: for skies */
-       
-       char                            editorImagePath[ MAX_QPATH ];   /* use this image to generate texture coordinates */
-       char                            lightImagePath[ MAX_QPATH ];    /* use this image to generate color / averageColor */
-       char                            normalImagePath[ MAX_QPATH ];   /* ydnar: normalmap image for bumpmapping */
-       
-       implicitMap_t           implicitMap;                                    /* ydnar: enemy territory implicit shaders */
-       char                            implicitImagePath[ MAX_QPATH ];
-       
-       image_t                         *shaderImage;
-       image_t                         *lightImage;
-       image_t                         *normalImage;
-       
-       float                           skyLightValue;                                  /* ydnar */
-       int                                     skyLightIterations;                             /* ydnar */
-       sun_t                           *sun;                                                   /* ydnar */
-       
-       vec3_t                          color;                                                  /* normalized color */
-       vec3_t                          averageColor;
-       byte                            lightStyle;                                     
+       char shader[ MAX_QPATH ];
+       int surfaceFlags;
+       int contentFlags;
+       int compileFlags;
+       float value;                                        /* light value */
+
+       char                *flareShader;                   /* for light flares */
+       char                *damageShader;                  /* ydnar: sof2 damage shader name */
+       char                *backShader;                    /* for surfaces that generate different front and back passes */
+       char                *cloneShader;                   /* ydnar: for cloning of a surface */
+       char                *remapShader;                   /* ydnar: remap a shader in final stage */
+       char                *deprecateShader;               /* vortex: shader is deprecated and replaced by this on use */
+
+       surfaceModel_t      *surfaceModel;                  /* ydnar: for distribution of models */
+       foliage_t           *foliage;                       /* ydnar/splash damage: wolf et foliage */
+
+       float subdivisions;                                 /* from a "tesssize xxx" */
+       float backsplashFraction;                           /* floating point value, usually 0.05 */
+       float backsplashDistance;                           /* default 16 */
+       float lightSubdivide;                               /* default 999 */
+       float lightFilterRadius;                            /* ydnar: lightmap filtering/blurring radius for lights created by this shader (default: 0) */
+
+       int lightmapSampleSize;                             /* lightmap sample size */
+       float lightmapSampleOffset;                         /* ydnar: lightmap sample offset (default: 1.0) */
+
+       float bounceScale;                                  /* ydnar: radiosity re-emission [0,1.0+] */
+       float offset;                                       /* ydnar: offset in units */
+       float shadeAngleDegrees;                            /* ydnar: breaking angle for smooth shading (degrees) */
+
+       vec3_t mins, maxs;                                  /* ydnar: for particle studio vertexDeform move support */
+
+       qb_t legacyTerrain;                                 /* ydnar: enable legacy terrain crutches */
+       qb_t indexed;                                       /* ydnar: attempt to use indexmap (terrain alphamap style) */
+       qb_t forceMeta;                                     /* ydnar: force metasurface path */
+       qb_t noClip;                                        /* ydnar: don't clip into bsp, preserve original face winding */
+       qb_t noFast;                                        /* ydnar: supress fast lighting for surfaces with this shader */
+       qb_t invert;                                        /* ydnar: reverse facing */
+       qb_t nonplanar;                                     /* ydnar: for nonplanar meta surface merging */
+       qb_t tcGen;                                         /* ydnar: has explicit texcoord generation */
+       vec3_t vecs[ 2 ];                                   /* ydnar: explicit texture vectors for [0,1] texture space */
+       tcMod_t mod;                                        /* ydnar: q3map_tcMod matrix for djbob :) */
+       vec3_t lightmapAxis;                                /* ydnar: explicit lightmap axis projection */
+       colorMod_t          *colorMod;                      /* ydnar: q3map_rgb/color/alpha/Set/Mod support */
+
+       int furNumLayers;                                   /* ydnar: number of fur layers */
+       float furOffset;                                    /* ydnar: offset of each layer */
+       float furFade;                                      /* ydnar: alpha fade amount per layer */
+
+       qb_t splotchFix;                                    /* ydnar: filter splotches on lightmaps */
+
+       qb_t hasPasses;                                     /* false if the shader doesn't define any rendering passes */
+       qb_t globalTexture;                                 /* don't normalize texture repeats */
+       qb_t twoSided;                                      /* cull none */
+       qb_t autosprite;                                    /* autosprite shaders will become point lights instead of area lights */
+       qb_t polygonOffset;                                 /* ydnar: don't face cull this or against this */
+       qb_t patchShadows;                                  /* have patches casting shadows when using -light for this surface */
+       qb_t vertexShadows;                                 /* shadows will be casted at this surface even when vertex lit */
+       qb_t forceSunlight;                                 /* force sun light at this surface even tho we might not calculate shadows in vertex lighting */
+       qb_t notjunc;                                       /* don't use this surface for tjunction fixing */
+       qb_t fogParms;                                      /* ydnar: has fogparms */
+       qb_t noFog;                                         /* ydnar: supress fogging */
+       qb_t clipModel;                                     /* ydnar: solid model hack */
+       qb_t noVertexLight;                                 /* ydnar: leave vertex color alone */
+       qb_t noDirty;                                       /* jal: do not apply the dirty pass to this surface */
+
+       byte styleMarker;                                   /* ydnar: light styles hack */
+
+       float vertexScale;                                  /* vertex light scale */
+
+       char skyParmsImageBase[ MAX_QPATH ];                /* ydnar: for skies */
+
+       char editorImagePath[ MAX_QPATH ];                  /* use this image to generate texture coordinates */
+       char lightImagePath[ MAX_QPATH ];                   /* use this image to generate color / averageColor */
+       char normalImagePath[ MAX_QPATH ];                  /* ydnar: normalmap image for bumpmapping */
+
+       implicitMap_t implicitMap;                          /* ydnar: enemy territory implicit shaders */
+       char implicitImagePath[ MAX_QPATH ];
+
+       image_t             *shaderImage;
+       image_t             *lightImage;
+       image_t             *normalImage;
+
+       float skyLightValue;                                /* ydnar */
+       int skyLightIterations;                             /* ydnar */
+       sun_t               *sun;                           /* ydnar */
+
+       vec3_t color;                                       /* normalized color */
+       vec3_t averageColor;
+       byte lightStyle;
 
        /* vortex: per-surface floodlight */
-       float                           floodlightDirectionScale;
-       vec3_t                          floodlightRGB; 
-       float                           floodlightIntensity;
-       float                           floodlightDistance;
-       
-       qb_t                            lmMergable;                                             /* ydnar */
-       int                                     lmCustomWidth, lmCustomHeight;  /* ydnar */
-       float                           lmBrightness;                                   /* ydnar */
-       float                           lmFilterRadius;                                 /* ydnar: lightmap filtering/blurring radius for this shader (default: 0) */
-       
-       int                                     shaderWidth, shaderHeight;              /* ydnar */
-       float                           stFlat[ 2 ];
-       
-       vec3_t                          fogDir;                                                 /* ydnar */
-       
-       char                            *shaderText;                                    /* ydnar */
-       qb_t                            custom;
-       qb_t                            finished;
+       float floodlightDirectionScale;
+       vec3_t floodlightRGB;
+       float floodlightIntensity;
+       float floodlightDistance;
+
+       qb_t lmMergable;                                    /* ydnar */
+       int lmCustomWidth, lmCustomHeight;                  /* ydnar */
+       float lmBrightness;                                 /* ydnar */
+       float lmFilterRadius;                               /* ydnar: lightmap filtering/blurring radius for this shader (default: 0) */
+
+       int shaderWidth, shaderHeight;                      /* ydnar */
+       float stFlat[ 2 ];
+
+       vec3_t fogDir;                                      /* ydnar */
+
+       char                *shaderText;                    /* ydnar */
+       qb_t custom;
+       qb_t finished;
 }
 shaderInfo_t;
 
@@ -826,57 +826,57 @@ shaderInfo_t;
 
 typedef struct face_s
 {
-       struct face_s           *next;
-       int                                     planenum;
-       int                                     priority;
+       struct face_s       *next;
+       int planenum;
+       int priority;
        //qboolean                      checked;
-       int                                     compileFlags;
-       winding_t                       *w;
+       int compileFlags;
+       winding_t           *w;
 }
 face_t;
 
 
 typedef struct plane_s
 {
-       vec3_t                          normal;
-       vec_t                           dist;
-       int                                     type;
-       int                 counter;
-       int                                     hash_chain;
+       vec3_t normal;
+       vec_t dist;
+       int type;
+       int counter;
+       int hash_chain;
 }
 plane_t;
 
 
 typedef struct side_s
 {
-       int                                     planenum;
-       
-       int                                     outputNum;                      /* set when the side is written to the file list */
-       
-       float                           texMat[ 2 ][ 3 ];       /* brush primitive texture matrix */
-       float                           vecs[ 2 ][ 4 ];         /* old-style texture coordinate mapping */
-
-       winding_t                       *winding;
-       winding_t                       *visibleHull;           /* convex hull of all visible fragments */
-
-       shaderInfo_t            *shaderInfo;
-
-       int                                     contentFlags;           /* from shaderInfo */
-       int                                     surfaceFlags;           /* from shaderInfo */
-       int                                     compileFlags;           /* from shaderInfo */
-       int                                     value;                          /* from shaderInfo */
-
-       qboolean                        visible;                        /* choose visble planes first */
-       qboolean                        bevel;                          /* don't ever use for bsp splitting, and don't bother making windings for it */
-       qboolean                        culled;                         /* ydnar: face culling */
+       int planenum;
+
+       int outputNum;                          /* set when the side is written to the file list */
+
+       float texMat[ 2 ][ 3 ];                 /* brush primitive texture matrix */
+       float vecs[ 2 ][ 4 ];                   /* old-style texture coordinate mapping */
+
+       winding_t           *winding;
+       winding_t           *visibleHull;       /* convex hull of all visible fragments */
+
+       shaderInfo_t        *shaderInfo;
+
+       int contentFlags;                       /* from shaderInfo */
+       int surfaceFlags;                       /* from shaderInfo */
+       int compileFlags;                       /* from shaderInfo */
+       int value;                              /* from shaderInfo */
+
+       qboolean visible;                       /* choose visble planes first */
+       qboolean bevel;                         /* don't ever use for bsp splitting, and don't bother making windings for it */
+       qboolean culled;                        /* ydnar: face culling */
 }
 side_t;
 
 
 typedef struct sideRef_s
 {
-       struct sideRef_s        *next;
-       side_t                          *side;
+       struct sideRef_s    *next;
+       side_t              *side;
 }
 sideRef_t;
 
@@ -884,105 +884,105 @@ sideRef_t;
 /* ydnar: generic index mapping for entities (natural extension of terrain texturing) */
 typedef struct indexMap_s
 {
-       int                                     w, h, numLayers;
-       char                            name[ MAX_QPATH ], shader[ MAX_QPATH ];
-       float                           offsets[ 256 ];
-       byte                            *pixels;
+       int w, h, numLayers;
+       char name[ MAX_QPATH ], shader[ MAX_QPATH ];
+       float offsets[ 256 ];
+       byte                *pixels;
 }
 indexMap_t;
 
 
 typedef struct brush_s
 {
-       struct brush_s          *next;
-       struct brush_s          *nextColorModBrush;     /* ydnar: colorMod volume brushes go here */
-       struct brush_s          *original;                      /* chopped up brushes will reference the originals */
-       
+       struct brush_s      *next;
+       struct brush_s      *nextColorModBrush; /* ydnar: colorMod volume brushes go here */
+       struct brush_s      *original;          /* chopped up brushes will reference the originals */
+
        int entityNum, brushNum;                /* editor numbering */
-       int                                     outputNum;                      /* set when the brush is written to the file list */
-       
+       int outputNum;                          /* set when the brush is written to the file list */
+
        /* ydnar: for shadowcasting entities */
-       int                                     castShadows;
-       int                                     recvShadows;
-       
-       shaderInfo_t            *contentShader;
-       shaderInfo_t            *celShader;                     /* :) */
-       
+       int castShadows;
+       int recvShadows;
+
+       shaderInfo_t        *contentShader;
+       shaderInfo_t        *celShader;         /* :) */
+
        /* ydnar: gs mods */
-       int                                     lightmapSampleSize; /* jal : entity based _lightmapsamplesize */
-       float                           lightmapScale;
+       int lightmapSampleSize;                 /* jal : entity based _lightmapsamplesize */
+       float lightmapScale;
        vec3_t                          colormod;
-       float                           shadeAngleDegrees; /* jal : entity based _shadeangle */
-       vec3_t                          eMins, eMaxs;
-       indexMap_t                      *im;
+       float shadeAngleDegrees;               /* jal : entity based _shadeangle */
+       vec3_t eMins, eMaxs;
+       indexMap_t          *im;
 
-       int                                     contentFlags;
-       int                                     compileFlags;           /* ydnar */
-       qboolean                        detail;
-       qboolean                        opaque;
+       int contentFlags;
+       int compileFlags;                       /* ydnar */
+       qboolean detail;
+       qboolean opaque;
 
-       int                                     portalareas[ 2 ];
+       int portalareas[ 2 ];
 
-       vec3_t                          mins, maxs;
-       int                                     numsides;
+       vec3_t mins, maxs;
+       int numsides;
 
-       side_t                          sides[ 6 ];                     /* variably sized */
+       side_t sides[ 6 ];                      /* variably sized */
 }
 brush_t;
 
 
 typedef struct fog_s
 {
-       shaderInfo_t            *si;
-       brush_t                         *brush;
-       int                                     visibleSide;            /* the brush side that ray tests need to clip against (-1 == none) */
+       shaderInfo_t        *si;
+       brush_t             *brush;
+       int visibleSide;                        /* the brush side that ray tests need to clip against (-1 == none) */
 }
 fog_t;
 
 
 typedef struct
 {
-       int                                     width, height;
-       bspDrawVert_t           *verts;
+       int width, height;
+       bspDrawVert_t       *verts;
 }
 mesh_t;
 
 
 typedef struct parseMesh_s
 {
-       struct parseMesh_s      *next;
-       
-       int                                     entityNum, brushNum;    /* ydnar: editor numbering */
-       
+       struct parseMesh_s  *next;
+
+       int entityNum, brushNum;                    /* ydnar: editor numbering */
+
        /* ydnar: for shadowcasting entities */
-       int                                     castShadows;
-       int                                     recvShadows;
-       
-       mesh_t                          mesh;
-       shaderInfo_t            *shaderInfo;
-       shaderInfo_t            *celShader;                             /* :) */
-       
+       int castShadows;
+       int recvShadows;
+
+       mesh_t mesh;
+       shaderInfo_t        *shaderInfo;
+       shaderInfo_t        *celShader;             /* :) */
+
        /* ydnar: gs mods */
-       int                                     lightmapSampleSize;             /* jal : entity based _lightmapsamplesize */
-       float                           lightmapScale;
+       int lightmapSampleSize;                     /* jal : entity based _lightmapsamplesize */
+       float lightmapScale;
        vec3_t                          colormod;
-       vec3_t                          eMins, eMaxs;
-       indexMap_t                      *im;
-       
+       vec3_t eMins, eMaxs;
+       indexMap_t          *im;
+
        /* grouping */
-       qboolean                        grouped;
-       float                           longestCurve;
-       int                                     maxIterations;
+       qboolean grouped;
+       float longestCurve;
+       int maxIterations;
 }
 parseMesh_t;
 
 
 /*
-       ydnar: the drawsurf struct was extended to allow for:
-       - non-convex planar surfaces
-       - non-planar brushface surfaces
-       - lightmapped terrain
-       - planar patches
+    ydnar: the drawsurf struct was extended to allow for:
+    - non-convex planar surfaces
+    - non-planar brushface surfaces
+    - lightmapped terrain
+    - planar patches
  */
 
 typedef enum
@@ -993,114 +993,114 @@ typedef enum
        SURFACE_PATCH,
        SURFACE_TRIANGLES,
        SURFACE_FLARE,
-       SURFACE_FOLIAGE,        /* wolf et */
-       
+       SURFACE_FOLIAGE,    /* wolf et */
+
        /* ydnar: compiler-relevant surface types */
        SURFACE_FORCED_META,
        SURFACE_META,
        SURFACE_FOGHULL,
        SURFACE_DECAL,
        SURFACE_SHADER,
-       
+
        NUM_SURFACE_TYPES
 }
 surfaceType_t;
 
-char                   *surfaceTypes[ NUM_SURFACE_TYPES ]
+char            *surfaceTypes[ NUM_SURFACE_TYPES ]
 #ifndef MAIN_C
 ;
 #else
-                               =
-                               {
-                                       "SURFACE_BAD",
-                                       "SURFACE_FACE",
-                                       "SURFACE_PATCH",
-                                       "SURFACE_TRIANGLES",
-                                       "SURFACE_FLARE",
-                                       "SURFACE_FOLIAGE",
-                                       "SURFACE_FORCED_META",
-                                       "SURFACE_META",
-                                       "SURFACE_FOGHULL",
-                                       "SURFACE_DECAL",
-                                       "SURFACE_SHADER"
-                               };
+       =
+       {
+       "SURFACE_BAD",
+       "SURFACE_FACE",
+       "SURFACE_PATCH",
+       "SURFACE_TRIANGLES",
+       "SURFACE_FLARE",
+       "SURFACE_FOLIAGE",
+       "SURFACE_FORCED_META",
+       "SURFACE_META",
+       "SURFACE_FOGHULL",
+       "SURFACE_DECAL",
+       "SURFACE_SHADER"
+       };
 #endif
 
 
 /* ydnar: this struct needs an overhaul (again, heh) */
 typedef struct mapDrawSurface_s
 {
-       surfaceType_t           type;
-       qboolean                        planar;
-       int                                     outputNum;                      /* ydnar: to match this sort of thing up */
-       
-       qboolean                        fur;                            /* ydnar: this is kind of a hack, but hey... */
-       qboolean                        skybox;                         /* ydnar: yet another fun hack */
-       qboolean                        backSide;                       /* ydnar: q3map_backShader support */
-       
-       struct mapDrawSurface_s *parent;                /* ydnar: for cloned (skybox) surfaces to share lighting data */
-       struct mapDrawSurface_s *clone;                 /* ydnar: for cloned surfaces */
-       struct mapDrawSurface_s *cel;                   /* ydnar: for cloned cel surfaces */
-       
-       shaderInfo_t            *shaderInfo;
-       shaderInfo_t            *celShader;
-       brush_t                         *mapBrush;
-       parseMesh_t                     *mapMesh;
-       sideRef_t                       *sideRef;
-       
-       int                                     fogNum;
-       
-       int                                     numVerts;                       /* vertexes and triangles */
-       bspDrawVert_t           *verts;
-       int                                     numIndexes;
-       int                                     *indexes;
-       
-       int                                     planeNum;
-       vec3_t                          lightmapOrigin;         /* also used for flares */
-       vec3_t                          lightmapVecs[ 3 ];      /* also used for flares */
-       int                                     lightStyle;                     /* used for flares */
-       
+       surfaceType_t type;
+       qboolean planar;
+       int outputNum;                          /* ydnar: to match this sort of thing up */
+
+       qboolean fur;                           /* ydnar: this is kind of a hack, but hey... */
+       qboolean skybox;                        /* ydnar: yet another fun hack */
+       qboolean backSide;                      /* ydnar: q3map_backShader support */
+
+       struct mapDrawSurface_s *parent;        /* ydnar: for cloned (skybox) surfaces to share lighting data */
+       struct mapDrawSurface_s *clone;         /* ydnar: for cloned surfaces */
+       struct mapDrawSurface_s *cel;           /* ydnar: for cloned cel surfaces */
+
+       shaderInfo_t        *shaderInfo;
+       shaderInfo_t        *celShader;
+       brush_t             *mapBrush;
+       parseMesh_t         *mapMesh;
+       sideRef_t           *sideRef;
+
+       int fogNum;
+
+       int numVerts;                           /* vertexes and triangles */
+       bspDrawVert_t       *verts;
+       int numIndexes;
+       int                 *indexes;
+
+       int planeNum;
+       vec3_t lightmapOrigin;                  /* also used for flares */
+       vec3_t lightmapVecs[ 3 ];               /* also used for flares */
+       int lightStyle;                         /* used for flares */
+
        /* ydnar: per-surface (per-entity, actually) lightmap sample size scaling */
-       float                           lightmapScale;
+       float lightmapScale;
 
        /* divVerent: per-surface (per-entity, actually) color modding */
        vec3_t                          colormod;
 
        /* jal: per-surface (per-entity, actually) shadeangle */
-       float                           shadeAngleDegrees;
-       
+       float shadeAngleDegrees;
+
        /* ydnar: surface classification */
-       vec3_t                          mins, maxs;
-       vec3_t                          lightmapAxis;
-       int                                     sampleSize;
-       
+       vec3_t mins, maxs;
+       vec3_t lightmapAxis;
+       int sampleSize;
+
        /* ydnar: shadow group support */
-       int                                     castShadows, recvShadows;
-       
+       int castShadows, recvShadows;
+
        /* ydnar: texture coordinate range monitoring for hardware with limited texcoord precision (in texel space) */
-       float                           bias[ 2 ];
-       int                                     texMins[ 2 ], texMaxs[ 2 ], texRange[ 2 ];
-               
+       float bias[ 2 ];
+       int texMins[ 2 ], texMaxs[ 2 ], texRange[ 2 ];
+
        /* ydnar: for patches */
-       float                           longestCurve;
-       int                                     maxIterations;
-       int                                     patchWidth, patchHeight;
-       vec3_t                          bounds[ 2 ];
+       float longestCurve;
+       int maxIterations;
+       int patchWidth, patchHeight;
+       vec3_t bounds[ 2 ];
 
        /* ydnar/sd: for foliage */
-       int                                     numFoliageInstances;
-       
+       int numFoliageInstances;
+
        /* ydnar: editor/useful numbering */
-       int                                     entityNum;
-       int                                     surfaceNum;
+       int entityNum;
+       int surfaceNum;
 }
 mapDrawSurface_t;
 
 
 typedef struct drawSurfRef_s
 {
-       struct drawSurfRef_s    *nextRef;
-       int                                     outputNum;
+       struct drawSurfRef_s    *nextRef;
+       int outputNum;
 }
 drawSurfRef_t;
 
@@ -1108,34 +1108,34 @@ drawSurfRef_t;
 /* ydnar: metasurfaces are constructed from lists of metatriangles so they can be merged in the best way */
 typedef struct metaTriangle_s
 {
-       shaderInfo_t            *si;
-       side_t                          *side;
-       int                                     entityNum, surfaceNum, planeNum, fogNum, sampleSize, castShadows, recvShadows;
-       float                           shadeAngleDegrees;
-       vec4_t                          plane;
-       vec3_t                          lightmapAxis;
-       int                                     indexes[ 3 ];
+       shaderInfo_t        *si;
+       side_t              *side;
+       int entityNum, surfaceNum, planeNum, fogNum, sampleSize, castShadows, recvShadows;
+       float shadeAngleDegrees;
+       vec4_t plane;
+       vec3_t lightmapAxis;
+       int indexes[ 3 ];
 }
 metaTriangle_t;
 
 
 typedef struct epair_s
 {
-       struct epair_s          *next;
-       char                            *key, *value;
+       struct epair_s      *next;
+       char                *key, *value;
 }
 epair_t;
 
 
 typedef struct
 {
-       vec3_t                          origin;
-       brush_t                         *brushes, *lastBrush, *colorModBrushes;
-       parseMesh_t                     *patches;
-       int                                     mapEntityNum, firstDrawSurf;
-       int                                     firstBrush, numBrushes;         /* only valid during BSP compile */
-       epair_t                         *epairs;
-       vec3_t                          originbrush_origin;
+       vec3_t origin;
+       brush_t             *brushes, *lastBrush, *colorModBrushes;
+       parseMesh_t         *patches;
+       int mapEntityNum, firstDrawSurf;
+       int firstBrush, numBrushes;                     /* only valid during BSP compile */
+       epair_t             *epairs;
+       vec3_t originbrush_origin;
 }
 entity_t;
 
@@ -1143,58 +1143,58 @@ entity_t;
 typedef struct node_s
 {
        /* both leafs and nodes */
-       int                                     planenum;               /* -1 = leaf node */
-       struct node_s           *parent;
-       vec3_t                          mins, maxs;             /* valid after portalization */
-       brush_t                         *volume;                /* one for each leaf/node */
+       int planenum;                       /* -1 = leaf node */
+       struct node_s       *parent;
+       vec3_t mins, maxs;                  /* valid after portalization */
+       brush_t             *volume;        /* one for each leaf/node */
 
        /* nodes only */
-       side_t                          *side;                  /* the side that created the node */
-       struct node_s           *children[ 2 ];
-       int                                     compileFlags;   /* ydnar: hint, antiportal */
-       int                                     tinyportals;
-       vec3_t                          referencepoint;
+       side_t              *side;          /* the side that created the node */
+       struct node_s       *children[ 2 ];
+       int compileFlags;                   /* ydnar: hint, antiportal */
+       int tinyportals;
+       vec3_t referencepoint;
 
        /* leafs only */
-       qboolean                        opaque;                 /* view can never be inside */
-       qboolean                        areaportal;
-       qboolean                        skybox;                 /* ydnar: a skybox leaf */
-       qboolean                        sky;                    /* ydnar: a sky leaf */
-       int                                     cluster;                /* for portalfile writing */
-       int                                     area;                   /* for areaportals */
-       brush_t                         *brushlist;             /* fragments of all brushes in this leaf */
-       drawSurfRef_t           *drawSurfReferences;
+       qboolean opaque;                    /* view can never be inside */
+       qboolean areaportal;
+       qboolean skybox;                    /* ydnar: a skybox leaf */
+       qboolean sky;                       /* ydnar: a sky leaf */
+       int cluster;                        /* for portalfile writing */
+       int area;                           /* for areaportals */
+       brush_t             *brushlist;     /* fragments of all brushes in this leaf */
+       drawSurfRef_t       *drawSurfReferences;
 
-       int                                     occupied;               /* 1 or greater can reach entity */
-       entity_t                        *occupant;              /* for leak file testing */
+       int occupied;                       /* 1 or greater can reach entity */
+       entity_t            *occupant;      /* for leak file testing */
 
-       struct portal_s         *portals;               /* also on nodes during construction */
+       struct portal_s     *portals;       /* also on nodes during construction */
 
-       qboolean            has_structural_children;
+       qboolean has_structural_children;
 }
 node_t;
 
 
 typedef struct portal_s
 {
-       plane_t                         plane;
-       node_t                          *onnode;                /* NULL = outside box */
-       node_t                          *nodes[ 2 ];    /* [ 0 ] = front side of plane */
-       struct portal_s         *next[ 2 ];
-       winding_t                       *winding;
-
-       qboolean                        sidefound;              /* false if ->side hasn't been checked */
-       int                                     compileFlags;   /* from original face that caused the split */
-       side_t                          *side;                  /* NULL = non-visible */
+       plane_t plane;
+       node_t              *onnode;        /* NULL = outside box */
+       node_t              *nodes[ 2 ];    /* [ 0 ] = front side of plane */
+       struct portal_s     *next[ 2 ];
+       winding_t           *winding;
+
+       qboolean sidefound;                 /* false if ->side hasn't been checked */
+       int compileFlags;                   /* from original face that caused the split */
+       side_t              *side;          /* NULL = non-visible */
 }
 portal_t;
 
 
 typedef struct
 {
-       node_t                          *headnode;
-       node_t                          outside_node;
-       vec3_t                          mins, maxs;
+       node_t              *headnode;
+       node_t outside_node;
+       vec3_t mins, maxs;
 }
 tree_t;
 
@@ -1208,24 +1208,24 @@ tree_t;
 
 typedef struct
 {
-       vec3_t                          normal;
-       float                           dist;
+       vec3_t normal;
+       float dist;
 }
 visPlane_t;
 
 
 typedef struct
 {
-       int                                     numpoints;
-       vec3_t                          points[ MAX_POINTS_ON_FIXED_WINDING     ];              /* variable sized */
-} 
+       int numpoints;
+       vec3_t points[ MAX_POINTS_ON_FIXED_WINDING ];                   /* variable sized */
+}
 fixedWinding_t;
 
 
 typedef struct passage_s
 {
-       struct passage_s        *next;
-       byte                            cansee[ 1 ];    /* all portals that can be seen through this passage */
+       struct passage_s    *next;
+       byte cansee[ 1 ];                   /* all portals that can be seen through this passage */
 } passage_t;
 
 
@@ -1240,54 +1240,54 @@ vstatus_t;
 
 typedef struct
 {
-       int                                     num;
-       qboolean                        hint;                   /* true if this portal was created from a hint splitter */
-       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 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;
 
 
 typedef struct leaf_s
 {
-       int                                     numportals;
-       int                                     merged;
-       vportal_t                       *portals[MAX_PORTALS_ON_LEAF];
+       int numportals;
+       int merged;
+       vportal_t           *portals[MAX_PORTALS_ON_LEAF];
 }
 leaf_t;
 
-       
+
 typedef struct pstack_s
 {
-       byte                            mightsee[ MAX_PORTALS / 8 ];
-       struct pstack_s         *next;
-       leaf_t                          *leaf;
-       vportal_t                       *portal;                /* portal exiting */
-       fixedWinding_t          *source;
-       fixedWinding_t          *pass;
+       byte mightsee[ MAX_PORTALS / 8 ];
+       struct pstack_s     *next;
+       leaf_t              *leaf;
+       vportal_t           *portal;        /* portal exiting */
+       fixedWinding_t      *source;
+       fixedWinding_t      *pass;
 
-       fixedWinding_t          windings[ 3 ];  /* source, pass, temp in any order */
-       int                                     freewindings[ 3 ];
+       fixedWinding_t windings[ 3 ];       /* source, pass, temp in any order */
+       int freewindings[ 3 ];
 
-       visPlane_t                      portalplane;
+       visPlane_t portalplane;
        int depth;
 #ifdef SEPERATORCACHE
-       visPlane_t                      seperators[ 2 ][ MAX_SEPERATORS ];
-       int                                     numseperators[ 2 ];
+       visPlane_t seperators[ 2 ][ MAX_SEPERATORS ];
+       int numseperators[ 2 ];
 #endif
 }
 pstack_t;
@@ -1295,9 +1295,9 @@ pstack_t;
 
 typedef struct
 {
-       vportal_t                       *base;
-       int                                     c_chains;
-       pstack_t                        pstack_head;
+       vportal_t           *base;
+       int c_chains;
+       pstack_t pstack_head;
 }
 threaddata_t;
 
@@ -1312,35 +1312,35 @@ threaddata_t;
 /* ydnar: new light struct with flags */
 typedef struct light_s
 {
-       struct light_s          *next;
-       
-       int                                     type;
-       int                                     flags;                  /* ydnar: condensed all the booleans into one flags int */
-       shaderInfo_t            *si;
-       
-       vec3_t                          origin;
-       vec3_t                          normal;                 /* for surfaces, spotlights, and suns */
-       float                           dist;                   /* plane location along normal */
-       
-       float                           photons;
-       int                                     style;
-       vec3_t                          color;
-       float                           radiusByDist;   /* for spotlights */
-       float                           fade;                   /* ydnar: from wolf, for linear lights */
-       float                           angleScale;             /* ydnar: stolen from vlight for K */
-       float                           extraDist;              /* "extra dimension" distance of the light, to kill hot spots */
-
-       float                           add;                    /* ydnar: used for area lights */
-       float                           envelope;               /* ydnar: units until falloff < tolerance */
-       float                           envelope2;              /* ydnar: envelope squared (tiny optimization) */
-       vec3_t                          mins, maxs;             /* ydnar: pvs envelope */
-       int                                     cluster;                /* ydnar: cluster light falls into */
-       
-       winding_t                       *w;
-       vec3_t                          emitColor;              /* full out-of-gamut value */
-       
-       float                           falloffTolerance;       /* ydnar: minimum attenuation threshold */
-       float                           filterRadius;   /* ydnar: lightmap filter radius in world units, 0 == default */
+       struct light_s      *next;
+
+       int type;
+       int flags;                          /* ydnar: condensed all the booleans into one flags int */
+       shaderInfo_t        *si;
+
+       vec3_t origin;
+       vec3_t normal;                      /* for surfaces, spotlights, and suns */
+       float dist;                         /* plane location along normal */
+
+       float photons;
+       int style;
+       vec3_t color;
+       float radiusByDist;                 /* for spotlights */
+       float fade;                         /* ydnar: from wolf, for linear lights */
+       float angleScale;                   /* ydnar: stolen from vlight for K */
+       float extraDist;                    /* "extra dimension" distance of the light, to kill hot spots */
+
+       float add;                          /* ydnar: used for area lights */
+       float envelope;                     /* ydnar: units until falloff < tolerance */
+       float envelope2;                    /* ydnar: envelope squared (tiny optimization) */
+       vec3_t mins, maxs;                  /* ydnar: pvs envelope */
+       int cluster;                        /* ydnar: cluster light falls into */
+
+       winding_t           *w;
+       vec3_t emitColor;                   /* full out-of-gamut value */
+
+       float falloffTolerance;                 /* ydnar: minimum attenuation threshold */
+       float filterRadius;                 /* ydnar: lightmap filter radius in world units, 0 == default */
 }
 light_t;
 
@@ -1348,45 +1348,45 @@ light_t;
 typedef struct
 {
        /* constant input */
-       qboolean                        testOcclusion, forceSunlight, testAll;
-       int                                     recvShadows;
-       
-       int                                     numSurfaces;
-       int                                     *surfaces;
-       
-       int                                     numLights;
-       light_t                         **lights;
-       
-       qboolean                        twoSided;
-       
+       qboolean testOcclusion, forceSunlight, testAll;
+       int recvShadows;
+
+       int numSurfaces;
+       int                 *surfaces;
+
+       int numLights;
+       light_t             **lights;
+
+       qboolean twoSided;
+
        /* per-sample input */
-       int                                     cluster;
-       vec3_t                          origin, normal;
-       vec_t                           inhibitRadius;  /* sphere in which occluding geometry is ignored */
-       
+       int cluster;
+       vec3_t origin, normal;
+       vec_t inhibitRadius;                /* sphere in which occluding geometry is ignored */
+
        /* per-light input */
-       light_t                         *light;
-       vec3_t                          end;
-       
+       light_t             *light;
+       vec3_t end;
+
        /* calculated input */
-       vec3_t                          displacement, direction;
-       vec_t                           distance;
-       
+       vec3_t displacement, direction;
+       vec_t distance;
+
        /* input and output */
-       vec3_t                          color;                  /* starts out at full color, may be reduced if transparent surfaces are crossed */
-       vec3_t                          colorNoShadow;  /* result color with no shadow casting */
-       vec3_t                          directionContribution; /* result contribution to the deluxe map */
+       vec3_t color;                       /* starts out at full color, may be reduced if transparent surfaces are crossed */
+       vec3_t colorNoShadow;               /* result color with no shadow casting */
+       vec3_t directionContribution;              /* result contribution to the deluxe map */
 
        /* output */
-       vec3_t                          hit;
-       int                                     compileFlags;   /* for determining surface compile flags traced through */
-       qboolean                        passSolid;
-       qboolean                        opaque;
-       vec_t                   forceSubsampling; /* needs subsampling (alphashadow), value = max color contribution possible from it */
-       
+       vec3_t hit;
+       int compileFlags;                   /* for determining surface compile flags traced through */
+       qboolean passSolid;
+       qboolean opaque;
+       vec_t forceSubsampling;           /* needs subsampling (alphashadow), value = max color contribution possible from it */
+
        /* working data */
-       int                                     numTestNodes;
-       int                                     testNodes[ MAX_TRACE_TEST_NODES ]; 
+       int numTestNodes;
+       int testNodes[ MAX_TRACE_TEST_NODES ];
 }
 trace_t;
 
@@ -1395,19 +1395,19 @@ trace_t;
 /* must be identical to bspDrawVert_t except for float color! */
 typedef struct
 {
-       vec3_t                          xyz;
-       float                           st[ 2 ];
-       float                           lightmap[ MAX_LIGHTMAPS ][ 2 ];
-       vec3_t                          normal;
-       float                           color[ MAX_LIGHTMAPS ][ 4 ];
+       vec3_t xyz;
+       float st[ 2 ];
+       float lightmap[ MAX_LIGHTMAPS ][ 2 ];
+       vec3_t normal;
+       float color[ MAX_LIGHTMAPS ][ 4 ];
 }
 radVert_t;
 
 
 typedef struct
 {
-       int                                     numVerts;
-       radVert_t                       verts[ MAX_POINTS_ON_WINDING ];
+       int numVerts;
+       radVert_t verts[ MAX_POINTS_ON_WINDING ];
 }
 radWinding_t;
 
@@ -1415,8 +1415,8 @@ radWinding_t;
 /* crutch for poor local allocations in win32 smp */
 typedef struct
 {
-       vec_t                           dists[ MAX_POINTS_ON_WINDING + 4 ];
-       int                                     sides[ MAX_POINTS_ON_WINDING + 4 ];
+       vec_t dists[ MAX_POINTS_ON_WINDING + 4 ];
+       int sides[ MAX_POINTS_ON_WINDING + 4 ];
 }
 clipWork_t;
 
@@ -1424,90 +1424,90 @@ clipWork_t;
 /* ydnar: new lightmap handling code */
 typedef struct outLightmap_s
 {
-       int                                     lightmapNum, extLightmapNum;
-       int                                     customWidth, customHeight;
-       int                                     numLightmaps;
-       int                                     freeLuxels;
-       int                                     numShaders;
-       shaderInfo_t            *shaders[ MAX_LIGHTMAP_SHADERS ];
-       byte                            *lightBits;
-       byte                            *bspLightBytes;
-       byte                            *bspDirBytes;
+       int lightmapNum, extLightmapNum;
+       int customWidth, customHeight;
+       int numLightmaps;
+       int freeLuxels;
+       int numShaders;
+       shaderInfo_t        *shaders[ MAX_LIGHTMAP_SHADERS ];
+       byte                *lightBits;
+       byte                *bspLightBytes;
+       byte                *bspDirBytes;
 }
 outLightmap_t;
 
 
 typedef struct rawLightmap_s
 {
-       qboolean                                finished, splotchFix, wrap[ 2 ];
-       int                                             customWidth, customHeight;
-       float                                   brightness;
-       float                                   filterRadius;
-       
-       int                                             firstLightSurface, numLightSurfaces;    /* index into lightSurfaces */
-       int                                             numLightClusters, *lightClusters;
-       
-       int                                             sampleSize, actualSampleSize, axisNum;
+       qboolean finished, splotchFix, wrap[ 2 ];
+       int customWidth, customHeight;
+       float brightness;
+       float filterRadius;
+
+       int firstLightSurface, numLightSurfaces;                        /* index into lightSurfaces */
+       int numLightClusters, *lightClusters;
+
+       int sampleSize, actualSampleSize, axisNum;
 
        /* vortex: per-surface floodlight */
-       float                                   floodlightDirectionScale;
-       vec3_t                                  floodlightRGB; 
-       float                                   floodlightIntensity;
-       float                                   floodlightDistance;
-
-       int                                             entityNum;
-       int                                             recvShadows;
-       vec3_t                                  mins, maxs, axis, origin, *vecs;
-       float                                   *plane;
-       int                                             w, h, sw, sh, used;
-       
-       qboolean                                solid[ MAX_LIGHTMAPS ];
-       vec3_t                                  solidColor[ MAX_LIGHTMAPS ];
-       
-       int                                             numStyledTwins;
-       struct rawLightmap_s    *twins[ MAX_LIGHTMAPS ];
-
-       int                                             outLightmapNums[ MAX_LIGHTMAPS ];
-       int                                             twinNums[ MAX_LIGHTMAPS ];
-       int                                             lightmapX[ MAX_LIGHTMAPS ], lightmapY[ MAX_LIGHTMAPS ];
-       byte                                    styles[ MAX_LIGHTMAPS ];
-       float                                   *bspLuxels[ MAX_LIGHTMAPS ];
-       float                                   *radLuxels[ MAX_LIGHTMAPS ];
-       float                                   *superLuxels[ MAX_LIGHTMAPS ];
-       unsigned char                           *superFlags;
-       float                                   *superOrigins;
-       float                                   *superNormals;
-       int                                             *superClusters;
-       
-       float                                   *superDeluxels; /* average light direction */
-       float                                   *bspDeluxels;
-       float                                   *superFloodLight;
+       float floodlightDirectionScale;
+       vec3_t floodlightRGB;
+       float floodlightIntensity;
+       float floodlightDistance;
+
+       int entityNum;
+       int recvShadows;
+       vec3_t mins, maxs, axis, origin, *vecs;
+       float                   *plane;
+       int w, h, sw, sh, used;
+
+       qboolean solid[ MAX_LIGHTMAPS ];
+       vec3_t solidColor[ MAX_LIGHTMAPS ];
+
+       int numStyledTwins;
+       struct rawLightmap_s    *twins[ MAX_LIGHTMAPS ];
+
+       int outLightmapNums[ MAX_LIGHTMAPS ];
+       int twinNums[ MAX_LIGHTMAPS ];
+       int lightmapX[ MAX_LIGHTMAPS ], lightmapY[ MAX_LIGHTMAPS ];
+       byte styles[ MAX_LIGHTMAPS ];
+       float                   *bspLuxels[ MAX_LIGHTMAPS ];
+       float                   *radLuxels[ MAX_LIGHTMAPS ];
+       float                   *superLuxels[ MAX_LIGHTMAPS ];
+       unsigned char               *superFlags;
+       float                   *superOrigins;
+       float                   *superNormals;
+       int                     *superClusters;
+
+       float                   *superDeluxels; /* average light direction */
+       float                   *bspDeluxels;
+       float                   *superFloodLight;
 }
 rawLightmap_t;
 
 
 typedef struct rawGridPoint_s
 {
-       vec3_t                          ambient[ MAX_LIGHTMAPS ];
-       vec3_t                          directed[ MAX_LIGHTMAPS ];
-       vec3_t                          dir;
-       byte                            styles[ MAX_LIGHTMAPS ];
+       vec3_t ambient[ MAX_LIGHTMAPS ];
+       vec3_t directed[ MAX_LIGHTMAPS ];
+       vec3_t dir;
+       byte styles[ MAX_LIGHTMAPS ];
 }
 rawGridPoint_t;
 
 
 typedef struct surfaceInfo_s
 {
-       int                                     modelindex;
-       shaderInfo_t            *si;
-       rawLightmap_t           *lm;
-       int                                     parentSurfaceNum, childSurfaceNum;
-       int                                     entityNum, castShadows, recvShadows, sampleSize, patchIterations;
-       float                           longestCurve;
-       float                           *plane;
-       vec3_t                          axis, mins, maxs;
-       qboolean                        hasLightmap, approximated;
-       int                                     firstSurfaceCluster, numSurfaceClusters;
+       int modelindex;
+       shaderInfo_t        *si;
+       rawLightmap_t       *lm;
+       int parentSurfaceNum, childSurfaceNum;
+       int entityNum, castShadows, recvShadows, sampleSize, patchIterations;
+       float longestCurve;
+       float               *plane;
+       vec3_t axis, mins, maxs;
+       qboolean hasLightmap, approximated;
+       int firstSurfaceCluster, numSurfaceClusters;
 }
 surfaceInfo_t;
 
@@ -1518,94 +1518,94 @@ surfaceInfo_t;
    ------------------------------------------------------------------------------- */
 
 /* main.c */
-vec_t                                          Random( void );
+vec_t                       Random( void );
 char                        *Q_strncpyz( char *dst, const char *src, size_t len );
 char                        *Q_strcat( char *dst, size_t dlen, const char *src );
 char                        *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen );
-int                                                    BSPInfo( int count, char **fileNames );
-int                                                    ScaleBSPMain( int argc, char **argv );
-int                                                    ConvertMain( int argc, char **argv );
+int                         BSPInfo( int count, char **fileNames );
+int                         ScaleBSPMain( int argc, char **argv );
+int                         ConvertMain( int argc, char **argv );
 
 
 /* path_init.c */
-game_t                                         *GetGame( char *arg );
-void                                           InitPaths( int *argc, char **argv );
+game_t                      *GetGame( char *arg );
+void                        InitPaths( int *argc, char **argv );
 
 
 /* bsp.c */
-int                                                    BSPMain( int argc, char **argv );
+int                         BSPMain( int argc, char **argv );
 
 
 /* convert_map.c */
-int                                                    ConvertBSPToMap( char *bspName );
-int                                                    ConvertBSPToMap_BP( char *bspName );
+int                         ConvertBSPToMap( char *bspName );
+int                         ConvertBSPToMap_BP( char *bspName );
 
 
 /* convert_ase.c */
-int                                                    ConvertBSPToASE( char *bspName );
+int                         ConvertBSPToASE( char *bspName );
 
 /* convert_obj.c */
-int                                                    ConvertBSPToOBJ( char *bspName );
+int                         ConvertBSPToOBJ( char *bspName );
 
 
 /* brush.c */
-sideRef_t                                      *AllocSideRef( side_t *side, sideRef_t *next );
-int                                                    CountBrushList( brush_t *brushes );
-brush_t                                                *AllocBrush( int numsides );
-void                                           FreeBrush( brush_t *brushes );
-void                                           FreeBrushList( brush_t *brushes );
-brush_t                                                *CopyBrush( brush_t *brush );
-qboolean                                       BoundBrush( brush_t *brush );
-qboolean                                       CreateBrushWindings( brush_t *brush );
-brush_t                                                *BrushFromBounds( vec3_t mins, vec3_t maxs );
-vec_t                                          BrushVolume( brush_t *brush );
-void                                           WriteBSPBrushMap( char *name, brush_t *list );
-
-void                                           FilterDetailBrushesIntoTree( entity_t *e, tree_t *tree );
-void                                           FilterStructuralBrushesIntoTree( entity_t *e, tree_t *tree );
-
-int                                                    BoxOnPlaneSide( vec3_t mins, vec3_t maxs, plane_t *plane );
-qboolean                                       WindingIsTiny( winding_t *w );
+sideRef_t                   *AllocSideRef( side_t *side, sideRef_t *next );
+int                         CountBrushList( brush_t *brushes );
+brush_t                     *AllocBrush( int numsides );
+void                        FreeBrush( brush_t *brushes );
+void                        FreeBrushList( brush_t *brushes );
+brush_t                     *CopyBrush( brush_t *brush );
+qboolean                    BoundBrush( brush_t *brush );
+qboolean                    CreateBrushWindings( brush_t *brush );
+brush_t                     *BrushFromBounds( vec3_t mins, vec3_t maxs );
+vec_t                       BrushVolume( brush_t *brush );
+void                        WriteBSPBrushMap( char *name, brush_t *list );
+
+void                        FilterDetailBrushesIntoTree( entity_t *e, tree_t *tree );
+void                        FilterStructuralBrushesIntoTree( entity_t *e, tree_t *tree );
+
+int                         BoxOnPlaneSide( vec3_t mins, vec3_t maxs, plane_t *plane );
+qboolean                    WindingIsTiny( winding_t *w );
 
 void                        SplitBrush( brush_t *brush, int planenum, brush_t **front, brush_t **back );
 
-tree_t                                         *AllocTree( void );
-node_t                                         *AllocNode( void );
+tree_t                      *AllocTree( void );
+node_t                      *AllocNode( void );
 
 
 /* mesh.c */
-void                                           LerpDrawVert( bspDrawVert_t *a, bspDrawVert_t *b, bspDrawVert_t *out );
-void                                           LerpDrawVertAmount( bspDrawVert_t *a, bspDrawVert_t *b, float amount, bspDrawVert_t *out );
-void                                           FreeMesh( mesh_t *m );
-mesh_t                                         *CopyMesh( mesh_t *mesh );
-void                                           PrintMesh( mesh_t *m );
-mesh_t                                         *TransposeMesh( mesh_t *in );
-void                                           InvertMesh( mesh_t *m );
-mesh_t                                         *SubdivideMesh( mesh_t in, float maxError, float minLength );
-int                                                    IterationsForCurve( float len, int subdivisions );
-mesh_t                                         *SubdivideMesh2( mesh_t in, int iterations );
-mesh_t                                         *SubdivideMeshQuads( mesh_t *in, float minLength, int maxsize, int *widthtable, int *heighttable );
-mesh_t                                         *RemoveLinearMeshColumnsRows( mesh_t *in );
-void                                           MakeMeshNormals( mesh_t in );
-void                                           PutMeshOnCurve( mesh_t in );
-
-void                                           MakeNormalVectors( vec3_t forward, vec3_t right, vec3_t up );
+void                        LerpDrawVert( bspDrawVert_t *a, bspDrawVert_t *b, bspDrawVert_t *out );
+void                        LerpDrawVertAmount( bspDrawVert_t *a, bspDrawVert_t *b, float amount, bspDrawVert_t *out );
+void                        FreeMesh( mesh_t *m );
+mesh_t                      *CopyMesh( mesh_t *mesh );
+void                        PrintMesh( mesh_t *m );
+mesh_t                      *TransposeMesh( mesh_t *in );
+void                        InvertMesh( mesh_t *m );
+mesh_t                      *SubdivideMesh( mesh_t in, float maxError, float minLength );
+int                         IterationsForCurve( float len, int subdivisions );
+mesh_t                      *SubdivideMesh2( mesh_t in, int iterations );
+mesh_t                      *SubdivideMeshQuads( mesh_t *in, float minLength, int maxsize, int *widthtable, int *heighttable );
+mesh_t                      *RemoveLinearMeshColumnsRows( mesh_t *in );
+void                        MakeMeshNormals( mesh_t in );
+void                        PutMeshOnCurve( mesh_t in );
+
+void                        MakeNormalVectors( vec3_t forward, vec3_t right, vec3_t up );
 
 
 /* map.c */
-void                                           LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups );
-int                                                    FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points );
-int                                                    PlaneTypeForNormal( vec3_t normal );
-void                                           AddBrushBevels( void );
+void                        LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups );
+int                         FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points );
+int                         PlaneTypeForNormal( vec3_t normal );
+void                        AddBrushBevels( void );
 brush_t                     *FinishBrush( qboolean noCollapseGroups );
 
 
 /* portals.c */
-void                                           MakeHeadnodePortals( tree_t *tree );
-void                                           MakeNodePortal( node_t *node );
-void                                           SplitNodePortals( node_t *node );
+void                        MakeHeadnodePortals( tree_t *tree );
+void                        MakeNodePortal( node_t *node );
+void                        SplitNodePortals( node_t *node );
 
-qboolean                                       PortalPassable( portal_t *p );
+qboolean                    PortalPassable( portal_t *p );
 
 #define FLOODENTITIES_LEAKED 1
 #define FLOODENTITIES_GOOD 0
@@ -1613,310 +1613,310 @@ qboolean                                      PortalPassable( portal_t *p );
 int                     FloodEntities( tree_t *tree );
 void                        FillOutside( node_t *headnode );
 void                        FloodAreas( tree_t *tree );
-face_t                                         *VisibleFaces( entity_t *e, tree_t *tree );
-void                                           FreePortal( portal_t *p );
+face_t                      *VisibleFaces( entity_t *e, tree_t *tree );
+void                        FreePortal( portal_t *p );
 
-void                                           MakeTreePortals( tree_t *tree );
+void                        MakeTreePortals( tree_t *tree );
 
 
 /* leakfile.c */
-xmlNodePtr                                     LeakFile( tree_t *tree );
+xmlNodePtr                  LeakFile( tree_t *tree );
 
 
 /* prtfile.c */
-void                                           NumberClusters( tree_t *tree );
-void                                           WritePortalFile( tree_t *tree );
+void                        NumberClusters( tree_t *tree );
+void                        WritePortalFile( tree_t *tree );
 
 
 /* writebsp.c */
-void                                           SetModelNumbers( void );
-void                                           SetLightStyles( void );
+void                        SetModelNumbers( void );
+void                        SetLightStyles( void );
 
-int                                                    EmitShader( const char *shader, int *contentFlags, int *surfaceFlags );
+int                         EmitShader( const char *shader, int *contentFlags, int *surfaceFlags );
 
-void                                           BeginBSPFile( void );
-void                                           EndBSPFile( qboolean do_write );
-void                                           EmitBrushes( brush_t *brushes, int *firstBrush, int *numBrushes );
-void                                           EmitFogs( void );
+void                        BeginBSPFile( void );
+void                        EndBSPFile( qboolean do_write );
+void                        EmitBrushes( brush_t *brushes, int *firstBrush, int *numBrushes );
+void                        EmitFogs( void );
 
-void                                           BeginModel( void );
-void                                           EndModel( entity_t *e, node_t *headnode );
+void                        BeginModel( void );
+void                        EndModel( entity_t *e, node_t *headnode );
 
 
 /* tree.c */
-void                                           FreeTree( tree_t *tree );
-void                                           FreeTree_r( node_t *node );
-void                                           PrintTree_r( node_t *node, int depth );
-void                                           FreeTreePortals_r( node_t *node );
+void                        FreeTree( tree_t *tree );
+void                        FreeTree_r( node_t *node );
+void                        PrintTree_r( node_t *node, int depth );
+void                        FreeTreePortals_r( node_t *node );
 
 
 /* patch.c */
-void                                           ParsePatch( qboolean onlyLights );
-mesh_t                                         *SubdivideMesh( mesh_t in, float maxError, float minLength );
-void                                           PatchMapDrawSurfs( entity_t *e );
+void                        ParsePatch( qboolean onlyLights );
+mesh_t                      *SubdivideMesh( mesh_t in, float maxError, float minLength );
+void                        PatchMapDrawSurfs( entity_t *e );
 void                        TriangulatePatchSurface( entity_t *e, mapDrawSurface_t *ds );
 
 
 /* tjunction.c */
-void                                           FixTJunctions( entity_t *e );
+void                        FixTJunctions( entity_t *e );
 
 
 /* fog.c */
-winding_t                                      *WindingFromDrawSurf( mapDrawSurface_t *ds );
-void                                           FogDrawSurfaces( entity_t *e );
-int                                                    FogForPoint( vec3_t point, float epsilon );
-int                                                    FogForBounds( vec3_t mins, vec3_t maxs, float epsilon );
-void                                           CreateMapFogs( void );
+winding_t                   *WindingFromDrawSurf( mapDrawSurface_t *ds );
+void                        FogDrawSurfaces( entity_t *e );
+int                         FogForPoint( vec3_t point, float epsilon );
+int                         FogForBounds( vec3_t mins, vec3_t maxs, float epsilon );
+void                        CreateMapFogs( void );
 
 
 /* facebsp.c */
-face_t                                         *MakeStructuralBSPFaceList( brush_t *list );
-face_t                                         *MakeVisibleBSPFaceList( brush_t *list );
-tree_t                                         *FaceBSP( face_t *list );
+face_t                      *MakeStructuralBSPFaceList( brush_t *list );
+face_t                      *MakeVisibleBSPFaceList( brush_t *list );
+tree_t                      *FaceBSP( face_t *list );
 
 
 /* model.c */
-void                                           PicoPrintFunc( int level, const char *str );
-void                                           PicoLoadFileFunc( const char *name, byte **buffer, int *bufSize );
-picoModel_t                                    *FindModel( const char *name, int frame );
-picoModel_t                                    *LoadModel( const char *name, int frame );
+void                        PicoPrintFunc( int level, const char *str );
+void                        PicoLoadFileFunc( const char *name, byte **buffer, int *bufSize );
+picoModel_t                 *FindModel( const char *name, int frame );
+picoModel_t                 *LoadModel( const char *name, int frame );
 void                                           InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle, vec3_t colormod );
-void                                           AddTriangleModels( entity_t *e );
+void                        AddTriangleModels( entity_t *e );
 
 
 /* surface.c */
-mapDrawSurface_t                       *AllocDrawSurface( surfaceType_t type );
-void                                           FinishSurface( mapDrawSurface_t *ds );
-void                                           StripFaceSurface( mapDrawSurface_t *ds );
-void                                           MaxAreaFaceSurface( mapDrawSurface_t *ds );
-qboolean                                       CalcSurfaceTextureRange( mapDrawSurface_t *ds );
-qboolean                                       CalcLightmapAxis( vec3_t normal, vec3_t axis );
-void                                           ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds );
-void                                           ClassifyEntitySurfaces( entity_t *e );
-void                                           TidyEntitySurfaces( entity_t *e );
-mapDrawSurface_t                       *CloneSurface( mapDrawSurface_t *src, shaderInfo_t *si );
-mapDrawSurface_t                       *MakeCelSurface( mapDrawSurface_t *src, shaderInfo_t *si );
-qboolean                                       IsTriangleDegenerate( bspDrawVert_t *points, int a, int b, int c );
-void                                           ClearSurface( mapDrawSurface_t *ds );
-void                                           AddEntitySurfaceModels( entity_t *e );
-mapDrawSurface_t                       *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, winding_t *w );
-mapDrawSurface_t                       *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh );
-mapDrawSurface_t                       *DrawSurfaceForFlare( int entNum, vec3_t origin, vec3_t normal, vec3_t color, const char *flareShader, int lightStyle );
-mapDrawSurface_t                       *DrawSurfaceForShader( char *shader );
-void                                           ClipSidesIntoTree( entity_t *e, tree_t *tree );
-void                                           MakeDebugPortalSurfs( tree_t *tree );
-void                                           MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader );
-void                                           SubdivideFaceSurfaces( entity_t *e, tree_t *tree );
-void                                           AddEntitySurfaceModels( entity_t *e );
-int                                                    AddSurfaceModels( mapDrawSurface_t *ds );
-void                                           FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree );
-void                                           EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds );
-void                                           EmitTriangleSurface( mapDrawSurface_t *ds );
+mapDrawSurface_t            *AllocDrawSurface( surfaceType_t type );
+void                        FinishSurface( mapDrawSurface_t *ds );
+void                        StripFaceSurface( mapDrawSurface_t *ds );
+void                        MaxAreaFaceSurface( mapDrawSurface_t *ds );
+qboolean                    CalcSurfaceTextureRange( mapDrawSurface_t *ds );
+qboolean                    CalcLightmapAxis( vec3_t normal, vec3_t axis );
+void                        ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds );
+void                        ClassifyEntitySurfaces( entity_t *e );
+void                        TidyEntitySurfaces( entity_t *e );
+mapDrawSurface_t            *CloneSurface( mapDrawSurface_t *src, shaderInfo_t *si );
+mapDrawSurface_t            *MakeCelSurface( mapDrawSurface_t *src, shaderInfo_t *si );
+qboolean                    IsTriangleDegenerate( bspDrawVert_t *points, int a, int b, int c );
+void                        ClearSurface( mapDrawSurface_t *ds );
+void                        AddEntitySurfaceModels( entity_t *e );
+mapDrawSurface_t            *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, winding_t *w );
+mapDrawSurface_t            *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh );
+mapDrawSurface_t            *DrawSurfaceForFlare( int entNum, vec3_t origin, vec3_t normal, vec3_t color, const char *flareShader, int lightStyle );
+mapDrawSurface_t            *DrawSurfaceForShader( char *shader );
+void                        ClipSidesIntoTree( entity_t *e, tree_t *tree );
+void                        MakeDebugPortalSurfs( tree_t *tree );
+void                        MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader );
+void                        SubdivideFaceSurfaces( entity_t *e, tree_t *tree );
+void                        AddEntitySurfaceModels( entity_t *e );
+int                         AddSurfaceModels( mapDrawSurface_t *ds );
+void                        FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree );
+void                        EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds );
+void                        EmitTriangleSurface( mapDrawSurface_t *ds );
 
 
 /* surface_fur.c */
-void                                           Fur( mapDrawSurface_t *src );
+void                        Fur( mapDrawSurface_t *src );
 
 
 /* surface_foliage.c */
-void                                           Foliage( mapDrawSurface_t *src );
+void                        Foliage( mapDrawSurface_t *src );
 
 
 /* ydnar: surface_meta.c */
-void                                           ClearMetaTriangles( void );
-int                                                    FindMetaTriangle( metaTriangle_t *src, bspDrawVert_t *a, bspDrawVert_t *b, bspDrawVert_t *c, int planeNum );
-void                                           MakeEntityMetaTriangles( entity_t *e );
-void                                           FixMetaTJunctions( void );
-void                                           SmoothMetaTriangles( void );
-void                                           MergeMetaTriangles( void );
-void                                           EmitMetaStats(); // vortex: print meta statistics even in no-verbose mode
+void                        ClearMetaTriangles( void );
+int                         FindMetaTriangle( metaTriangle_t *src, bspDrawVert_t *a, bspDrawVert_t *b, bspDrawVert_t *c, int planeNum );
+void                        MakeEntityMetaTriangles( entity_t *e );
+void                        FixMetaTJunctions( void );
+void                        SmoothMetaTriangles( void );
+void                        MergeMetaTriangles( void );
+void                        EmitMetaStats(); // vortex: print meta statistics even in no-verbose mode
 
 
 /* surface_extra.c */
-void                                           SetDefaultSampleSize( int sampleSize );
+void                        SetDefaultSampleSize( int sampleSize );
 
-void                                           SetSurfaceExtra( mapDrawSurface_t *ds, int num );
+void                        SetSurfaceExtra( mapDrawSurface_t *ds, int num );
 
-shaderInfo_t                           *GetSurfaceExtraShaderInfo( int num );
-int                                                    GetSurfaceExtraParentSurfaceNum( int num );
-int                                                    GetSurfaceExtraEntityNum( int num );
-int                                                    GetSurfaceExtraCastShadows( int num );
-int                                                    GetSurfaceExtraRecvShadows( int num );
-int                                                    GetSurfaceExtraSampleSize( int num );
-int                                                    GetSurfaceExtraMinSampleSize( int num );
-float                                          GetSurfaceExtraLongestCurve( int num );
-void                                           GetSurfaceExtraLightmapAxis( int num, vec3_t lightmapAxis );
+shaderInfo_t                *GetSurfaceExtraShaderInfo( int num );
+int                         GetSurfaceExtraParentSurfaceNum( int num );
+int                         GetSurfaceExtraEntityNum( int num );
+int                         GetSurfaceExtraCastShadows( int num );
+int                         GetSurfaceExtraRecvShadows( int num );
+int                         GetSurfaceExtraSampleSize( int num );
+int                         GetSurfaceExtraMinSampleSize( int num );
+float                       GetSurfaceExtraLongestCurve( int num );
+void                        GetSurfaceExtraLightmapAxis( int num, vec3_t lightmapAxis );
 
-void                                           WriteSurfaceExtraFile( const char *path );
-void                                           LoadSurfaceExtraFile( const char *path );
+void                        WriteSurfaceExtraFile( const char *path );
+void                        LoadSurfaceExtraFile( const char *path );
 
 
 /* decals.c */
-void                                           ProcessDecals( void );
-void                                           MakeEntityDecals( entity_t *e );
+void                        ProcessDecals( void );
+void                        MakeEntityDecals( entity_t *e );
 
 /* map.c */
-void                                           TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv );
+void                        TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv );
 
 /* brush_primit.c */
 void                        ComputeAxisBase( vec3_t normal, vec3_t texX, vec3_t texY );
 
 
 /* vis.c */
-fixedWinding_t                         *NewFixedWinding( int points );
-int                                                    VisMain( int argc, char **argv );
+fixedWinding_t              *NewFixedWinding( int points );
+int                         VisMain( int argc, char **argv );
 
 /* visflow.c */
-int                                                    CountBits( byte *bits, int numbits );
-void                                           PassageFlow( int portalnum );
-void                                           CreatePassages( int portalnum );
-void                                           PassageMemory( void );
-void                                           BasePortalVis( int portalnum );
-void                                           BetterPortalVis( int portalnum );
-void                                           PortalFlow( int portalnum );
-void                                           PassagePortalFlow( int portalnum );
+int                         CountBits( byte *bits, int numbits );
+void                        PassageFlow( int portalnum );
+void                        CreatePassages( int portalnum );
+void                        PassageMemory( void );
+void                        BasePortalVis( int portalnum );
+void                        BetterPortalVis( int portalnum );
+void                        PortalFlow( int portalnum );
+void                        PassagePortalFlow( int portalnum );
 
 
 
 /* light.c  */
-float                                          PointToPolygonFormFactor( const vec3_t point, const vec3_t normal, const winding_t *w );
-int                                                    LightContributionToSample( trace_t *trace );
+float                       PointToPolygonFormFactor( const vec3_t point, const vec3_t normal, const winding_t *w );
+int                         LightContributionToSample( trace_t *trace );
 void LightingAtSample( trace_t * trace, byte styles[ MAX_LIGHTMAPS ], vec3_t colors[ MAX_LIGHTMAPS ] );
-int                                                    LightContributionToPoint( trace_t *trace );
-int                                                    LightMain( int argc, char **argv );
+int                         LightContributionToPoint( trace_t *trace );
+int                         LightMain( int argc, char **argv );
 
 
 /* light_trace.c */
-void                                           SetupTraceNodes( void );
-void                                           TraceLine( trace_t *trace );
-float                                          SetupTrace( trace_t *trace );
+void                        SetupTraceNodes( void );
+void                        TraceLine( trace_t *trace );
+float                       SetupTrace( trace_t *trace );
 
 
 /* light_bounce.c */
 qboolean RadSampleImage( byte * pixels, int width, int height, float st[ 2 ], float color[ 4 ] );
-void                                           RadLightForTriangles( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw );
-void                                           RadLightForPatch( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw );
-void                                           RadCreateDiffuseLights( void );
-void                                           RadFreeLights();
+void                        RadLightForTriangles( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw );
+void                        RadLightForPatch( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw );
+void                        RadCreateDiffuseLights( void );
+void                        RadFreeLights();
 
 
 /* light_ydnar.c */
-void                                           ColorToBytes( const float *color, byte *colorBytes, float scale );
-void                                           SmoothNormals( void );
+void                        ColorToBytes( const float *color, byte *colorBytes, float scale );
+void                        SmoothNormals( void );
 
-void                                           MapRawLightmap( int num );
+void                        MapRawLightmap( int num );
 
-void                                           SetupDirt();
-float                                          DirtForSample( trace_t *trace );
-void                                           DirtyRawLightmap( int num );
+void                        SetupDirt();
+float                       DirtForSample( trace_t *trace );
+void                        DirtyRawLightmap( int num );
 
-void                                           SetupFloodLight();
-void                                           FloodlightRawLightmaps();
-void                                           FloodlightIlluminateLightmap( rawLightmap_t *lm );
+void                        SetupFloodLight();
+void                        FloodlightRawLightmaps();
+void                        FloodlightIlluminateLightmap( rawLightmap_t *lm );
 float                       FloodLightForSample( trace_t *trace, float floodLightDistance, qboolean floodLightLowQuality );
-void                                           FloodLightRawLightmap( int num );
+void                        FloodLightRawLightmap( int num );
 
-void                                           IlluminateRawLightmap( int num );
-void                                           IlluminateVertexes( int num );
+void                        IlluminateRawLightmap( int num );
+void                        IlluminateVertexes( int num );
 
 void                        SetupBrushesFlags( int mask_any, int test_any, int mask_all, int test_all );
-void                                           SetupBrushes( void );
-void                                           SetupClusters( void );
-qboolean                                       ClusterVisible( int a, int b );
-qboolean                                       ClusterVisibleToPoint( vec3_t point, int cluster );
-int                                                    ClusterForPoint( vec3_t point );
-int                                                    ClusterForPointExt( vec3_t point, float epsilon );
-int                                                    ClusterForPointExtFilter( vec3_t point, float epsilon, int numClusters, int *clusters );
-int                                                    ShaderForPointInLeaf( vec3_t point, int leafNum, float epsilon, int wantContentFlags, int wantSurfaceFlags, int *contentFlags, int *surfaceFlags );
-void                                           SetupEnvelopes( qboolean forGrid, qboolean fastFlag );
-void                                           FreeTraceLights( trace_t *trace );
-void                                           CreateTraceLightsForBounds( vec3_t mins, vec3_t maxs, vec3_t normal, int numClusters, int *clusters, int flags, trace_t *trace );
-void                                           CreateTraceLightsForSurface( int num, trace_t *trace );
+void                        SetupBrushes( void );
+void                        SetupClusters( void );
+qboolean                    ClusterVisible( int a, int b );
+qboolean                    ClusterVisibleToPoint( vec3_t point, int cluster );
+int                         ClusterForPoint( vec3_t point );
+int                         ClusterForPointExt( vec3_t point, float epsilon );
+int                         ClusterForPointExtFilter( vec3_t point, float epsilon, int numClusters, int *clusters );
+int                         ShaderForPointInLeaf( vec3_t point, int leafNum, float epsilon, int wantContentFlags, int wantSurfaceFlags, int *contentFlags, int *surfaceFlags );
+void                        SetupEnvelopes( qboolean forGrid, qboolean fastFlag );
+void                        FreeTraceLights( trace_t *trace );
+void                        CreateTraceLightsForBounds( vec3_t mins, vec3_t maxs, vec3_t normal, int numClusters, int *clusters, int flags, trace_t *trace );
+void                        CreateTraceLightsForSurface( int num, trace_t *trace );
 
 
 /* lightmaps_ydnar.c */
-void                                           ExportLightmaps( void );
+void                        ExportLightmaps( void );
 
-int                                                    ExportLightmapsMain( int argc, char **argv );
-int                                                    ImportLightmapsMain( int argc, char **argv );
+int                         ExportLightmapsMain( int argc, char **argv );
+int                         ImportLightmapsMain( int argc, char **argv );
 
-void                                           SetupSurfaceLightmaps( void );
-void                                           StitchSurfaceLightmaps( void );
-void                                           StoreSurfaceLightmaps( void );
+void                        SetupSurfaceLightmaps( void );
+void                        StitchSurfaceLightmaps( void );
+void                        StoreSurfaceLightmaps( void );
 
 
 /* image.c */
-void                                           ImageFree( image_t *image );
-image_t                                                *ImageFind( const char *filename );
-image_t                                                *ImageLoad( const char *filename );
+void                        ImageFree( image_t *image );
+image_t                     *ImageFind( const char *filename );
+image_t                     *ImageLoad( const char *filename );
 
 
 /* shaders.c */
-void                                           ColorMod( colorMod_t *am, int numVerts, bspDrawVert_t *drawVerts );
+void                        ColorMod( colorMod_t *am, int numVerts, bspDrawVert_t *drawVerts );
 
-void                                           TCMod( tcMod_t mod, float st[ 2 ] );
-void                                           TCModIdentity( tcMod_t mod );
-void                                           TCModMultiply( tcMod_t a, tcMod_t b, tcMod_t out );
-void                                           TCModTranslate( tcMod_t mod, float s, float t );
-void                                           TCModScale( tcMod_t mod, float s, float t );
-void                                           TCModRotate( tcMod_t mod, float euler );
+void TCMod( tcMod_t mod, float st[ 2 ] );
+void                        TCModIdentity( tcMod_t mod );
+void                        TCModMultiply( tcMod_t a, tcMod_t b, tcMod_t out );
+void                        TCModTranslate( tcMod_t mod, float s, float t );
+void                        TCModScale( tcMod_t mod, float s, float t );
+void                        TCModRotate( tcMod_t mod, float euler );
 
-qboolean                                       ApplySurfaceParm( char *name, int *contentFlags, int *surfaceFlags, int *compileFlags );
+qboolean                    ApplySurfaceParm( char *name, int *contentFlags, int *surfaceFlags, int *compileFlags );
 
-void                                           BeginMapShaderFile( const char *mapFile );
-void                                           WriteMapShaderFile( void );
-shaderInfo_t                           *CustomShader( shaderInfo_t *si, char *find, char *replace );
-void                                           EmitVertexRemapShader( char *from, char *to );
+void                        BeginMapShaderFile( const char *mapFile );
+void                        WriteMapShaderFile( void );
+shaderInfo_t                *CustomShader( shaderInfo_t *si, char *find, char *replace );
+void                        EmitVertexRemapShader( char *from, char *to );
 
-void                                           LoadShaderInfo( void );
-shaderInfo_t                           *ShaderInfoForShader( const char *shader );
+void                        LoadShaderInfo( void );
+shaderInfo_t                *ShaderInfoForShader( const char *shader );
 shaderInfo_t                *ShaderInfoForShaderNull( const char *shader );
 
 
 /* bspfile_abstract.c */
-void                                           SetGridPoints( int n );
-void                                           SetDrawVerts( int n );
-void                                           IncDrawVerts();
+void                        SetGridPoints( int n );
+void                        SetDrawVerts( int n );
+void                        IncDrawVerts();
 void                        SetDrawSurfaces( int n );
-void                                           SetDrawSurfacesBuffer();
-void                                           BSPFilesCleanup();
-
-void                                           SwapBlock( int *block, int size );
-
-int                                                    GetLumpElements( bspHeader_t *header, int lump, int size );
-void                                           *GetLump( bspHeader_t *header, int lump );
-int                                                    CopyLump( bspHeader_t *header, int lump, void *dest, int size );
-int                                                    CopyLump_Allocate( bspHeader_t *header, int lump, void **dest, int size, int *allocationVariable );
-void                                           AddLump( FILE *file, bspHeader_t *header, int lumpNum, const void *data, int length );
-
-void                                           LoadBSPFile( const char *filename );
-void                                           WriteBSPFile( const char *filename );
-void                                           PrintBSPFileSizes( void );
-
-epair_t                                                *ParseEPair( void );
-void                                           ParseEntities( void );
-void                                           UnparseEntities( void );
-void                                           PrintEntity( const entity_t *ent );
-void                                           SetKeyValue( entity_t *ent, const char *key, const char *value );
-qboolean                                       KeyExists( const entity_t *ent, const char *key ); /* VorteX: check if key exists */
-const char                                     *ValueForKey( const entity_t *ent, const char *key );
-int                                                    IntForKey( const entity_t *ent, const char *key );
-vec_t                                          FloatForKey( const entity_t *ent, const char *key );
-void                                           GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec );
-entity_t                                       *FindTargetEntity( const char *target );
-void                                           GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows );
+void                        SetDrawSurfacesBuffer();
+void                        BSPFilesCleanup();
+
+void                        SwapBlock( int *block, int size );
+
+int                         GetLumpElements( bspHeader_t *header, int lump, int size );
+void                        *GetLump( bspHeader_t *header, int lump );
+int                         CopyLump( bspHeader_t *header, int lump, void *dest, int size );
+int                         CopyLump_Allocate( bspHeader_t *header, int lump, void **dest, int size, int *allocationVariable );
+void                        AddLump( FILE *file, bspHeader_t *header, int lumpNum, const void *data, int length );
+
+void                        LoadBSPFile( const char *filename );
+void                        WriteBSPFile( const char *filename );
+void                        PrintBSPFileSizes( void );
+
+epair_t                     *ParseEPair( void );
+void                        ParseEntities( void );
+void                        UnparseEntities( void );
+void                        PrintEntity( const entity_t *ent );
+void                        SetKeyValue( entity_t *ent, const char *key, const char *value );
+qboolean                    KeyExists( const entity_t *ent, const char *key ); /* VorteX: check if key exists */
+const char                  *ValueForKey( const entity_t *ent, const char *key );
+int                         IntForKey( const entity_t *ent, const char *key );
+vec_t                       FloatForKey( const entity_t *ent, const char *key );
+void                        GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec );
+entity_t                    *FindTargetEntity( const char *target );
+void                        GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows );
 void InjectCommandLine( char **argv, int beginArgs, int endArgs );
-               
+
 
 
 /* bspfile_ibsp.c */
-void                                           LoadIBSPFile( const char *filename );
-void                                           WriteIBSPFile( const char *filename );
+void                        LoadIBSPFile( const char *filename );
+void                        WriteIBSPFile( const char *filename );
 
 
 /* bspfile_rbsp.c */
-void                                           LoadRBSPFile( const char *filename );
-void                                           WriteRBSPFile( const char *filename );
+void                        LoadRBSPFile( const char *filename );
+void                        WriteRBSPFile( const char *filename );
 
 
 
@@ -1928,122 +1928,122 @@ void                                          WriteRBSPFile( const char *filename );
 
 #ifdef MAIN_C
        #define Q_EXTERN
-       #define Q_ASSIGN( a )   = a
+       #define Q_ASSIGN( a )   = a
 #else
        #define Q_EXTERN extern
-       #define Q_ASSIGN( a )   
+       #define Q_ASSIGN( a )
 #endif
 
 /* game support */
-Q_EXTERN game_t                                games[]
+Q_EXTERN game_t games[]
 #ifndef MAIN_C
 ;
 #else
-                                                       =
-                                                       {
+       =
+       {
                                                                #include "game_quake3.h"
-                                                               ,
+       ,
                                                                #include "game_quakelive.h" /* most be after game_quake3.h as they share defines! */
-                                                               ,
+       ,
                                                                #include "game_nexuiz.h" /* most be after game_quake3.h as they share defines! */
-                                                               ,
+       ,
                                                                #include "game_xonotic.h" /* most be after game_quake3.h as they share defines! */
-                                                               ,
+       ,
                                                                #include "game_tremulous.h" /*LinuxManMikeC: must be after game_quake3.h, depends on #define's set in it */
-                                                               ,
+       ,
                                                                #include "game_tenebrae.h"
-                                                               ,
+       ,
                                                                #include "game_wolf.h"
-                                                               ,
+       ,
                                                                #include "game_wolfet.h" /* most be after game_wolf.h as they share defines! */
-                                                               ,
+       ,
                                                                #include "game_etut.h"
-                                                               ,
+       ,
                                                                #include "game_ef.h"
-                                                               ,
+       ,
                                                                #include "game_sof2.h"
-                                                               ,
-                                                               #include "game_jk2.h"   /* most be after game_sof2.h as they share defines! */
-                                                               ,
-                                                               #include "game_ja.h"    /* most be after game_jk2.h as they share defines! */
-                                                               ,
-                                                               #include "game_qfusion.h"       /* qfusion game */
-                                                               ,
+       ,
+                                                               #include "game_jk2.h"   /* most be after game_sof2.h as they share defines! */
+       ,
+                                                               #include "game_ja.h"    /* most be after game_jk2.h as they share defines! */
+       ,
+                                                               #include "game_qfusion.h"   /* qfusion game */
+       ,
                                                                #include "game_reaction.h" /* must be after game_quake3.h */
-                                                               ,
-                                                               #include "game_darkplaces.h"    /* vortex: darkplaces q1 engine */
-                                                               ,
-                                                               #include "game_dq.h"    /* vortex: deluxe quake game ( darkplaces q1 engine) */
-                                                               ,
-                                                               #include "game_prophecy.h"      /* vortex: prophecy game ( darkplaces q1 engine) */
-                                                               ,
-                                                               #include "game__null.h" /* null game (must be last item) */
-                                                       };
+       ,
+                                                               #include "game_darkplaces.h"    /* vortex: darkplaces q1 engine */
+       ,
+                                                               #include "game_dq.h"    /* vortex: deluxe quake game ( darkplaces q1 engine) */
+       ,
+                                                               #include "game_prophecy.h"  /* vortex: prophecy game ( darkplaces q1 engine) */
+       ,
+                                                               #include "game__null.h" /* null game (must be last item) */
+       };
 #endif
-Q_EXTERN game_t                                *game Q_ASSIGN( &games[ 0 ] );
+Q_EXTERN game_t             *game Q_ASSIGN( &games[ 0 ] );
 
 
 /* general */
-Q_EXTERN int                           numImages Q_ASSIGN( 0 );
-Q_EXTERN image_t                       images[ MAX_IMAGES ];
+Q_EXTERN int numImages Q_ASSIGN( 0 );
+Q_EXTERN image_t images[ MAX_IMAGES ];
 
-Q_EXTERN int                           numPicoModels Q_ASSIGN( 0 );
-Q_EXTERN picoModel_t           *picoModels[ MAX_MODELS ];
+Q_EXTERN int numPicoModels Q_ASSIGN( 0 );
+Q_EXTERN picoModel_t        *picoModels[ MAX_MODELS ];
 
-Q_EXTERN shaderInfo_t          *shaderInfo Q_ASSIGN( NULL );
-Q_EXTERN int                           numShaderInfo Q_ASSIGN( 0 );
-Q_EXTERN int                           numVertexRemaps Q_ASSIGN( 0 );
+Q_EXTERN shaderInfo_t       *shaderInfo Q_ASSIGN( NULL );
+Q_EXTERN int numShaderInfo Q_ASSIGN( 0 );
+Q_EXTERN int numVertexRemaps Q_ASSIGN( 0 );
 
-Q_EXTERN surfaceParm_t         custSurfaceParms[ MAX_CUST_SURFACEPARMS ];
-Q_EXTERN int                           numCustSurfaceParms Q_ASSIGN( 0 );
+Q_EXTERN surfaceParm_t custSurfaceParms[ MAX_CUST_SURFACEPARMS ];
+Q_EXTERN int numCustSurfaceParms Q_ASSIGN( 0 );
 
-Q_EXTERN char                          mapName[ MAX_QPATH ];   /* ydnar: per-map custom shaders for larger lightmaps */
-Q_EXTERN char                          mapShaderFile[ 1024 ];
-Q_EXTERN qboolean                      warnImage Q_ASSIGN( qtrue );
+Q_EXTERN char mapName[ MAX_QPATH ];                 /* ydnar: per-map custom shaders for larger lightmaps */
+Q_EXTERN char mapShaderFile[ 1024 ];
+Q_EXTERN qboolean warnImage Q_ASSIGN( qtrue );
 
 /* ydnar: sinusoid samples */
-Q_EXTERN float                         jitters[ MAX_JITTERS ];
+Q_EXTERN float jitters[ MAX_JITTERS ];
 
 
 /* commandline arguments */
-Q_EXTERN qboolean                      verbose;
-Q_EXTERN qboolean                      verboseEntities Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      force Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      infoMode Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      useCustomInfoParms Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      noprune Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      leaktest Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      nodetail Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      nosubdivide Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      notjunc Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      fulldetail Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      nowater Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      noCurveBrushes Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      fakemap Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      coplanar Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      nofog Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      noHint Q_ASSIGN( qfalse );                              /* ydnar */
-Q_EXTERN qboolean                      renameModelShaders Q_ASSIGN( qfalse );  /* ydnar */
-Q_EXTERN qboolean                      skyFixHack Q_ASSIGN( qfalse );                  /* ydnar */
-Q_EXTERN qboolean                      bspAlternateSplitWeights Q_ASSIGN( qfalse );                    /* 27 */
-Q_EXTERN qboolean                      deepBSP Q_ASSIGN( qfalse );                     /* div0 */
-Q_EXTERN qboolean                      maxAreaFaceSurface Q_ASSIGN( qfalse );                  /* divVerent */
-
-Q_EXTERN int                           patchSubdivisions Q_ASSIGN( 8 );                /* ydnar: -patchmeta subdivisions */
-
-Q_EXTERN int                           maxLMSurfaceVerts Q_ASSIGN( 64 );               /* ydnar */
-Q_EXTERN int                           maxSurfaceVerts Q_ASSIGN( 999 );                /* ydnar */
-Q_EXTERN int                           maxSurfaceIndexes Q_ASSIGN( 6000 );             /* ydnar */
-Q_EXTERN float                         npDegrees Q_ASSIGN( 0.0f );                             /* ydnar: nonplanar degrees */
-Q_EXTERN int                           bevelSnap Q_ASSIGN( 0 );                                /* ydnar: bevel plane snap */
-Q_EXTERN int                           texRange Q_ASSIGN( 0 );
-Q_EXTERN qboolean                      flat Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      meta Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      patchMeta Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      emitFlares Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      debugSurfaces Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      debugInset Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      debugPortals Q_ASSIGN( qfalse );
+Q_EXTERN qboolean verbose;
+Q_EXTERN qboolean verboseEntities Q_ASSIGN( qfalse );
+Q_EXTERN qboolean force Q_ASSIGN( qfalse );
+Q_EXTERN qboolean infoMode Q_ASSIGN( qfalse );
+Q_EXTERN qboolean useCustomInfoParms Q_ASSIGN( qfalse );
+Q_EXTERN qboolean noprune Q_ASSIGN( qfalse );
+Q_EXTERN qboolean leaktest Q_ASSIGN( qfalse );
+Q_EXTERN qboolean nodetail Q_ASSIGN( qfalse );
+Q_EXTERN qboolean nosubdivide Q_ASSIGN( qfalse );
+Q_EXTERN qboolean notjunc Q_ASSIGN( qfalse );
+Q_EXTERN qboolean fulldetail Q_ASSIGN( qfalse );
+Q_EXTERN qboolean nowater Q_ASSIGN( qfalse );
+Q_EXTERN qboolean noCurveBrushes Q_ASSIGN( qfalse );
+Q_EXTERN qboolean fakemap Q_ASSIGN( qfalse );
+Q_EXTERN qboolean coplanar Q_ASSIGN( qfalse );
+Q_EXTERN qboolean nofog Q_ASSIGN( qfalse );
+Q_EXTERN qboolean noHint Q_ASSIGN( qfalse );                        /* ydnar */
+Q_EXTERN qboolean renameModelShaders Q_ASSIGN( qfalse );            /* ydnar */
+Q_EXTERN qboolean skyFixHack Q_ASSIGN( qfalse );                    /* ydnar */
+Q_EXTERN qboolean bspAlternateSplitWeights Q_ASSIGN( qfalse );                      /* 27 */
+Q_EXTERN qboolean deepBSP Q_ASSIGN( qfalse );                   /* div0 */
+Q_EXTERN qboolean maxAreaFaceSurface Q_ASSIGN( qfalse );                    /* divVerent */
+
+Q_EXTERN int patchSubdivisions Q_ASSIGN( 8 );                       /* ydnar: -patchmeta subdivisions */
+
+Q_EXTERN int maxLMSurfaceVerts Q_ASSIGN( 64 );                      /* ydnar */
+Q_EXTERN int maxSurfaceVerts Q_ASSIGN( 999 );                       /* ydnar */
+Q_EXTERN int maxSurfaceIndexes Q_ASSIGN( 6000 );                    /* ydnar */
+Q_EXTERN float npDegrees Q_ASSIGN( 0.0f );                          /* ydnar: nonplanar degrees */
+Q_EXTERN int bevelSnap Q_ASSIGN( 0 );                               /* ydnar: bevel plane snap */
+Q_EXTERN int texRange Q_ASSIGN( 0 );
+Q_EXTERN qboolean flat Q_ASSIGN( qfalse );
+Q_EXTERN qboolean meta Q_ASSIGN( qfalse );
+Q_EXTERN qboolean patchMeta Q_ASSIGN( qfalse );
+Q_EXTERN qboolean emitFlares Q_ASSIGN( qfalse );
+Q_EXTERN qboolean debugSurfaces Q_ASSIGN( qfalse );
+Q_EXTERN qboolean debugInset Q_ASSIGN( qfalse );
+Q_EXTERN qboolean debugPortals Q_ASSIGN( qfalse );
 Q_EXTERN qboolean lightmapTriangleCheck Q_ASSIGN( qfalse );
 Q_EXTERN qboolean lightmapExtraVisClusterNudge Q_ASSIGN( qfalse );
 Q_EXTERN qboolean lightmapFill Q_ASSIGN( qfalse );
@@ -2059,7 +2059,7 @@ Q_EXTERN float metaMaxBBoxDistance Q_ASSIGN( -1 );
 // of this writing, FindFloatPlane() and AddBrushBevels()).
 Q_EXTERN double normalEpsilon Q_ASSIGN( 0.00005 );
 #else
-Q_EXTERN double                                normalEpsilon Q_ASSIGN( 0.00001 );
+Q_EXTERN double normalEpsilon Q_ASSIGN( 0.00001 );
 #endif
 
 #if Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES
@@ -2073,90 +2073,90 @@ Q_EXTERN double                         normalEpsilon Q_ASSIGN( 0.00001 );
 // (or even 2^14).
 Q_EXTERN double distanceEpsilon Q_ASSIGN( 0.005 );
 #else
-Q_EXTERN double                                distanceEpsilon Q_ASSIGN( 0.01 );
+Q_EXTERN double distanceEpsilon Q_ASSIGN( 0.01 );
 #endif
 
 
 /* bsp */
-Q_EXTERN int                           numMapEntities Q_ASSIGN( 0 );
+Q_EXTERN int numMapEntities Q_ASSIGN( 0 );
 
-Q_EXTERN int                           blockSize[ 3 ]                                  /* should be the same as in radiant */
+Q_EXTERN int blockSize[ 3 ]                                 /* should be the same as in radiant */
 #ifndef MAIN_C
 ;
 #else
-                                                       = { 1024, 1024, 1024 };
+       = { 1024, 1024, 1024 };
 #endif
 
-Q_EXTERN char                          name[ 1024 ];
-Q_EXTERN char                          source[ 1024 ];
-Q_EXTERN char                          outbase[ 32 ];
+Q_EXTERN char name[ 1024 ];
+Q_EXTERN char source[ 1024 ];
+Q_EXTERN char outbase[ 32 ];
 
-Q_EXTERN int                           sampleSize;                                             /* lightmap sample size in units */
-Q_EXTERN int                           minSampleSize;                  /* minimum sample size to use at all */
-Q_EXTERN int                           sampleScale;                                    /* vortex: lightmap sample scale (ie quality)*/
+Q_EXTERN int sampleSize;                                    /* lightmap sample size in units */
+Q_EXTERN int minSampleSize;                                 /* minimum sample size to use at all */
+Q_EXTERN int sampleScale;                                   /* vortex: lightmap sample scale (ie quality)*/
 
-Q_EXTERN int                           mapEntityNum Q_ASSIGN( 0 );
+Q_EXTERN int mapEntityNum Q_ASSIGN( 0 );
 
-Q_EXTERN int                           entitySourceBrushes;
+Q_EXTERN int entitySourceBrushes;
 
 Q_EXTERN plane_t            *mapplanes Q_ASSIGN( NULL );  /* mapplanes[ num ^ 1 ] will always be the mirror or mapplanes[ num ] */
 Q_EXTERN int nummapplanes Q_ASSIGN( 0 );                    /* nummapplanes will always be even */
 Q_EXTERN int allocatedmapplanes Q_ASSIGN( 0 );
-Q_EXTERN int                           numMapPatches;
-Q_EXTERN vec3_t                                mapMins, mapMaxs;
+Q_EXTERN int numMapPatches;
+Q_EXTERN vec3_t mapMins, mapMaxs;
 
-Q_EXTERN int                           defaultFogNum Q_ASSIGN( -1 );   /* ydnar: cleaner fog handling */
-Q_EXTERN int                           numMapFogs Q_ASSIGN( 0 );
-Q_EXTERN fog_t                         mapFogs[ MAX_MAP_FOGS ];
+Q_EXTERN int defaultFogNum Q_ASSIGN( -1 );                  /* ydnar: cleaner fog handling */
+Q_EXTERN int numMapFogs Q_ASSIGN( 0 );
+Q_EXTERN fog_t mapFogs[ MAX_MAP_FOGS ];
 
-Q_EXTERN entity_t                      *mapEnt;
-Q_EXTERN brush_t                       *buildBrush;
-Q_EXTERN int                           numActiveBrushes;
-Q_EXTERN int                           g_bBrushPrimit;
+Q_EXTERN entity_t           *mapEnt;
+Q_EXTERN brush_t            *buildBrush;
+Q_EXTERN int numActiveBrushes;
+Q_EXTERN int g_bBrushPrimit;
 
-Q_EXTERN int                           numStrippedLights Q_ASSIGN( 0 );
+Q_EXTERN int numStrippedLights Q_ASSIGN( 0 );
 
 
 /* surface stuff */
-Q_EXTERN mapDrawSurface_t      *mapDrawSurfs Q_ASSIGN( NULL );
-Q_EXTERN int                           numMapDrawSurfs;
+Q_EXTERN mapDrawSurface_t   *mapDrawSurfs Q_ASSIGN( NULL );
+Q_EXTERN int numMapDrawSurfs;
 
-Q_EXTERN int                           numSurfacesByType[ NUM_SURFACE_TYPES ];
-Q_EXTERN int                           numClearedSurfaces;
-Q_EXTERN int                           numStripSurfaces;
-Q_EXTERN int                           numMaxAreaSurfaces;
-Q_EXTERN int                           numFanSurfaces;
-Q_EXTERN int                           numMergedSurfaces;
-Q_EXTERN int                           numMergedVerts;
+Q_EXTERN int numSurfacesByType[ NUM_SURFACE_TYPES ];
+Q_EXTERN int numClearedSurfaces;
+Q_EXTERN int numStripSurfaces;
+Q_EXTERN int numMaxAreaSurfaces;
+Q_EXTERN int numFanSurfaces;
+Q_EXTERN int numMergedSurfaces;
+Q_EXTERN int numMergedVerts;
 
-Q_EXTERN int                           numRedundantIndexes;
+Q_EXTERN int numRedundantIndexes;
 
-Q_EXTERN int                           numSurfaceModels Q_ASSIGN( 0 );
+Q_EXTERN int numSurfaceModels Q_ASSIGN( 0 );
 
-Q_EXTERN byte                          debugColors[ 12 ][ 3 ]
+Q_EXTERN byte debugColors[ 12 ][ 3 ]
 #ifndef MAIN_C
 ;
 #else
-                                                       =
-                                                       {
-                                                               { 255, 0, 0 },
-                                                               { 192, 128, 128 },
-                                                               { 255, 255, 0 },
-                                                               { 192, 192, 128 },
-                                                               { 0, 255, 255 },
-                                                               { 128, 192, 192 },
-                                                               { 0, 0, 255 },
-                                                               { 128, 128, 192 },
-                                                               { 255, 0, 255 },
-                                                               { 192, 128, 192 },
-                                                               { 0, 255, 0 },
-                                                               { 128, 192, 128 }
-                                                       };
+       =
+       {
+       { 255, 0, 0 },
+       { 192, 128, 128 },
+       { 255, 255, 0 },
+       { 192, 192, 128 },
+       { 0, 255, 255 },
+       { 128, 192, 192 },
+       { 0, 0, 255 },
+       { 128, 128, 192 },
+       { 255, 0, 255 },
+       { 192, 128, 192 },
+       { 0, 255, 0 },
+       { 128, 192, 128 }
+       };
 #endif
 
-Q_EXTERN qboolean                      skyboxPresent Q_ASSIGN( qfalse );
-Q_EXTERN int                           skyboxArea Q_ASSIGN( -1 );
-Q_EXTERN m4x4_t                                skyboxTransform;
+Q_EXTERN qboolean skyboxPresent Q_ASSIGN( qfalse );
+Q_EXTERN int skyboxArea Q_ASSIGN( -1 );
+Q_EXTERN m4x4_t skyboxTransform;
 
 
 
@@ -2167,45 +2167,45 @@ Q_EXTERN m4x4_t                         skyboxTransform;
    ------------------------------------------------------------------------------- */
 
 /* commandline arguments */
-Q_EXTERN qboolean                      fastvis;
-Q_EXTERN qboolean                      noPassageVis;
-Q_EXTERN qboolean                      passageVisOnly;
-Q_EXTERN qboolean                      mergevis;
-Q_EXTERN qboolean                      mergevisportals;
-Q_EXTERN qboolean                      nosort;
-Q_EXTERN qboolean                      saveprt;
-Q_EXTERN qboolean                      hint;   /* ydnar */
-Q_EXTERN char                          inbase[ MAX_QPATH ];
-Q_EXTERN char                          globalCelShader[ MAX_QPATH ];
+Q_EXTERN qboolean fastvis;
+Q_EXTERN qboolean noPassageVis;
+Q_EXTERN qboolean passageVisOnly;
+Q_EXTERN qboolean mergevis;
+Q_EXTERN qboolean mergevisportals;
+Q_EXTERN qboolean nosort;
+Q_EXTERN qboolean saveprt;
+Q_EXTERN qboolean hint;             /* ydnar */
+Q_EXTERN char inbase[ MAX_QPATH ];
+Q_EXTERN char globalCelShader[ MAX_QPATH ];
 
-Q_EXTERN float                         farPlaneDist;   /* rr2do2, rf, mre, ydnar all contributed to this one... */
+Q_EXTERN float farPlaneDist;                /* rr2do2, rf, mre, ydnar all contributed to this one... */
 
-Q_EXTERN int                           numportals;
-Q_EXTERN int                           portalclusters;
+Q_EXTERN int numportals;
+Q_EXTERN int portalclusters;
 
-Q_EXTERN vportal_t                     *portals;
-Q_EXTERN leaf_t                                *leafs;
+Q_EXTERN vportal_t          *portals;
+Q_EXTERN leaf_t             *leafs;
 
-Q_EXTERN vportal_t                     *faces;
-Q_EXTERN leaf_t                                *faceleafs;
+Q_EXTERN vportal_t          *faces;
+Q_EXTERN leaf_t             *faceleafs;
 
-Q_EXTERN int                           numfaces;
+Q_EXTERN int numfaces;
 
-Q_EXTERN int                           c_portaltest, c_portalpass, c_portalcheck;
-Q_EXTERN int                           c_portalskip, c_leafskip;
-Q_EXTERN int                           c_vistest, c_mighttest;
-Q_EXTERN int                           c_chains;
+Q_EXTERN int c_portaltest, c_portalpass, c_portalcheck;
+Q_EXTERN int c_portalskip, c_leafskip;
+Q_EXTERN int c_vistest, c_mighttest;
+Q_EXTERN int c_chains;
 
-Q_EXTERN byte                          *vismap, *vismap_p, *vismap_end;
+Q_EXTERN byte               *vismap, *vismap_p, *vismap_end;
 
-Q_EXTERN int                           testlevel;
+Q_EXTERN int testlevel;
 
-Q_EXTERN byte                          *uncompressed;
+Q_EXTERN byte               *uncompressed;
 
-Q_EXTERN int                           leafbytes, leaflongs;
-Q_EXTERN int                           portalbytes, portallongs;
+Q_EXTERN int leafbytes, leaflongs;
+Q_EXTERN int portalbytes, portallongs;
 
-Q_EXTERN vportal_t                     *sorted_portals[ MAX_MAP_PORTALS * 2 ];
+Q_EXTERN vportal_t          *sorted_portals[ MAX_MAP_PORTALS * 2 ];
 
 
 
@@ -2216,245 +2216,245 @@ Q_EXTERN vportal_t                    *sorted_portals[ MAX_MAP_PORTALS * 2 ];
    ------------------------------------------------------------------------------- */
 
 /* commandline arguments */
-Q_EXTERN qboolean                      wolfLight Q_ASSIGN( qfalse );
-Q_EXTERN float                         extraDist Q_ASSIGN( 0.0f );
-Q_EXTERN qboolean                      loMem Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      noStyles Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      keepLights Q_ASSIGN( qfalse );
-
-Q_EXTERN int                           sampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_SAMPLE_SIZE );
-Q_EXTERN int                           minSampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE );
-Q_EXTERN qboolean                      noVertexLighting Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      noGridLighting Q_ASSIGN( qfalse );
-
-Q_EXTERN qboolean                      noTrace Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      noSurfaces Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      patchShadows Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      cpmaHack Q_ASSIGN( qfalse );
-
-Q_EXTERN qboolean                      deluxemap Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      debugDeluxemap Q_ASSIGN( qfalse );
-Q_EXTERN int                           deluxemode Q_ASSIGN( 0 );       /* deluxemap format (0 - modelspace, 1 - tangentspace with renormalization, 2 - tangentspace without renormalization) */
-
-Q_EXTERN qboolean                      fast Q_ASSIGN( qfalse );
+Q_EXTERN qboolean wolfLight Q_ASSIGN( qfalse );
+Q_EXTERN float extraDist Q_ASSIGN( 0.0f );
+Q_EXTERN qboolean loMem Q_ASSIGN( qfalse );
+Q_EXTERN qboolean noStyles Q_ASSIGN( qfalse );
+Q_EXTERN qboolean keepLights Q_ASSIGN( qfalse );
+
+Q_EXTERN int sampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_SAMPLE_SIZE );
+Q_EXTERN int minSampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE );
+Q_EXTERN qboolean noVertexLighting Q_ASSIGN( qfalse );
+Q_EXTERN qboolean noGridLighting Q_ASSIGN( qfalse );
+
+Q_EXTERN qboolean noTrace Q_ASSIGN( qfalse );
+Q_EXTERN qboolean noSurfaces Q_ASSIGN( qfalse );
+Q_EXTERN qboolean patchShadows Q_ASSIGN( qfalse );
+Q_EXTERN qboolean cpmaHack Q_ASSIGN( qfalse );
+
+Q_EXTERN qboolean deluxemap Q_ASSIGN( qfalse );
+Q_EXTERN qboolean debugDeluxemap Q_ASSIGN( qfalse );
+Q_EXTERN int deluxemode Q_ASSIGN( 0 );                  /* deluxemap format (0 - modelspace, 1 - tangentspace with renormalization, 2 - tangentspace without renormalization) */
+
+Q_EXTERN qboolean fast Q_ASSIGN( qfalse );
 Q_EXTERN qboolean fastpoint Q_ASSIGN( qtrue );
-Q_EXTERN qboolean                      faster Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      fastgrid Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      fastbounce Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      cheap Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      cheapgrid Q_ASSIGN( qfalse );
-Q_EXTERN int                           bounce Q_ASSIGN( 0 );
-Q_EXTERN qboolean                      bounceOnly Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      bouncing Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      bouncegrid Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      normalmap Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      trisoup Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      shade Q_ASSIGN( qfalse );
-Q_EXTERN float                         shadeAngleDegrees Q_ASSIGN( 0.0f );
-Q_EXTERN int                           superSample Q_ASSIGN( 0 );
-Q_EXTERN int                           lightSamples Q_ASSIGN( 1 );
-Q_EXTERN qboolean                      lightRandomSamples Q_ASSIGN( qfalse );
-Q_EXTERN int                           lightSamplesSearchBoxSize Q_ASSIGN( 1 );
-Q_EXTERN qboolean                      filter Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      dark Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      sunOnly Q_ASSIGN( qfalse );
-Q_EXTERN int                           approximateTolerance Q_ASSIGN( 0 );
-Q_EXTERN qboolean                      noCollapse Q_ASSIGN( qfalse );
-Q_EXTERN int                           lightmapSearchBlockSize Q_ASSIGN( 0 );
-Q_EXTERN qboolean                      exportLightmaps Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      externalLightmaps Q_ASSIGN( qfalse );
-Q_EXTERN int                           lmCustomSize Q_ASSIGN( LIGHTMAP_WIDTH );
-Q_EXTERN char *                                lmCustomDir Q_ASSIGN( NULL );
-Q_EXTERN int                           lmLimitSize Q_ASSIGN( 0 );
-
-Q_EXTERN qboolean                      dirty Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      dirtDebug Q_ASSIGN( qfalse );
-Q_EXTERN int                           dirtMode Q_ASSIGN( 0 );
-Q_EXTERN float                         dirtDepth Q_ASSIGN( 128.0f );
-Q_EXTERN float                         dirtScale Q_ASSIGN( 1.0f );
-Q_EXTERN float                         dirtGain Q_ASSIGN( 1.0f );
+Q_EXTERN qboolean faster Q_ASSIGN( qfalse );
+Q_EXTERN qboolean fastgrid Q_ASSIGN( qfalse );
+Q_EXTERN qboolean fastbounce Q_ASSIGN( qfalse );
+Q_EXTERN qboolean cheap Q_ASSIGN( qfalse );
+Q_EXTERN qboolean cheapgrid Q_ASSIGN( qfalse );
+Q_EXTERN int bounce Q_ASSIGN( 0 );
+Q_EXTERN qboolean bounceOnly Q_ASSIGN( qfalse );
+Q_EXTERN qboolean bouncing Q_ASSIGN( qfalse );
+Q_EXTERN qboolean bouncegrid Q_ASSIGN( qfalse );
+Q_EXTERN qboolean normalmap Q_ASSIGN( qfalse );
+Q_EXTERN qboolean trisoup Q_ASSIGN( qfalse );
+Q_EXTERN qboolean shade Q_ASSIGN( qfalse );
+Q_EXTERN float shadeAngleDegrees Q_ASSIGN( 0.0f );
+Q_EXTERN int superSample Q_ASSIGN( 0 );
+Q_EXTERN int lightSamples Q_ASSIGN( 1 );
+Q_EXTERN qboolean lightRandomSamples Q_ASSIGN( qfalse );
+Q_EXTERN int lightSamplesSearchBoxSize Q_ASSIGN( 1 );
+Q_EXTERN qboolean filter Q_ASSIGN( qfalse );
+Q_EXTERN qboolean dark Q_ASSIGN( qfalse );
+Q_EXTERN qboolean sunOnly Q_ASSIGN( qfalse );
+Q_EXTERN int approximateTolerance Q_ASSIGN( 0 );
+Q_EXTERN qboolean noCollapse Q_ASSIGN( qfalse );
+Q_EXTERN int lightmapSearchBlockSize Q_ASSIGN( 0 );
+Q_EXTERN qboolean exportLightmaps Q_ASSIGN( qfalse );
+Q_EXTERN qboolean externalLightmaps Q_ASSIGN( qfalse );
+Q_EXTERN int lmCustomSize Q_ASSIGN( LIGHTMAP_WIDTH );
+Q_EXTERN char *             lmCustomDir Q_ASSIGN( NULL );
+Q_EXTERN int lmLimitSize Q_ASSIGN( 0 );
+
+Q_EXTERN qboolean dirty Q_ASSIGN( qfalse );
+Q_EXTERN qboolean dirtDebug Q_ASSIGN( qfalse );
+Q_EXTERN int dirtMode Q_ASSIGN( 0 );
+Q_EXTERN float dirtDepth Q_ASSIGN( 128.0f );
+Q_EXTERN float dirtScale Q_ASSIGN( 1.0f );
+Q_EXTERN float dirtGain Q_ASSIGN( 1.0f );
 
 /* 27: floodlighting */
-Q_EXTERN qboolean                                      debugnormals Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                                      floodlighty Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                                      floodlight_lowquality Q_ASSIGN( qfalse );
-Q_EXTERN vec3_t                                                floodlightRGB;
-Q_EXTERN float                                         floodlightIntensity Q_ASSIGN( 512.0f );
-Q_EXTERN float                                         floodlightDistance Q_ASSIGN( 1024.0f );
-Q_EXTERN float                                         floodlightDirectionScale Q_ASSIGN( 1.0f );
-
-Q_EXTERN qboolean                      dump Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      debug Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      debugUnused Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      debugAxis Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      debugCluster Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      debugOrigin Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      lightmapBorder Q_ASSIGN( qfalse );
+Q_EXTERN qboolean debugnormals Q_ASSIGN( qfalse );
+Q_EXTERN qboolean floodlighty Q_ASSIGN( qfalse );
+Q_EXTERN qboolean floodlight_lowquality Q_ASSIGN( qfalse );
+Q_EXTERN vec3_t floodlightRGB;
+Q_EXTERN float floodlightIntensity Q_ASSIGN( 512.0f );
+Q_EXTERN float floodlightDistance Q_ASSIGN( 1024.0f );
+Q_EXTERN float floodlightDirectionScale Q_ASSIGN( 1.0f );
+
+Q_EXTERN qboolean dump Q_ASSIGN( qfalse );
+Q_EXTERN qboolean debug Q_ASSIGN( qfalse );
+Q_EXTERN qboolean debugUnused Q_ASSIGN( qfalse );
+Q_EXTERN qboolean debugAxis Q_ASSIGN( qfalse );
+Q_EXTERN qboolean debugCluster Q_ASSIGN( qfalse );
+Q_EXTERN qboolean debugOrigin Q_ASSIGN( qfalse );
+Q_EXTERN qboolean lightmapBorder Q_ASSIGN( qfalse );
 
 /* longest distance across the map */
-Q_EXTERN float                         maxMapDistance Q_ASSIGN( 0 );
+Q_EXTERN float maxMapDistance Q_ASSIGN( 0 );
 
 /* for run time tweaking of light sources */
-Q_EXTERN float                         pointScale Q_ASSIGN( 7500.0f );
+Q_EXTERN float pointScale Q_ASSIGN( 7500.0f );
 Q_EXTERN float spotScale Q_ASSIGN( 7500.0f );
-Q_EXTERN float                         areaScale Q_ASSIGN( 0.25f );
-Q_EXTERN float                         skyScale Q_ASSIGN( 1.0f );
-Q_EXTERN float                         bounceScale Q_ASSIGN( 0.25f );
+Q_EXTERN float areaScale Q_ASSIGN( 0.25f );
+Q_EXTERN float skyScale Q_ASSIGN( 1.0f );
+Q_EXTERN float bounceScale Q_ASSIGN( 0.25f );
 
 /* jal: alternative angle attenuation curve */
-Q_EXTERN qboolean                      lightAngleHL Q_ASSIGN( qfalse );
+Q_EXTERN qboolean lightAngleHL Q_ASSIGN( qfalse );
+
 /* vortex: gridscale and gridambientscale */
-Q_EXTERN float                         gridScale Q_ASSIGN( 1.0f );
-Q_EXTERN float                         gridAmbientScale Q_ASSIGN( 1.0f );
-Q_EXTERN float                         gridDirectionality Q_ASSIGN( 1.0f );
-Q_EXTERN float                         gridAmbientDirectionality Q_ASSIGN( 0.0f );
+Q_EXTERN float gridScale Q_ASSIGN( 1.0f );
+Q_EXTERN float gridAmbientScale Q_ASSIGN( 1.0f );
+Q_EXTERN float gridDirectionality Q_ASSIGN( 1.0f );
+Q_EXTERN float gridAmbientDirectionality Q_ASSIGN( 0.0f );
 Q_EXTERN qboolean inGrid Q_ASSIGN( 0 );
 
 /* ydnar: lightmap gamma/compensation */
-Q_EXTERN float                         lightmapGamma Q_ASSIGN( 1.0f );
+Q_EXTERN float lightmapGamma Q_ASSIGN( 1.0f );
 Q_EXTERN float lightmapsRGB Q_ASSIGN( qfalse );
 Q_EXTERN float texturesRGB Q_ASSIGN( qfalse );
 Q_EXTERN float colorsRGB Q_ASSIGN( qfalse );
 Q_EXTERN float lightmapExposure Q_ASSIGN( 0.0f );
-Q_EXTERN float                         lightmapCompensate Q_ASSIGN( 1.0f );
+Q_EXTERN float lightmapCompensate Q_ASSIGN( 1.0f );
 
 /* ydnar: for runtime tweaking of falloff tolerance */
-Q_EXTERN float                         falloffTolerance Q_ASSIGN( 1.0f );
-Q_EXTERN qboolean                      exactPointToPolygon Q_ASSIGN( qtrue );
-Q_EXTERN float                         formFactorValueScale Q_ASSIGN( 3.0f );
-Q_EXTERN float                         linearScale Q_ASSIGN( 1.0f / 8000.0f );
+Q_EXTERN float falloffTolerance Q_ASSIGN( 1.0f );
+Q_EXTERN qboolean exactPointToPolygon Q_ASSIGN( qtrue );
+Q_EXTERN float formFactorValueScale Q_ASSIGN( 3.0f );
+Q_EXTERN float linearScale Q_ASSIGN( 1.0f / 8000.0f );
 
 // for .ase conversion
-Q_EXTERN qboolean                      shadersAsBitmap Q_ASSIGN( qfalse );
-Q_EXTERN qboolean                      lightmapsAsTexcoord Q_ASSIGN( qfalse );
+Q_EXTERN qboolean shadersAsBitmap Q_ASSIGN( qfalse );
+Q_EXTERN qboolean lightmapsAsTexcoord Q_ASSIGN( qfalse );
 
-Q_EXTERN light_t                       *lights;
-Q_EXTERN int                           numPointLights;
-Q_EXTERN int                           numSpotLights;
-Q_EXTERN int                           numSunLights;
-Q_EXTERN int                           numAreaLights;
+Q_EXTERN light_t            *lights;
+Q_EXTERN int numPointLights;
+Q_EXTERN int numSpotLights;
+Q_EXTERN int numSunLights;
+Q_EXTERN int numAreaLights;
 
 /* ydnar: for luxel placement */
-Q_EXTERN int                           numSurfaceClusters, maxSurfaceClusters;
-Q_EXTERN int                           *surfaceClusters;
+Q_EXTERN int numSurfaceClusters, maxSurfaceClusters;
+Q_EXTERN int                *surfaceClusters;
 
 /* ydnar: for radiosity */
-Q_EXTERN int                           numDiffuseLights;
-Q_EXTERN int                           numBrushDiffuseLights;
-Q_EXTERN int                           numTriangleDiffuseLights;
-Q_EXTERN int                           numPatchDiffuseLights;
+Q_EXTERN int numDiffuseLights;
+Q_EXTERN int numBrushDiffuseLights;
+Q_EXTERN int numTriangleDiffuseLights;
+Q_EXTERN int numPatchDiffuseLights;
 
 /* ydnar: general purpose extra copy of drawvert list */
-Q_EXTERN bspDrawVert_t         *yDrawVerts;
+Q_EXTERN bspDrawVert_t      *yDrawVerts;
 
 /* ydnar: for tracing statistics */
-Q_EXTERN int                           minSurfacesTested;
-Q_EXTERN int                           maxSurfacesTested;
-Q_EXTERN int                           totalSurfacesTested;
-Q_EXTERN int                           totalTraces;
+Q_EXTERN int minSurfacesTested;
+Q_EXTERN int maxSurfacesTested;
+Q_EXTERN int totalSurfacesTested;
+Q_EXTERN int totalTraces;
 
-Q_EXTERN FILE                          *dumpFile;
+Q_EXTERN FILE               *dumpFile;
 
-Q_EXTERN int                           c_visible, c_occluded;
-Q_EXTERN int                           c_subsampled;   /* ydnar */
+Q_EXTERN int c_visible, c_occluded;
+Q_EXTERN int c_subsampled;                  /* ydnar */
 
-Q_EXTERN int                           defaultLightSubdivide Q_ASSIGN( 999 );
+Q_EXTERN int defaultLightSubdivide Q_ASSIGN( 999 );
 
-Q_EXTERN vec3_t                                ambientColor;
-Q_EXTERN vec3_t                                minLight, minVertexLight, minGridLight;
+Q_EXTERN vec3_t ambientColor;
+Q_EXTERN vec3_t minLight, minVertexLight, minGridLight;
 
-Q_EXTERN int                           *entitySurface;
-Q_EXTERN vec3_t                                *surfaceOrigin;
+Q_EXTERN int                *entitySurface;
+Q_EXTERN vec3_t             *surfaceOrigin;
 
-Q_EXTERN vec3_t                                sunDirection;
-Q_EXTERN vec3_t                                sunLight;
+Q_EXTERN vec3_t sunDirection;
+Q_EXTERN vec3_t sunLight;
 
 /* tracing */
-Q_EXTERN int                           c_totalTrace;
-Q_EXTERN int                           c_cullTrace, c_testTrace;
-Q_EXTERN int                           c_testFacets;
+Q_EXTERN int c_totalTrace;
+Q_EXTERN int c_cullTrace, c_testTrace;
+Q_EXTERN int c_testFacets;
 
 /* ydnar: light optimization */
-Q_EXTERN float                         subdivideThreshold Q_ASSIGN( DEFAULT_SUBDIVIDE_THRESHOLD );
+Q_EXTERN float subdivideThreshold Q_ASSIGN( DEFAULT_SUBDIVIDE_THRESHOLD );
 
-Q_EXTERN int                           numOpaqueBrushes, maxOpaqueBrush;
-Q_EXTERN byte                          *opaqueBrushes;
+Q_EXTERN int numOpaqueBrushes, maxOpaqueBrush;
+Q_EXTERN byte               *opaqueBrushes;
 
-Q_EXTERN int                           numLights;
-Q_EXTERN int                           numCulledLights;
+Q_EXTERN int numLights;
+Q_EXTERN int numCulledLights;
 
-Q_EXTERN int                           gridBoundsCulled;
-Q_EXTERN int                           gridEnvelopeCulled;
+Q_EXTERN int gridBoundsCulled;
+Q_EXTERN int gridEnvelopeCulled;
 
-Q_EXTERN int                           lightsBoundsCulled;
-Q_EXTERN int                           lightsEnvelopeCulled;
-Q_EXTERN int                           lightsPlaneCulled;
-Q_EXTERN int                           lightsClusterCulled;
+Q_EXTERN int lightsBoundsCulled;
+Q_EXTERN int lightsEnvelopeCulled;
+Q_EXTERN int lightsPlaneCulled;
+Q_EXTERN int lightsClusterCulled;
 
 /* ydnar: radiosity */
-Q_EXTERN float                         diffuseSubdivide Q_ASSIGN( 256.0f );
-Q_EXTERN float                         minDiffuseSubdivide Q_ASSIGN( 64.0f );
-Q_EXTERN int                           numDiffuseSurfaces Q_ASSIGN( 0 );
+Q_EXTERN float diffuseSubdivide Q_ASSIGN( 256.0f );
+Q_EXTERN float minDiffuseSubdivide Q_ASSIGN( 64.0f );
+Q_EXTERN int numDiffuseSurfaces Q_ASSIGN( 0 );
 
 /* ydnar: list of surface information necessary for lightmap calculation */
-Q_EXTERN surfaceInfo_t         *surfaceInfos Q_ASSIGN( NULL );
+Q_EXTERN surfaceInfo_t      *surfaceInfos Q_ASSIGN( NULL );
 
 /* ydnar: sorted list of surfaces */
-Q_EXTERN int                           *sortSurfaces Q_ASSIGN( NULL );
+Q_EXTERN int                *sortSurfaces Q_ASSIGN( NULL );
 
 /* clumps of surfaces that share a raw lightmap */
-Q_EXTERN int                           numLightSurfaces Q_ASSIGN( 0 );
-Q_EXTERN int                           *lightSurfaces Q_ASSIGN( NULL );
+Q_EXTERN int numLightSurfaces Q_ASSIGN( 0 );
+Q_EXTERN int                *lightSurfaces Q_ASSIGN( NULL );
 
 /* raw lightmaps */
-Q_EXTERN int                           numRawSuperLuxels Q_ASSIGN( 0 );
-Q_EXTERN int                           numRawLightmaps Q_ASSIGN( 0 );
-Q_EXTERN rawLightmap_t         *rawLightmaps Q_ASSIGN( NULL );
-Q_EXTERN int                           *sortLightmaps Q_ASSIGN( NULL );
+Q_EXTERN int numRawSuperLuxels Q_ASSIGN( 0 );
+Q_EXTERN int numRawLightmaps Q_ASSIGN( 0 );
+Q_EXTERN rawLightmap_t      *rawLightmaps Q_ASSIGN( NULL );
+Q_EXTERN int                *sortLightmaps Q_ASSIGN( NULL );
 
 /* vertex luxels */
-Q_EXTERN float                         *vertexLuxels[ MAX_LIGHTMAPS ];
-Q_EXTERN float                         *radVertexLuxels[ MAX_LIGHTMAPS ];
+Q_EXTERN float              *vertexLuxels[ MAX_LIGHTMAPS ];
+Q_EXTERN float              *radVertexLuxels[ MAX_LIGHTMAPS ];
 
 /* bsp lightmaps */
-Q_EXTERN int                           numLightmapShaders Q_ASSIGN( 0 );
-Q_EXTERN int                           numSolidLightmaps Q_ASSIGN( 0 );
-Q_EXTERN int                           numOutLightmaps Q_ASSIGN( 0 );
-Q_EXTERN int                           numBSPLightmaps Q_ASSIGN( 0 );
-Q_EXTERN int                           numExtLightmaps Q_ASSIGN( 0 );
-Q_EXTERN outLightmap_t         *outLightmaps Q_ASSIGN( NULL );
+Q_EXTERN int numLightmapShaders Q_ASSIGN( 0 );
+Q_EXTERN int numSolidLightmaps Q_ASSIGN( 0 );
+Q_EXTERN int numOutLightmaps Q_ASSIGN( 0 );
+Q_EXTERN int numBSPLightmaps Q_ASSIGN( 0 );
+Q_EXTERN int numExtLightmaps Q_ASSIGN( 0 );
+Q_EXTERN outLightmap_t      *outLightmaps Q_ASSIGN( NULL );
 
 /* vortex: per surface floodlight statictics */
-Q_EXTERN int                           numSurfacesFloodlighten Q_ASSIGN( 0 );
+Q_EXTERN int numSurfacesFloodlighten Q_ASSIGN( 0 );
 
 /* grid points */
-Q_EXTERN int                           numRawGridPoints Q_ASSIGN( 0 );
-Q_EXTERN rawGridPoint_t                *rawGridPoints Q_ASSIGN( NULL );
-
-Q_EXTERN int                           numSurfsVertexLit Q_ASSIGN( 0 );
-Q_EXTERN int                           numSurfsVertexForced Q_ASSIGN( 0 );
-Q_EXTERN int                           numSurfsVertexApproximated Q_ASSIGN( 0 );
-Q_EXTERN int                           numSurfsLightmapped Q_ASSIGN( 0 );
-Q_EXTERN int                           numPlanarsLightmapped Q_ASSIGN( 0 );
-Q_EXTERN int                           numNonPlanarsLightmapped Q_ASSIGN( 0 );
-Q_EXTERN int                           numPatchesLightmapped Q_ASSIGN( 0 );
-Q_EXTERN int                           numPlanarPatchesLightmapped Q_ASSIGN( 0 );
-
-Q_EXTERN int                           numLuxels Q_ASSIGN( 0 );
-Q_EXTERN int                           numLuxelsMapped Q_ASSIGN( 0 );
-Q_EXTERN int                           numLuxelsOccluded Q_ASSIGN( 0 );
-Q_EXTERN int                           numLuxelsIlluminated Q_ASSIGN( 0 );
-Q_EXTERN int                           numVertsIlluminated Q_ASSIGN( 0 );
+Q_EXTERN int numRawGridPoints Q_ASSIGN( 0 );
+Q_EXTERN rawGridPoint_t     *rawGridPoints Q_ASSIGN( NULL );
+
+Q_EXTERN int numSurfsVertexLit Q_ASSIGN( 0 );
+Q_EXTERN int numSurfsVertexForced Q_ASSIGN( 0 );
+Q_EXTERN int numSurfsVertexApproximated Q_ASSIGN( 0 );
+Q_EXTERN int numSurfsLightmapped Q_ASSIGN( 0 );
+Q_EXTERN int numPlanarsLightmapped Q_ASSIGN( 0 );
+Q_EXTERN int numNonPlanarsLightmapped Q_ASSIGN( 0 );
+Q_EXTERN int numPatchesLightmapped Q_ASSIGN( 0 );
+Q_EXTERN int numPlanarPatchesLightmapped Q_ASSIGN( 0 );
+
+Q_EXTERN int numLuxels Q_ASSIGN( 0 );
+Q_EXTERN int numLuxelsMapped Q_ASSIGN( 0 );
+Q_EXTERN int numLuxelsOccluded Q_ASSIGN( 0 );
+Q_EXTERN int numLuxelsIlluminated Q_ASSIGN( 0 );
+Q_EXTERN int numVertsIlluminated Q_ASSIGN( 0 );
 
 /* lightgrid */
-Q_EXTERN vec3_t                                gridMins;
-Q_EXTERN int                           gridBounds[ 3 ];
-Q_EXTERN vec3_t                                gridSize
+Q_EXTERN vec3_t gridMins;
+Q_EXTERN int gridBounds[ 3 ];
+Q_EXTERN vec3_t gridSize
 #ifndef MAIN_C
 ;
 #else
-                                                       = { 64, 64, 128 };
+       = { 64, 64, 128 };
 #endif
 
 
@@ -2465,77 +2465,77 @@ Q_EXTERN vec3_t                         gridSize
 
    ------------------------------------------------------------------------------- */
 
-Q_EXTERN int                           numEntities Q_ASSIGN( 0 );
-Q_EXTERN int                           numBSPEntities Q_ASSIGN( 0 );
+Q_EXTERN int numEntities Q_ASSIGN( 0 );
+Q_EXTERN int numBSPEntities Q_ASSIGN( 0 );
 Q_EXTERN int allocatedEntities Q_ASSIGN( 0 );
 Q_EXTERN entity_t*          entities Q_ASSIGN( NULL );
 
-Q_EXTERN int                           numBSPModels Q_ASSIGN( 0 );
-Q_EXTERN int                           allocatedBSPModels Q_ASSIGN( 0 );
+Q_EXTERN int numBSPModels Q_ASSIGN( 0 );
+Q_EXTERN int allocatedBSPModels Q_ASSIGN( 0 );
 Q_EXTERN bspModel_t*        bspModels Q_ASSIGN( NULL );
 
-Q_EXTERN int                           numBSPShaders Q_ASSIGN( 0 );
-Q_EXTERN int                           allocatedBSPShaders Q_ASSIGN( 0 );
+Q_EXTERN int numBSPShaders Q_ASSIGN( 0 );
+Q_EXTERN int allocatedBSPShaders Q_ASSIGN( 0 );
 Q_EXTERN bspShader_t*       bspShaders Q_ASSIGN( 0 );
 
-Q_EXTERN int                           bspEntDataSize Q_ASSIGN( 0 );
-Q_EXTERN int                           allocatedBSPEntData Q_ASSIGN( 0 );
+Q_EXTERN int bspEntDataSize Q_ASSIGN( 0 );
+Q_EXTERN int allocatedBSPEntData Q_ASSIGN( 0 );
 Q_EXTERN char               *bspEntData Q_ASSIGN( 0 );
 
-Q_EXTERN int                           numBSPLeafs Q_ASSIGN( 0 );
-Q_EXTERN bspLeaf_t                     bspLeafs[ MAX_MAP_LEAFS ];
+Q_EXTERN int numBSPLeafs Q_ASSIGN( 0 );
+Q_EXTERN bspLeaf_t bspLeafs[ MAX_MAP_LEAFS ];
 
-Q_EXTERN int                           numBSPPlanes Q_ASSIGN( 0 );
+Q_EXTERN int numBSPPlanes Q_ASSIGN( 0 );
 Q_EXTERN int allocatedBSPPlanes Q_ASSIGN( 0 );
-Q_EXTERN bspPlane_t                    *bspPlanes;
+Q_EXTERN bspPlane_t         *bspPlanes;
 
-Q_EXTERN int                           numBSPNodes Q_ASSIGN( 0 );
-Q_EXTERN int                           allocatedBSPNodes Q_ASSIGN( 0 );
+Q_EXTERN int numBSPNodes Q_ASSIGN( 0 );
+Q_EXTERN int allocatedBSPNodes Q_ASSIGN( 0 );
 Q_EXTERN bspNode_t*         bspNodes Q_ASSIGN( NULL );
 
-Q_EXTERN int                           numBSPLeafSurfaces Q_ASSIGN( 0 );
-Q_EXTERN int                           allocatedBSPLeafSurfaces Q_ASSIGN( 0 );
+Q_EXTERN int numBSPLeafSurfaces Q_ASSIGN( 0 );
+Q_EXTERN int allocatedBSPLeafSurfaces Q_ASSIGN( 0 );
 Q_EXTERN int*               bspLeafSurfaces Q_ASSIGN( NULL );
 
-Q_EXTERN int                           numBSPLeafBrushes Q_ASSIGN( 0 );
-Q_EXTERN int                           allocatedBSPLeafBrushes Q_ASSIGN( 0 );
+Q_EXTERN int numBSPLeafBrushes Q_ASSIGN( 0 );
+Q_EXTERN int allocatedBSPLeafBrushes Q_ASSIGN( 0 );
 Q_EXTERN int*               bspLeafBrushes Q_ASSIGN( NULL );
 
-Q_EXTERN int                           numBSPBrushes Q_ASSIGN( 0 );
-Q_EXTERN int                           allocatedBSPBrushes Q_ASSIGN( 0 );
+Q_EXTERN int numBSPBrushes Q_ASSIGN( 0 );
+Q_EXTERN int allocatedBSPBrushes Q_ASSIGN( 0 );
 Q_EXTERN bspBrush_t*        bspBrushes Q_ASSIGN( NULL );
 
-Q_EXTERN int                           numBSPBrushSides Q_ASSIGN( 0 );
-Q_EXTERN int                           allocatedBSPBrushSides Q_ASSIGN( 0 );
+Q_EXTERN int numBSPBrushSides Q_ASSIGN( 0 );
+Q_EXTERN int allocatedBSPBrushSides Q_ASSIGN( 0 );
 Q_EXTERN bspBrushSide_t*    bspBrushSides Q_ASSIGN( NULL );
 
-Q_EXTERN int                           numBSPLightBytes Q_ASSIGN( 0 );
-Q_EXTERN byte                          *bspLightBytes Q_ASSIGN( NULL );
+Q_EXTERN int numBSPLightBytes Q_ASSIGN( 0 );
+Q_EXTERN byte               *bspLightBytes Q_ASSIGN( NULL );
 
 //%    Q_EXTERN int                            numBSPGridPoints Q_ASSIGN( 0 );
 //%    Q_EXTERN byte                           *bspGridPoints Q_ASSIGN( NULL );
 
-Q_EXTERN int                           numBSPGridPoints Q_ASSIGN( 0 );
-Q_EXTERN bspGridPoint_t                *bspGridPoints Q_ASSIGN( NULL );
+Q_EXTERN int numBSPGridPoints Q_ASSIGN( 0 );
+Q_EXTERN bspGridPoint_t     *bspGridPoints Q_ASSIGN( NULL );
 
-Q_EXTERN int                           numBSPVisBytes Q_ASSIGN( 0 );
-Q_EXTERN byte                          bspVisBytes[ MAX_MAP_VISIBILITY ];
+Q_EXTERN int numBSPVisBytes Q_ASSIGN( 0 );
+Q_EXTERN byte bspVisBytes[ MAX_MAP_VISIBILITY ];
 
-Q_EXTERN int                           numBSPDrawVerts Q_ASSIGN( 0 );
-Q_EXTERN bspDrawVert_t         *bspDrawVerts Q_ASSIGN( NULL );
+Q_EXTERN int numBSPDrawVerts Q_ASSIGN( 0 );
+Q_EXTERN bspDrawVert_t          *bspDrawVerts Q_ASSIGN( NULL );
 
-Q_EXTERN int                           numBSPDrawIndexes Q_ASSIGN( 0 );
+Q_EXTERN int numBSPDrawIndexes Q_ASSIGN( 0 );
 Q_EXTERN int allocatedBSPDrawIndexes Q_ASSIGN( 0 );
 Q_EXTERN int                *bspDrawIndexes Q_ASSIGN( NULL );
 
-Q_EXTERN int                           numBSPDrawSurfaces Q_ASSIGN( 0 );
-Q_EXTERN bspDrawSurface_t      *bspDrawSurfaces Q_ASSIGN( NULL );
+Q_EXTERN int numBSPDrawSurfaces Q_ASSIGN( 0 );
+Q_EXTERN bspDrawSurface_t   *bspDrawSurfaces Q_ASSIGN( NULL );
 
-Q_EXTERN int                           numBSPFogs Q_ASSIGN( 0 );
-Q_EXTERN bspFog_t                      bspFogs[ MAX_MAP_FOGS ];
+Q_EXTERN int numBSPFogs Q_ASSIGN( 0 );
+Q_EXTERN bspFog_t bspFogs[ MAX_MAP_FOGS ];
 
-Q_EXTERN int                           numBSPAds Q_ASSIGN( 0 );
-Q_EXTERN bspAdvertisement_t    bspAds[ MAX_MAP_ADVERTISEMENTS ];
+Q_EXTERN int numBSPAds Q_ASSIGN( 0 );
+Q_EXTERN bspAdvertisement_t bspAds[ MAX_MAP_ADVERTISEMENTS ];
 
 #define AUTOEXPAND_BY_REALLOC( ptr, reqitem, allocated, def ) \
        do \
@@ -2545,7 +2545,7 @@ Q_EXTERN bspAdvertisement_t       bspAds[ MAX_MAP_ADVERTISEMENTS ];
                        if ( allocated == 0 ) { \
                                allocated = def; } \
                        while ( reqitem >= allocated && allocated )     \
-                               allocated *= 2; \
+                               allocated *= 2; \
                        if ( !allocated || allocated > 2147483647 / (int)sizeof( *ptr ) ) \
                        { \
                                Error( # ptr " over 2 GB" ); \
index 7d990bb626ce549e3824fce1404fc7ba543caf48..0e2a25d04cf308be3f6349b442ee74c3f261dc93 100644 (file)
  */
 
 mapDrawSurface_t *AllocDrawSurface( surfaceType_t type ){
-       mapDrawSurface_t        *ds;
-       
-       
+       mapDrawSurface_t    *ds;
+
+
        /* ydnar: gs mods: only allocate valid types */
        if ( type <= SURFACE_BAD || type >= NUM_SURFACE_TYPES ) {
                Error( "AllocDrawSurface: Invalid surface type %d specified", type );
        }
-       
+
        /* bounds check */
        if ( numMapDrawSurfs >= MAX_MAP_DRAW_SURFS ) {
                Error( "MAX_MAP_DRAW_SURFS (%d) exceeded", MAX_MAP_DRAW_SURFS );
        }
        ds = &mapDrawSurfs[ numMapDrawSurfs ];
        numMapDrawSurfs++;
-       
+
        /* ydnar: do initial surface setup */
        memset( ds, 0, sizeof( mapDrawSurface_t ) );
        ds->type = type;
        ds->planeNum = -1;
-       ds->fogNum = defaultFogNum;                             /* ydnar 2003-02-12 */
-       ds->outputNum = -1;                                             /* ydnar 2002-08-13 */
-       ds->surfaceNum = numMapDrawSurfs - 1;   /* ydnar 2003-02-16 */
-       
+       ds->fogNum = defaultFogNum;             /* ydnar 2003-02-12 */
+       ds->outputNum = -1;                     /* ydnar 2002-08-13 */
+       ds->surfaceNum = numMapDrawSurfs - 1;   /* ydnar 2003-02-16 */
+
        return ds;
 }
 
@@ -78,29 +78,29 @@ mapDrawSurface_t *AllocDrawSurface( surfaceType_t type ){
  */
 
 void FinishSurface( mapDrawSurface_t *ds ){
-       mapDrawSurface_t        *ds2;
-       
-       
+       mapDrawSurface_t    *ds2;
+
+
        /* dummy check */
        if ( ds->type <= SURFACE_BAD || ds->type >= NUM_SURFACE_TYPES || ds == NULL || ds->shaderInfo == NULL ) {
                return;
        }
-       
+
        /* ydnar: rocking tek-fu celshading */
        if ( ds->celShader != NULL ) {
                MakeCelSurface( ds, ds->celShader );
        }
-       
+
        /* backsides stop here */
        if ( ds->backSide ) {
                return;
        }
-       
+
        /* ydnar: rocking surface cloning (fur baby yeah!) */
        if ( ds->shaderInfo->cloneShader != NULL && ds->shaderInfo->cloneShader[ 0 ] != '\0' ) {
                CloneSurface( ds, ShaderInfoForShader( ds->shaderInfo->cloneShader ) );
        }
-       
+
        /* ydnar: q3map_backShader support */
        if ( ds->shaderInfo->backShader != NULL && ds->shaderInfo->backShader[ 0 ] != '\0' ) {
                ds2 = CloneSurface( ds, ShaderInfoForShader( ds->shaderInfo->backShader ) );
@@ -116,42 +116,42 @@ void FinishSurface( mapDrawSurface_t *ds ){
  */
 
 mapDrawSurface_t *CloneSurface( mapDrawSurface_t *src, shaderInfo_t *si ){
-       mapDrawSurface_t        *ds;
-       
-       
+       mapDrawSurface_t    *ds;
+
+
        /* dummy check */
        if ( src == NULL || si == NULL ) {
                return NULL;
        }
-       
+
        /* allocate a new surface */
        ds = AllocDrawSurface( src->type );
        if ( ds == NULL ) {
                return NULL;
        }
-       
+
        /* copy it */
        memcpy( ds, src, sizeof( *ds ) );
-       
+
        /* destroy side reference */
        ds->sideRef = NULL;
-       
+
        /* set shader */
        ds->shaderInfo = si;
-       
+
        /* copy verts */
        if ( ds->numVerts > 0 ) {
                ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
                memcpy( ds->verts, src->verts, ds->numVerts * sizeof( *ds->verts ) );
        }
-       
+
        /* copy indexes */
        if ( ds->numIndexes <= 0 ) {
                return ds;
        }
        ds->indexes = safe_malloc( ds->numIndexes * sizeof( *ds->indexes ) );
        memcpy( ds->indexes, src->indexes, ds->numIndexes * sizeof( *ds->indexes ) );
-       
+
        /* return the surface */
        return ds;
 }
@@ -164,31 +164,31 @@ mapDrawSurface_t *CloneSurface( mapDrawSurface_t *src, shaderInfo_t *si ){
  */
 
 mapDrawSurface_t *MakeCelSurface( mapDrawSurface_t *src, shaderInfo_t *si ){
-       mapDrawSurface_t        *ds;
-       
-       
+       mapDrawSurface_t    *ds;
+
+
        /* dummy check */
        if ( src == NULL || si == NULL ) {
                return NULL;
        }
-       
+
        /* don't create cel surfaces for certain types of shaders */
        if ( ( src->shaderInfo->compileFlags & C_TRANSLUCENT ) ||
                 ( src->shaderInfo->compileFlags & C_SKY ) ) {
                return NULL;
        }
-       
+
        /* make a copy */
        ds = CloneSurface( src, si );
        if ( ds == NULL ) {
                return NULL;
        }
-       
+
        /* do some fixups for celshading */
        ds->planar = qfalse;
        ds->planeNum = -1;
        ds->celShader = NULL; /* don't cel shade cels :P */
-       
+
        /* return the surface */
        return ds;
 }
@@ -201,37 +201,37 @@ mapDrawSurface_t *MakeCelSurface( mapDrawSurface_t *src, shaderInfo_t *si ){
  */
 
 mapDrawSurface_t *MakeSkyboxSurface( mapDrawSurface_t *src ){
-       int                                     i;
-       mapDrawSurface_t        *ds;
-       
-       
+       int i;
+       mapDrawSurface_t    *ds;
+
+
        /* dummy check */
        if ( src == NULL ) {
                return NULL;
        }
-       
+
        /* make a copy */
        ds = CloneSurface( src, src->shaderInfo );
        if ( ds == NULL ) {
                return NULL;
        }
-       
+
        /* set parent */
        ds->parent = src;
-       
+
        /* scale the surface vertexes */
        for ( i = 0; i < ds->numVerts; i++ )
        {
                m4x4_transform_point( skyboxTransform, ds->verts[ i ].xyz );
-               
+
                /* debug code */
                //%     bspDrawVerts[ bspDrawSurfaces[ ds->outputNum ].firstVert + i ].color[ 0 ][ 1 ] = 0;
                //%     bspDrawVerts[ bspDrawSurfaces[ ds->outputNum ].firstVert + i ].color[ 0 ][ 2 ] = 0;
        }
-       
+
        /* so backface culling creep doesn't bork the surface */
        VectorClear( ds->lightmapVecs[ 2 ] );
-       
+
        /* return the surface */
        return ds;
 }
@@ -243,24 +243,24 @@ mapDrawSurface_t *MakeSkyboxSurface( mapDrawSurface_t *src ){
    returns qtrue if all three points are colinear, backwards, or the triangle is just plain bogus
  */
 
-#define        TINY_AREA       1.0f
+#define TINY_AREA   1.0f
 
 qboolean IsTriangleDegenerate( bspDrawVert_t *points, int a, int b, int c ){
-       vec3_t          v1, v2, v3;
-       float           d;
-       
-       
+       vec3_t v1, v2, v3;
+       float d;
+
+
        /* calcuate the area of the triangle */
        VectorSubtract( points[ b ].xyz, points[ a ].xyz, v1 );
        VectorSubtract( points[ c ].xyz, points[ a ].xyz, v2 );
        CrossProduct( v1, v2, v3 );
        d = VectorLength( v3 );
-       
+
        /* assume all very small or backwards triangles will cause problems */
        if ( d < TINY_AREA ) {
                return qtrue;
        }
-       
+
        /* must be a good triangle */
        return qfalse;
 }
@@ -297,46 +297,46 @@ void ClearSurface( mapDrawSurface_t *ds ){
  */
 
 void TidyEntitySurfaces( entity_t *e ){
-       int                                     i, j, deleted;
-       mapDrawSurface_t        *out, *in = NULL;
-       
-       
+       int i, j, deleted;
+       mapDrawSurface_t    *out, *in = NULL;
+
+
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- TidyEntitySurfaces ---\n" );
-       
+
        /* walk the surface list */
        deleted = 0;
        for ( i = e->firstDrawSurf, j = e->firstDrawSurf; j < numMapDrawSurfs; i++, j++ )
        {
                /* get out surface */
                out = &mapDrawSurfs[ i ];
-               
+
                /* walk the surface list again until a proper surface is found */
                for ( ; j < numMapDrawSurfs; j++ )
                {
                        /* get in surface */
                        in = &mapDrawSurfs[ j ];
-                       
+
                        /* this surface ok? */
                        if ( in->type == SURFACE_FLARE || in->type == SURFACE_SHADER ||
                                 ( in->type != SURFACE_BAD && in->numVerts > 0 ) ) {
                                break;
                        }
-                       
+
                        /* nuke it */
                        ClearSurface( in );
                        deleted++;
                }
-               
+
                /* copy if necessary */
                if ( i != j ) {
                        memcpy( out, in, sizeof( mapDrawSurface_t ) );
+               }
        }
-       }
-       
+
        /* set the new number of drawsurfs */
        numMapDrawSurfs = i;
-       
+
        /* emit some stats */
        Sys_FPrintf( SYS_VRB, "%9d empty or malformed surfaces deleted\n", deleted );
 }
@@ -349,15 +349,15 @@ void TidyEntitySurfaces( entity_t *e ){
  */
 
 qboolean CalcSurfaceTextureRange( mapDrawSurface_t *ds ){
-       int             i, j, v, size[ 2 ];
-       float   mins[ 2 ], maxs[ 2 ];
-       
-       
+       int i, j, v, size[ 2 ];
+       float mins[ 2 ], maxs[ 2 ];
+
+
        /* try to early out */
        if ( ds->numVerts <= 0 ) {
                return qtrue;
        }
-       
+
        /* walk the verts and determine min/max st values */
        mins[ 0 ] = 999999;
        mins[ 1 ] = 999999;
@@ -372,14 +372,14 @@ qboolean CalcSurfaceTextureRange( mapDrawSurface_t *ds ){
                        }
                        if ( ds->verts[ i ].st[ j ] > maxs[ j ] ) {
                                maxs[ j ] = ds->verts[ i ].st[ j ];
+                       }
                }
        }
-       }
-       
+
        /* clamp to integer range and calculate surface bias values */
        for ( j = 0; j < 2; j++ )
                ds->bias[ j ] = -floor( 0.5f * ( mins[ j ] + maxs[ j ] ) );
-       
+
        /* find biased texture coordinate mins/maxs */
        size[ 0 ] = ds->shaderInfo->shaderWidth;
        size[ 1 ] = ds->shaderInfo->shaderHeight;
@@ -397,27 +397,27 @@ qboolean CalcSurfaceTextureRange( mapDrawSurface_t *ds ){
                        }
                        if ( v > ds->texMaxs[ j ] ) {
                                ds->texMaxs[ j ] = v;
+                       }
                }
        }
-       }
-       
+
        /* calc ranges */
        for ( j = 0; j < 2; j++ )
                ds->texRange[ j ] = ( ds->texMaxs[ j ] - ds->texMins[ j ] );
-       
+
        /* if range is zero, then assume unlimited precision */
        if ( texRange == 0 ) {
                return qtrue;
        }
-       
+
        /* within range? */
        for ( j = 0; j < 2; j++ )
        {
                if ( ds->texMins[ j ] < -texRange || ds->texMaxs[ j ] > texRange ) {
                        return qfalse;
+               }
        }
-       }
-       
+
        /* within range */
        return qtrue;
 }
@@ -430,20 +430,20 @@ qboolean CalcSurfaceTextureRange( mapDrawSurface_t *ds ){
  */
 
 qboolean CalcLightmapAxis( vec3_t normal, vec3_t axis ){
-       vec3_t  absolute;
-               
-       
+       vec3_t absolute;
+
+
        /* test */
        if ( normal[ 0 ] == 0.0f && normal[ 1 ] == 0.0f && normal[ 2 ] == 0.0f ) {
                VectorClear( axis );
                return qfalse;
        }
-       
+
        /* get absolute normal */
        absolute[ 0 ] = fabs( normal[ 0 ] );
        absolute[ 1 ] = fabs( normal[ 1 ] );
        absolute[ 2 ] = fabs( normal[ 2 ] );
-       
+
        /* test and set */
        if ( absolute[ 2 ] > absolute[ 0 ] - 0.0001f && absolute[ 2 ] > absolute[ 1 ] - 0.0001f ) {
                if ( normal[ 2 ] > 0.0f ) {
@@ -451,7 +451,7 @@ qboolean CalcLightmapAxis( vec3_t normal, vec3_t axis ){
                }
                else{
                        VectorSet( axis, 0.0f, 0.0f, -1.0f );
-       }
+               }
        }
        else if ( absolute[ 0 ] > absolute[ 1 ] - 0.0001f && absolute[ 0 ] > absolute[ 2 ] - 0.0001f ) {
                if ( normal[ 0 ] > 0.0f ) {
@@ -459,7 +459,7 @@ qboolean CalcLightmapAxis( vec3_t normal, vec3_t axis ){
                }
                else{
                        VectorSet( axis, -1.0f, 0.0f, 0.0f );
-       }
+               }
        }
        else
        {
@@ -468,9 +468,9 @@ qboolean CalcLightmapAxis( vec3_t normal, vec3_t axis ){
                }
                else{
                        VectorSet( axis, 0.0f, -1.0f, 0.0f );
+               }
        }
-       }
-       
+
        /* return ok */
        return qtrue;
 }
@@ -482,24 +482,24 @@ qboolean CalcLightmapAxis( vec3_t normal, vec3_t axis ){
    fills out a bunch of info in the surfaces, including planar status, lightmap projection, and bounding box
  */
 
-#define PLANAR_EPSILON 0.5f    //% 0.126f 0.25f
+#define PLANAR_EPSILON  0.5f    //% 0.126f 0.25f
 
 void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ){
-       int                                     i, bestAxis;
-       float                           dist;
-       vec4_t                          plane;
-       shaderInfo_t            *si;
-       static vec3_t           axii[ 6 ] =
-                                               {
-                                                       { 0, 0, -1 },
-                                                       { 0, 0, 1 },
-                                                       { -1, 0, 0 },
-                                                       { 1, 0, 0 },
-                                                       { 0, -1, 0 },
-                                                       { 0, 1, 0 }
-                                               };
-       
-       
+       int i, bestAxis;
+       float dist;
+       vec4_t plane;
+       shaderInfo_t        *si;
+       static vec3_t axii[ 6 ] =
+       {
+               { 0, 0, -1 },
+               { 0, 0, 1 },
+               { -1, 0, 0 },
+               { 1, 0, 0 },
+               { 0, -1, 0 },
+               { 0, 1, 0 }
+       };
+
+
        /* walk the list of surfaces */
        for ( ; numSurfs > 0; numSurfs--, ds++ )
        {
@@ -507,42 +507,42 @@ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ){
                if ( ds->type == SURFACE_BAD || ds->numVerts <= 0 ) {
                        continue;
                }
-               
+
                /* get shader */
                si = ds->shaderInfo;
-               
+
                /* -----------------------------------------------------------------
                   force meta if vertex count is too high or shader requires it
                   ----------------------------------------------------------------- */
-               
+
                if ( ds->type != SURFACE_PATCH && ds->type != SURFACE_FACE ) {
                        if ( ds->numVerts > SHADER_MAX_VERTEXES ) {
                                ds->type = SURFACE_FORCED_META;
+                       }
                }
-               }
-               
+
                /* -----------------------------------------------------------------
-                  plane and bounding box classification 
+                  plane and bounding box classification
                   ----------------------------------------------------------------- */
-               
+
                /* set surface bounding box */
                ClearBounds( ds->mins, ds->maxs );
                for ( i = 0; i < ds->numVerts; i++ )
                        AddPointToBounds( ds->verts[ i ].xyz, ds->mins, ds->maxs );
-               
+
                /* try to get an existing plane */
                if ( ds->planeNum >= 0 ) {
                        VectorCopy( mapplanes[ ds->planeNum ].normal, plane );
                        plane[ 3 ] = mapplanes[ ds->planeNum ].dist;
                }
-               
+
                /* construct one from the first vert with a valid normal */
                else
                {
                        VectorClear( plane );
                        plane[ 3 ] = 0.0f;
                        for ( i = 0; i < ds->numVerts; i++ )
-                               {
+                       {
                                if ( ds->verts[ i ].normal[ 0 ] != 0.0f && ds->verts[ i ].normal[ 1 ] != 0.0f && ds->verts[ i ].normal[ 2 ] != 0.0f ) {
                                        VectorCopy( ds->verts[ i ].normal, plane );
                                        plane[ 3 ] = DotProduct( ds->verts[ i ].xyz, plane );
@@ -550,7 +550,7 @@ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ){
                                }
                        }
                }
-               
+
                /* test for bogus plane */
                if ( VectorLength( plane ) <= 0.0f ) {
                        ds->planar = qfalse;
@@ -560,7 +560,7 @@ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ){
                {
                        /* determine if surface is planar */
                        ds->planar = qtrue;
-                       
+
                        /* test each vert */
                        for ( i = 0; i < ds->numVerts; i++ )
                        {
@@ -577,7 +577,7 @@ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ){
                                }
                        }
                }
-               
+
                /* find map plane if necessary */
                if ( ds->planar ) {
                        if ( ds->planeNum < 0 ) {
@@ -592,11 +592,11 @@ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ){
                        //% if( ds->type == SURF_META || ds->type == SURF_FACE )
                        //%             Sys_Printf( "WARNING: Non-planar face (%d): %s\n", ds->planeNum, ds->shaderInfo->shader );
                }
-               
+
                /* -----------------------------------------------------------------
                   lightmap bounds and axis projection
                   ----------------------------------------------------------------- */
-               
+
                /* vertex lit surfaces don't need this information */
                if ( si->compileFlags & C_VERTEXLIT || ds->type == SURFACE_TRIANGLES ) {
                        VectorClear( ds->lightmapAxis );
@@ -604,7 +604,7 @@ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ){
                        ds->sampleSize = 0;
                        continue;
                }
-               
+
                /* the shader can specify an explicit lightmap axis */
                if ( si->lightmapAxis[ 0 ] || si->lightmapAxis[ 1 ] || si->lightmapAxis[ 2 ] ) {
                        VectorCopy( si->lightmapAxis, ds->lightmapAxis );
@@ -623,30 +623,30 @@ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ){
                                for ( i = 0; i < ds->numVerts && bestAxis < 6; i++ )
                                {
                                        //% Sys_Printf( "Comparing %1.3f %1.3f %1.3f to %1.3f %1.3f %1.3f\n",
-                                       //%     ds->verts[ i ].normal[ 0 ], ds->verts[ i ].normal[ 1 ], ds->verts[ i ].normal[ 2 ],
-                                       //%     axii[ bestAxis ][ 0 ], axii[ bestAxis ][ 1 ], axii[ bestAxis ][ 2 ] );
+                                       //%     ds->verts[ i ].normal[ 0 ], ds->verts[ i ].normal[ 1 ], ds->verts[ i ].normal[ 2 ],
+                                       //%     axii[ bestAxis ][ 0 ], axii[ bestAxis ][ 1 ], axii[ bestAxis ][ 2 ] );
                                        if ( DotProduct( ds->verts[ i ].normal, axii[ bestAxis ] ) < 0.25f ) { /* fixme: adjust this tolerance to taste */
                                                break;
+                                       }
                                }
-                               }
-                               
+
                                if ( i == ds->numVerts ) {
                                        break;
+                               }
                        }
-                       }
-                       
+
                        /* set axis if possible */
                        if ( bestAxis < 6 ) {
                                //% if( ds->type == SURFACE_PATCH )
-                               //%     Sys_Printf( "Mapped axis %d onto patch\n", bestAxis );
+                               //%     Sys_Printf( "Mapped axis %d onto patch\n", bestAxis );
                                VectorCopy( axii[ bestAxis ], ds->lightmapAxis );
                        }
-                       
+
                        /* debug code */
                        //% if( ds->type == SURFACE_PATCH )
-                       //%     Sys_Printf( "Failed to map axis %d onto patch\n", bestAxis );
+                       //%     Sys_Printf( "Failed to map axis %d onto patch\n", bestAxis );
                }
-               
+
                /* calculate lightmap sample size */
                if ( ds->shaderInfo->lightmapSampleSize > 0 ) { /* shader value overrides every other */
                        ds->sampleSize = ds->shaderInfo->lightmapSampleSize;
@@ -670,7 +670,7 @@ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ){
 
                if ( ds->sampleSize > 16384 ) { /* powers of 2 are preferred */
                        ds->sampleSize = 16384;
-       }
+               }
        }
 }
 
@@ -682,19 +682,19 @@ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ){
  */
 
 void ClassifyEntitySurfaces( entity_t *e ){
-       int             i;
-       
-       
+       int i;
+
+
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- ClassifyEntitySurfaces ---\n" );
-       
+
        /* walk the surface list */
        for ( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
        {
                FinishSurface( &mapDrawSurfs[ i ] );
                ClassifySurfaces( 1, &mapDrawSurfs[ i ] );
        }
-       
+
        /* tidy things up */
        TidyEntitySurfaces( e );
 }
@@ -707,75 +707,75 @@ void ClassifyEntitySurfaces( entity_t *e ){
  */
 
 byte GetShaderIndexForPoint( indexMap_t *im, vec3_t eMins, vec3_t eMaxs, vec3_t point ){
-       int                     i, x, y;
-       float           s, t;
-       vec3_t          mins, maxs, size;
-       
-       
+       int i, x, y;
+       float s, t;
+       vec3_t mins, maxs, size;
+
+
        /* early out if no indexmap */
        if ( im == NULL ) {
                return 0;
        }
-       
+
        /* this code is really broken */
        #if 0
-               /* legacy precision fudges for terrain */
+       /* legacy precision fudges for terrain */
        for ( i = 0; i < 3; i++ )
-               {
-                       mins[ i ] = floor( eMins[ i ] + 0.1 );
-                       maxs[ i ] = floor( eMaxs[ i ] + 0.1 );
-                       size[ i ] = maxs[ i ] - mins[ i ];
-               }
-               
-               /* find st (fixme: support more than just z-axis projection) */
-               s = floor( point[ 0 ] + 0.1f - mins[ 0 ] ) / size[ 0 ];
-               t = floor( maxs[ 1 ] - point[ 1 ] + 0.1f ) / size[ 1 ];
+       {
+               mins[ i ] = floor( eMins[ i ] + 0.1 );
+               maxs[ i ] = floor( eMaxs[ i ] + 0.1 );
+               size[ i ] = maxs[ i ] - mins[ i ];
+       }
+
+       /* find st (fixme: support more than just z-axis projection) */
+       s = floor( point[ 0 ] + 0.1f - mins[ 0 ] ) / size[ 0 ];
+       t = floor( maxs[ 1 ] - point[ 1 ] + 0.1f ) / size[ 1 ];
        if ( s < 0.0f ) {
-                       s = 0.0f;
+               s = 0.0f;
        }
        else if ( s > 1.0f ) {
-                       s = 1.0f;
+               s = 1.0f;
        }
        if ( t < 0.0f ) {
-                       t = 0.0f;
+               t = 0.0f;
        }
        else if ( t > 1.0f ) {
-                       t = 1.0f;
+               t = 1.0f;
        }
-               
-               /* make xy */
+
+       /* make xy */
        x = ( im->w - 1 ) * s;
        y = ( im->h - 1 ) * t;
        #else
-               /* get size */
+       /* get size */
        for ( i = 0; i < 3; i++ )
-               {
-                       mins[ i ] = eMins[ i ];
-                       maxs[ i ] = eMaxs[ i ];
-                       size[ i ] = maxs[ i ] - mins[ i ];
-               }
-               
-               /* calc st */
+       {
+               mins[ i ] = eMins[ i ];
+               maxs[ i ] = eMaxs[ i ];
+               size[ i ] = maxs[ i ] - mins[ i ];
+       }
+
+       /* calc st */
        s = ( point[ 0 ] - mins[ 0 ] ) / size[ 0 ];
        t = ( maxs[ 1 ] - point[ 1 ] ) / size[ 1 ];
-               
-               /* calc xy */
-               x = s * im->w;
-               y = t * im->h;
+
+       /* calc xy */
+       x = s * im->w;
+       y = t * im->h;
        if ( x < 0 ) {
-                       x = 0;
+               x = 0;
        }
        else if ( x > ( im->w - 1 ) ) {
                x = ( im->w - 1 );
        }
        if ( y < 0 ) {
-                       y = 0;
+               y = 0;
        }
        else if ( y > ( im->h - 1 ) ) {
                y = ( im->h - 1 );
        }
        #endif
-       
+
        /* return index */
        return im->pixels[ y * im->w + x ];
 }
@@ -789,17 +789,17 @@ byte GetShaderIndexForPoint( indexMap_t *im, vec3_t eMins, vec3_t eMaxs, vec3_t
  */
 
 shaderInfo_t *GetIndexedShader( shaderInfo_t *parent, indexMap_t *im, int numPoints, byte *shaderIndexes ){
-       int                             i;
-       byte                    minShaderIndex, maxShaderIndex;
-       char                    shader[ MAX_QPATH ];
-       shaderInfo_t    *si;
-       
-       
+       int i;
+       byte minShaderIndex, maxShaderIndex;
+       char shader[ MAX_QPATH ];
+       shaderInfo_t    *si;
+
+
        /* early out if bad data */
        if ( im == NULL || numPoints <= 0 || shaderIndexes == NULL ) {
                return ShaderInfoForShader( "default" );
        }
-       
+
        /* determine min/max index */
        minShaderIndex = 255;
        maxShaderIndex = 0;
@@ -810,9 +810,9 @@ shaderInfo_t *GetIndexedShader( shaderInfo_t *parent, indexMap_t *im, int numPoi
                }
                if ( shaderIndexes[ i ] > maxShaderIndex ) {
                        maxShaderIndex = shaderIndexes[ i ];
+               }
        }
-       }
-       
+
        /* set alpha inline */
        for ( i = 0; i < numPoints; i++ )
        {
@@ -822,9 +822,9 @@ shaderInfo_t *GetIndexedShader( shaderInfo_t *parent, indexMap_t *im, int numPoi
                }
                else{
                        shaderIndexes[ i ] = 255;
+               }
        }
-       }
-       
+
        /* make a shader name */
        if ( minShaderIndex == maxShaderIndex ) {
                sprintf( shader, "textures/%s_%d", im->shader, maxShaderIndex );
@@ -832,10 +832,10 @@ shaderInfo_t *GetIndexedShader( shaderInfo_t *parent, indexMap_t *im, int numPoi
        else{
                sprintf( shader, "textures/%s_%dto%d", im->shader, minShaderIndex, maxShaderIndex );
        }
-       
+
        /* get the shader */
        si = ShaderInfoForShader( shader );
-       
+
        /* inherit a few things from parent shader */
        if ( parent->globalTexture ) {
                si->globalTexture = qtrue;
@@ -859,7 +859,7 @@ shaderInfo_t *GetIndexedShader( shaderInfo_t *parent, indexMap_t *im, int numPoi
                /* set lightmap projection axis */
                VectorCopy( parent->lightmapAxis, si->lightmapAxis );
        }
-       
+
        /* return the shader */
        return si;
 }
@@ -872,41 +872,41 @@ shaderInfo_t *GetIndexedShader( shaderInfo_t *parent, indexMap_t *im, int numPoi
    creates a SURF_FACE drawsurface from a given brush side and winding
  */
 
-#define        SNAP_FLOAT_TO_INT       8
+#define SNAP_FLOAT_TO_INT   8
 #define SNAP_INT_TO_FLOAT   ( 1.0 / SNAP_FLOAT_TO_INT )
 
 mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, winding_t *w ){
-       int                                     i, j, k;
-       mapDrawSurface_t        *ds;
-       shaderInfo_t            *si, *parent;
-       bspDrawVert_t           *dv;
-       vec3_t                          texX, texY;
-       vec_t                           x, y;
-       vec3_t                          vTranslated;
-       qboolean                        indexed;
-       byte                            shaderIndexes[ 256 ];
-       float                           offsets[ 256 ];
-       char                            tempShader[ MAX_QPATH ];
-
-       
+       int i, j, k;
+       mapDrawSurface_t    *ds;
+       shaderInfo_t        *si, *parent;
+       bspDrawVert_t       *dv;
+       vec3_t texX, texY;
+       vec_t x, y;
+       vec3_t vTranslated;
+       qboolean indexed;
+       byte shaderIndexes[ 256 ];
+       float offsets[ 256 ];
+       char tempShader[ MAX_QPATH ];
+
+
        /* ydnar: don't make a drawsurf for culled sides */
        if ( s->culled ) {
                return NULL;
        }
-       
+
        /* range check */
        if ( w->numpoints > MAX_POINTS_ON_WINDING ) {
                Error( "DrawSurfaceForSide: w->numpoints = %d (> %d)", w->numpoints, MAX_POINTS_ON_WINDING );
        }
-       
+
        /* get shader */
        si = s->shaderInfo;
-       
+
        /* ydnar: gs mods: check for indexed shader */
        if ( si->indexed && b->im != NULL ) {
                /* indexed */
                indexed = qtrue;
-               
+
                /* get shader indexes for each point */
                for ( i = 0; i < w->numpoints; i++ )
                {
@@ -914,7 +914,7 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
                        offsets[ i ] = b->im->offsets[ shaderIndexes[ i ] ];
                        //%     Sys_Printf( "%f ", offsets[ i ] );
                }
-               
+
                /* get matching shader and set alpha */
                parent = si;
                si = GetIndexedShader( parent, b->im, w->numpoints, shaderIndexes );
@@ -922,7 +922,7 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
        else{
                indexed = qfalse;
        }
-       
+
        /* ydnar: sky hack/fix for GL_CLAMP borders on ati cards */
        if ( skyFixHack && si->skyParmsImageBase[ 0 ] != '\0' ) {
                //%     Sys_FPrintf( SYS_VRB, "Enabling sky hack for shader %s using env %s\n", si->shader, si->skyParmsImageBase );
@@ -939,17 +939,17 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
                sprintf( tempShader, "%s_dn", si->skyParmsImageBase );
                DrawSurfaceForShader( tempShader );
        }
-       
+
        /* ydnar: gs mods */
        ds = AllocDrawSurface( SURFACE_FACE );
        ds->entityNum = b->entityNum;
        ds->castShadows = b->castShadows;
        ds->recvShadows = b->recvShadows;
-       
+
        ds->planar = qtrue;
        ds->planeNum = s->planenum;
        VectorCopy( mapplanes[ s->planenum ].normal, ds->lightmapVecs[ 2 ] );
-       
+
        ds->shaderInfo = si;
        ds->mapBrush = b;
        ds->sideRef = AllocSideRef( s, NULL );
@@ -960,39 +960,39 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
        ds->numVerts = w->numpoints;
        ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
        memset( ds->verts, 0, ds->numVerts * sizeof( *ds->verts ) );
-       
+
        /* compute s/t coordinates from brush primitive texture matrix (compute axis base) */
        ComputeAxisBase( mapplanes[ s->planenum ].normal, texX, texY );
-       
+
        /* create the vertexes */
        for ( j = 0; j < w->numpoints; j++ )
        {
                /* get the drawvert */
                dv = ds->verts + j;
-               
+
                /* copy xyz and do potential z offset */
                VectorCopy( w->p[ j ], dv->xyz );
                if ( indexed ) {
                        dv->xyz[ 2 ] += offsets[ j ];
                }
-               
+
                /* round the xyz to a given precision and translate by origin */
                for ( i = 0 ; i < 3 ; i++ )
                        dv->xyz[ i ] = SNAP_INT_TO_FLOAT * floor( dv->xyz[ i ] * SNAP_FLOAT_TO_INT + 0.5f );
                VectorAdd( dv->xyz, e->origin, vTranslated );
-               
+
                /* ydnar: tek-fu celshading support for flat shaded shit */
                if ( flat ) {
                        dv->st[ 0 ] = si->stFlat[ 0 ];
                        dv->st[ 1 ] = si->stFlat[ 1 ];
                }
-               
+
                /* ydnar: gs mods: added support for explicit shader texcoord generation */
                else if ( si->tcGen ) {
                        dv->st[ 0 ] = DotProduct( si->vecs[ 0 ], vTranslated );
                        dv->st[ 1 ] = DotProduct( si->vecs[ 1 ], vTranslated );
                }
-               
+
                /* old quake-style texturing */
                else if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) {
                        /* nearest-axial projection */
@@ -1001,7 +1001,7 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
                        dv->st[ 0 ] /= si->shaderWidth;
                        dv->st[ 1 ] /= si->shaderHeight;
                }
-               
+
                /* brush primitive texturing */
                else
                {
@@ -1011,22 +1011,22 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
                        dv->st[ 0 ] = s->texMat[ 0 ][ 0 ] * x + s->texMat[ 0 ][ 1 ] * y + s->texMat[ 0 ][ 2 ];
                        dv->st[ 1 ] = s->texMat[ 1 ][ 0 ] * x + s->texMat[ 1 ][ 1 ] * y + s->texMat[ 1 ][ 2 ];
                }
-               
+
                /* copy normal */
                VectorCopy( mapplanes[ s->planenum ].normal, dv->normal );
-               
+
                /* ydnar: set color */
                for ( k = 0; k < MAX_LIGHTMAPS; k++ )
                {
                        dv->color[ k ][ 0 ] = 255;
                        dv->color[ k ][ 1 ] = 255;
                        dv->color[ k ][ 2 ] = 255;
-                       
+
                        /* ydnar: gs mods: handle indexed shader blending */
                        dv->color[ k ][ 3 ] = ( indexed ? shaderIndexes[ j ] : 255 );
                }
        }
-       
+
        /* set cel shader */
        ds->celShader = b->celShader;
 
@@ -1034,7 +1034,7 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
        if ( b->shadeAngleDegrees > 0.0f ) {
                ds->shadeAngleDegrees = b->shadeAngleDegrees;
        }
-       
+
        /* ydnar: gs mods: moved st biasing elsewhere */
        return ds;
 }
@@ -1049,9 +1049,9 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
 #define YDNAR_NORMAL_EPSILON 0.50f
 
 qboolean VectorCompareExt( vec3_t n1, vec3_t n2, float epsilon ){
-       int             i;
-       
-       
+       int i;
+
+
        /* test */
        for ( i = 0; i < 3; i++ )
                if ( fabs( n1[ i ] - n2[ i ] ) > epsilon ) {
@@ -1061,20 +1061,20 @@ qboolean VectorCompareExt( vec3_t n1, vec3_t n2, float epsilon ){
 }
 
 mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh ){
-       int                                     i, k, numVerts;
-       vec4_t                          plane;
-       qboolean                        planar;
-       float                           dist;
-       mapDrawSurface_t        *ds;
-       shaderInfo_t            *si, *parent;
-       bspDrawVert_t           *dv;
-       vec3_t                          vTranslated;
-       mesh_t                          *copy;
-       qboolean                        indexed;
-       byte                            shaderIndexes[ MAX_EXPANDED_AXIS * MAX_EXPANDED_AXIS ];
-       float                           offsets[ MAX_EXPANDED_AXIS * MAX_EXPANDED_AXIS ];
-       
-       
+       int i, k, numVerts;
+       vec4_t plane;
+       qboolean planar;
+       float dist;
+       mapDrawSurface_t    *ds;
+       shaderInfo_t        *si, *parent;
+       bspDrawVert_t       *dv;
+       vec3_t vTranslated;
+       mesh_t              *copy;
+       qboolean indexed;
+       byte shaderIndexes[ MAX_EXPANDED_AXIS * MAX_EXPANDED_AXIS ];
+       float offsets[ MAX_EXPANDED_AXIS * MAX_EXPANDED_AXIS ];
+
+
        /* get mesh and shader shader */
        if ( mesh == NULL ) {
                mesh = &p->mesh;
@@ -1083,22 +1083,22 @@ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh
        if ( mesh == NULL || si == NULL ) {
                return NULL;
        }
-       
+
        /* get vertex count */
        numVerts = mesh->width * mesh->height;
-       
+
        /* to make valid normals for patches with degenerate edges,
           we need to make a copy of the mesh and put the aproximating
           points onto the curve */
-       
+
        /* create a copy of the mesh */
        copy = CopyMesh( mesh );
-       
+
        /* store off the original (potentially bad) normals */
        MakeMeshNormals( *copy );
        for ( i = 0; i < numVerts; i++ )
                VectorCopy( copy->verts[ i ].normal, mesh->verts[ i ].normal );
-       
+
        /* put the mesh on the curve */
        PutMeshOnCurve( *copy );
 
@@ -1109,12 +1109,12 @@ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh
                /* ydnar: only copy normals that are significantly different from the originals */
                if ( DotProduct( copy->verts[ i ].normal, mesh->verts[ i ].normal ) < 0.75f ) {
                        VectorCopy( copy->verts[ i ].normal, mesh->verts[ i ].normal );
+               }
        }
-       }
-       
+
        /* free the old mesh */
        FreeMesh( copy );
-       
+
        /* ydnar: gs mods: check for indexed shader */
        if ( si->indexed && p->im != NULL ) {
                /* indexed */
@@ -1126,7 +1126,7 @@ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh
                        shaderIndexes[ i ] = GetShaderIndexForPoint( p->im, p->eMins, p->eMaxs, mesh->verts[ i ].xyz );
                        offsets[ i ] = p->im->offsets[ shaderIndexes[ i ] ];
                }
-               
+
                /* get matching shader and set alpha */
                parent = si;
                si = GetIndexedShader( parent, p->im, numVerts, shaderIndexes );
@@ -1134,41 +1134,41 @@ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh
        else{
                indexed = qfalse;
        }
-       
-       
+
+
        /* ydnar: gs mods */
        ds = AllocDrawSurface( SURFACE_PATCH );
        ds->entityNum = p->entityNum;
        ds->castShadows = p->castShadows;
        ds->recvShadows = p->recvShadows;
-       
+
        ds->shaderInfo = si;
        ds->mapMesh = p;
        ds->sampleSize = p->lightmapSampleSize;
-       ds->lightmapScale = p->lightmapScale;   /* ydnar */
+       ds->lightmapScale = p->lightmapScale;   /* ydnar */
        ds->colormod = p->colormod;
        ds->patchWidth = mesh->width;
        ds->patchHeight = mesh->height;
        ds->numVerts = ds->patchWidth * ds->patchHeight;
        ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
        memcpy( ds->verts, mesh->verts, ds->numVerts * sizeof( *ds->verts ) );
-       
+
        ds->fogNum = -1;
        ds->planeNum = -1;
-       
+
        ds->longestCurve = p->longestCurve;
        ds->maxIterations = p->maxIterations;
-       
+
        /* construct a plane from the first vert */
        VectorCopy( mesh->verts[ 0 ].normal, plane );
        plane[ 3 ] = DotProduct( mesh->verts[ 0 ].xyz, plane );
        planar = qtrue;
-       
+
        /* spew forth errors */
        if ( VectorLength( plane ) < 0.001f ) {
                Sys_Printf( "BOGUS " );
        }
-       
+
        /* test each vert */
        for ( i = 1; i < ds->numVerts && planar; i++ )
        {
@@ -1176,37 +1176,37 @@ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh
                if ( VectorCompare( plane, mesh->verts[ i ].normal ) == qfalse ) {
                        planar = qfalse;
                }
-               
+
                /* point-plane test */
                dist = DotProduct( mesh->verts[ i ].xyz, plane ) - plane[ 3 ];
                if ( fabs( dist ) > EQUAL_EPSILON ) {
                        planar = qfalse;
+               }
        }
-       }
-       
+
        /* add a map plane */
        if ( planar ) {
                /* make a map plane */
                ds->planeNum = FindFloatPlane( plane, plane[ 3 ], 1, &mesh->verts[ 0 ].xyz );
                VectorCopy( plane, ds->lightmapVecs[ 2 ] );
-               
+
                /* push this normal to all verts (ydnar 2003-02-14: bad idea, small patches get screwed up) */
                for ( i = 0; i < ds->numVerts; i++ )
                        VectorCopy( plane, ds->verts[ i ].normal );
        }
-       
+
        /* walk the verts to do special stuff */
        for ( i = 0; i < ds->numVerts; i++ )
        {
                /* get the drawvert */
                dv = &ds->verts[ i ];
-               
+
                /* ydnar: tek-fu celshading support for flat shaded shit */
                if ( flat ) {
                        dv->st[ 0 ] = si->stFlat[ 0 ];
                        dv->st[ 1 ] = si->stFlat[ 1 ];
                }
-               
+
                /* ydnar: gs mods: added support for explicit shader texcoord generation */
                else if ( si->tcGen ) {
                        /* translate by origin and project the texture */
@@ -1214,27 +1214,27 @@ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh
                        dv->st[ 0 ] = DotProduct( si->vecs[ 0 ], vTranslated );
                        dv->st[ 1 ] = DotProduct( si->vecs[ 1 ], vTranslated );
                }
-               
+
                /* ydnar: set color */
                for ( k = 0; k < MAX_LIGHTMAPS; k++ )
                {
                        dv->color[ k ][ 0 ] = 255;
                        dv->color[ k ][ 1 ] = 255;
                        dv->color[ k ][ 2 ] = 255;
-                       
+
                        /* ydnar: gs mods: handle indexed shader blending */
                        dv->color[ k ][ 3 ] = ( indexed ? shaderIndexes[ i ] : 255 );
                }
-               
+
                /* ydnar: offset */
                if ( indexed ) {
                        dv->xyz[ 2 ] += offsets[ i ];
+               }
        }
-       }
-       
+
        /* set cel shader */
        ds->celShader = p->celShader;
-       
+
        /* return the drawsurface */
        return ds;
 }
@@ -1247,18 +1247,18 @@ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh
  */
 
 mapDrawSurface_t *DrawSurfaceForFlare( int entNum, vec3_t origin, vec3_t normal, vec3_t color, const char *flareShader, int lightStyle ){
-       mapDrawSurface_t        *ds;
-       
-       
+       mapDrawSurface_t    *ds;
+
+
        /* emit flares? */
        if ( emitFlares == qfalse ) {
                return NULL;
        }
-       
+
        /* allocate drawsurface */
        ds = AllocDrawSurface( SURFACE_FLARE );
        ds->entityNum = entNum;
-       
+
        /* set it up */
        if ( flareShader != NULL && flareShader[ 0 ] != '\0' ) {
                ds->shaderInfo = ShaderInfoForShader( flareShader );
@@ -1275,15 +1275,15 @@ mapDrawSurface_t *DrawSurfaceForFlare( int entNum, vec3_t origin, vec3_t normal,
        if ( color != NULL ) {
                VectorCopy( color, ds->lightmapVecs[ 0 ] );
        }
-       
+
        /* store light style */
        ds->lightStyle = lightStyle;
        if ( ds->lightStyle < 0 || ds->lightStyle >= LS_NONE ) {
                ds->lightStyle = LS_NORMAL;
        }
-       
+
        /* fixme: fog */
-       
+
        /* return to sender */
        return ds;
 }
@@ -1296,11 +1296,11 @@ mapDrawSurface_t *DrawSurfaceForFlare( int entNum, vec3_t origin, vec3_t normal,
  */
 
 mapDrawSurface_t *DrawSurfaceForShader( char *shader ){
-       int                                     i;
-       shaderInfo_t            *si;
-       mapDrawSurface_t        *ds;
-       
-       
+       int i;
+       shaderInfo_t        *si;
+       mapDrawSurface_t    *ds;
+
+
        /* get shader */
        si = ShaderInfoForShader( shader );
 
@@ -1309,18 +1309,18 @@ mapDrawSurface_t *DrawSurfaceForShader( char *shader ){
        {
                /* get surface */
                ds = &mapDrawSurfs[ i ];
-               
+
                /* check it */
                if ( ds->shaderInfo == si ) {
                        return ds;
+               }
        }
-       }
-       
+
        /* create a new surface */
        ds = AllocDrawSurface( SURFACE_SHADER );
        ds->entityNum = 0;
        ds->shaderInfo = ShaderInfoForShader( shader );
-       
+
        /* return to sender */
        return ds;
 }
@@ -1333,10 +1333,10 @@ mapDrawSurface_t *DrawSurfaceForShader( char *shader ){
  */
 
 static void AddSurfaceFlare( mapDrawSurface_t *ds, vec3_t entityOrigin ){
-       vec3_t                          origin;
-       int                                     i;
-       
-       
+       vec3_t origin;
+       int i;
+
+
        /* find centroid */
        VectorClear( origin );
        for ( i = 0; i < ds->numVerts; i++ )
@@ -1345,10 +1345,10 @@ static void AddSurfaceFlare( mapDrawSurface_t *ds, vec3_t entityOrigin ){
        if ( entityOrigin != NULL ) {
                VectorAdd( origin, entityOrigin, origin );
        }
-       
+
        /* push origin off surface a bit */
        VectorMA( origin, 2.0f,  ds->lightmapVecs[ 2 ], origin );
-       
+
        /* create the drawsurface */
        DrawSurfaceForFlare( ds->entityNum, origin, ds->lightmapVecs[ 2 ], ds->shaderInfo->color, ds->shaderInfo->flareShader, ds->shaderInfo->lightStyle );
 }
@@ -1361,15 +1361,15 @@ static void AddSurfaceFlare( mapDrawSurface_t *ds, vec3_t entityOrigin ){
  */
 
 static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, winding_t *w, int fogNum, float subdivisions ){
-       int                                     i;
-       int                                     axis;
-       vec3_t                          bounds[ 2 ];
-       const float                     epsilon = 0.1;
-       int                                     subFloor, subCeil;
-       winding_t                       *frontWinding, *backWinding;
-       mapDrawSurface_t        *ds;
-       
-       
+       int i;
+       int axis;
+       vec3_t bounds[ 2 ];
+       const float epsilon = 0.1;
+       int subFloor, subCeil;
+       winding_t           *frontWinding, *backWinding;
+       mapDrawSurface_t    *ds;
+
+
        /* dummy check */
        if ( w == NULL ) {
                return;
@@ -1377,20 +1377,20 @@ static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, winding_
        if ( w->numpoints < 3 ) {
                Error( "SubdivideFace_r: Bad w->numpoints (%d < 3)", w->numpoints );
        }
-       
+
        /* determine surface bounds */
        ClearBounds( bounds[ 0 ], bounds[ 1 ] );
        for ( i = 0; i < w->numpoints; i++ )
                AddPointToBounds( w->p[ i ], bounds[ 0 ], bounds[ 1 ] );
-       
+
        /* split the face */
        for ( axis = 0; axis < 3; axis++ )
        {
-               vec3_t                  planePoint = { 0, 0, 0 };
-               vec3_t                  planeNormal = { 0, 0, 0 };
-               float                   d;
-               
-               
+               vec3_t planePoint = { 0, 0, 0 };
+               vec3_t planeNormal = { 0, 0, 0 };
+               float d;
+
+
                /* create an axial clipping plane */
                subFloor = floor( bounds[ 0 ][ axis ] / subdivisions ) * subdivisions;
                subCeil = ceil( bounds[ 1 ][ axis ] / subdivisions ) * subdivisions;
@@ -1418,10 +1418,10 @@ static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, winding_
                        }
                }
        }
-       
+
        /* create a face surface */
        ds = DrawSurfaceForSide( e, brush, side, w );
-       
+
        /* set correct fog num */
        ds->fogNum = fogNum;
 }
@@ -1435,18 +1435,18 @@ static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, winding_
  */
 
 void SubdivideFaceSurfaces( entity_t *e, tree_t *tree ){
-       int                                     i, j, numBaseDrawSurfs, fogNum;
-       mapDrawSurface_t        *ds;
-       brush_t                         *brush;
-       side_t                          *side;
-       shaderInfo_t            *si;
-       winding_t                       *w;
-       float                           range, size, subdivisions, s2;
-       
-       
+       int i, j, numBaseDrawSurfs, fogNum;
+       mapDrawSurface_t    *ds;
+       brush_t             *brush;
+       side_t              *side;
+       shaderInfo_t        *si;
+       winding_t           *w;
+       float range, size, subdivisions, s2;
+
+
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- SubdivideFaceSurfaces ---\n" );
-       
+
        /* walk the list of surfaces */
        numBaseDrawSurfs = numMapDrawSurfs;
        for ( i = e->firstDrawSurf; i < numBaseDrawSurfs; i++ )
@@ -1458,22 +1458,22 @@ void SubdivideFaceSurfaces( entity_t *e, tree_t *tree ){
                if ( ds->type != SURFACE_FACE || ds->mapBrush == NULL || ds->sideRef == NULL || ds->sideRef->side == NULL ) {
                        continue;
                }
-               
+
                /* get bits */
                brush = ds->mapBrush;
                side = ds->sideRef->side;
-               
+
                /* check subdivision for shader */
                si = side->shaderInfo;
                if ( si == NULL ) {
                        continue;
                }
-               
+
                /* ydnar: don't subdivide sky surfaces */
                if ( si->compileFlags & C_SKY ) {
                        continue;
                }
-               
+
                /* do texture coordinate range check */
                ClassifySurfaces( 1, ds );
                if ( CalcSurfaceTextureRange( ds ) == qfalse ) {
@@ -1498,7 +1498,7 @@ void SubdivideFaceSurfaces( entity_t *e, tree_t *tree ){
                else{
                        subdivisions = si->subdivisions;
                }
-               
+
                /* get subdivisions from shader */
                if ( si->subdivisions > 0 && si->subdivisions < subdivisions ) {
                        subdivisions = si->subdivisions;
@@ -1506,14 +1506,14 @@ void SubdivideFaceSurfaces( entity_t *e, tree_t *tree ){
                if ( subdivisions < 1.0f ) {
                        continue;
                }
-               
+
                /* preserve fog num */
                fogNum = ds->fogNum;
-               
+
                /* make a winding and free the surface */
                w = WindingFromDrawSurf( ds );
                ClearSurface( ds );
-               
+
                /* subdivide it */
                SubdivideFace_r( e, brush, side, w, fogNum, subdivisions );
        }
@@ -1530,8 +1530,8 @@ void SubdivideFaceSurfaces( entity_t *e, tree_t *tree ){
  */
 
 void ClipSideIntoTree_r( winding_t *w, side_t *side, node_t *node ){
-       plane_t                 *plane;
-       winding_t               *front, *back;
+       plane_t         *plane;
+       winding_t       *front, *back;
 
        if ( !w ) {
                return;
@@ -1588,9 +1588,9 @@ static int g_numHiddenFaces, g_numCoinFaces;
 #define CULL_EPSILON 0.1f
 
 qboolean CullVectorCompare( const vec3_t v1, const vec3_t v2 ){
-       int             i;
-       
-       
+       int i;
+
+
        for ( i = 0; i < 3; i++ )
                if ( fabs( v1[ i ] - v2[ i ] ) > CULL_EPSILON ) {
                        return qfalse;
@@ -1606,10 +1606,10 @@ qboolean CullVectorCompare( const vec3_t v1, const vec3_t v2 ){
  */
 
 qboolean SideInBrush( side_t *side, brush_t *b ){
-       int                     i, s;
-       plane_t         *plane;
-       
-       
+       int i, s;
+       plane_t     *plane;
+
+
        /* ignore sides w/o windings or shaders */
        if ( side->winding == NULL || side->shaderInfo == NULL ) {
                return qtrue;
@@ -1633,16 +1633,16 @@ qboolean SideInBrush( side_t *side, brush_t *b ){
                s = WindingOnPlaneSide( side->winding, plane->normal, plane->dist );
                if ( s == SIDE_FRONT || s == SIDE_CROSS ) {
                        return qfalse;
+               }
        }
-       }
-       
+
        /* don't cull autosprite or polygonoffset surfaces */
        if ( side->shaderInfo ) {
                if ( side->shaderInfo->autosprite || side->shaderInfo->polygonOffset ) {
                        return qfalse;
+               }
        }
-       }
-       
+
        /* inside */
        side->culled = qtrue;
        g_numHiddenFaces++;
@@ -1656,19 +1656,19 @@ qboolean SideInBrush( side_t *side, brush_t *b ){
  */
 
 void CullSides( entity_t *e ){
-       int                     numPoints;
-       int                     i, j, k, l, first, second, dir;
-       winding_t       *w1, *w2;
-       brush_t *b1, *b2;
-       side_t          *side1, *side2;
-       
-       
+       int numPoints;
+       int i, j, k, l, first, second, dir;
+       winding_t   *w1, *w2;
+       brush_t *b1, *b2;
+       side_t      *side1, *side2;
+
+
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- CullSides ---\n" );
-       
+
        g_numHiddenFaces = 0;
        g_numCoinFaces = 0;
-       
+
        /* brush interator 1 */
        for ( b1 = e->brushes; b1; b1 = b1->next )
        {
@@ -1684,12 +1684,12 @@ void CullSides( entity_t *e ){
                        if ( b2->numsides < 1 ) {
                                continue;
                        }
-                       
+
                        /* original check */
                        if ( b1->original == b2->original && b1->original != NULL ) {
                                continue;
                        }
-                       
+
                        /* bbox check */
                        j = 0;
                        for ( i = 0; i < 3; i++ )
@@ -1705,7 +1705,7 @@ void CullSides( entity_t *e ){
                                SideInBrush( &b1->sides[ i ], b2 );
                        for ( i = 0; i < b2->numsides; i++ )
                                SideInBrush( &b2->sides[ i ], b1 );
-                       
+
                        /* side iterator 1 */
                        for ( i = 0; i < b1->numsides; i++ )
                        {
@@ -1719,7 +1719,7 @@ void CullSides( entity_t *e ){
                                if ( side1->shaderInfo == NULL ) {
                                        continue;
                                }
-                               
+
                                /* side iterator 2 */
                                for ( j = 0; j < b2->numsides; j++ )
                                {
@@ -1738,12 +1738,12 @@ void CullSides( entity_t *e ){
                                        if ( side1->culled == qtrue && side2->culled == qtrue ) {
                                                continue;
                                        }
-                                       
+
                                        /* compare planes */
                                        if ( ( side1->planenum & ~0x00000001 ) != ( side2->planenum & ~0x00000001 ) ) {
                                                continue;
                                        }
-                                       
+
                                        /* get autosprite and polygonoffset status */
                                        if ( side1->shaderInfo &&
                                                 ( side1->shaderInfo->autosprite || side1->shaderInfo->polygonOffset ) ) {
@@ -1753,11 +1753,11 @@ void CullSides( entity_t *e ){
                                                 ( side2->shaderInfo->autosprite || side2->shaderInfo->polygonOffset ) ) {
                                                continue;
                                        }
-                                       
+
                                        /* find first common point */
                                        first = -1;
                                        for ( k = 0; k < numPoints; k++ )
-                                               {
+                                       {
                                                if ( VectorCompare( w1->p[ 0 ], w2->p[ k ] ) ) {
                                                        first = k;
                                                        k = numPoints;
@@ -1766,7 +1766,7 @@ void CullSides( entity_t *e ){
                                        if ( first == -1 ) {
                                                continue;
                                        }
-                                       
+
                                        /* find second common point (regardless of winding order) */
                                        second = -1;
                                        dir = 0;
@@ -1789,12 +1789,12 @@ void CullSides( entity_t *e ){
                                                }
                                                if ( CullVectorCompare( w1->p[ 1 ], w2->p[ second ] ) ) {
                                                        dir = -1;
-                                       }
+                                               }
                                        }
                                        if ( dir == 0 ) {
                                                continue;
                                        }
-                                       
+
                                        /* compare the rest of the points */
                                        l = first;
                                        for ( k = 0; k < numPoints; k++ )
@@ -1802,29 +1802,29 @@ void CullSides( entity_t *e ){
                                                if ( !CullVectorCompare( w1->p[ k ], w2->p[ l ] ) ) {
                                                        k = 100000;
                                                }
-                                               
+
                                                l += dir;
                                                if ( l < 0 ) {
                                                        l = numPoints - 1;
                                                }
                                                else if ( l >= numPoints ) {
                                                        l = 0;
-                                       }
+                                               }
                                        }
                                        if ( k >= 100000 ) {
                                                continue;
                                        }
-                                       
+
                                        /* cull face 1 */
                                        if ( !side2->culled && !( side2->compileFlags & C_TRANSLUCENT ) && !( side2->compileFlags & C_NODRAW ) ) {
                                                side1->culled = qtrue;
                                                g_numCoinFaces++;
                                        }
-                                       
+
                                        if ( side1->planenum == side2->planenum && side1->culled == qtrue ) {
                                                continue;
                                        }
-                                       
+
                                        /* cull face 2 */
                                        if ( !side1->culled && !( side1->compileFlags & C_TRANSLUCENT ) && !( side1->compileFlags & C_NODRAW ) ) {
                                                side2->culled = qtrue;
@@ -1834,7 +1834,7 @@ void CullSides( entity_t *e ){
                        }
                }
        }
-       
+
        /* emit some stats */
        Sys_FPrintf( SYS_VRB, "%9d hidden faces culled\n", g_numHiddenFaces );
        Sys_FPrintf( SYS_VRB, "%9d coincident faces culled\n", g_numCoinFaces );
@@ -1854,19 +1854,19 @@ void CullSides( entity_t *e ){
  */
 
 void ClipSidesIntoTree( entity_t *e, tree_t *tree ){
-       brush_t         *b;
-       int                             i;
-       winding_t               *w;
-       side_t                  *side, *newSide;
-       shaderInfo_t    *si;
-  
-       
+       brush_t     *b;
+       int i;
+       winding_t       *w;
+       side_t          *side, *newSide;
+       shaderInfo_t    *si;
+
+
        /* ydnar: cull brush sides */
        CullSides( e );
-       
+
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- ClipSidesIntoTree ---\n" );
-       
+
        /* walk the brush list */
        for ( b = e->brushes; b; b = b->next )
        {
@@ -1878,35 +1878,35 @@ void ClipSidesIntoTree( entity_t *e, tree_t *tree ){
                        if ( side->winding == NULL ) {
                                continue;
                        }
-                       
+
                        /* copy the winding */
                        w = CopyWinding( side->winding );
                        side->visibleHull = NULL;
                        ClipSideIntoTree_r( w, side, tree->headnode );
-                       
+
                        /* anything left? */
                        w = side->visibleHull;
                        if ( w == NULL ) {
                                continue;
                        }
-                       
+
                        /* shader? */
                        si = side->shaderInfo;
                        if ( si == NULL ) {
                                continue;
                        }
-                       
+
                        /* don't create faces for non-visible sides */
                        /* ydnar: except indexed shaders, like common/terrain and nodraw fog surfaces */
                        if ( ( si->compileFlags & C_NODRAW ) && si->indexed == qfalse && !( si->compileFlags & C_FOG ) ) {
                                continue;
                        }
-                       
+
                        /* always use the original winding for autosprites and noclip faces */
                        if ( si->autosprite || si->noClip ) {
                                w = side->winding;
                        }
-                       
+
                        /* save this winding as a visible surface */
                        DrawSurfaceForSide( e, b, side, w );
 
@@ -1914,14 +1914,14 @@ void ClipSidesIntoTree( entity_t *e, tree_t *tree ){
                        if ( !( si->compileFlags & C_FOG ) ) {
                                continue;
                        }
-                       
+
                        /* duplicate the up-facing side */
                        w = ReverseWinding( w );
                        newSide = safe_malloc( sizeof( *side ) );
                        *newSide = *side;
                        newSide->visibleHull = w;
                        newSide->planenum ^= 1;
-                       
+
                        /* save this winding as a visible surface */
                        DrawSurfaceForSide( e, b, newSide, w );
                }
@@ -1943,28 +1943,28 @@ void ClipSidesIntoTree( entity_t *e, tree_t *tree ){
  */
 
 int AddReferenceToLeaf( mapDrawSurface_t *ds, node_t *node ){
-       drawSurfRef_t   *dsr;
-       
-       
+       drawSurfRef_t   *dsr;
+
+
        /* dummy check */
        if ( node->planenum != PLANENUM_LEAF || node->opaque ) {
                return 0;
        }
-       
+
        /* try to find an existing reference */
        for ( dsr = node->drawSurfReferences; dsr; dsr = dsr->nextRef )
        {
                if ( dsr->outputNum == numBSPDrawSurfaces ) {
                        return 0;
+               }
        }
-       }
-       
+
        /* add a new reference */
        dsr = safe_malloc( sizeof( *dsr ) );
        dsr->outputNum = numBSPDrawSurfaces;
        dsr->nextRef = node->drawSurfReferences;
        node->drawSurfReferences = dsr;
-       
+
        /* ydnar: sky/skybox surfaces */
        if ( node->skybox ) {
                ds->skybox = qtrue;
@@ -1972,7 +1972,7 @@ int AddReferenceToLeaf( mapDrawSurface_t *ds, node_t *node ){
        if ( ds->shaderInfo->compileFlags & C_SKY ) {
                node->sky = qtrue;
        }
-       
+
        /* return */
        return 1;
 }
@@ -1985,14 +1985,14 @@ int AddReferenceToLeaf( mapDrawSurface_t *ds, node_t *node ){
  */
 
 int AddReferenceToTree_r( mapDrawSurface_t *ds, node_t *node, qboolean skybox ){
-       int             i, refs = 0;
-       
-       
+       int i, refs = 0;
+
+
        /* dummy check */
        if ( node == NULL ) {
                return 0;
        }
-       
+
        /* is this a decision node? */
        if ( node->planenum != PLANENUM_LEAF ) {
                /* add to child nodes and return */
@@ -2000,19 +2000,19 @@ int AddReferenceToTree_r( mapDrawSurface_t *ds, node_t *node, qboolean skybox ){
                refs += AddReferenceToTree_r( ds, node->children[ 1 ], skybox );
                return refs;
        }
-       
+
        /* ydnar */
        if ( skybox ) {
                /* skybox surfaces only get added to sky leaves */
                if ( !node->sky ) {
                        return 0;
                }
-               
+
                /* increase the leaf bounds */
                for ( i = 0; i < ds->numVerts; i++ )
                        AddPointToBounds( ds->verts[ i ].xyz, node->mins, node->maxs );
        }
-       
+
        /* add a reference */
        return AddReferenceToLeaf( ds, node );
 }
@@ -2025,17 +2025,17 @@ int AddReferenceToTree_r( mapDrawSurface_t *ds, node_t *node, qboolean skybox ){
  */
 
 int FilterPointIntoTree_r( vec3_t point, mapDrawSurface_t *ds, node_t *node ){
-       float                   d;
-       plane_t                 *plane;
-       int                             refs = 0;
-       
-       
+       float d;
+       plane_t         *plane;
+       int refs = 0;
+
+
        /* is this a decision node? */
        if ( node->planenum != PLANENUM_LEAF ) {
                /* classify the point in relation to the plane */
                plane = &mapplanes[ node->planenum ];
                d = DotProduct( point, plane->normal ) - plane->dist;
-               
+
                /* filter by this plane */
                refs = 0;
                if ( d >= -ON_EPSILON ) {
@@ -2044,11 +2044,11 @@ int FilterPointIntoTree_r( vec3_t point, mapDrawSurface_t *ds, node_t *node ){
                if ( d <= ON_EPSILON ) {
                        refs += FilterPointIntoTree_r( point, ds, node->children[ 1 ] );
                }
-               
+
                /* return */
                return refs;
        }
-       
+
        /* add a reference */
        return AddReferenceToLeaf( ds, node );
 }
@@ -2059,15 +2059,15 @@ int FilterPointIntoTree_r( vec3_t point, mapDrawSurface_t *ds, node_t *node ){
  */
 
 int FilterPointConvexHullIntoTree_r( vec3_t **points, int npoints, mapDrawSurface_t *ds, node_t *node ){
-       float                   d, dmin, dmax;
-       plane_t                 *plane;
-       int                             refs = 0;
-       int                             i;
+       float d, dmin, dmax;
+       plane_t         *plane;
+       int refs = 0;
+       int i;
 
        if ( !points ) {
                return 0;
        }
-       
+
        /* is this a decision node? */
        if ( node->planenum != PLANENUM_LEAF ) {
                /* classify the point in relation to the plane */
@@ -2082,9 +2082,9 @@ int FilterPointConvexHullIntoTree_r( vec3_t **points, int npoints, mapDrawSurfac
                        }
                        if ( d < dmin ) {
                                dmin = d;
+                       }
                }
-               }
-               
+
                /* filter by this plane */
                refs = 0;
                if ( dmax >= -ON_EPSILON ) {
@@ -2093,11 +2093,11 @@ int FilterPointConvexHullIntoTree_r( vec3_t **points, int npoints, mapDrawSurfac
                if ( dmin <= ON_EPSILON ) {
                        refs += FilterPointConvexHullIntoTree_r( points, npoints, ds, node->children[ 1 ] );
                }
-               
+
                /* return */
                return refs;
        }
-       
+
        /* add a reference */
        return AddReferenceToLeaf( ds, node );
 }
@@ -2109,20 +2109,20 @@ int FilterPointConvexHullIntoTree_r( vec3_t **points, int npoints, mapDrawSurfac
  */
 
 int FilterWindingIntoTree_r( winding_t *w, mapDrawSurface_t *ds, node_t *node ){
-       int                             i, refs = 0;
-       plane_t                 *p1, *p2;
+       int i, refs = 0;
+       plane_t         *p1, *p2;
        vec4_t plane1, plane2;
-       winding_t               *fat, *front, *back;
-       shaderInfo_t    *si;
-       
-       
+       winding_t       *fat, *front, *back;
+       shaderInfo_t    *si;
+
+
        /* get shaderinfo */
        si = ds->shaderInfo;
-       
+
        /* ydnar: is this the head node? */
        if ( node->parent == NULL && si != NULL &&
                 ( si->mins[ 0 ] != 0.0f || si->maxs[ 0 ] != 0.0f ||
-               si->mins[ 1 ] != 0.0f || si->maxs[ 1 ] != 0.0f ||
+                  si->mins[ 1 ] != 0.0f || si->maxs[ 1 ] != 0.0f ||
                   si->mins[ 2 ] != 0.0f || si->maxs[ 2 ] != 0.0f ) ) {
                static qboolean warned = qfalse;
                if ( !warned ) {
@@ -2151,56 +2151,56 @@ int FilterWindingIntoTree_r( winding_t *w, mapDrawSurface_t *ds, node_t *node ){
                 * added to the three sub-windings, the fattening at least doesn't make
                 * it worse
                 */
-               
+
                FreeWinding( w );
                w = fat;
        }
-       
+
        /* is this a decision node? */
        if ( node->planenum != PLANENUM_LEAF ) {
                /* get node plane */
                p1 = &mapplanes[ node->planenum ];
                VectorCopy( p1->normal, plane1 );
                plane1[ 3 ] = p1->dist;
-               
+
                /* check if surface is planar */
                if ( ds->planeNum >= 0 ) {
                        /* get surface plane */
                        p2 = &mapplanes[ ds->planeNum ];
                        VectorCopy( p2->normal, plane2 );
                        plane2[ 3 ] = p2->dist;
-                       
+
                        #if 0
                        /* div0: this is the plague (inaccurate) */
                        vec4_t reverse;
 
-                               /* invert surface plane */
-                               VectorSubtract( vec3_origin, plane2, reverse );
-                               reverse[ 3 ] = -plane2[ 3 ];
-                               
-                               /* compare planes */
+                       /* invert surface plane */
+                       VectorSubtract( vec3_origin, plane2, reverse );
+                       reverse[ 3 ] = -plane2[ 3 ];
+
+                       /* compare planes */
                        if ( DotProduct( plane1, plane2 ) > 0.999f && fabs( plane1[ 3 ] - plane2[ 3 ] ) < 0.001f ) {
-                                       return FilterWindingIntoTree_r( w, ds, node->children[ 0 ] );
+                               return FilterWindingIntoTree_r( w, ds, node->children[ 0 ] );
                        }
                        if ( DotProduct( plane1, reverse ) > 0.999f && fabs( plane1[ 3 ] - reverse[ 3 ] ) < 0.001f ) {
-                                       return FilterWindingIntoTree_r( w, ds, node->children[ 1 ] );
+                               return FilterWindingIntoTree_r( w, ds, node->children[ 1 ] );
                        }
                        #else
                        /* div0: this is the cholera (doesn't hit enough) */
 
-                               /* the drawsurf might have an associated plane, if so, force a filter here */
+                       /* the drawsurf might have an associated plane, if so, force a filter here */
                        if ( ds->planeNum == node->planenum ) {
-                                       return FilterWindingIntoTree_r( w, ds, node->children[ 0 ] );
+                               return FilterWindingIntoTree_r( w, ds, node->children[ 0 ] );
                        }
                        if ( ds->planeNum == ( node->planenum ^ 1 ) ) {
-                                       return FilterWindingIntoTree_r( w, ds, node->children[ 1 ] );
+                               return FilterWindingIntoTree_r( w, ds, node->children[ 1 ] );
                        }
                        #endif
                }
-               
+
                /* clip the winding by this plane */
                ClipWindingEpsilonStrict( w, plane1, plane1[ 3 ], ON_EPSILON, &front, &back ); /* strict; we handle the "winding disappeared" case */
-               
+
                /* filter by this plane */
                refs = 0;
                if ( front == NULL && back == NULL ) {
@@ -2216,11 +2216,11 @@ int FilterWindingIntoTree_r( winding_t *w, mapDrawSurface_t *ds, node_t *node ){
                        refs += FilterWindingIntoTree_r( back, ds, node->children[ 1 ] );
                }
                FreeWinding( w );
-               
+
                /* return */
                return refs;
        }
-       
+
        /* add a reference */
        return AddReferenceToLeaf( ds, node );
 }
@@ -2233,14 +2233,14 @@ int FilterWindingIntoTree_r( winding_t *w, mapDrawSurface_t *ds, node_t *node ){
  */
 
 int FilterFaceIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
-       winding_t       *w;
-       int                     refs = 0;
-       
-       
+       winding_t   *w;
+       int refs = 0;
+
+
        /* make a winding and filter it into the tree */
        w = WindingFromDrawSurf( ds );
        refs = FilterWindingIntoTree_r( w, ds, tree->headnode );
-       
+
        /* return */
        return refs;
 }
@@ -2252,11 +2252,11 @@ int FilterFaceIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
    subdivides a patch into an approximate curve and filters it into the tree
  */
 
-#define        FILTER_SUBDIVISION              8
+#define FILTER_SUBDIVISION      8
 
 static int FilterPatchIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
-       int                                     x, y, refs = 0;
-       
+       int x, y, refs = 0;
+
        for ( y = 0; y + 2 < ds->patchHeight; y += 2 )
                for ( x = 0; x + 2 < ds->patchWidth; x += 2 )
                {
@@ -2284,21 +2284,21 @@ static int FilterPatchIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
  */
 
 static int FilterTrianglesIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
-       int                     i, refs;
-       winding_t       *w;
-       
-       
+       int i, refs;
+       winding_t   *w;
+
+
        /* ydnar: gs mods: this was creating bogus triangles before */
        refs = 0;
        for ( i = 0; i < ds->numIndexes; i += 3 )
        {
                /* error check */
                if ( ds->indexes[ i ] >= ds->numVerts ||
-                       ds->indexes[ i + 1 ] >= ds->numVerts ||
+                        ds->indexes[ i + 1 ] >= ds->numVerts ||
                         ds->indexes[ i + 2 ] >= ds->numVerts ) {
                        Error( "Index %d greater than vertex count %d", ds->indexes[ i ], ds->numVerts );
                }
-               
+
                /* make a triangle winding and filter it into the tree */
                w = AllocWinding( 3 );
                w->numpoints = 3;
@@ -2307,7 +2307,7 @@ static int FilterTrianglesIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
                VectorCopy( ds->verts[ ds->indexes[ i + 2 ] ].xyz, w->p[ 2 ] );
                refs += FilterWindingIntoTree_r( w, ds, tree->headnode );
        }
-       
+
        /* use point filtering as well */
        for ( i = 0; i < ds->numVerts; i++ )
                refs += FilterPointIntoTree_r( ds->verts[ i ].xyz, ds, tree->headnode );
@@ -2323,29 +2323,29 @@ static int FilterTrianglesIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
  */
 
 static int FilterFoliageIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
-       int                             f, i, refs;
-       bspDrawVert_t   *instance;
-       vec3_t                  xyz;
-       winding_t               *w;
-       
-       
+       int f, i, refs;
+       bspDrawVert_t   *instance;
+       vec3_t xyz;
+       winding_t       *w;
+
+
        /* walk origin list */
        refs = 0;
        for ( f = 0; f < ds->numFoliageInstances; f++ )
        {
                /* get instance */
                instance = ds->verts + ds->patchHeight + f;
-               
+
                /* walk triangle list */
                for ( i = 0; i < ds->numIndexes; i += 3 )
                {
                        /* error check */
                        if ( ds->indexes[ i ] >= ds->numVerts ||
-                               ds->indexes[ i + 1 ] >= ds->numVerts ||
+                                ds->indexes[ i + 1 ] >= ds->numVerts ||
                                 ds->indexes[ i + 2 ] >= ds->numVerts ) {
                                Error( "Index %d greater than vertex count %d", ds->indexes[ i ], ds->numVerts );
                        }
-                       
+
                        /* make a triangle winding and filter it into the tree */
                        w = AllocWinding( 3 );
                        w->numpoints = 3;
@@ -2354,7 +2354,7 @@ static int FilterFoliageIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
                        VectorAdd( instance->xyz, ds->verts[ ds->indexes[ i + 2 ] ].xyz, w->p[ 2 ] );
                        refs += FilterWindingIntoTree_r( w, ds, tree->headnode );
                }
-               
+
                /* use point filtering as well */
                for ( i = 0; i < ( ds->numVerts - ds->numFoliageInstances ); i++ )
                {
@@ -2362,7 +2362,7 @@ static int FilterFoliageIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
                        refs += FilterPointIntoTree_r( xyz, ds, tree->headnode );
                }
        }
-       
+
        return refs;
 }
 
@@ -2384,16 +2384,16 @@ static int FilterFlareSurfIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
  */
 
 void EmitDrawVerts( mapDrawSurface_t *ds, bspDrawSurface_t *out ){
-       int                             i, k;
-       bspDrawVert_t   *dv;
-       shaderInfo_t    *si;
-       float                   offset;
-       
-       
+       int i, k;
+       bspDrawVert_t   *dv;
+       shaderInfo_t    *si;
+       float offset;
+
+
        /* get stuff */
        si = ds->shaderInfo;
        offset = si->offset;
-       
+
        /* copy the verts */
        out->firstVert = numBSPDrawVerts;
        out->numVerts = ds->numVerts;
@@ -2402,22 +2402,22 @@ void EmitDrawVerts( mapDrawSurface_t *ds, bspDrawSurface_t *out ){
                /* allocate a new vert */
                IncDrawVerts();
                dv = &bspDrawVerts[ numBSPDrawVerts - 1 ];
-               
+
                /* copy it */
                memcpy( dv, &ds->verts[ i ], sizeof( *dv ) );
-               
+
                /* offset? */
                if ( offset != 0.0f ) {
                        VectorMA( dv->xyz, offset, dv->normal, dv->xyz );
                }
-               
+
                /* expand model bounds
                   necessary because of misc_model surfaces on entities
                   note: does not happen on worldspawn as its bounds is only used for determining lightgrid bounds */
                if ( numBSPModels > 0 ) {
                        AddPointToBounds( dv->xyz, bspModels[ numBSPModels ].mins, bspModels[ numBSPModels ].maxs );
                }
-               
+
                /* debug color? */
                if ( debugSurfaces ) {
                        for ( k = 0; k < MAX_LIGHTMAPS; k++ )
@@ -2436,17 +2436,17 @@ void EmitDrawVerts( mapDrawSurface_t *ds, bspDrawSurface_t *out ){
  */
 
 int FindDrawIndexes( int numIndexes, int *indexes ){
-       int             i, j, numTestIndexes;
-       
-       
+       int i, j, numTestIndexes;
+
+
        /* dummy check */
        if ( numIndexes < 3 || numBSPDrawIndexes < numIndexes || indexes == NULL ) {
                return numBSPDrawIndexes;
        }
-       
+
        /* set limit */
        numTestIndexes = 1 + numBSPDrawIndexes - numIndexes;
-       
+
        /* handle 3 indexes as a special case for performance */
        if ( numIndexes == 3 ) {
                /* run through all indexes */
@@ -2454,30 +2454,30 @@ int FindDrawIndexes( int numIndexes, int *indexes ){
                {
                        /* test 3 indexes */
                        if ( indexes[ 0 ] == bspDrawIndexes[ i ] &&
-                               indexes[ 1 ] == bspDrawIndexes[ i + 1 ] &&
+                                indexes[ 1 ] == bspDrawIndexes[ i + 1 ] &&
                                 indexes[ 2 ] == bspDrawIndexes[ i + 2 ] ) {
                                numRedundantIndexes += numIndexes;
                                return i;
                        }
                }
-               
+
                /* failed */
                return numBSPDrawIndexes;
        }
-       
+
        /* handle 4 or more indexes */
        for ( i = 0; i < numTestIndexes; i++ )
        {
                /* test first 4 indexes */
                if ( indexes[ 0 ] == bspDrawIndexes[ i ] &&
-                       indexes[ 1 ] == bspDrawIndexes[ i + 1 ] &&
-                       indexes[ 2 ] == bspDrawIndexes[ i + 2 ] &&
+                        indexes[ 1 ] == bspDrawIndexes[ i + 1 ] &&
+                        indexes[ 2 ] == bspDrawIndexes[ i + 2 ] &&
                         indexes[ 3 ] == bspDrawIndexes[ i + 3 ] ) {
                        /* handle 4 indexes */
                        if ( numIndexes == 4 ) {
                                return i;
                        }
-                       
+
                        /* test the remainder */
                        for ( j = 4; j < numIndexes; j++ )
                        {
@@ -2491,7 +2491,7 @@ int FindDrawIndexes( int numIndexes, int *indexes ){
                        }
                }
        }
-       
+
        /* failed */
        return numBSPDrawIndexes;
 }
@@ -2504,9 +2504,9 @@ int FindDrawIndexes( int numIndexes, int *indexes ){
  */
 
 void EmitDrawIndexes( mapDrawSurface_t *ds, bspDrawSurface_t *out ){
-       int                     i;
-       
-       
+       int i;
+
+
        /* attempt to use redundant indexing */
        out->firstIndex = FindDrawIndexes( ds->numIndexes, ds->indexes );
        out->numIndexes = ds->numIndexes;
@@ -2521,14 +2521,14 @@ void EmitDrawIndexes( mapDrawSurface_t *ds, bspDrawSurface_t *out ){
                        if ( ds->type != SURFACE_PATCH ) {
                                if ( bspDrawIndexes[ numBSPDrawIndexes ] < 0 || bspDrawIndexes[ numBSPDrawIndexes ] >= ds->numVerts ) {
                                        Sys_Printf( "WARNING: %d %s has invalid index %d (%d)\n",
-                                               numBSPDrawSurfaces,
-                                               ds->shaderInfo->shader,
-                                               bspDrawIndexes[ numBSPDrawIndexes ],
-                                               i );
+                                                               numBSPDrawSurfaces,
+                                                               ds->shaderInfo->shader,
+                                                               bspDrawIndexes[ numBSPDrawIndexes ],
+                                                               i );
                                        bspDrawIndexes[ numBSPDrawIndexes ] = 0;
                                }
                        }
-                       
+
                        /* increment index count */
                        numBSPDrawIndexes++;
                }
@@ -2544,20 +2544,20 @@ void EmitDrawIndexes( mapDrawSurface_t *ds, bspDrawSurface_t *out ){
  */
 
 void EmitFlareSurface( mapDrawSurface_t *ds ){
-       int                                             i;
-       bspDrawSurface_t                *out;
-       
-       
+       int i;
+       bspDrawSurface_t        *out;
+
+
        /* ydnar: nuking useless flare drawsurfaces */
        if ( emitFlares == qfalse && ds->type != SURFACE_SHADER ) {
                return;
        }
-       
+
        /* limit check */
        if ( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS ) {
                Error( "MAX_MAP_DRAW_SURFS" );
        }
-       
+
        /* allocate a new surface */
        if ( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS ) {
                Error( "MAX_MAP_DRAW_SURFS" );
@@ -2566,12 +2566,12 @@ void EmitFlareSurface( mapDrawSurface_t *ds ){
        ds->outputNum = numBSPDrawSurfaces;
        numBSPDrawSurfaces++;
        memset( out, 0, sizeof( *out ) );
-       
+
        /* set it up */
        out->surfaceType = MST_FLARE;
        out->shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags );
        out->fogNum = ds->fogNum;
-       
+
        /* RBSP */
        for ( i = 0; i < MAX_LIGHTMAPS; i++ )
        {
@@ -2581,12 +2581,12 @@ void EmitFlareSurface( mapDrawSurface_t *ds ){
        }
        out->lightmapStyles[ 0 ] = ds->lightStyle;
        out->vertexStyles[ 0 ] = ds->lightStyle;
-       
-       VectorCopy( ds->lightmapOrigin, out->lightmapOrigin );                  /* origin */
-       VectorCopy( ds->lightmapVecs[ 0 ], out->lightmapVecs[ 0 ] );    /* color */
+
+       VectorCopy( ds->lightmapOrigin, out->lightmapOrigin );          /* origin */
+       VectorCopy( ds->lightmapVecs[ 0 ], out->lightmapVecs[ 0 ] );    /* color */
        VectorCopy( ds->lightmapVecs[ 1 ], out->lightmapVecs[ 1 ] );
-       VectorCopy( ds->lightmapVecs[ 2 ], out->lightmapVecs[ 2 ] );    /* normal */
-       
+       VectorCopy( ds->lightmapVecs[ 2 ], out->lightmapVecs[ 2 ] );    /* normal */
+
        /* add to count */
        numSurfacesByType[ ds->type ]++;
 }
@@ -2597,25 +2597,25 @@ void EmitFlareSurface( mapDrawSurface_t *ds ){
  */
 
 void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){
-       int                                     i, j;
-       bspDrawSurface_t        *out;
-       int                                     surfaceFlags, contentFlags;
-       int                                     forcePatchMeta;
+       int i, j;
+       bspDrawSurface_t    *out;
+       int surfaceFlags, contentFlags;
+       int forcePatchMeta;
 
        /* vortex: _patchMeta support */
        forcePatchMeta = IntForKey( e, "_patchMeta" );
        if ( !forcePatchMeta ) {
                forcePatchMeta = IntForKey( e, "patchMeta" );
        }
-       
+
        /* invert the surface if necessary */
        if ( ds->backSide || ds->shaderInfo->invert ) {
-               bspDrawVert_t   *dv1, *dv2, temp;
+               bspDrawVert_t   *dv1, *dv2, temp;
 
                /* walk the verts, flip the normal */
                for ( i = 0; i < ds->numVerts; i++ )
                        VectorScale( ds->verts[ i ].normal, -1.0f, ds->verts[ i ].normal );
-               
+
                /* walk the verts again, but this time reverse their order */
                for ( j = 0; j < ds->patchHeight; j++ )
                {
@@ -2628,7 +2628,7 @@ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){
                                memcpy( dv2, &temp, sizeof( bspDrawVert_t ) );
                        }
                }
-               
+
                /* invert facing */
                VectorScale( ds->lightmapVecs[ 2 ], -1.0f, ds->lightmapVecs[ 2 ] );
        }
@@ -2653,7 +2653,7 @@ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){
                contentFlags = ds->shaderInfo->contentFlags;
                ApplySurfaceParm( "nodraw", &contentFlags, &surfaceFlags, NULL );
                ApplySurfaceParm( "pointlight", &contentFlags, &surfaceFlags, NULL );
-               
+
                /* we don't want this patch getting lightmapped */
                VectorClear( ds->lightmapVecs[ 2 ] );
                VectorClear( ds->lightmapAxis );
@@ -2668,7 +2668,7 @@ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){
        out->patchWidth = ds->patchWidth;
        out->patchHeight = ds->patchHeight;
        out->fogNum = ds->fogNum;
-       
+
        /* RBSP */
        for ( i = 0; i < MAX_LIGHTMAPS; i++ )
        {
@@ -2678,22 +2678,22 @@ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){
        }
        out->lightmapStyles[ 0 ] = LS_NORMAL;
        out->vertexStyles[ 0 ] = LS_NORMAL;
-       
+
        /* ydnar: gs mods: previously, the lod bounds were stored in lightmapVecs[ 0 ] and [ 1 ], moved to bounds[ 0 ] and [ 1 ] */
        VectorCopy( ds->lightmapOrigin, out->lightmapOrigin );
        VectorCopy( ds->bounds[ 0 ], out->lightmapVecs[ 0 ] );
        VectorCopy( ds->bounds[ 1 ], out->lightmapVecs[ 1 ] );
        VectorCopy( ds->lightmapVecs[ 2 ], out->lightmapVecs[ 2 ] );
-       
+
        /* ydnar: gs mods: clear out the plane normal */
        if ( ds->planar == qfalse ) {
                VectorClear( out->lightmapVecs[ 2 ] );
        }
-       
+
        /* emit the verts and indexes */
        EmitDrawVerts( ds, out );
        EmitDrawIndexes( ds, out );
-       
+
        /* add to count */
        numSurfacesByType[ ds->type ]++;
 }
@@ -2703,28 +2703,28 @@ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){
    optimizes the vertex/index data in a triangle surface
  */
 
-#define VERTEX_CACHE_SIZE      16
+#define VERTEX_CACHE_SIZE   16
 
 static void OptimizeTriangleSurface( mapDrawSurface_t *ds ){
-       int             i, j, k, temp, first, best, bestScore, score;
-       int             vertexCache[ VERTEX_CACHE_SIZE + 1 ];   /* one more for optimizing insert */
-       int             *indexes;
-       
-       
+       int i, j, k, temp, first, best, bestScore, score;
+       int vertexCache[ VERTEX_CACHE_SIZE + 1 ];       /* one more for optimizing insert */
+       int     *indexes;
+
+
        /* certain surfaces don't get optimized */
        if ( ds->numIndexes <= VERTEX_CACHE_SIZE ||
                 ds->shaderInfo->autosprite ) {
                return;
        }
-       
+
        /* create index scratch pad */
        indexes = safe_malloc( ds->numIndexes * sizeof( *indexes ) );
        memcpy( indexes, ds->indexes, ds->numIndexes * sizeof( *indexes ) );
-       
+
        /* setup */
        for ( i = 0; i <= VERTEX_CACHE_SIZE && i < ds->numIndexes; i++ )
                vertexCache[ i ] = indexes[ i ];
-       
+
        /* add triangles in a vertex cache-aware order */
        for ( i = 0; i < ds->numIndexes; i += 3 )
        {
@@ -2740,34 +2740,34 @@ static void OptimizeTriangleSurface( mapDrawSurface_t *ds ){
                                if ( first < 0 ) {
                                        first = j;
                                }
-                               
+
                                /* score the triangle */
                                score = 0;
                                for ( k = 0; k < VERTEX_CACHE_SIZE; k++ )
                                {
                                        if ( indexes[ j ] == vertexCache[ k ] || indexes[ j + 1 ] == vertexCache[ k ] || indexes[ j + 2 ] == vertexCache[ k ] ) {
                                                score++;
+                                       }
                                }
-                               }
-                               
+
                                /* better triangle? */
                                if ( score > bestScore ) {
                                        bestScore = score;
                                        best = j;
                                }
-                               
+
                                /* a perfect score of 3 means this triangle's verts are already present in the vertex cache */
                                if ( score == 3 ) {
                                        break;
+                               }
                        }
                }
-               }
-               
+
                /* check if no decent triangle was found, and use first available */
                if ( best < 0 ) {
                        best = first;
                }
-               
+
                /* valid triangle? */
                if ( best >= 0 ) {
                        /* add triangle to vertex cache */
@@ -2777,29 +2777,29 @@ static void OptimizeTriangleSurface( mapDrawSurface_t *ds ){
                                {
                                        if ( indexes[ best + j ] == vertexCache[ k ] ) {
                                                break;
+                                       }
                                }
-                               }
-                               
+
                                if ( k >= VERTEX_CACHE_SIZE ) {
                                        /* pop off top of vertex cache */
                                        for ( k = VERTEX_CACHE_SIZE; k > 0; k-- )
                                                vertexCache[ k ] = vertexCache[ k - 1 ];
-                                       
+
                                        /* add vertex */
                                        vertexCache[ 0 ] = indexes[ best + j ];
                                }
                        }
-                       
+
                        /* add triangle to surface */
                        ds->indexes[ i ] = indexes[ best ];
                        ds->indexes[ i + 1 ] = indexes[ best + 1 ];
                        ds->indexes[ i + 2 ] = indexes[ best + 2 ];
-                       
+
                        /* clear from input pool */
                        indexes[ best ] = -1;
                        indexes[ best + 1 ] = -1;
                        indexes[ best + 2 ] = -1;
-                       
+
                        /* sort triangle windings (312 -> 123) */
                        while ( ds->indexes[ i ] > ds->indexes[ i + 1 ] || ds->indexes[ i ] > ds->indexes[ i + 2 ] )
                        {
@@ -2810,7 +2810,7 @@ static void OptimizeTriangleSurface( mapDrawSurface_t *ds ){
                        }
                }
        }
-       
+
        /* clean up */
        free( indexes );
 }
@@ -2823,8 +2823,8 @@ static void OptimizeTriangleSurface( mapDrawSurface_t *ds ){
  */
 
 void EmitTriangleSurface( mapDrawSurface_t *ds ){
-       int                                             i, temp;
-       bspDrawSurface_t                *out;
+       int i, temp;
+       bspDrawSurface_t        *out;
 
        /* invert the surface if necessary */
        if ( ds->backSide || ds->shaderInfo->invert ) {
@@ -2835,15 +2835,15 @@ void EmitTriangleSurface( mapDrawSurface_t *ds ){
                        ds->indexes[ i ] = ds->indexes[ i + 1 ];
                        ds->indexes[ i + 1 ] = temp;
                }
-                       
+
                /* walk the verts, flip the normal */
                for ( i = 0; i < ds->numVerts; i++ )
                        VectorScale( ds->verts[ i ].normal, -1.0f, ds->verts[ i ].normal );
-                       
+
                /* invert facing */
                VectorScale( ds->lightmapVecs[ 2 ], -1.0f, ds->lightmapVecs[ 2 ] );
        }
-               
+
        /* allocate a new surface */
        if ( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS ) {
                Error( "MAX_MAP_DRAW_SURFS" );
@@ -2852,27 +2852,27 @@ void EmitTriangleSurface( mapDrawSurface_t *ds ){
        ds->outputNum = numBSPDrawSurfaces;
        numBSPDrawSurfaces++;
        memset( out, 0, sizeof( *out ) );
-       
+
        /* ydnar/sd: handle wolf et foliage surfaces */
        if ( ds->type == SURFACE_FOLIAGE ) {
                out->surfaceType = MST_FOLIAGE;
        }
-       
+
        /* ydnar: gs mods: handle lightmapped terrain (force to planar type) */
        //%     else if( VectorLength( ds->lightmapAxis ) <= 0.0f || ds->type == SURFACE_TRIANGLES || ds->type == SURFACE_FOGHULL || debugSurfaces )
        else if ( ( VectorLength( ds->lightmapAxis ) <= 0.0f && ds->planar == qfalse ) ||
-               ds->type == SURFACE_TRIANGLES ||
-               ds->type == SURFACE_FOGHULL ||
-               ds->numVerts > maxLMSurfaceVerts ||
+                         ds->type == SURFACE_TRIANGLES ||
+                         ds->type == SURFACE_FOGHULL ||
+                         ds->numVerts > maxLMSurfaceVerts ||
                          debugSurfaces ) {
                out->surfaceType = MST_TRIANGLE_SOUP;
        }
-       
+
        /* set to a planar face */
        else{
                out->surfaceType = MST_PLANAR;
        }
-       
+
        /* set it up */
        if ( debugSurfaces ) {
                out->shaderNum = EmitShader( "debugsurfaces", NULL, NULL );
@@ -2883,13 +2883,13 @@ void EmitTriangleSurface( mapDrawSurface_t *ds ){
        out->patchWidth = ds->patchWidth;
        out->patchHeight = ds->patchHeight;
        out->fogNum = ds->fogNum;
-       
+
        /* debug inset (push each triangle vertex towards the center of each triangle it is on */
        if ( debugInset ) {
-               bspDrawVert_t   *a, *b, *c;
-               vec3_t                  cent, dir;
+               bspDrawVert_t   *a, *b, *c;
+               vec3_t cent, dir;
+
 
-               
                /* walk triangle list */
                for ( i = 0; i < ds->numIndexes; i += 3 )
                {
@@ -2897,13 +2897,13 @@ void EmitTriangleSurface( mapDrawSurface_t *ds ){
                        a = &ds->verts[ ds->indexes[ i ] ];
                        b = &ds->verts[ ds->indexes[ i + 1 ] ];
                        c = &ds->verts[ ds->indexes[ i + 2 ] ];
-                       
+
                        /* calculate centroid */
                        VectorCopy( a->xyz, cent );
                        VectorAdd( cent, b->xyz, cent );
                        VectorAdd( cent, c->xyz, cent );
                        VectorScale( cent, 1.0f / 3.0f, cent );
-                       
+
                        /* offset each vertex */
                        VectorSubtract( cent, a->xyz, dir );
                        VectorNormalize( dir, dir );
@@ -2916,7 +2916,7 @@ void EmitTriangleSurface( mapDrawSurface_t *ds ){
                        VectorAdd( c->xyz, dir, c->xyz );
                }
        }
-       
+
        /* RBSP */
        for ( i = 0; i < MAX_LIGHTMAPS; i++ )
        {
@@ -2926,25 +2926,25 @@ void EmitTriangleSurface( mapDrawSurface_t *ds ){
        }
        out->lightmapStyles[ 0 ] = LS_NORMAL;
        out->vertexStyles[ 0 ] = LS_NORMAL;
-       
+
        /* lightmap vectors (lod bounds for patches */
        VectorCopy( ds->lightmapOrigin, out->lightmapOrigin );
        VectorCopy( ds->lightmapVecs[ 0 ], out->lightmapVecs[ 0 ] );
        VectorCopy( ds->lightmapVecs[ 1 ], out->lightmapVecs[ 1 ] );
        VectorCopy( ds->lightmapVecs[ 2 ], out->lightmapVecs[ 2 ] );
-       
+
        /* ydnar: gs mods: clear out the plane normal */
        if ( ds->planar == qfalse ) {
                VectorClear( out->lightmapVecs[ 2 ] );
        }
-       
+
        /* optimize the surface's triangles */
        OptimizeTriangleSurface( ds );
-       
+
        /* emit the verts and indexes */
        EmitDrawVerts( ds, out );
        EmitDrawIndexes( ds, out );
-       
+
        /* add to count */
        numSurfacesByType[ ds->type ]++;
 }
@@ -2974,44 +2974,44 @@ static void EmitFaceSurface( mapDrawSurface_t *ds ){
  */
 
 static void MakeDebugPortalSurfs_r( node_t *node, shaderInfo_t *si ){
-       int                                     i, k, c, s;     
-       portal_t                        *p;
-       winding_t                       *w;
-       mapDrawSurface_t        *ds;
-       bspDrawVert_t           *dv;
-       
-       
+       int i, k, c, s;
+       portal_t            *p;
+       winding_t           *w;
+       mapDrawSurface_t    *ds;
+       bspDrawVert_t       *dv;
+
+
        /* recurse if decision node */
        if ( node->planenum != PLANENUM_LEAF ) {
                MakeDebugPortalSurfs_r( node->children[ 0 ], si );
                MakeDebugPortalSurfs_r( node->children[ 1 ], si );
                return;
        }
-       
+
        /* don't bother with opaque leaves */
        if ( node->opaque ) {
                return;
        }
-       
+
        /* walk the list of portals */
        for ( c = 0, p = node->portals; p != NULL; c++, p = p->next[ s ] )
        {
                /* get winding and side even/odd */
                w = p->winding;
                s = ( p->nodes[ 1 ] == node );
-               
+
                /* is this a valid portal for this leaf? */
                if ( w && p->nodes[ 0 ] == node ) {
                        /* is this portal passable? */
                        if ( PortalPassable( p ) == qfalse ) {
                                continue;
                        }
-                       
+
                        /* check max points */
                        if ( w->numpoints > 64 ) {
                                Error( "MakePortalSurfs_r: w->numpoints = %d", w->numpoints );
                        }
-                       
+
                        /* allocate a drawsurface */
                        ds = AllocDrawSurface( SURFACE_FACE );
                        ds->shaderInfo = si;
@@ -3023,13 +3023,13 @@ static void MakeDebugPortalSurfs_r( node_t *node, shaderInfo_t *si ){
                        ds->numVerts = w->numpoints;
                        ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
                        memset( ds->verts, 0, ds->numVerts * sizeof( *ds->verts ) );
-                       
+
                        /* walk the winding */
                        for ( i = 0; i < ds->numVerts; i++ )
                        {
                                /* get vert */
                                dv = ds->verts + i;
-                               
+
                                /* set it */
                                VectorCopy( w->p[ i ], dv->xyz );
                                VectorCopy( p->plane.normal, dv->normal );
@@ -3053,15 +3053,15 @@ static void MakeDebugPortalSurfs_r( node_t *node, shaderInfo_t *si ){
  */
 
 void MakeDebugPortalSurfs( tree_t *tree ){
-       shaderInfo_t    *si;
-       
-       
+       shaderInfo_t    *si;
+
+
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- MakeDebugPortalSurfs ---\n" );
-       
+
        /* get portal debug shader */
        si = ShaderInfoForShader( "debugportals" );
-       
+
        /* walk the tree */
        MakeDebugPortalSurfs_r( tree->headnode, si );
 }
@@ -3074,28 +3074,28 @@ void MakeDebugPortalSurfs( tree_t *tree ){
  */
 
 void MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader ){
-       shaderInfo_t            *si;
-       mapDrawSurface_t        *ds;
-       vec3_t                          fogMins, fogMaxs;
-       int                                     i, indexes[] =
-                                               {
-                                                       0, 1, 2, 0, 2, 3,
-                                                       4, 7, 5, 5, 7, 6,
-                                                       1, 5, 6, 1, 6, 2,
-                                                       0, 4, 5, 0, 5, 1,
-                                                       2, 6, 7, 2, 7, 3,
-                                                       3, 7, 4, 3, 4, 0
-                                               };
-
-       
+       shaderInfo_t        *si;
+       mapDrawSurface_t    *ds;
+       vec3_t fogMins, fogMaxs;
+       int i, indexes[] =
+       {
+               0, 1, 2, 0, 2, 3,
+               4, 7, 5, 5, 7, 6,
+               1, 5, 6, 1, 6, 2,
+               0, 4, 5, 0, 5, 1,
+               2, 6, 7, 2, 7, 3,
+               3, 7, 4, 3, 4, 0
+       };
+
+
        /* dummy check */
        if ( shader == NULL || shader[ 0 ] == '\0' ) {
                return;
        }
-       
+
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- MakeFogHullSurfs ---\n" );
-       
+
        /* get hull bounds */
        VectorCopy( mapMins, fogMins );
        VectorCopy( mapMaxs, fogMaxs );
@@ -3104,10 +3104,10 @@ void MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader ){
                fogMins[ i ] -= 128;
                fogMaxs[ i ] += 128;
        }
-       
+
        /* get foghull shader */
        si = ShaderInfoForShader( shader );
-       
+
        /* allocate a drawsurface */
        ds = AllocDrawSurface( SURFACE_FOGHULL );
        ds->shaderInfo = si;
@@ -3118,18 +3118,18 @@ void MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader ){
        ds->numIndexes = 36;
        ds->indexes = safe_malloc( ds->numIndexes * sizeof( *ds->indexes ) );
        memset( ds->indexes, 0, ds->numIndexes * sizeof( *ds->indexes ) );
-       
+
        /* set verts */
        VectorSet( ds->verts[ 0 ].xyz, fogMins[ 0 ], fogMins[ 1 ], fogMins[ 2 ] );
        VectorSet( ds->verts[ 1 ].xyz, fogMins[ 0 ], fogMaxs[ 1 ], fogMins[ 2 ] );
        VectorSet( ds->verts[ 2 ].xyz, fogMaxs[ 0 ], fogMaxs[ 1 ], fogMins[ 2 ] );
        VectorSet( ds->verts[ 3 ].xyz, fogMaxs[ 0 ], fogMins[ 1 ], fogMins[ 2 ] );
-       
+
        VectorSet( ds->verts[ 4 ].xyz, fogMins[ 0 ], fogMins[ 1 ], fogMaxs[ 2 ] );
        VectorSet( ds->verts[ 5 ].xyz, fogMins[ 0 ], fogMaxs[ 1 ], fogMaxs[ 2 ] );
        VectorSet( ds->verts[ 6 ].xyz, fogMaxs[ 0 ], fogMaxs[ 1 ], fogMaxs[ 2 ] );
        VectorSet( ds->verts[ 7 ].xyz, fogMaxs[ 0 ], fogMins[ 1 ], fogMaxs[ 2 ] );
-       
+
        /* set indexes */
        memcpy( ds->indexes, indexes, ds->numIndexes * sizeof( *ds->indexes ) );
 }
@@ -3142,17 +3142,17 @@ void MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader ){
  */
 
 void BiasSurfaceTextures( mapDrawSurface_t *ds ){
-       int             i;
-       
-       
+       int i;
+
+
        /* calculate the surface texture bias */
        CalcSurfaceTextureRange( ds );
-       
+
        /* don't bias globaltextured shaders */
        if ( ds->shaderInfo->globalTexture ) {
                return;
        }
-       
+
        /* bias the texture coordinates */
        for ( i = 0; i < ds->numVerts; i++ )
        {
@@ -3169,19 +3169,19 @@ void BiasSurfaceTextures( mapDrawSurface_t *ds ){
  */
 
 int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, bspDrawVert_t **tri ){
-       bspDrawVert_t   mid, *tri2[ 3 ];
-       int                             max, n, localNumSurfaceModels;
-       
-       
+       bspDrawVert_t mid, *tri2[ 3 ];
+       int max, n, localNumSurfaceModels;
+
+
        /* init */
        localNumSurfaceModels = 0;
-       
+
        /* subdivide calc */
        {
-               int                     i;
-               float           *a, *b, dx, dy, dz, dist, maxDist;
-               
-               
+               int i;
+               float       *a, *b, dx, dy, dz, dist, maxDist;
+
+
                /* find the longest edge and split it */
                max = -1;
                maxDist = 0.0f;
@@ -3190,47 +3190,47 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
                        /* get verts */
                        a = tri[ i ]->xyz;
                        b = tri[ ( i + 1 ) % 3 ]->xyz;
-                       
+
                        /* get dists */
                        dx = a[ 0 ] - b[ 0 ];
                        dy = a[ 1 ] - b[ 1 ];
                        dz = a[ 2 ] - b[ 2 ];
                        dist = ( dx * dx ) + ( dy * dy ) + ( dz * dz );
-                       
+
                        /* longer? */
                        if ( dist > maxDist ) {
                                maxDist = dist;
                                max = i;
                        }
                }
-               
+
                /* is the triangle small enough? */
                if ( max < 0 || maxDist <= ( model->density * model->density ) ) {
-                       float   odds, r, angle;
-                       vec3_t  origin, normal, scale, axis[ 3 ], angles;
-                       m4x4_t  transform, temp;
+                       float odds, r, angle;
+                       vec3_t origin, normal, scale, axis[ 3 ], angles;
+                       m4x4_t transform, temp;
+
 
-                       
                        /* roll the dice (model's odds scaled by vertex alpha) */
                        odds = model->odds * ( tri[ 0 ]->color[ 0 ][ 3 ] + tri[ 0 ]->color[ 0 ][ 3 ] + tri[ 0 ]->color[ 0 ][ 3 ] ) / 765.0f;
                        r = Random();
                        if ( r > odds ) {
                                return 0;
                        }
-                       
+
                        /* calculate scale */
                        r = model->minScale + Random() * ( model->maxScale - model->minScale );
                        VectorSet( scale, r, r, r );
-                       
+
                        /* calculate angle */
                        angle = model->minAngle + Random() * ( model->maxAngle - model->minAngle );
-                       
+
                        /* calculate average origin */
                        VectorCopy( tri[ 0 ]->xyz, origin );
                        VectorAdd( origin, tri[ 1 ]->xyz, origin );
                        VectorAdd( origin, tri[ 2 ]->xyz, origin );
                        VectorScale( origin, ( 1.0f / 3.0f ), origin );
-                       
+
                        /* clear transform matrix */
                        m4x4_identity( transform );
 
@@ -3238,7 +3238,7 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
                        if ( model->oriented ) {
                                /* set angles */
                                VectorSet( angles, 0.0f, 0.0f, angle );
-                               
+
                                /* calculate average normal */
                                VectorCopy( tri[ 0 ]->normal, normal );
                                VectorAdd( normal, tri[ 1 ]->normal, normal );
@@ -3246,50 +3246,50 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
                                if ( VectorNormalize( normal, axis[ 2 ] ) == 0.0f ) {
                                        VectorCopy( tri[ 0 ]->normal, axis[ 2 ] );
                                }
-                               
+
                                /* make perpendicular vectors */
                                MakeNormalVectors( axis[ 2 ], axis[ 1 ], axis[ 0 ] );
-                               
+
                                /* copy to matrix */
                                m4x4_identity( temp );
-                               temp[ 0 ] = axis[ 0 ][ 0 ];     temp[ 1 ] = axis[ 0 ][ 1 ];     temp[ 2 ] = axis[ 0 ][ 2 ];
-                               temp[ 4 ] = axis[ 1 ][ 0 ];     temp[ 5 ] = axis[ 1 ][ 1 ];     temp[ 6 ] = axis[ 1 ][ 2 ];
-                               temp[ 8 ] = axis[ 2 ][ 0 ];     temp[ 9 ] = axis[ 2 ][ 1 ];     temp[ 10 ] = axis[ 2 ][ 2 ];
-                               
+                               temp[ 0 ] = axis[ 0 ][ 0 ]; temp[ 1 ] = axis[ 0 ][ 1 ]; temp[ 2 ] = axis[ 0 ][ 2 ];
+                               temp[ 4 ] = axis[ 1 ][ 0 ]; temp[ 5 ] = axis[ 1 ][ 1 ]; temp[ 6 ] = axis[ 1 ][ 2 ];
+                               temp[ 8 ] = axis[ 2 ][ 0 ]; temp[ 9 ] = axis[ 2 ][ 1 ]; temp[ 10 ] = axis[ 2 ][ 2 ];
+
                                /* scale */
                                m4x4_scale_by_vec3( temp, scale );
-                               
+
                                /* rotate around z axis */
                                m4x4_rotate_by_vec3( temp, angles, eXYZ );
-                               
+
                                /* translate */
                                m4x4_translate_by_vec3( transform, origin );
-                               
+
                                /* tranform into axis space */
                                m4x4_multiply_by_m4x4( transform, temp );
                        }
-                       
+
                        /* handle z-up models */
                        else
                        {
                                /* set angles */
                                VectorSet( angles, 0.0f, 0.0f, angle );
-                               
+
                                /* set matrix */
                                m4x4_pivoted_transform_by_vec3( transform, origin, angles, eXYZ, scale, vec3_origin );
                        }
-                       
+
                        /* insert the model */
                        InsertModel( (char *) model->model, 0, 0, transform, NULL, ds->celShader, ds->entityNum, ds->castShadows, ds->recvShadows, 0, ds->lightmapScale, 0, 0, ds->colormod );
-                       
+
                        /* return to sender */
                        return 1;
                }
        }
-       
+
        /* split the longest edge and map it */
        LerpDrawVert( tri[ max ], tri[ ( max + 1 ) % 3 ], &mid );
-       
+
        /* recurse to first triangle */
        VectorCopy( tri, tri2 );
        tri2[ max ] = &mid;
@@ -3298,7 +3298,7 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
                return n;
        }
        localNumSurfaceModels += n;
-       
+
        /* recurse to second triangle */
        VectorCopy( tri, tri2 );
        tri2[ ( max + 1 ) % 3 ] = &mid;
@@ -3307,7 +3307,7 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
                return n;
        }
        localNumSurfaceModels += n;
-       
+
        /* return count */
        return localNumSurfaceModels;
 }
@@ -3320,158 +3320,158 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
  */
 
 int AddSurfaceModels( mapDrawSurface_t *ds ){
-       surfaceModel_t  *model;
-       int                             i, x, y, n, pw[ 5 ], r, localNumSurfaceModels, iterations;
-       mesh_t                  src, *mesh, *subdivided;
-       bspDrawVert_t   centroid, *tri[ 3 ];
-       float                   alpha;
-       
-       
+       surfaceModel_t  *model;
+       int i, x, y, n, pw[ 5 ], r, localNumSurfaceModels, iterations;
+       mesh_t src, *mesh, *subdivided;
+       bspDrawVert_t centroid, *tri[ 3 ];
+       float alpha;
+
+
        /* dummy check */
        if ( ds == NULL || ds->shaderInfo == NULL || ds->shaderInfo->surfaceModel == NULL ) {
                return 0;
        }
-       
+
        /* init */
        localNumSurfaceModels = 0;
-       
+
        /* walk the model list */
        for ( model = ds->shaderInfo->surfaceModel; model != NULL; model = model->next )
        {
                /* switch on type */
                switch ( ds->type )
                {
-                       /* handle brush faces and decals */
-                       case SURFACE_FACE:
-                       case SURFACE_DECAL:
-                               /* calculate centroid */
-                               memset( &centroid, 0, sizeof( centroid ) );
-                               alpha = 0.0f;
-                               
-                               /* walk verts */
+               /* handle brush faces and decals */
+               case SURFACE_FACE:
+               case SURFACE_DECAL:
+                       /* calculate centroid */
+                       memset( &centroid, 0, sizeof( centroid ) );
+                       alpha = 0.0f;
+
+                       /* walk verts */
                        for ( i = 0; i < ds->numVerts; i++ )
-                               {
-                                       VectorAdd( centroid.xyz, ds->verts[ i ].xyz, centroid.xyz );
-                                       VectorAdd( centroid.normal, ds->verts[ i ].normal, centroid.normal );
-                                       centroid.st[ 0 ] += ds->verts[ i ].st[ 0 ];
-                                       centroid.st[ 1 ] += ds->verts[ i ].st[ 1 ];
-                                       alpha += ds->verts[ i ].color[ 0 ][ 3 ];
-                               }
-                               
-                               /* average */
-                               centroid.xyz[ 0 ] /= ds->numVerts;
-                               centroid.xyz[ 1 ] /= ds->numVerts;
-                               centroid.xyz[ 2 ] /= ds->numVerts;
+                       {
+                               VectorAdd( centroid.xyz, ds->verts[ i ].xyz, centroid.xyz );
+                               VectorAdd( centroid.normal, ds->verts[ i ].normal, centroid.normal );
+                               centroid.st[ 0 ] += ds->verts[ i ].st[ 0 ];
+                               centroid.st[ 1 ] += ds->verts[ i ].st[ 1 ];
+                               alpha += ds->verts[ i ].color[ 0 ][ 3 ];
+                       }
+
+                       /* average */
+                       centroid.xyz[ 0 ] /= ds->numVerts;
+                       centroid.xyz[ 1 ] /= ds->numVerts;
+                       centroid.xyz[ 2 ] /= ds->numVerts;
                        if ( VectorNormalize( centroid.normal, centroid.normal ) == 0.0f ) {
-                                       VectorCopy( ds->verts[ 0 ].normal, centroid.normal );
-                       }
-                               centroid.st[ 0 ]  /= ds->numVerts;
-                               centroid.st[ 1 ]  /= ds->numVerts;
-                               alpha /= ds->numVerts;
-                               centroid.color[ 0 ][ 0 ] = 0xFF;
-                               centroid.color[ 0 ][ 1 ] = 0xFF;
-                               centroid.color[ 0 ][ 2 ] = 0xFF;
+                               VectorCopy( ds->verts[ 0 ].normal, centroid.normal );
+                       }
+                       centroid.st[ 0 ]  /= ds->numVerts;
+                       centroid.st[ 1 ]  /= ds->numVerts;
+                       alpha /= ds->numVerts;
+                       centroid.color[ 0 ][ 0 ] = 0xFF;
+                       centroid.color[ 0 ][ 1 ] = 0xFF;
+                       centroid.color[ 0 ][ 2 ] = 0xFF;
                        centroid.color[ 0 ][ 2 ] = ( alpha > 255.0f ? 0xFF : alpha );
-                               
-                               /* head vert is centroid */
-                               tri[ 0 ] = &centroid;
-                               
-                               /* walk fanned triangles */
+
+                       /* head vert is centroid */
+                       tri[ 0 ] = &centroid;
+
+                       /* walk fanned triangles */
                        for ( i = 0; i < ds->numVerts; i++ )
-                               {
-                                       /* set triangle */
-                                       tri[ 1 ] = &ds->verts[ i ];
+                       {
+                               /* set triangle */
+                               tri[ 1 ] = &ds->verts[ i ];
                                tri[ 2 ] = &ds->verts[ ( i + 1 ) % ds->numVerts ];
-                                       
-                                       /* create models */
-                                       n = AddSurfaceModelsToTriangle_r( ds, model, tri );
+
+                               /* create models */
+                               n = AddSurfaceModelsToTriangle_r( ds, model, tri );
                                if ( n < 0 ) {
-                                               return n;
+                                       return n;
                                }
-                                       localNumSurfaceModels += n;
-                               }
-                               break;
-                       
-                       /* handle patches */
-                       case SURFACE_PATCH:
-                               /* subdivide the surface */
-                               src.width = ds->patchWidth;
-                               src.height = ds->patchHeight;
-                               src.verts = ds->verts;
-                               //%     subdivided = SubdivideMesh( src, 8.0f, 512 );
-                               iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions );
-                               subdivided = SubdivideMesh2( src, iterations );
-                               
-                               /* fit it to the curve and remove colinear verts on rows/columns */
-                               PutMeshOnCurve( *subdivided );
-                               mesh = RemoveLinearMeshColumnsRows( subdivided );
-                               FreeMesh( subdivided );
-                               
-                               /* subdivide each quad to place the models */
+                               localNumSurfaceModels += n;
+                       }
+                       break;
+
+               /* handle patches */
+               case SURFACE_PATCH:
+                       /* subdivide the surface */
+                       src.width = ds->patchWidth;
+                       src.height = ds->patchHeight;
+                       src.verts = ds->verts;
+                       //%     subdivided = SubdivideMesh( src, 8.0f, 512 );
+                       iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions );
+                       subdivided = SubdivideMesh2( src, iterations );
+
+                       /* fit it to the curve and remove colinear verts on rows/columns */
+                       PutMeshOnCurve( *subdivided );
+                       mesh = RemoveLinearMeshColumnsRows( subdivided );
+                       FreeMesh( subdivided );
+
+                       /* subdivide each quad to place the models */
                        for ( y = 0; y < ( mesh->height - 1 ); y++ )
-                               {
+                       {
                                for ( x = 0; x < ( mesh->width - 1 ); x++ )
-                                       {
-                                               /* set indexes */
+                               {
+                                       /* set indexes */
                                        pw[ 0 ] = x + ( y * mesh->width );
                                        pw[ 1 ] = x + ( ( y + 1 ) * mesh->width );
                                        pw[ 2 ] = x + 1 + ( ( y + 1 ) * mesh->width );
                                        pw[ 3 ] = x + 1 + ( y * mesh->width );
                                        pw[ 4 ] = x + ( y * mesh->width );      /* same as pw[ 0 ] */
-                                               
-                                               /* set radix */
+
+                                       /* set radix */
                                        r = ( x + y ) & 1;
-                                               
-                                               /* triangle 1 */
-                                               tri[ 0 ] = &mesh->verts[ pw[ r + 0 ] ];
-                                               tri[ 1 ] = &mesh->verts[ pw[ r + 1 ] ];
-                                               tri[ 2 ] = &mesh->verts[ pw[ r + 2 ] ];
-                                               n = AddSurfaceModelsToTriangle_r( ds, model, tri );
+
+                                       /* triangle 1 */
+                                       tri[ 0 ] = &mesh->verts[ pw[ r + 0 ] ];
+                                       tri[ 1 ] = &mesh->verts[ pw[ r + 1 ] ];
+                                       tri[ 2 ] = &mesh->verts[ pw[ r + 2 ] ];
+                                       n = AddSurfaceModelsToTriangle_r( ds, model, tri );
                                        if ( n < 0 ) {
-                                                       return n;
+                                               return n;
                                        }
-                                               localNumSurfaceModels += n;
-                                               
-                                               /* triangle 2 */
-                                               tri[ 0 ] = &mesh->verts[ pw[ r + 0 ] ];
-                                               tri[ 1 ] = &mesh->verts[ pw[ r + 2 ] ];
-                                               tri[ 2 ] = &mesh->verts[ pw[ r + 3 ] ];
-                                               n = AddSurfaceModelsToTriangle_r( ds, model, tri );
+                                       localNumSurfaceModels += n;
+
+                                       /* triangle 2 */
+                                       tri[ 0 ] = &mesh->verts[ pw[ r + 0 ] ];
+                                       tri[ 1 ] = &mesh->verts[ pw[ r + 2 ] ];
+                                       tri[ 2 ] = &mesh->verts[ pw[ r + 3 ] ];
+                                       n = AddSurfaceModelsToTriangle_r( ds, model, tri );
                                        if ( n < 0 ) {
-                                                       return n;
-                                       }
-                                               localNumSurfaceModels += n;
+                                               return n;
                                        }
+                                       localNumSurfaceModels += n;
                                }
-                               
-                               /* free the subdivided mesh */
-                               FreeMesh( mesh );
-                               break;
-                       
-                       /* handle triangle surfaces */
-                       case SURFACE_TRIANGLES:
-                       case SURFACE_FORCED_META:
-                       case SURFACE_META:
-                               /* walk the triangle list */
+                       }
+
+                       /* free the subdivided mesh */
+                       FreeMesh( mesh );
+                       break;
+
+               /* handle triangle surfaces */
+               case SURFACE_TRIANGLES:
+               case SURFACE_FORCED_META:
+               case SURFACE_META:
+                       /* walk the triangle list */
                        for ( i = 0; i < ds->numIndexes; i += 3 )
-                               {
-                                       tri[ 0 ] = &ds->verts[ ds->indexes[ i ] ];
-                                       tri[ 1 ] = &ds->verts[ ds->indexes[ i + 1 ] ];
-                                       tri[ 2 ] = &ds->verts[ ds->indexes[ i + 2 ] ];
-                                       n = AddSurfaceModelsToTriangle_r( ds, model, tri );
+                       {
+                               tri[ 0 ] = &ds->verts[ ds->indexes[ i ] ];
+                               tri[ 1 ] = &ds->verts[ ds->indexes[ i + 1 ] ];
+                               tri[ 2 ] = &ds->verts[ ds->indexes[ i + 2 ] ];
+                               n = AddSurfaceModelsToTriangle_r( ds, model, tri );
                                if ( n < 0 ) {
-                                               return n;
+                                       return n;
                                }
-                                       localNumSurfaceModels += n;
-                               }
-                               break;
-                       
-                       /* no support for flares, foghull, etc */
-                       default:
-                               break;
+                               localNumSurfaceModels += n;
+                       }
+                       break;
+
+               /* no support for flares, foghull, etc */
+               default:
+                       break;
                }
        }
-       
+
        /* return count */
        return localNumSurfaceModels;
 }
@@ -3484,12 +3484,12 @@ int AddSurfaceModels( mapDrawSurface_t *ds ){
  */
 
 void AddEntitySurfaceModels( entity_t *e ){
-       int             i;
-       
-       
+       int i;
+
+
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- AddEntitySurfaceModels ---\n" );
-       
+
        /* walk the surface list */
        for ( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
                numSurfaceModels += AddSurfaceModels( &mapDrawSurfs[ i ] );
@@ -3503,17 +3503,17 @@ void AddEntitySurfaceModels( entity_t *e ){
  */
 
 static void VolumeColorMods( entity_t *e, mapDrawSurface_t *ds ){
-       int                     i, j;
-       float           d;
-       brush_t         *b;
-       plane_t         *plane;
-       
-       
+       int i, j;
+       float d;
+       brush_t     *b;
+       plane_t     *plane;
+
+
        /* early out */
        if ( e->colorModBrushes == NULL ) {
                return;
        }
-       
+
        /* iterate brushes */
        for ( b = e->colorModBrushes; b != NULL; b = b->nextColorModBrush )
        {
@@ -3521,14 +3521,14 @@ static void VolumeColorMods( entity_t *e, mapDrawSurface_t *ds ){
                if ( b->entityNum != 0 && b->entityNum != ds->entityNum ) {
                        continue;
                }
-               
+
                /* test bbox */
                if ( b->mins[ 0 ] > ds->maxs[ 0 ] || b->maxs[ 0 ] < ds->mins[ 0 ] ||
-                       b->mins[ 1 ] > ds->maxs[ 1 ] || b->maxs[ 1 ] < ds->mins[ 1 ] ||
+                        b->mins[ 1 ] > ds->maxs[ 1 ] || b->maxs[ 1 ] < ds->mins[ 1 ] ||
                         b->mins[ 2 ] > ds->maxs[ 2 ] || b->maxs[ 2 ] < ds->mins[ 2 ] ) {
                        continue;
                }
-               
+
                /* iterate verts */
                for ( i = 0; i < ds->numVerts; i++ )
                {
@@ -3540,15 +3540,15 @@ static void VolumeColorMods( entity_t *e, mapDrawSurface_t *ds ){
                                d = DotProduct( ds->verts[ i ].xyz, plane->normal ) - plane->dist;
                                if ( d > 1.0f ) {
                                        break;
+                               }
                        }
-                       }
-                       
+
                        /* apply colormods */
                        if ( j == b->numsides ) {
                                ColorMod( b->contentShader->colorMod, 1, &ds->verts[ i ] );
+                       }
                }
        }
-       }
 }
 
 
@@ -3561,18 +3561,18 @@ static void VolumeColorMods( entity_t *e, mapDrawSurface_t *ds ){
  */
 
 void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree ){
-       int                                     i, j;
-       mapDrawSurface_t        *ds;
-       shaderInfo_t            *si;
-       vec3_t                          origin, mins, maxs;
-       int                                     refs;
-       int                                     numSurfs, numRefs, numSkyboxSurfaces;
-       qboolean        sb;
-       
-       
+       int i, j;
+       mapDrawSurface_t    *ds;
+       shaderInfo_t        *si;
+       vec3_t origin, mins, maxs;
+       int refs;
+       int numSurfs, numRefs, numSkyboxSurfaces;
+       qboolean sb;
+
+
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- FilterDrawsurfsIntoTree ---\n" );
-       
+
        /* filter surfaces into the tree */
        numSurfs = 0;
        numRefs = 0;
@@ -3584,7 +3584,7 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree ){
                if ( ds->numVerts == 0 && ds->type != SURFACE_FLARE && ds->type != SURFACE_SHADER ) {
                        continue;
                }
-               
+
                /* get shader */
                si = ds->shaderInfo;
 
@@ -3600,138 +3600,138 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree ){
 
                        /* refs initially zero */
                        refs = 0;
-                       
+
                        /* apply texture coordinate mods */
                        for ( j = 0; j < ds->numVerts; j++ )
                                TCMod( si->mod, ds->verts[ j ].st );
-                       
+
                        /* ydnar: apply shader colormod */
                        ColorMod( ds->shaderInfo->colorMod, ds->numVerts, ds->verts );
-                       
+
                        /* ydnar: apply brush colormod */
                        VolumeColorMods( e, ds );
-                       
+
                        /* ydnar: make fur surfaces */
                        if ( si->furNumLayers > 0 ) {
                                Fur( ds );
                        }
-                       
+
                        /* ydnar/sd: make foliage surfaces */
                        if ( si->foliage != NULL ) {
                                Foliage( ds );
                        }
-                       
+
                        /* create a flare surface if necessary */
                        if ( si->flareShader != NULL && si->flareShader[ 0 ] ) {
                                AddSurfaceFlare( ds, e->origin );
                        }
-                       
+
                        /* ydnar: don't emit nodraw surfaces (like nodraw fog) */
                        if ( ( si->compileFlags & C_NODRAW ) && ds->type != SURFACE_PATCH ) {
                                continue;
                        }
-                       
+
                        /* ydnar: bias the surface textures */
                        BiasSurfaceTextures( ds );
-                       
+
                        /* ydnar: globalizing of fog volume handling (eek a hack) */
                        if ( e != entities && si->noFog == qfalse ) {
                                /* find surface origin and offset by entity origin */
                                VectorAdd( ds->mins, ds->maxs, origin );
                                VectorScale( origin, 0.5f, origin );
                                VectorAdd( origin, e->origin, origin );
-                               
+
                                VectorAdd( ds->mins, e->origin, mins );
                                VectorAdd( ds->maxs, e->origin, maxs );
-                               
+
                                /* set the fog number for this surface */
-                               ds->fogNum = FogForBounds( mins, maxs, 1.0f );  //%     FogForPoint( origin, 0.0f );
+                               ds->fogNum = FogForBounds( mins, maxs, 1.0f );  //%     FogForPoint( origin, 0.0f );
                        }
                }
-               
+
                /* ydnar: remap shader */
                if ( ds->shaderInfo->remapShader && ds->shaderInfo->remapShader[ 0 ] ) {
                        ds->shaderInfo = ShaderInfoForShader( ds->shaderInfo->remapShader );
                }
-               
+
                /* ydnar: gs mods: handle the various types of surfaces */
                switch ( ds->type )
                {
-                       /* handle brush faces */
-                       case SURFACE_FACE:
-                       case SURFACE_DECAL:
+               /* handle brush faces */
+               case SURFACE_FACE:
+               case SURFACE_DECAL:
                        if ( refs == 0 ) {
-                                       refs = FilterFaceIntoTree( ds, tree );
+                               refs = FilterFaceIntoTree( ds, tree );
                        }
                        if ( refs > 0 ) {
-                                       EmitFaceSurface( ds );
+                               EmitFaceSurface( ds );
                        }
-                               break;
-                       
-                       /* handle patches */
-                       case SURFACE_PATCH:
+                       break;
+
+               /* handle patches */
+               case SURFACE_PATCH:
                        if ( refs == 0 ) {
-                                       refs = FilterPatchIntoTree( ds, tree );
+                               refs = FilterPatchIntoTree( ds, tree );
                        }
                        if ( refs > 0 ) {
-                                       EmitPatchSurface( e, ds );
+                               EmitPatchSurface( e, ds );
                        }
-                               break;
-                       
-                       /* handle triangle surfaces */
-                       case SURFACE_TRIANGLES:
-                       case SURFACE_FORCED_META:
-                       case SURFACE_META:
-                               //%     Sys_FPrintf( SYS_VRB, "Surface %4d: [%1d] %4d verts %s\n", numSurfs, ds->planar, ds->numVerts, si->shader );
+                       break;
+
+               /* handle triangle surfaces */
+               case SURFACE_TRIANGLES:
+               case SURFACE_FORCED_META:
+               case SURFACE_META:
+                       //%     Sys_FPrintf( SYS_VRB, "Surface %4d: [%1d] %4d verts %s\n", numSurfs, ds->planar, ds->numVerts, si->shader );
                        if ( refs == 0 ) {
-                                       refs = FilterTrianglesIntoTree( ds, tree );
+                               refs = FilterTrianglesIntoTree( ds, tree );
                        }
                        if ( refs > 0 ) {
-                                       EmitTriangleSurface( ds );
+                               EmitTriangleSurface( ds );
                        }
-                               break;
-                       
-                       /* handle foliage surfaces (splash damage/wolf et) */
-                       case SURFACE_FOLIAGE:
-                               //%     Sys_FPrintf( SYS_VRB, "Surface %4d: [%d] %4d verts %s\n", numSurfs, ds->numFoliageInstances, ds->numVerts, si->shader );
+                       break;
+
+               /* handle foliage surfaces (splash damage/wolf et) */
+               case SURFACE_FOLIAGE:
+                       //%     Sys_FPrintf( SYS_VRB, "Surface %4d: [%d] %4d verts %s\n", numSurfs, ds->numFoliageInstances, ds->numVerts, si->shader );
                        if ( refs == 0 ) {
-                                       refs = FilterFoliageIntoTree( ds, tree );
+                               refs = FilterFoliageIntoTree( ds, tree );
                        }
                        if ( refs > 0 ) {
-                                       EmitTriangleSurface( ds );
+                               EmitTriangleSurface( ds );
                        }
-                               break;
-                       
-                       /* handle foghull surfaces */
-                       case SURFACE_FOGHULL:
+                       break;
+
+               /* handle foghull surfaces */
+               case SURFACE_FOGHULL:
                        if ( refs == 0 ) {
-                                       refs = AddReferenceToTree_r( ds, tree->headnode, qfalse );
+                               refs = AddReferenceToTree_r( ds, tree->headnode, qfalse );
                        }
                        if ( refs > 0 ) {
-                                       EmitTriangleSurface( ds );
+                               EmitTriangleSurface( ds );
                        }
-                               break;
-                       
-                       /* handle flares */
-                       case SURFACE_FLARE:
+                       break;
+
+               /* handle flares */
+               case SURFACE_FLARE:
                        if ( refs == 0 ) {
-                                       refs = FilterFlareSurfIntoTree( ds, tree );
+                               refs = FilterFlareSurfIntoTree( ds, tree );
                        }
                        if ( refs > 0 ) {
-                                       EmitFlareSurface( ds );
-                       }
-                               break;
-                       
-                       /* handle shader-only surfaces */
-                       case SURFACE_SHADER:
-                               refs = 1;
                                EmitFlareSurface( ds );
-                               break;
-                       
-                       /* no references */
-                       default:
-                               refs = 0;
-                               break;
+                       }
+                       break;
+
+               /* handle shader-only surfaces */
+               case SURFACE_SHADER:
+                       refs = 1;
+                       EmitFlareSurface( ds );
+                       break;
+
+               /* no references */
+               default:
+                       refs = 0;
+                       break;
                }
 
                /* maybe surface got marked as skybox again */
@@ -3739,28 +3739,28 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree ){
                if ( sb ) {
                        ds->skybox = qfalse;
                }
-               
+
                /* tot up the references */
                if ( refs > 0 ) {
                        /* tot up counts */
                        numSurfs++;
                        numRefs += refs;
-                       
+
                        /* emit extra surface data */
                        SetSurfaceExtra( ds, numBSPDrawSurfaces - 1 );
                        //%     Sys_FPrintf( SYS_VRB, "%d verts %d indexes\n", ds->numVerts, ds->numIndexes );
-                       
+
                        /* one last sanity check */
                        {
-                               bspDrawSurface_t        *out;
+                               bspDrawSurface_t    *out;
                                out = &bspDrawSurfaces[ numBSPDrawSurfaces - 1 ];
                                if ( out->numVerts == 3 && out->numIndexes > 3 ) {
                                        Sys_Printf( "\nWARNING: Potentially bad %s surface (%d: %d, %d)\n     %s\n",
-                                               surfaceTypes[ ds->type ],
-                                               numBSPDrawSurfaces - 1, out->numVerts, out->numIndexes, si->shader );
+                                                               surfaceTypes[ ds->type ],
+                                                               numBSPDrawSurfaces - 1, out->numVerts, out->numIndexes, si->shader );
                                }
                        }
-                       
+
                        /* ydnar: handle skybox surfaces */
                        if ( ds->skybox ) {
                                MakeSkyboxSurface( ds );
@@ -3768,7 +3768,7 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree ){
                        }
                }
        }
-       
+
        /* emit some statistics */
        Sys_FPrintf( SYS_VRB, "%9d references\n", numRefs );
        Sys_FPrintf( SYS_VRB, "%9d (%d) emitted drawsurfs\n", numSurfs, numBSPDrawSurfaces );
@@ -3779,6 +3779,6 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree ){
        Sys_FPrintf( SYS_VRB, "%9d skybox surfaces generated\n", numSkyboxSurfaces );
        for ( i = 0; i < NUM_SURFACE_TYPES; i++ )
                Sys_FPrintf( SYS_VRB, "%9d %s surfaces\n", numSurfacesByType[ i ], surfaceTypes[ i ] );
-       
+
        Sys_FPrintf( SYS_VRB, "%9d redundant indexes supressed, saving %d Kbytes\n", numRedundantIndexes, ( numRedundantIndexes * 4 / 1024 ) );
 }
index b4b44189edaa51b71ab13547f8daa16adf843520..b0d57539ddec158b1e0af8da4db3554438ac3db4 100644 (file)
 
 
 
-#define MAX_FOLIAGE_INSTANCES  8192
+#define MAX_FOLIAGE_INSTANCES   8192
 
-static int                                             numFoliageInstances;
-static foliageInstance_t               foliageInstances[ MAX_FOLIAGE_INSTANCES ];
+static int numFoliageInstances;
+static foliageInstance_t foliageInstances[ MAX_FOLIAGE_INSTANCES ];
 
 
 
@@ -51,41 +51,41 @@ static foliageInstance_t            foliageInstances[ MAX_FOLIAGE_INSTANCES ];
  */
 
 static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage, bspDrawVert_t **tri ){
-       bspDrawVert_t   mid, *tri2[ 3 ];
-       int                             max;
-       
-       
+       bspDrawVert_t mid, *tri2[ 3 ];
+       int max;
+
+
        /* limit test */
        if ( numFoliageInstances >= MAX_FOLIAGE_INSTANCES ) {
                return;
        }
-       
+
        /* plane test */
        {
-               vec4_t          plane;
-               
-               
+               vec4_t plane;
+
+
                /* make a plane */
                if ( !PlaneFromPoints( plane, tri[ 0 ]->xyz, tri[ 1 ]->xyz, tri[ 2 ]->xyz ) ) {
                        return;
                }
-               
+
                /* if normal is too far off vertical, then don't place an instance */
                if ( plane[ 2 ] < 0.5f ) {
                        return;
+               }
        }
-       }
-       
+
        /* subdivide calc */
        {
-               int                                     i;
-               float                           *a, *b, dx, dy, dz, dist, maxDist;
-               foliageInstance_t       *fi;
-               
-               
+               int i;
+               float               *a, *b, dx, dy, dz, dist, maxDist;
+               foliageInstance_t   *fi;
+
+
                /* get instance */
                fi = &foliageInstances[ numFoliageInstances ];
-               
+
                /* find the longest edge and split it */
                max = -1;
                maxDist = 0.0f;
@@ -96,29 +96,29 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage
                        /* get verts */
                        a = tri[ i ]->xyz;
                        b = tri[ ( i + 1 ) % 3 ]->xyz;
-                       
+
                        /* get dists */
                        dx = a[ 0 ] - b[ 0 ];
                        dy = a[ 1 ] - b[ 1 ];
                        dz = a[ 2 ] - b[ 2 ];
                        dist = ( dx * dx ) + ( dy * dy ) + ( dz * dz );
-                       
+
                        /* longer? */
                        if ( dist > maxDist ) {
                                maxDist = dist;
                                max = i;
                        }
-                       
+
                        /* add to centroid */
                        VectorAdd( fi->xyz, tri[ i ]->xyz, fi->xyz );
                        VectorAdd( fi->normal, tri[ i ]->normal, fi->normal );
                }
-               
+
                /* is the triangle small enough? */
                if ( maxDist <= ( foliage->density * foliage->density ) ) {
-                       float   alpha, odds, r;
-                       
-                       
+                       float alpha, odds, r;
+
+
                        /* get average alpha */
                        if ( foliage->inverseAlpha == 2 ) {
                                alpha = 1.0f;
@@ -131,36 +131,36 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage
                                }
                                if ( alpha < 0.75f ) {
                                        return;
+                               }
                        }
-                       }
-                       
+
                        /* roll the dice */
                        odds = foliage->odds * alpha;
                        r = Random();
                        if ( r > odds ) {
                                return;
                        }
-                       
+
                        /* scale centroid */
                        VectorScale( fi->xyz, 0.33333333f, fi->xyz );
                        if ( VectorNormalize( fi->normal, fi->normal ) == 0.0f ) {
                                return;
                        }
-                       
+
                        /* add to count and return */
                        numFoliageInstances++;
                        return;
                }
        }
-       
+
        /* split the longest edge and map it */
        LerpDrawVert( tri[ max ], tri[ ( max + 1 ) % 3 ], &mid );
-       
+
        /* recurse to first triangle */
        VectorCopy( tri, tri2 );
        tri2[ max ] = &mid;
        SubdivideFoliageTriangle_r( ds, foliage, tri2 );
-       
+
        /* recurse to second triangle */
        VectorCopy( tri, tri2 );
        tri2[ ( max + 1 ) % 3 ] = &mid;
@@ -175,138 +175,138 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage
  */
 
 void Foliage( mapDrawSurface_t *src ){
-       int                                     i, j, k, x, y, pw[ 5 ], r, oldNumMapDrawSurfs;
-       mapDrawSurface_t        *ds;
-       shaderInfo_t            *si;
-       foliage_t                       *foliage;
-       mesh_t                          srcMesh, *subdivided, *mesh;
-       bspDrawVert_t           *verts, *dv[ 3 ], *fi;
-       vec3_t                          scale;
-       m4x4_t                          transform;
-       
-       
+       int i, j, k, x, y, pw[ 5 ], r, oldNumMapDrawSurfs;
+       mapDrawSurface_t    *ds;
+       shaderInfo_t        *si;
+       foliage_t           *foliage;
+       mesh_t srcMesh, *subdivided, *mesh;
+       bspDrawVert_t       *verts, *dv[ 3 ], *fi;
+       vec3_t scale;
+       m4x4_t transform;
+
+
        /* get shader */
        si = src->shaderInfo;
        if ( si == NULL || si->foliage == NULL ) {
                return;
        }
-       
+
        /* do every foliage */
        for ( foliage = si->foliage; foliage != NULL; foliage = foliage->next )
        {
                /* zero out */
                numFoliageInstances = 0;
-               
+
                /* map the surface onto the lightmap origin/cluster/normal buffers */
                switch ( src->type )
                {
-                       case SURFACE_META:
-                       case SURFACE_FORCED_META:
-                       case SURFACE_TRIANGLES:
-                               /* get verts */
-                               verts = src->verts;
-                               
-                               /* map the triangles */
+               case SURFACE_META:
+               case SURFACE_FORCED_META:
+               case SURFACE_TRIANGLES:
+                       /* get verts */
+                       verts = src->verts;
+
+                       /* map the triangles */
                        for ( i = 0; i < src->numIndexes; i += 3 )
-                               {
-                                       dv[ 0 ] = &verts[ src->indexes[ i ] ];
-                                       dv[ 1 ] = &verts[ src->indexes[ i + 1 ] ];
-                                       dv[ 2 ] = &verts[ src->indexes[ i + 2 ] ];
-                                       SubdivideFoliageTriangle_r( src, foliage, dv );
-                               }
-                               break;
-                       
-                       case SURFACE_PATCH:
-                               /* make a mesh from the drawsurf */ 
-                               srcMesh.width = src->patchWidth;
-                               srcMesh.height = src->patchHeight;
-                               srcMesh.verts = src->verts;
-                               subdivided = SubdivideMesh( srcMesh, 8, 512 );
-                               
-                               /* fit it to the curve and remove colinear verts on rows/columns */
-                               PutMeshOnCurve( *subdivided );
-                               mesh = RemoveLinearMeshColumnsRows( subdivided );
-                               FreeMesh( subdivided );
-                               
-                               /* get verts */
-                               verts = mesh->verts;
-                               
-                               /* map the mesh quads */
+                       {
+                               dv[ 0 ] = &verts[ src->indexes[ i ] ];
+                               dv[ 1 ] = &verts[ src->indexes[ i + 1 ] ];
+                               dv[ 2 ] = &verts[ src->indexes[ i + 2 ] ];
+                               SubdivideFoliageTriangle_r( src, foliage, dv );
+                       }
+                       break;
+
+               case SURFACE_PATCH:
+                       /* make a mesh from the drawsurf */
+                       srcMesh.width = src->patchWidth;
+                       srcMesh.height = src->patchHeight;
+                       srcMesh.verts = src->verts;
+                       subdivided = SubdivideMesh( srcMesh, 8, 512 );
+
+                       /* fit it to the curve and remove colinear verts on rows/columns */
+                       PutMeshOnCurve( *subdivided );
+                       mesh = RemoveLinearMeshColumnsRows( subdivided );
+                       FreeMesh( subdivided );
+
+                       /* get verts */
+                       verts = mesh->verts;
+
+                       /* map the mesh quads */
                        for ( y = 0; y < ( mesh->height - 1 ); y++ )
-                               {
+                       {
                                for ( x = 0; x < ( mesh->width - 1 ); x++ )
-                                       {
-                                               /* set indexes */
+                               {
+                                       /* set indexes */
                                        pw[ 0 ] = x + ( y * mesh->width );
                                        pw[ 1 ] = x + ( ( y + 1 ) * mesh->width );
                                        pw[ 2 ] = x + 1 + ( ( y + 1 ) * mesh->width );
                                        pw[ 3 ] = x + 1 + ( y * mesh->width );
                                        pw[ 4 ] = x + ( y * mesh->width );      /* same as pw[ 0 ] */
-                                               
-                                               /* set radix */
+
+                                       /* set radix */
                                        r = ( x + y ) & 1;
-                                               
-                                               /* get drawverts and map first triangle */
-                                               dv[ 0 ] = &verts[ pw[ r + 0 ] ];
-                                               dv[ 1 ] = &verts[ pw[ r + 1 ] ];
-                                               dv[ 2 ] = &verts[ pw[ r + 2 ] ];
-                                               SubdivideFoliageTriangle_r( src, foliage, dv );
-                                               
-                                               /* get drawverts and map second triangle */
-                                               dv[ 0 ] = &verts[ pw[ r + 0 ] ];
-                                               dv[ 1 ] = &verts[ pw[ r + 2 ] ];
-                                               dv[ 2 ] = &verts[ pw[ r + 3 ] ];
-                                               SubdivideFoliageTriangle_r( src, foliage, dv );
-                                       }
+
+                                       /* get drawverts and map first triangle */
+                                       dv[ 0 ] = &verts[ pw[ r + 0 ] ];
+                                       dv[ 1 ] = &verts[ pw[ r + 1 ] ];
+                                       dv[ 2 ] = &verts[ pw[ r + 2 ] ];
+                                       SubdivideFoliageTriangle_r( src, foliage, dv );
+
+                                       /* get drawverts and map second triangle */
+                                       dv[ 0 ] = &verts[ pw[ r + 0 ] ];
+                                       dv[ 1 ] = &verts[ pw[ r + 2 ] ];
+                                       dv[ 2 ] = &verts[ pw[ r + 3 ] ];
+                                       SubdivideFoliageTriangle_r( src, foliage, dv );
                                }
-                               
-                               /* free the mesh */
-                               FreeMesh( mesh );
-                               break;
-                       
-                       default:
-                               break;
+                       }
+
+                       /* free the mesh */
+                       FreeMesh( mesh );
+                       break;
+
+               default:
+                       break;
                }
-               
+
                /* any origins? */
                if ( numFoliageInstances < 1 ) {
                        continue;
                }
-               
+
                /* remember surface count */
                oldNumMapDrawSurfs = numMapDrawSurfs;
-               
+
                /* set transform matrix */
                VectorSet( scale, foliage->scale, foliage->scale, foliage->scale );
                m4x4_scale_for_vec3( transform, scale );
-               
+
                /* add the model to the bsp */
                InsertModel( foliage->model, 0, 0, transform, NULL, NULL, src->entityNum, src->castShadows, src->recvShadows, 0, src->lightmapScale, 0, 0, src->colormod );
-               
+
                /* walk each new surface */
                for ( i = oldNumMapDrawSurfs; i < numMapDrawSurfs; i++ )
                {
                        /* get surface */
                        ds = &mapDrawSurfs[ i ];
-                       
+
                        /* set up */
                        ds->type = SURFACE_FOLIAGE;
                        ds->numFoliageInstances = numFoliageInstances;
-                       
+
                        /* a wee hack */
                        ds->patchWidth = ds->numFoliageInstances;
                        ds->patchHeight = ds->numVerts;
-                       
+
                        /* set fog to be same as source surface */
                        ds->fogNum = src->fogNum;
-                       
+
                        /* add a drawvert for every instance */
                        verts = safe_malloc( ( ds->numVerts + ds->numFoliageInstances ) * sizeof( *verts ) );
                        memset( verts, 0, ( ds->numVerts + ds->numFoliageInstances ) * sizeof( *verts ) );
                        memcpy( verts, ds->verts, ds->numVerts * sizeof( *verts ) );
                        free( ds->verts );
                        ds->verts = verts;
-                       
+
                        /* copy the verts */
                        for ( j = 0; j < ds->numFoliageInstances; j++ )
                        {
@@ -326,7 +326,7 @@ void Foliage( mapDrawSurface_t *src ){
                                        fi->color[ k ][ 3 ] = 255;
                                }
                        }
-                       
+
                        /* increment */
                        ds->numVerts += ds->numFoliageInstances;
                }