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
167 static int clustersizehistogram[MAX_MAP_LEAFS] = {0};
169 void ClusterMerge( int leafnum ){
171 byte portalvector[MAX_PORTALS / 8];
172 byte uncompressed[MAX_MAP_LEAFS / 8];
174 int numvis, mergedleafnum;
178 // OR together all the portalvis bits
180 mergedleafnum = leafnum;
181 while ( leafs[mergedleafnum].merged >= 0 )
182 mergedleafnum = leafs[mergedleafnum].merged;
184 memset( portalvector, 0, portalbytes );
185 leaf = &leafs[mergedleafnum];
186 for ( i = 0; i < leaf->numportals; i++ )
188 p = leaf->portals[i];
193 if ( p->status != stat_done ) {
194 Error( "portal not done" );
196 for ( j = 0 ; j < portallongs ; j++ )
197 ( (long *)portalvector )[j] |= ( (long *)p->portalvis )[j];
199 portalvector[pnum >> 3] |= 1 << ( pnum & 7 );
202 memset( uncompressed, 0, leafbytes );
204 uncompressed[mergedleafnum >> 3] |= ( 1 << ( mergedleafnum & 7 ) );
205 // convert portal bits to leaf bits
206 numvis = LeafVectorFromPortalVector( portalvector, uncompressed );
208 // if (uncompressed[leafnum>>3] & (1<<(leafnum&7)))
209 // Sys_FPrintf (SYS_WRN, "WARNING: Leaf portals saw into leaf\n");
211 // uncompressed[leafnum>>3] |= (1<<(leafnum&7));
213 numvis++; // count the leaf itself
215 //Sys_FPrintf( SYS_VRB,"cluster %4i : %4i visible\n", leafnum, numvis );
216 ++clustersizehistogram[numvis];
218 memcpy( bspVisBytes + VIS_HEADER_SIZE + leafnum * leafbytes, uncompressed, leafbytes );
226 void CalcPortalVis( void ){
228 Sys_Printf( "%6d portals out of %d", 0, numportals * 2 );
229 //get rid of the counter
230 RunThreadsOnIndividual( numportals * 2, qfalse, PortalFlow );
232 RunThreadsOnIndividual( numportals * 2, qtrue, PortalFlow );
242 void CalcPassageVis( void ){
246 _printf( "%6d portals out of %d", 0, numportals * 2 );
247 RunThreadsOnIndividual( numportals * 2, qfalse, CreatePassages );
249 _printf( "%6d portals out of %d", 0, numportals * 2 );
250 RunThreadsOnIndividual( numportals * 2, qfalse, PassageFlow );
253 Sys_Printf( "\n--- CreatePassages (%d) ---\n", numportals * 2 );
254 RunThreadsOnIndividual( numportals * 2, qtrue, CreatePassages );
256 Sys_Printf( "\n--- PassageFlow (%d) ---\n", numportals * 2 );
257 RunThreadsOnIndividual( numportals * 2, qtrue, PassageFlow );
266 void CalcPassagePortalVis( void ){
270 Sys_Printf( "%6d portals out of %d", 0, numportals * 2 );
271 RunThreadsOnIndividual( numportals * 2, qfalse, CreatePassages );
273 Sys_Printf( "%6d portals out of %d", 0, numportals * 2 );
274 RunThreadsOnIndividual( numportals * 2, qfalse, PassagePortalFlow );
277 Sys_Printf( "\n--- CreatePassages (%d) ---\n", numportals * 2 );
278 RunThreadsOnIndividual( numportals * 2, qtrue, CreatePassages );
280 Sys_Printf( "\n--- PassagePortalFlow (%d) ---\n", numportals * 2 );
281 RunThreadsOnIndividual( numportals * 2, qtrue, PassagePortalFlow );
290 void CalcFastVis( void ){
293 // fastvis just uses mightsee for a very loose bound
294 for ( i = 0 ; i < numportals * 2 ; i++ )
296 portals[i].portalvis = portals[i].portalflood;
297 portals[i].status = stat_done;
306 void CalcVis( void ){
307 int i, minvis, maxvis;
309 double mu, sigma, totalvis, totalvis2;
312 /* ydnar: rr2do2's farplane code */
314 value = ValueForKey( &entities[ 0 ], "_farplanedist" ); /* proper '_' prefixed key */
315 if ( value[ 0 ] == '\0' ) {
316 value = ValueForKey( &entities[ 0 ], "fogclip" ); /* wolf compatibility */
318 if ( value[ 0 ] == '\0' ) {
319 value = ValueForKey( &entities[ 0 ], "distancecull" ); /* sof2 compatibility */
321 if ( value[ 0 ] != '\0' ) {
322 farPlaneDist = atof( value );
323 if ( farPlaneDist > 0.0f ) {
324 Sys_Printf( "farplane distance = %.1f\n", farPlaneDist );
333 Sys_Printf( "\n--- BasePortalVis (%d) ---\n", numportals * 2 );
334 RunThreadsOnIndividual( numportals * 2, qtrue, BasePortalVis );
336 // RunThreadsOnIndividual (numportals*2, qtrue, BetterPortalVis);
343 else if ( noPassageVis ) {
346 else if ( passageVisOnly ) {
350 CalcPassagePortalVis();
353 // assemble the leaf vis lists by oring and compressing the portal lists
355 Sys_Printf( "creating leaf vis...\n" );
356 for ( i = 0 ; i < portalclusters ; i++ )
363 for ( i = 0; i < MAX_MAP_LEAFS; ++i )
364 if ( clustersizehistogram[i] ) {
365 if ( debugCluster ) {
366 Sys_FPrintf( SYS_VRB, "%4i clusters have exactly %4i visible clusters\n", clustersizehistogram[i], i );
368 /* cast is to prevent integer overflow */
369 totalvis += ( (double) i ) * ( (double) clustersizehistogram[i] );
370 totalvis2 += ( (double) i ) * ( (double) i ) * ( (double) clustersizehistogram[i] );
378 mu = totalvis / portalclusters;
379 sigma = sqrt( totalvis2 / portalclusters - mu * mu );
381 Sys_Printf( "Total clusters: %i\n", portalclusters );
382 Sys_Printf( "Total visible clusters: %.0f\n", totalvis );
383 Sys_Printf( "Average clusters visible: %.2f (%.3f%%/total)\n", mu, mu / portalclusters * 100.0 );
384 Sys_Printf( " Standard deviation: %.2f (%.3f%%/total, %.3f%%/avg)\n", sigma, sigma / portalclusters * 100.0, sigma / mu * 100.0 );
385 Sys_Printf( " Minimum: %i (%.3f%%/total, %.3f%%/avg)\n", minvis, minvis / (double) portalclusters * 100.0, minvis / mu * 100.0 );
386 Sys_Printf( " Maximum: %i (%.3f%%/total, %.3f%%/avg)\n", maxvis, maxvis / (double) portalclusters * 100.0, maxvis / mu * 100.0 );
394 void SetPortalSphere( vportal_t *p ){
401 VectorCopy( vec3_origin, total );
402 for ( i = 0 ; i < w->numpoints ; i++ )
404 VectorAdd( total, w->points[i], total );
407 for ( i = 0 ; i < 3 ; i++ )
408 total[i] /= w->numpoints;
411 for ( i = 0 ; i < w->numpoints ; i++ )
413 VectorSubtract( w->points[i], total, dist );
414 r = VectorLength( dist );
419 VectorCopy( total, p->origin );
425 Winding_PlanesConcave
428 #define WCONVEX_EPSILON 0.2
430 int Winding_PlanesConcave( fixedWinding_t *w1, fixedWinding_t *w2,
431 vec3_t normal1, vec3_t normal2,
432 float dist1, float dist2 ){
439 // check if one of the points of winding 1 is at the front of the plane of winding 2
440 for ( i = 0; i < w1->numpoints; i++ )
442 if ( DotProduct( normal2, w1->points[i] ) - dist2 > WCONVEX_EPSILON ) {
446 // check if one of the points of winding 2 is at the front of the plane of winding 1
447 for ( i = 0; i < w2->numpoints; i++ )
449 if ( DotProduct( normal1, w2->points[i] ) - dist1 > WCONVEX_EPSILON ) {
462 int TryMergeLeaves( int l1num, int l2num ){
463 int i, j, k, n, numportals;
464 visPlane_t plane1, plane2;
467 vportal_t *portals[MAX_PORTALS_ON_LEAF];
469 for ( k = 0; k < 2; k++ )
474 else{l1 = &faceleafs[l1num]; }
475 for ( i = 0; i < l1->numportals; i++ )
478 if ( p1->leaf == l2num ) {
481 for ( n = 0; n < 2; n++ )
486 else{l2 = &faceleafs[l2num]; }
487 for ( j = 0; j < l2->numportals; j++ )
490 if ( p2->leaf == l1num ) {
496 if ( Winding_PlanesConcave( p1->winding, p2->winding, plane1.normal, plane2.normal, plane1.dist, plane2.dist ) ) {
503 for ( k = 0; k < 2; k++ )
511 l1 = &faceleafs[l1num];
512 l2 = &faceleafs[l2num];
515 //the leaves can be merged now
516 for ( i = 0; i < l1->numportals; i++ )
519 if ( p1->leaf == l2num ) {
523 portals[numportals++] = p1;
525 for ( j = 0; j < l2->numportals; j++ )
528 if ( p2->leaf == l1num ) {
532 portals[numportals++] = p2;
534 for ( i = 0; i < numportals; i++ )
536 l2->portals[i] = portals[i];
538 l2->numportals = numportals;
549 void UpdatePortals( void ){
553 for ( i = 0; i < numportals * 2; i++ )
559 while ( leafs[p->leaf].merged >= 0 )
560 p->leaf = leafs[p->leaf].merged;
568 try to merge leaves but don't merge through hint splitters
571 void MergeLeaves( void ){
572 int i, j, nummerges, totalnummerges;
580 for ( i = 0; i < portalclusters; i++ )
583 //if this leaf is merged already
585 /* ydnar: vmods: merge all non-hint portals */
586 if ( leaf->merged >= 0 && hint == qfalse ) {
591 for ( j = 0; j < leaf->numportals; j++ )
593 p = leaf->portals[j];
598 //never merge through hint portals
602 if ( TryMergeLeaves( i, p->leaf ) ) {
609 totalnummerges += nummerges;
610 } while ( nummerges );
611 Sys_Printf( "%6d leaves merged\n", totalnummerges );
619 #define CONTINUOUS_EPSILON 0.005
621 fixedWinding_t *TryMergeWinding( fixedWinding_t *f1, fixedWinding_t *f2, vec3_t planenormal ){
622 vec_t *p1, *p2, *p3, *p4, *back;
623 fixedWinding_t *newf;
625 vec3_t normal, delta;
627 qboolean keep1, keep2;
631 // find a common edge
633 p1 = p2 = NULL; // stop compiler warning
636 for ( i = 0; i < f1->numpoints; i++ )
639 p2 = f1->points[( i + 1 ) % f1->numpoints];
640 for ( j = 0; j < f2->numpoints; j++ )
643 p4 = f2->points[( j + 1 ) % f2->numpoints];
644 for ( k = 0; k < 3; k++ )
646 if ( fabs( p1[k] - p4[k] ) > 0.1 ) { //EQUAL_EPSILON) //ME
649 if ( fabs( p2[k] - p3[k] ) > 0.1 ) { //EQUAL_EPSILON) //ME
657 if ( j < f2->numpoints ) {
662 if ( i == f1->numpoints ) {
663 return NULL; // no matching edges
667 // check slope of connected lines
668 // if the slopes are colinear, the point can be removed
670 back = f1->points[( i + f1->numpoints - 1 ) % f1->numpoints];
671 VectorSubtract( p1, back, delta );
672 CrossProduct( planenormal, delta, normal );
673 VectorNormalize( normal, normal );
675 back = f2->points[( j + 2 ) % f2->numpoints];
676 VectorSubtract( back, p1, delta );
677 dot = DotProduct( delta, normal );
678 if ( dot > CONTINUOUS_EPSILON ) {
679 return NULL; // not a convex polygon
681 keep1 = (qboolean)( dot < -CONTINUOUS_EPSILON );
683 back = f1->points[( i + 2 ) % f1->numpoints];
684 VectorSubtract( back, p2, delta );
685 CrossProduct( planenormal, delta, normal );
686 VectorNormalize( normal, normal );
688 back = f2->points[( j + f2->numpoints - 1 ) % f2->numpoints];
689 VectorSubtract( back, p2, delta );
690 dot = DotProduct( delta, normal );
691 if ( dot > CONTINUOUS_EPSILON ) {
692 return NULL; // not a convex polygon
694 keep2 = (qboolean)( dot < -CONTINUOUS_EPSILON );
697 // build the new polygon
699 newf = NewFixedWinding( f1->numpoints + f2->numpoints );
701 // copy first polygon
702 for ( k = ( i + 1 ) % f1->numpoints ; k != i ; k = ( k + 1 ) % f1->numpoints )
704 if ( k == ( i + 1 ) % f1->numpoints && !keep2 ) {
708 VectorCopy( f1->points[k], newf->points[newf->numpoints] );
712 // copy second polygon
713 for ( l = ( j + 1 ) % f2->numpoints ; l != j ; l = ( l + 1 ) % f2->numpoints )
715 if ( l == ( j + 1 ) % f2->numpoints && !keep1 ) {
718 VectorCopy( f2->points[l], newf->points[newf->numpoints] );
730 void MergeLeafPortals( void ){
731 int i, j, k, nummerges, hintsmerged;
738 for ( i = 0; i < portalclusters; i++ )
741 if ( leaf->merged >= 0 ) {
744 for ( j = 0; j < leaf->numportals; j++ )
746 p1 = leaf->portals[j];
750 for ( k = j + 1; k < leaf->numportals; k++ )
752 p2 = leaf->portals[k];
756 if ( p1->leaf == p2->leaf ) {
757 w = TryMergeWinding( p1->winding, p2->winding, p1->plane.normal );
759 free( p1->winding ); //% FreeWinding(p1->winding);
761 if ( p1->hint && p2->hint ) {
764 p1->hint |= p2->hint;
765 SetPortalSphere( p1 );
773 if ( k < leaf->numportals ) {
778 Sys_Printf( "%6d portals merged\n", nummerges );
779 Sys_Printf( "%6d hint portals merged\n", hintsmerged );
788 int CountActivePortals( void ){
794 for ( j = 0; j < numportals * 2; j++ )
805 Sys_Printf( "%6d active portals\n", num );
806 Sys_Printf( "%6d hint portals\n", hints );
815 void WriteFloat( FILE *f, vec_t v );
817 void WritePortals( char *portalpathfile ){
824 pf = fopen( portalpathfile, "w" );
826 Error( "Error opening %s", portalpathfile );
830 for ( j = 0; j < numportals * 2; j++ )
841 fprintf( pf, "%s\n", PORTALFILE );
842 fprintf( pf, "%i\n", 0 );
843 fprintf( pf, "%i\n", num ); // + numfaces);
844 fprintf( pf, "%i\n", 0 );
846 for ( j = 0; j < numportals * 2; j++ )
855 fprintf( pf,"%i %i %i ",w->numpoints, 0, 0 );
856 fprintf( pf, "%d ", p->hint );
857 for ( i = 0 ; i < w->numpoints ; i++ )
860 WriteFloat( pf, w->points[i][0] );
861 WriteFloat( pf, w->points[i][1] );
862 WriteFloat( pf, w->points[i][2] );
869 for (j = 0; j < numfaces; j++)
873 fprintf (pf,"%i %i %i ",w->numpoints, 0, 0);
875 for (i=0 ; i<w->numpoints ; i++)
878 WriteFloat (pf, w->points[i][0]);
879 WriteFloat (pf, w->points[i][1]);
880 WriteFloat (pf, w->points[i][2]);
894 void LoadPortals( char *name ){
905 if ( !strcmp( name,"-" ) ) {
910 f = fopen( name, "r" );
912 Error( "LoadPortals: couldn't read %s\n",name );
916 if ( fscanf( f,"%79s\n%i\n%i\n%i\n",magic, &portalclusters, &numportals, &numfaces ) != 4 ) {
917 Error( "LoadPortals: failed to read header" );
919 if ( strcmp( magic,PORTALFILE ) ) {
920 Error( "LoadPortals: not a portal file" );
923 Sys_Printf( "%6i portalclusters\n", portalclusters );
924 Sys_Printf( "%6i numportals\n", numportals );
925 Sys_Printf( "%6i numfaces\n", numfaces );
927 if ( numportals > MAX_PORTALS ) {
928 Error( "MAX_PORTALS" );
931 // these counts should take advantage of 64 bit systems automatically
932 leafbytes = ( ( portalclusters + 63 ) & ~63 ) >> 3;
933 leaflongs = leafbytes / sizeof( long );
935 portalbytes = ( ( numportals * 2 + 63 ) & ~63 ) >> 3;
936 portallongs = portalbytes / sizeof( long );
938 // each file portal is split into two memory portals
939 portals = safe_malloc( 2 * numportals * sizeof( vportal_t ) );
940 memset( portals, 0, 2 * numportals * sizeof( vportal_t ) );
942 leafs = safe_malloc( portalclusters * sizeof( leaf_t ) );
943 memset( leafs, 0, portalclusters * sizeof( leaf_t ) );
945 for ( i = 0; i < portalclusters; i++ )
946 leafs[i].merged = -1;
948 numBSPVisBytes = VIS_HEADER_SIZE + portalclusters * leafbytes;
950 if ( numBSPVisBytes > MAX_MAP_VISIBILITY ) {
951 Error( "MAX_MAP_VISIBILITY exceeded" );
954 ( (int *)bspVisBytes )[0] = portalclusters;
955 ( (int *)bspVisBytes )[1] = leafbytes;
957 for ( i = 0, p = portals ; i < numportals ; i++ )
959 if ( fscanf( f, "%i %i %i ", &numpoints, &leafnums[0], &leafnums[1] ) != 3 ) {
960 Error( "LoadPortals: reading portal %i", i );
962 if ( numpoints > MAX_POINTS_ON_WINDING ) {
963 Error( "LoadPortals: portal %i has too many points", i );
965 if ( leafnums[0] > portalclusters
966 || leafnums[1] > portalclusters ) {
967 Error( "LoadPortals: reading portal %i", i );
969 if ( fscanf( f, "%i ", &flags ) != 1 ) {
970 Error( "LoadPortals: reading flags" );
973 w = p->winding = NewFixedWinding( numpoints );
974 w->numpoints = numpoints;
976 for ( j = 0 ; j < numpoints ; j++ )
981 // scanf into double, then assign to vec_t
982 // so we don't care what size vec_t is
983 if ( fscanf( f, "(%lf %lf %lf ) "
984 , &v[0], &v[1], &v[2] ) != 3 ) {
985 Error( "LoadPortals: reading portal %i", i );
987 for ( k = 0 ; k < 3 ; k++ )
988 w->points[j][k] = v[k];
990 if ( fscanf( f, "\n" ) != 0 ) {
991 // silence gcc warning
995 PlaneFromWinding( w, &plane );
997 // create forward portal
998 l = &leafs[leafnums[0]];
999 if ( l->numportals == MAX_PORTALS_ON_LEAF ) {
1000 Error( "Leaf with too many portals" );
1002 l->portals[l->numportals] = p;
1006 p->hint = ((flags & 1) != 0);
1007 p->sky = ((flags & 2) != 0);
1009 VectorSubtract( vec3_origin, plane.normal, p->plane.normal );
1010 p->plane.dist = -plane.dist;
1011 p->leaf = leafnums[1];
1012 SetPortalSphere( p );
1015 // create backwards portal
1016 l = &leafs[leafnums[1]];
1017 if ( l->numportals == MAX_PORTALS_ON_LEAF ) {
1018 Error( "Leaf with too many portals" );
1020 l->portals[l->numportals] = p;
1025 p->winding = NewFixedWinding( w->numpoints );
1026 p->winding->numpoints = w->numpoints;
1027 for ( j = 0 ; j < w->numpoints ; j++ )
1029 VectorCopy( w->points[w->numpoints - 1 - j], p->winding->points[j] );
1033 p->leaf = leafnums[0];
1034 SetPortalSphere( p );
1039 faces = safe_malloc( 2 * numfaces * sizeof( vportal_t ) );
1040 memset( faces, 0, 2 * numfaces * sizeof( vportal_t ) );
1042 faceleafs = safe_malloc( portalclusters * sizeof( leaf_t ) );
1043 memset( faceleafs, 0, portalclusters * sizeof( leaf_t ) );
1045 for ( i = 0, p = faces; i < numfaces; i++ )
1047 if ( fscanf( f, "%i %i ", &numpoints, &leafnums[0] ) != 2 ) {
1048 Error( "LoadPortals: reading portal %i", i );
1051 w = p->winding = NewFixedWinding( numpoints );
1052 w->numpoints = numpoints;
1054 for ( j = 0 ; j < numpoints ; j++ )
1059 // scanf into double, then assign to vec_t
1060 // so we don't care what size vec_t is
1061 if ( fscanf( f, "(%lf %lf %lf ) "
1062 , &v[0], &v[1], &v[2] ) != 3 ) {
1063 Error( "LoadPortals: reading portal %i", i );
1065 for ( k = 0 ; k < 3 ; k++ )
1066 w->points[j][k] = v[k];
1068 if ( fscanf( f, "\n" ) != 0 ) {
1069 // silence gcc warning
1073 PlaneFromWinding( w, &plane );
1075 l = &faceleafs[leafnums[0]];
1077 if ( l->numportals == MAX_PORTALS_ON_LEAF ) {
1078 Error( "Leaf with too many faces" );
1080 l->portals[l->numportals] = p;
1085 // normal pointing out of the leaf
1086 VectorSubtract( vec3_origin, plane.normal, p->plane.normal );
1087 p->plane.dist = -plane.dist;
1089 SetPortalSphere( p );
1103 int VisMain( int argc, char **argv ){
1105 char portalFilePath[ 1024 ];
1106 portalFilePath[0] = 0;
1110 Sys_Printf( "--- Vis ---\n" );
1112 /* process arguments */
1113 for ( i = 1 ; i < ( argc - 1 ) ; i++ )
1115 if ( !strcmp( argv[i], "-fast" ) ) {
1116 Sys_Printf( "fastvis = true\n" );
1119 else if ( !strcmp( argv[i], "-merge" ) ) {
1120 Sys_Printf( "merge = true\n" );
1123 else if ( !strcmp( argv[i], "-mergeportals" ) ) {
1124 Sys_Printf( "mergeportals = true\n" );
1125 mergevisportals = qtrue;
1127 else if ( !strcmp( argv[i], "-nopassage" ) ) {
1128 Sys_Printf( "nopassage = true\n" );
1129 noPassageVis = qtrue;
1131 else if ( !strcmp( argv[i], "-passageOnly" ) ) {
1132 Sys_Printf( "passageOnly = true\n" );
1133 passageVisOnly = qtrue;
1135 else if ( !strcmp( argv[i],"-nosort" ) ) {
1136 Sys_Printf( "nosort = true\n" );
1139 else if ( !strcmp( argv[i],"-saveprt" ) ) {
1140 Sys_Printf( "saveprt = true\n" );
1143 else if ( !strcmp( argv[ i ], "-v" ) ) {
1144 debugCluster = qtrue;
1145 Sys_Printf( "Extra verbous mode enabled\n" );
1147 else if ( !strcmp( argv[i],"-tmpin" ) ) {
1148 strcpy( inbase, "/tmp" );
1150 else if ( !strcmp( argv[i],"-tmpout" ) ) {
1151 strcpy( outbase, "/tmp" );
1154 /* ydnar: -hint to merge all but hint portals */
1155 else if ( !strcmp( argv[ i ], "-hint" ) ) {
1156 Sys_Printf( "hint = true\n" );
1160 else if ( !strcmp( argv[ i ], "-prtfile" ) )
1162 strcpy( portalFilePath, argv[i + 1] );
1164 Sys_Printf( "Use %s as portal file\n", portalFilePath );
1168 Sys_FPrintf( SYS_WRN, "WARNING: Unknown option \"%s\"\n", argv[ i ] );
1172 if ( i != argc - 1 ) {
1173 Error( "usage: vis [-threads #] [-fast] [-v] BSPFilePath" );
1178 sprintf( source, "%s%s", inbase, ExpandArg( argv[ i ] ) );
1179 StripExtension( source );
1180 strcat( source, ".bsp" );
1181 Sys_Printf( "Loading %s\n", source );
1182 LoadBSPFile( source );
1184 /* load the portal file */
1185 if (!portalFilePath[0]) {
1186 sprintf( portalFilePath, "%s%s", inbase, ExpandArg( argv[ i ] ) );
1187 StripExtension( portalFilePath );
1188 strcat( portalFilePath, ".prt" );
1190 Sys_Printf( "Loading %s\n", portalFilePath );
1191 LoadPortals( portalFilePath );
1193 /* ydnar: exit if no portals, hence no vis */
1194 if ( numportals == 0 ) {
1195 Sys_Printf( "No portals means no vis, exiting.\n" );
1199 /* ydnar: for getting far plane */
1202 /* inject command line parameters */
1203 InjectCommandLine( argv, 0, argc - 1 );
1210 if ( mergevis || mergevisportals ) {
1214 CountActivePortals();
1215 /* WritePortals( "maps/hints.prs" );*/
1217 Sys_Printf( "visdatasize:%i\n", numBSPVisBytes );
1221 /* delete the prt file */
1223 remove( portalFilePath );
1226 /* write the bsp file */
1227 Sys_Printf( "Writing %s\n", source );
1228 WriteBSPFile( source );