1 /* -------------------------------------------------------------------------------
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 ----------------------------------------------------------------------------------
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
27 ------------------------------------------------------------------------------- */
42 void PlaneFromWinding( fixedWinding_t *w, visPlane_t *plane ){
46 VectorSubtract( w->points[2], w->points[1], v1 );
47 VectorSubtract( w->points[0], w->points[1], v2 );
48 CrossProduct( v2, v1, plane->normal );
49 VectorNormalize( plane->normal, plane->normal );
50 plane->dist = DotProduct( w->points[0], plane->normal );
56 returns a new fixed winding
57 ydnar: altered this a bit to reconcile multiply-defined winding_t
60 fixedWinding_t *NewFixedWinding( int points ){
64 if ( points > MAX_POINTS_ON_WINDING ) {
65 Error( "NewWinding: %i points", points );
68 size = (int)( (size_t)( (fixedWinding_t *)0 )->points[points] );
69 w = safe_malloc( size );
77 void prl( leaf_t *l ){
82 for ( i = 0 ; i < l->numportals ; i++ )
86 Sys_Printf( "portal %4i to leaf %4i : %7.1f : (%4.1f, %4.1f, %4.1f)\n",(int)( p - portals ),p->leaf,pl.dist, pl.normal[0], pl.normal[1], pl.normal[2] );
91 //=============================================================================
97 Sorts the portals from the least complex, so the later ones can reuse
98 the earlier information.
101 int PComp( const void *a, const void *b ){
102 if ( ( *(const vportal_t *const *)a )->nummightsee == ( *(const vportal_t *const *)b )->nummightsee ) {
105 if ( ( *(const vportal_t *const *)a )->nummightsee < ( *(const vportal_t *const *)b )->nummightsee ) {
110 void SortPortals( void ){
113 for ( i = 0 ; i < numportals * 2 ; i++ )
114 sorted_portals[i] = &portals[i];
119 qsort( sorted_portals, numportals * 2, sizeof( sorted_portals[0] ), PComp );
125 LeafVectorFromPortalVector
128 int LeafVectorFromPortalVector( byte *portalbits, byte *leafbits ){
134 for ( i = 0 ; i < numportals * 2 ; i++ )
136 if ( portalbits[i >> 3] & ( 1 << ( i & 7 ) ) ) {
138 leafbits[p->leaf >> 3] |= ( 1 << ( p->leaf & 7 ) );
142 for ( j = 0; j < portalclusters; j++ )
145 while ( leafs[leafnum].merged >= 0 )
146 leafnum = leafs[leafnum].merged;
147 //if the merged leaf is visible then the original leaf is visible
148 if ( leafbits[leafnum >> 3] & ( 1 << ( leafnum & 7 ) ) ) {
149 leafbits[j >> 3] |= ( 1 << ( j & 7 ) );
153 c_leafs = CountBits( leafbits, portalclusters );
163 Merges the portal visibility for a leaf
166 static int clustersizehistogram[MAX_MAP_LEAFS] = {0};
167 void ClusterMerge( int leafnum ){
169 byte portalvector[MAX_PORTALS / 8];
170 byte uncompressed[MAX_MAP_LEAFS / 8];
172 int numvis, mergedleafnum;
176 // OR together all the portalvis bits
178 mergedleafnum = leafnum;
179 while ( leafs[mergedleafnum].merged >= 0 )
180 mergedleafnum = leafs[mergedleafnum].merged;
182 memset( portalvector, 0, portalbytes );
183 leaf = &leafs[mergedleafnum];
184 for ( i = 0; i < leaf->numportals; i++ )
186 p = leaf->portals[i];
191 if ( p->status != stat_done ) {
192 Error( "portal not done" );
194 for ( j = 0 ; j < portallongs ; j++ )
195 ( (long *)portalvector )[j] |= ( (long *)p->portalvis )[j];
197 portalvector[pnum >> 3] |= 1 << ( pnum & 7 );
200 memset( uncompressed, 0, leafbytes );
202 uncompressed[mergedleafnum >> 3] |= ( 1 << ( mergedleafnum & 7 ) );
203 // convert portal bits to leaf bits
204 numvis = LeafVectorFromPortalVector( portalvector, uncompressed );
206 // if (uncompressed[leafnum>>3] & (1<<(leafnum&7)))
207 // Sys_Printf ("WARNING: Leaf portals saw into leaf\n");
209 // uncompressed[leafnum>>3] |= (1<<(leafnum&7));
211 numvis++; // count the leaf itself
213 //Sys_FPrintf (SYS_VRB,"cluster %4i : %4i visible\n", leafnum, numvis);
214 ++clustersizehistogram[numvis];
216 memcpy( bspVisBytes + VIS_HEADER_SIZE + leafnum * leafbytes, uncompressed, leafbytes );
224 void CalcPortalVis( void ){
225 RunThreadsOnIndividual( numportals * 2, qtrue, PortalFlow );
234 void CalcPassageVis( void ){
237 Sys_Printf( "\n--- CreatePassages (%d) ---\n", numportals * 2 );
238 RunThreadsOnIndividual( numportals * 2, qtrue, CreatePassages );
240 Sys_Printf( "\n--- PassageFlow (%d) ---\n", numportals * 2 );
241 RunThreadsOnIndividual( numportals * 2, qtrue, PassageFlow );
249 void CalcPassagePortalVis( void ){
252 Sys_Printf( "\n--- CreatePassages (%d) ---\n", numportals * 2 );
253 RunThreadsOnIndividual( numportals * 2, qtrue, CreatePassages );
255 Sys_Printf( "\n--- PassagePortalFlow (%d) ---\n", numportals * 2 );
256 RunThreadsOnIndividual( numportals * 2, qtrue, PassagePortalFlow );
264 void CalcFastVis( void ){
267 // fastvis just uses mightsee for a very loose bound
268 for ( i = 0 ; i < numportals * 2 ; i++ )
270 portals[i].portalvis = portals[i].portalflood;
271 portals[i].status = stat_done;
280 void CalcVis( void ){
281 int i, minvis, maxvis;
283 double mu, sigma, totalvis, totalvis2;
286 /* ydnar: rr2do2's farplane code */
288 value = ValueForKey( &entities[ 0 ], "_farplanedist" ); /* proper '_' prefixed key */
289 if ( value[ 0 ] == '\0' ) {
290 value = ValueForKey( &entities[ 0 ], "fogclip" ); /* wolf compatibility */
292 if ( value[ 0 ] == '\0' ) {
293 value = ValueForKey( &entities[ 0 ], "distancecull" ); /* sof2 compatibility */
295 if ( value[ 0 ] != '\0' ) {
296 farPlaneDist = atof( value );
297 if ( farPlaneDist > 0.0f ) {
298 Sys_Printf( "farplane distance = %.1f\n", farPlaneDist );
307 Sys_Printf( "\n--- BasePortalVis (%d) ---\n", numportals * 2 );
308 RunThreadsOnIndividual( numportals * 2, qtrue, BasePortalVis );
310 // RunThreadsOnIndividual (numportals*2, qtrue, BetterPortalVis);
317 else if ( noPassageVis ) {
320 else if ( passageVisOnly ) {
324 CalcPassagePortalVis();
327 // assemble the leaf vis lists by oring and compressing the portal lists
329 Sys_Printf( "creating leaf vis...\n" );
330 for ( i = 0 ; i < portalclusters ; i++ )
337 for ( i = 0; i < MAX_MAP_LEAFS; ++i )
338 if ( clustersizehistogram[i] ) {
339 if ( debugCluster ) {
340 Sys_FPrintf( SYS_VRB, "%4i clusters have exactly %4i visible clusters\n", clustersizehistogram[i], i );
342 /* cast is to prevent integer overflow */
343 totalvis += ( (double) i ) * ( (double) clustersizehistogram[i] );
344 totalvis2 += ( (double) i ) * ( (double) i ) * ( (double) clustersizehistogram[i] );
352 mu = totalvis / portalclusters;
353 sigma = sqrt( totalvis2 / portalclusters - mu * mu );
355 Sys_Printf( "Total clusters: %i\n", portalclusters );
356 Sys_Printf( "Total visible clusters: %.0f\n", totalvis );
357 Sys_Printf( "Average clusters visible: %.2f (%.3f%%/total)\n", mu, mu / portalclusters * 100.0 );
358 Sys_Printf( " Standard deviation: %.2f (%.3f%%/total, %.3f%%/avg)\n", sigma, sigma / portalclusters * 100.0, sigma / mu * 100.0 );
359 Sys_Printf( " Minimum: %i (%.3f%%/total, %.3f%%/avg)\n", minvis, minvis / (double) portalclusters * 100.0, minvis / mu * 100.0 );
360 Sys_Printf( " Maximum: %i (%.3f%%/total, %.3f%%/avg)\n", maxvis, maxvis / (double) portalclusters * 100.0, maxvis / mu * 100.0 );
368 void SetPortalSphere( vportal_t *p ){
375 VectorCopy( vec3_origin, total );
376 for ( i = 0 ; i < w->numpoints ; i++ )
378 VectorAdd( total, w->points[i], total );
381 for ( i = 0 ; i < 3 ; i++ )
382 total[i] /= w->numpoints;
385 for ( i = 0 ; i < w->numpoints ; i++ )
387 VectorSubtract( w->points[i], total, dist );
388 r = VectorLength( dist );
393 VectorCopy( total, p->origin );
399 Winding_PlanesConcave
402 #define WCONVEX_EPSILON 0.2
404 int Winding_PlanesConcave( fixedWinding_t *w1, fixedWinding_t *w2,
405 vec3_t normal1, vec3_t normal2,
406 float dist1, float dist2 ){
413 // check if one of the points of winding 1 is at the front of the plane of winding 2
414 for ( i = 0; i < w1->numpoints; i++ )
416 if ( DotProduct( normal2, w1->points[i] ) - dist2 > WCONVEX_EPSILON ) {
420 // check if one of the points of winding 2 is at the front of the plane of winding 1
421 for ( i = 0; i < w2->numpoints; i++ )
423 if ( DotProduct( normal1, w2->points[i] ) - dist1 > WCONVEX_EPSILON ) {
436 int TryMergeLeaves( int l1num, int l2num ){
437 int i, j, k, n, numportals;
438 visPlane_t plane1, plane2;
441 vportal_t *portals[MAX_PORTALS_ON_LEAF];
443 for ( k = 0; k < 2; k++ )
448 else{l1 = &faceleafs[l1num]; }
449 for ( i = 0; i < l1->numportals; i++ )
452 if ( p1->leaf == l2num ) {
455 for ( n = 0; n < 2; n++ )
460 else{l2 = &faceleafs[l2num]; }
461 for ( j = 0; j < l2->numportals; j++ )
464 if ( p2->leaf == l1num ) {
470 if ( Winding_PlanesConcave( p1->winding, p2->winding, plane1.normal, plane2.normal, plane1.dist, plane2.dist ) ) {
477 for ( k = 0; k < 2; k++ )
485 l1 = &faceleafs[l1num];
486 l2 = &faceleafs[l2num];
489 //the leaves can be merged now
490 for ( i = 0; i < l1->numportals; i++ )
493 if ( p1->leaf == l2num ) {
497 portals[numportals++] = p1;
499 for ( j = 0; j < l2->numportals; j++ )
502 if ( p2->leaf == l1num ) {
506 portals[numportals++] = p2;
508 for ( i = 0; i < numportals; i++ )
510 l2->portals[i] = portals[i];
512 l2->numportals = numportals;
523 void UpdatePortals( void ){
527 for ( i = 0; i < numportals * 2; i++ )
533 while ( leafs[p->leaf].merged >= 0 )
534 p->leaf = leafs[p->leaf].merged;
542 try to merge leaves but don't merge through hint splitters
545 void MergeLeaves( void ){
546 int i, j, nummerges, totalnummerges;
554 for ( i = 0; i < portalclusters; i++ )
557 //if this leaf is merged already
559 /* ydnar: vmods: merge all non-hint portals */
560 if ( leaf->merged >= 0 && hint == qfalse ) {
565 for ( j = 0; j < leaf->numportals; j++ )
567 p = leaf->portals[j];
572 //never merge through hint portals
576 if ( TryMergeLeaves( i, p->leaf ) ) {
583 totalnummerges += nummerges;
584 } while ( nummerges );
585 Sys_Printf( "%6d leaves merged\n", totalnummerges );
593 #define CONTINUOUS_EPSILON 0.005
595 fixedWinding_t *TryMergeWinding( fixedWinding_t *f1, fixedWinding_t *f2, vec3_t planenormal ){
596 vec_t *p1, *p2, *p3, *p4, *back;
597 fixedWinding_t *newf;
599 vec3_t normal, delta;
601 qboolean keep1, keep2;
605 // find a common edge
607 p1 = p2 = NULL; // stop compiler warning
610 for ( i = 0; i < f1->numpoints; i++ )
613 p2 = f1->points[( i + 1 ) % f1->numpoints];
614 for ( j = 0; j < f2->numpoints; j++ )
617 p4 = f2->points[( j + 1 ) % f2->numpoints];
618 for ( k = 0; k < 3; k++ )
620 if ( fabs( p1[k] - p4[k] ) > 0.1 ) { //EQUAL_EPSILON) //ME
623 if ( fabs( p2[k] - p3[k] ) > 0.1 ) { //EQUAL_EPSILON) //ME
631 if ( j < f2->numpoints ) {
636 if ( i == f1->numpoints ) {
637 return NULL; // no matching edges
641 // check slope of connected lines
642 // if the slopes are colinear, the point can be removed
644 back = f1->points[( i + f1->numpoints - 1 ) % f1->numpoints];
645 VectorSubtract( p1, back, delta );
646 CrossProduct( planenormal, delta, normal );
647 VectorNormalize( normal, normal );
649 back = f2->points[( j + 2 ) % f2->numpoints];
650 VectorSubtract( back, p1, delta );
651 dot = DotProduct( delta, normal );
652 if ( dot > CONTINUOUS_EPSILON ) {
653 return NULL; // not a convex polygon
655 keep1 = (qboolean)( dot < -CONTINUOUS_EPSILON );
657 back = f1->points[( i + 2 ) % f1->numpoints];
658 VectorSubtract( back, p2, delta );
659 CrossProduct( planenormal, delta, normal );
660 VectorNormalize( normal, normal );
662 back = f2->points[( j + f2->numpoints - 1 ) % f2->numpoints];
663 VectorSubtract( back, p2, delta );
664 dot = DotProduct( delta, normal );
665 if ( dot > CONTINUOUS_EPSILON ) {
666 return NULL; // not a convex polygon
668 keep2 = (qboolean)( dot < -CONTINUOUS_EPSILON );
671 // build the new polygon
673 newf = NewFixedWinding( f1->numpoints + f2->numpoints );
675 // copy first polygon
676 for ( k = ( i + 1 ) % f1->numpoints ; k != i ; k = ( k + 1 ) % f1->numpoints )
678 if ( k == ( i + 1 ) % f1->numpoints && !keep2 ) {
682 VectorCopy( f1->points[k], newf->points[newf->numpoints] );
686 // copy second polygon
687 for ( l = ( j + 1 ) % f2->numpoints ; l != j ; l = ( l + 1 ) % f2->numpoints )
689 if ( l == ( j + 1 ) % f2->numpoints && !keep1 ) {
692 VectorCopy( f2->points[l], newf->points[newf->numpoints] );
704 void MergeLeafPortals( void ){
705 int i, j, k, nummerges, hintsmerged;
712 for ( i = 0; i < portalclusters; i++ )
715 if ( leaf->merged >= 0 ) {
718 for ( j = 0; j < leaf->numportals; j++ )
720 p1 = leaf->portals[j];
724 for ( k = j + 1; k < leaf->numportals; k++ )
726 p2 = leaf->portals[k];
730 if ( p1->leaf == p2->leaf ) {
731 w = TryMergeWinding( p1->winding, p2->winding, p1->plane.normal );
733 free( p1->winding ); //% FreeWinding(p1->winding);
735 if ( p1->hint && p2->hint ) {
738 p1->hint |= p2->hint;
739 SetPortalSphere( p1 );
747 if ( k < leaf->numportals ) {
752 Sys_Printf( "%6d portals merged\n", nummerges );
753 Sys_Printf( "%6d hint portals merged\n", hintsmerged );
762 int CountActivePortals( void ){
768 for ( j = 0; j < numportals * 2; j++ )
779 Sys_Printf( "%6d active portals\n", num );
780 Sys_Printf( "%6d hint portals\n", hints );
789 void WriteFloat( FILE *f, vec_t v );
791 void WritePortals( char *portalpathfile ){
798 pf = fopen( portalpathfile, "w" );
800 Error( "Error opening %s", portalpathfile );
804 for ( j = 0; j < numportals * 2; j++ )
815 fprintf( pf, "%s\n", PORTALFILE );
816 fprintf( pf, "%i\n", 0 );
817 fprintf( pf, "%i\n", num ); // + numfaces);
818 fprintf( pf, "%i\n", 0 );
820 for ( j = 0; j < numportals * 2; j++ )
829 fprintf( pf,"%i %i %i ",w->numpoints, 0, 0 );
830 fprintf( pf, "%d ", p->hint );
831 for ( i = 0 ; i < w->numpoints ; i++ )
834 WriteFloat( pf, w->points[i][0] );
835 WriteFloat( pf, w->points[i][1] );
836 WriteFloat( pf, w->points[i][2] );
843 for (j = 0; j < numfaces; j++)
847 fprintf (pf,"%i %i %i ",w->numpoints, 0, 0);
849 for (i=0 ; i<w->numpoints ; i++)
852 WriteFloat (pf, w->points[i][0]);
853 WriteFloat (pf, w->points[i][1]);
854 WriteFloat (pf, w->points[i][2]);
868 void LoadPortals( char *name ){
879 if ( !strcmp( name,"-" ) ) {
884 f = fopen( name, "r" );
886 Error( "LoadPortals: couldn't read %s\n",name );
890 if ( fscanf( f,"%79s\n%i\n%i\n%i\n",magic, &portalclusters, &numportals, &numfaces ) != 4 ) {
891 Error( "LoadPortals: failed to read header" );
893 if ( strcmp( magic,PORTALFILE ) ) {
894 Error( "LoadPortals: not a portal file" );
897 Sys_Printf( "%6i portalclusters\n", portalclusters );
898 Sys_Printf( "%6i numportals\n", numportals );
899 Sys_Printf( "%6i numfaces\n", numfaces );
901 if ( numportals > MAX_PORTALS ) {
902 Error( "MAX_PORTALS" );
905 // these counts should take advantage of 64 bit systems automatically
906 leafbytes = ( ( portalclusters + 63 ) & ~63 ) >> 3;
907 leaflongs = leafbytes / sizeof( long );
909 portalbytes = ( ( numportals * 2 + 63 ) & ~63 ) >> 3;
910 portallongs = portalbytes / sizeof( long );
912 // each file portal is split into two memory portals
913 portals = safe_malloc( 2 * numportals * sizeof( vportal_t ) );
914 memset( portals, 0, 2 * numportals * sizeof( vportal_t ) );
916 leafs = safe_malloc( portalclusters * sizeof( leaf_t ) );
917 memset( leafs, 0, portalclusters * sizeof( leaf_t ) );
919 for ( i = 0; i < portalclusters; i++ )
920 leafs[i].merged = -1;
922 numBSPVisBytes = VIS_HEADER_SIZE + portalclusters * leafbytes;
924 if ( numBSPVisBytes > MAX_MAP_VISIBILITY ) {
925 Error( "MAX_MAP_VISIBILITY exceeded" );
928 ( (int *)bspVisBytes )[0] = portalclusters;
929 ( (int *)bspVisBytes )[1] = leafbytes;
931 for ( i = 0, p = portals ; i < numportals ; i++ )
933 if ( fscanf( f, "%i %i %i ", &numpoints, &leafnums[0], &leafnums[1] ) != 3 ) {
934 Error( "LoadPortals: reading portal %i", i );
936 if ( numpoints > MAX_POINTS_ON_WINDING ) {
937 Error( "LoadPortals: portal %i has too many points", i );
939 if ( leafnums[0] > portalclusters
940 || leafnums[1] > portalclusters ) {
941 Error( "LoadPortals: reading portal %i", i );
943 if ( fscanf( f, "%i ", &flags ) != 1 ) {
944 Error( "LoadPortals: reading flags" );
947 w = p->winding = NewFixedWinding( numpoints );
948 w->numpoints = numpoints;
950 for ( j = 0 ; j < numpoints ; j++ )
955 // scanf into double, then assign to vec_t
956 // so we don't care what size vec_t is
957 if ( fscanf( f, "(%lf %lf %lf ) "
958 , &v[0], &v[1], &v[2] ) != 3 ) {
959 Error( "LoadPortals: reading portal %i", i );
961 for ( k = 0 ; k < 3 ; k++ )
962 w->points[j][k] = v[k];
964 if ( fscanf( f, "\n" ) != 0 ) {
965 // silence gcc warning
969 PlaneFromWinding( w, &plane );
971 // create forward portal
972 l = &leafs[leafnums[0]];
973 if ( l->numportals == MAX_PORTALS_ON_LEAF ) {
974 Error( "Leaf with too many portals" );
976 l->portals[l->numportals] = p;
980 p->hint = ((flags & 1) != 0);
981 p->sky = ((flags & 2) != 0);
983 VectorSubtract( vec3_origin, plane.normal, p->plane.normal );
984 p->plane.dist = -plane.dist;
985 p->leaf = leafnums[1];
986 SetPortalSphere( p );
989 // create backwards portal
990 l = &leafs[leafnums[1]];
991 if ( l->numportals == MAX_PORTALS_ON_LEAF ) {
992 Error( "Leaf with too many portals" );
994 l->portals[l->numportals] = p;
999 p->winding = NewFixedWinding( w->numpoints );
1000 p->winding->numpoints = w->numpoints;
1001 for ( j = 0 ; j < w->numpoints ; j++ )
1003 VectorCopy( w->points[w->numpoints - 1 - j], p->winding->points[j] );
1007 p->leaf = leafnums[0];
1008 SetPortalSphere( p );
1013 faces = safe_malloc( 2 * numfaces * sizeof( vportal_t ) );
1014 memset( faces, 0, 2 * numfaces * sizeof( vportal_t ) );
1016 faceleafs = safe_malloc( portalclusters * sizeof( leaf_t ) );
1017 memset( faceleafs, 0, portalclusters * sizeof( leaf_t ) );
1019 for ( i = 0, p = faces; i < numfaces; i++ )
1021 if ( fscanf( f, "%i %i ", &numpoints, &leafnums[0] ) != 2 ) {
1022 Error( "LoadPortals: reading portal %i", i );
1025 w = p->winding = NewFixedWinding( numpoints );
1026 w->numpoints = numpoints;
1028 for ( j = 0 ; j < numpoints ; j++ )
1033 // scanf into double, then assign to vec_t
1034 // so we don't care what size vec_t is
1035 if ( fscanf( f, "(%lf %lf %lf ) "
1036 , &v[0], &v[1], &v[2] ) != 3 ) {
1037 Error( "LoadPortals: reading portal %i", i );
1039 for ( k = 0 ; k < 3 ; k++ )
1040 w->points[j][k] = v[k];
1042 if ( fscanf( f, "\n" ) != 0 ) {
1043 // silence gcc warning
1047 PlaneFromWinding( w, &plane );
1049 l = &faceleafs[leafnums[0]];
1051 if ( l->numportals == MAX_PORTALS_ON_LEAF ) {
1052 Error( "Leaf with too many faces" );
1054 l->portals[l->numportals] = p;
1059 // normal pointing out of the leaf
1060 VectorSubtract( vec3_origin, plane.normal, p->plane.normal );
1061 p->plane.dist = -plane.dist;
1063 SetPortalSphere( p );
1077 int VisMain( int argc, char **argv ){
1079 char portalFilePath[ 1024 ];
1080 portalFilePath[0] = 0;
1084 Sys_Printf( "--- Vis ---\n" );
1086 /* process arguments */
1087 for ( i = 1 ; i < ( argc - 1 ) ; i++ )
1089 if ( !strcmp( argv[i], "-fast" ) ) {
1090 Sys_Printf( "fastvis = true\n" );
1093 else if ( !strcmp( argv[i], "-merge" ) ) {
1094 Sys_Printf( "merge = true\n" );
1097 else if ( !strcmp( argv[i], "-mergeportals" ) ) {
1098 Sys_Printf( "mergeportals = true\n" );
1099 mergevisportals = qtrue;
1101 else if ( !strcmp( argv[i], "-nopassage" ) ) {
1102 Sys_Printf( "nopassage = true\n" );
1103 noPassageVis = qtrue;
1105 else if ( !strcmp( argv[i], "-passageOnly" ) ) {
1106 Sys_Printf( "passageOnly = true\n" );
1107 passageVisOnly = qtrue;
1109 else if ( !strcmp( argv[i],"-nosort" ) ) {
1110 Sys_Printf( "nosort = true\n" );
1113 else if ( !strcmp( argv[i],"-saveprt" ) ) {
1114 Sys_Printf( "saveprt = true\n" );
1117 else if ( !strcmp( argv[ i ], "-v" ) ) {
1118 debugCluster = qtrue;
1119 Sys_Printf( "Extra verbous mode enabled\n" );
1121 else if ( !strcmp( argv[i],"-tmpin" ) ) {
1122 strcpy( inbase, "/tmp" );
1124 else if ( !strcmp( argv[i],"-tmpout" ) ) {
1125 strcpy( outbase, "/tmp" );
1128 /* ydnar: -hint to merge all but hint portals */
1129 else if ( !strcmp( argv[ i ], "-hint" ) ) {
1130 Sys_Printf( "hint = true\n" );
1134 else if ( !strcmp( argv[ i ], "-prtfile" ) )
1136 strcpy( portalFilePath, argv[i + 1] );
1138 Sys_Printf( "Use %s as portal file\n", portalFilePath );
1143 Sys_Printf( "WARNING: Unknown option \"%s\"\n", argv[ i ] );
1147 if ( i != argc - 1 ) {
1148 Error( "usage: vis [-threads #] [-level 0-4] [-fast] [-v] BSPFilePath" );
1153 sprintf( source, "%s%s", inbase, ExpandArg( argv[ i ] ) );
1154 StripExtension( source );
1155 strcat( source, ".bsp" );
1156 Sys_Printf( "Loading %s\n", source );
1157 LoadBSPFile( source );
1159 /* load the portal file */
1160 if (!portalFilePath[0]) {
1161 sprintf( portalFilePath, "%s%s", inbase, ExpandArg( argv[ i ] ) );
1162 StripExtension( portalFilePath );
1163 strcat( portalFilePath, ".prt" );
1164 Sys_Printf( "Loading %s\n", portalFilePath );
1165 LoadPortals( portalFilePath );
1168 /* ydnar: exit if no portals, hence no vis */
1169 if ( numportals == 0 ) {
1170 Sys_Printf( "No portals means no vis, exiting.\n" );
1174 /* ydnar: for getting far plane */
1177 /* inject command line parameters */
1178 InjectCommandLine( argv, 0, argc - 1 );
1185 if ( mergevis || mergevisportals ) {
1189 CountActivePortals();
1190 /* WritePortals( "maps/hints.prs" );*/
1192 Sys_Printf( "visdatasize:%i\n", numBSPVisBytes );
1196 /* delete the prt file */
1198 remove( portalFilePath );
1201 /* write the bsp file */
1202 Sys_Printf( "Writing %s\n", source );
1203 WriteBSPFile( source );