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_malloc0( size );
76 void prl( leaf_t *l ){
81 for ( i = 0 ; i < l->numportals ; i++ )
85 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] );
90 //=============================================================================
96 Sorts the portals from the least complex, so the later ones can reuse
97 the earlier information.
100 int PComp( const void *a, const void *b ){
101 if ( ( *(const vportal_t *const *)a )->nummightsee == ( *(const vportal_t *const *)b )->nummightsee ) {
104 if ( ( *(const vportal_t *const *)a )->nummightsee < ( *(const vportal_t *const *)b )->nummightsee ) {
109 void SortPortals( void ){
112 for ( i = 0 ; i < numportals * 2 ; i++ )
113 sorted_portals[i] = &portals[i];
118 qsort( sorted_portals, numportals * 2, sizeof( sorted_portals[0] ), PComp );
124 LeafVectorFromPortalVector
127 int LeafVectorFromPortalVector( byte *portalbits, byte *leafbits ){
133 for ( i = 0 ; i < numportals * 2 ; i++ )
135 if ( portalbits[i >> 3] & ( 1 << ( i & 7 ) ) ) {
137 leafbits[p->leaf >> 3] |= ( 1 << ( p->leaf & 7 ) );
141 for ( j = 0; j < portalclusters; j++ )
144 while ( leafs[leafnum].merged >= 0 )
145 leafnum = leafs[leafnum].merged;
146 //if the merged leaf is visible then the original leaf is visible
147 if ( leafbits[leafnum >> 3] & ( 1 << ( leafnum & 7 ) ) ) {
148 leafbits[j >> 3] |= ( 1 << ( j & 7 ) );
152 c_leafs = CountBits( leafbits, portalclusters );
162 Merges the portal visibility for a leaf
166 static int clustersizehistogram[MAX_MAP_LEAFS] = {0};
168 void ClusterMerge( int leafnum ){
170 byte portalvector[MAX_PORTALS / 8];
171 byte uncompressed[MAX_MAP_LEAFS / 8];
173 int numvis, mergedleafnum;
177 // OR together all the portalvis bits
179 mergedleafnum = leafnum;
180 while ( leafs[mergedleafnum].merged >= 0 )
181 mergedleafnum = leafs[mergedleafnum].merged;
183 memset( portalvector, 0, portalbytes );
184 leaf = &leafs[mergedleafnum];
185 for ( i = 0; i < leaf->numportals; i++ )
187 p = leaf->portals[i];
192 if ( p->status != stat_done ) {
193 Error( "portal not done" );
195 for ( j = 0 ; j < portallongs ; j++ )
196 ( (long *)portalvector )[j] |= ( (long *)p->portalvis )[j];
198 portalvector[pnum >> 3] |= 1 << ( pnum & 7 );
201 memset( uncompressed, 0, leafbytes );
203 uncompressed[mergedleafnum >> 3] |= ( 1 << ( mergedleafnum & 7 ) );
204 // convert portal bits to leaf bits
205 numvis = LeafVectorFromPortalVector( portalvector, uncompressed );
207 // if (uncompressed[leafnum>>3] & (1<<(leafnum&7)))
208 // Sys_FPrintf (SYS_WRN, "WARNING: Leaf portals saw into leaf\n");
210 // uncompressed[leafnum>>3] |= (1<<(leafnum&7));
212 numvis++; // count the leaf itself
214 //Sys_FPrintf( SYS_VRB,"cluster %4i : %4i visible\n", leafnum, numvis );
215 ++clustersizehistogram[numvis];
217 memcpy( bspVisBytes + VIS_HEADER_SIZE + leafnum * leafbytes, uncompressed, leafbytes );
225 void CalcPortalVis( void ){
227 Sys_Printf( "%6d portals out of %d", 0, numportals * 2 );
228 //get rid of the counter
229 RunThreadsOnIndividual( numportals * 2, qfalse, PortalFlow );
231 RunThreadsOnIndividual( numportals * 2, qtrue, PortalFlow );
241 void CalcPassageVis( void ){
245 _printf( "%6d portals out of %d", 0, numportals * 2 );
246 RunThreadsOnIndividual( numportals * 2, qfalse, CreatePassages );
248 _printf( "%6d portals out of %d", 0, numportals * 2 );
249 RunThreadsOnIndividual( numportals * 2, qfalse, PassageFlow );
252 Sys_Printf( "\n--- CreatePassages (%d) ---\n", numportals * 2 );
253 RunThreadsOnIndividual( numportals * 2, qtrue, CreatePassages );
255 Sys_Printf( "\n--- PassageFlow (%d) ---\n", numportals * 2 );
256 RunThreadsOnIndividual( numportals * 2, qtrue, PassageFlow );
265 void CalcPassagePortalVis( void ){
269 Sys_Printf( "%6d portals out of %d", 0, numportals * 2 );
270 RunThreadsOnIndividual( numportals * 2, qfalse, CreatePassages );
272 Sys_Printf( "%6d portals out of %d", 0, numportals * 2 );
273 RunThreadsOnIndividual( numportals * 2, qfalse, PassagePortalFlow );
276 Sys_Printf( "\n--- CreatePassages (%d) ---\n", numportals * 2 );
277 RunThreadsOnIndividual( numportals * 2, qtrue, CreatePassages );
279 Sys_Printf( "\n--- PassagePortalFlow (%d) ---\n", numportals * 2 );
280 RunThreadsOnIndividual( numportals * 2, qtrue, PassagePortalFlow );
289 void CalcFastVis( void ){
292 // fastvis just uses mightsee for a very loose bound
293 for ( i = 0 ; i < numportals * 2 ; i++ )
295 portals[i].portalvis = portals[i].portalflood;
296 portals[i].status = stat_done;
305 void CalcVis( void ){
306 int i, minvis, maxvis;
308 double mu, sigma, totalvis, totalvis2;
311 /* ydnar: rr2do2's farplane code */
313 value = ValueForKey( &entities[ 0 ], "_farplanedist" ); /* proper '_' prefixed key */
314 if ( value[ 0 ] == '\0' ) {
315 value = ValueForKey( &entities[ 0 ], "fogclip" ); /* wolf compatibility */
317 if ( value[ 0 ] == '\0' ) {
318 value = ValueForKey( &entities[ 0 ], "distancecull" ); /* sof2 compatibility */
320 if ( value[ 0 ] != '\0' ) {
321 farPlaneDist = atof( value );
322 farPlaneDistMode = value[strlen(value) - 1 ];
323 if ( farPlaneDist != 0.0f ) {
324 Sys_Printf( "farplane distance = %.1f\n", farPlaneDist );
326 if ( farPlaneDist != 0.0f && farPlaneDistMode == 'o' ) {
327 Sys_Printf( "farplane Origin2Origin mode on\n" );
329 if ( farPlaneDist != 0.0f && farPlaneDistMode == 'r' ) {
330 Sys_Printf( "farplane Radius+Radius mode on\n" );
332 if ( farPlaneDist != 0.0f && farPlaneDistMode == 'e' ) {
333 Sys_Printf( "farplane Exact distance mode on\n" );
341 Sys_Printf( "\n--- BasePortalVis (%d) ---\n", numportals * 2 );
342 RunThreadsOnIndividual( numportals * 2, qtrue, BasePortalVis );
344 // RunThreadsOnIndividual (numportals*2, qtrue, BetterPortalVis);
351 else if ( noPassageVis ) {
354 else if ( passageVisOnly ) {
358 CalcPassagePortalVis();
361 // assemble the leaf vis lists by oring and compressing the portal lists
363 Sys_Printf( "creating leaf vis...\n" );
364 for ( i = 0 ; i < portalclusters ; i++ )
371 for ( i = 0; i < MAX_MAP_LEAFS; ++i )
372 if ( clustersizehistogram[i] ) {
373 if ( debugCluster ) {
374 Sys_FPrintf( SYS_VRB, "%4i clusters have exactly %4i visible clusters\n", clustersizehistogram[i], i );
376 /* cast is to prevent integer overflow */
377 totalvis += ( (double) i ) * ( (double) clustersizehistogram[i] );
378 totalvis2 += ( (double) i ) * ( (double) i ) * ( (double) clustersizehistogram[i] );
386 mu = totalvis / portalclusters;
387 sigma = sqrt( totalvis2 / portalclusters - mu * mu );
389 Sys_Printf( "Total clusters: %i\n", portalclusters );
390 Sys_Printf( "Total visible clusters: %.0f\n", totalvis );
391 Sys_Printf( "Average clusters visible: %.2f (%.3f%%/total)\n", mu, mu / portalclusters * 100.0 );
392 Sys_Printf( " Standard deviation: %.2f (%.3f%%/total, %.3f%%/avg)\n", sigma, sigma / portalclusters * 100.0, sigma / mu * 100.0 );
393 Sys_Printf( " Minimum: %i (%.3f%%/total, %.3f%%/avg)\n", minvis, minvis / (double) portalclusters * 100.0, minvis / mu * 100.0 );
394 Sys_Printf( " Maximum: %i (%.3f%%/total, %.3f%%/avg)\n", maxvis, maxvis / (double) portalclusters * 100.0, maxvis / mu * 100.0 );
402 void SetPortalSphere( vportal_t *p ){
409 VectorCopy( vec3_origin, total );
410 for ( i = 0 ; i < w->numpoints ; i++ )
412 VectorAdd( total, w->points[i], total );
415 for ( i = 0 ; i < 3 ; i++ )
416 total[i] /= w->numpoints;
419 for ( i = 0 ; i < w->numpoints ; i++ )
421 VectorSubtract( w->points[i], total, dist );
422 r = VectorLength( dist );
427 VectorCopy( total, p->origin );
433 Winding_PlanesConcave
436 #define WCONVEX_EPSILON 0.2
438 int Winding_PlanesConcave( fixedWinding_t *w1, fixedWinding_t *w2,
439 vec3_t normal1, vec3_t normal2,
440 float dist1, float dist2 ){
447 // check if one of the points of winding 1 is at the front of the plane of winding 2
448 for ( i = 0; i < w1->numpoints; i++ )
450 if ( DotProduct( normal2, w1->points[i] ) - dist2 > WCONVEX_EPSILON ) {
454 // check if one of the points of winding 2 is at the front of the plane of winding 1
455 for ( i = 0; i < w2->numpoints; i++ )
457 if ( DotProduct( normal1, w2->points[i] ) - dist1 > WCONVEX_EPSILON ) {
470 int TryMergeLeaves( int l1num, int l2num ){
471 int i, j, k, n, numportals;
472 visPlane_t plane1, plane2;
475 vportal_t *portals[MAX_PORTALS_ON_LEAF];
477 for ( k = 0; k < 2; k++ )
482 else{l1 = &faceleafs[l1num]; }
483 for ( i = 0; i < l1->numportals; i++ )
486 if ( p1->leaf == l2num ) {
489 for ( n = 0; n < 2; n++ )
494 else{l2 = &faceleafs[l2num]; }
495 for ( j = 0; j < l2->numportals; j++ )
498 if ( p2->leaf == l1num ) {
504 if ( Winding_PlanesConcave( p1->winding, p2->winding, plane1.normal, plane2.normal, plane1.dist, plane2.dist ) ) {
511 for ( k = 0; k < 2; k++ )
519 l1 = &faceleafs[l1num];
520 l2 = &faceleafs[l2num];
523 //the leaves can be merged now
524 for ( i = 0; i < l1->numportals; i++ )
527 if ( p1->leaf == l2num ) {
531 portals[numportals++] = p1;
533 for ( j = 0; j < l2->numportals; j++ )
536 if ( p2->leaf == l1num ) {
540 portals[numportals++] = p2;
542 for ( i = 0; i < numportals; i++ )
544 l2->portals[i] = portals[i];
546 l2->numportals = numportals;
557 void UpdatePortals( void ){
561 for ( i = 0; i < numportals * 2; i++ )
567 while ( leafs[p->leaf].merged >= 0 )
568 p->leaf = leafs[p->leaf].merged;
576 try to merge leaves but don't merge through hint splitters
579 void MergeLeaves( void ){
580 int i, j, nummerges, totalnummerges;
588 for ( i = 0; i < portalclusters; i++ )
591 //if this leaf is merged already
593 /* ydnar: vmods: merge all non-hint portals */
594 if ( leaf->merged >= 0 && hint == qfalse ) {
599 for ( j = 0; j < leaf->numportals; j++ )
601 p = leaf->portals[j];
606 //never merge through hint portals
610 if ( TryMergeLeaves( i, p->leaf ) ) {
617 totalnummerges += nummerges;
618 } while ( nummerges );
619 Sys_Printf( "%6d leaves merged\n", totalnummerges );
627 #define CONTINUOUS_EPSILON 0.005
629 fixedWinding_t *TryMergeWinding( fixedWinding_t *f1, fixedWinding_t *f2, vec3_t planenormal ){
630 vec_t *p1, *p2, *p3, *p4, *back;
631 fixedWinding_t *newf;
633 vec3_t normal, delta;
635 qboolean keep1, keep2;
639 // find a common edge
641 p1 = p2 = NULL; // stop compiler warning
644 for ( i = 0; i < f1->numpoints; i++ )
647 p2 = f1->points[( i + 1 ) % f1->numpoints];
648 for ( j = 0; j < f2->numpoints; j++ )
651 p4 = f2->points[( j + 1 ) % f2->numpoints];
652 for ( k = 0; k < 3; k++ )
654 if ( fabs( p1[k] - p4[k] ) > 0.1 ) { //EQUAL_EPSILON) //ME
657 if ( fabs( p2[k] - p3[k] ) > 0.1 ) { //EQUAL_EPSILON) //ME
665 if ( j < f2->numpoints ) {
670 if ( i == f1->numpoints ) {
671 return NULL; // no matching edges
675 // check slope of connected lines
676 // if the slopes are colinear, the point can be removed
678 back = f1->points[( i + f1->numpoints - 1 ) % f1->numpoints];
679 VectorSubtract( p1, back, delta );
680 CrossProduct( planenormal, delta, normal );
681 VectorNormalize( normal, normal );
683 back = f2->points[( j + 2 ) % f2->numpoints];
684 VectorSubtract( back, p1, delta );
685 dot = DotProduct( delta, normal );
686 if ( dot > CONTINUOUS_EPSILON ) {
687 return NULL; // not a convex polygon
689 keep1 = (qboolean)( dot < -CONTINUOUS_EPSILON );
691 back = f1->points[( i + 2 ) % f1->numpoints];
692 VectorSubtract( back, p2, delta );
693 CrossProduct( planenormal, delta, normal );
694 VectorNormalize( normal, normal );
696 back = f2->points[( j + f2->numpoints - 1 ) % f2->numpoints];
697 VectorSubtract( back, p2, delta );
698 dot = DotProduct( delta, normal );
699 if ( dot > CONTINUOUS_EPSILON ) {
700 return NULL; // not a convex polygon
702 keep2 = (qboolean)( dot < -CONTINUOUS_EPSILON );
705 // build the new polygon
707 newf = NewFixedWinding( f1->numpoints + f2->numpoints );
709 // copy first polygon
710 for ( k = ( i + 1 ) % f1->numpoints ; k != i ; k = ( k + 1 ) % f1->numpoints )
712 if ( k == ( i + 1 ) % f1->numpoints && !keep2 ) {
716 VectorCopy( f1->points[k], newf->points[newf->numpoints] );
720 // copy second polygon
721 for ( l = ( j + 1 ) % f2->numpoints ; l != j ; l = ( l + 1 ) % f2->numpoints )
723 if ( l == ( j + 1 ) % f2->numpoints && !keep1 ) {
726 VectorCopy( f2->points[l], newf->points[newf->numpoints] );
738 void MergeLeafPortals( void ){
739 int i, j, k, nummerges, hintsmerged;
746 for ( i = 0; i < portalclusters; i++ )
749 if ( leaf->merged >= 0 ) {
752 for ( j = 0; j < leaf->numportals; j++ )
754 p1 = leaf->portals[j];
758 for ( k = j + 1; k < leaf->numportals; k++ )
760 p2 = leaf->portals[k];
764 if ( p1->leaf == p2->leaf ) {
765 w = TryMergeWinding( p1->winding, p2->winding, p1->plane.normal );
767 free( p1->winding ); //% FreeWinding(p1->winding);
769 if ( p1->hint && p2->hint ) {
772 p1->hint |= p2->hint;
773 SetPortalSphere( p1 );
781 if ( k < leaf->numportals ) {
786 Sys_Printf( "%6d portals merged\n", nummerges );
787 Sys_Printf( "%6d hint portals merged\n", hintsmerged );
796 int CountActivePortals( void ){
802 for ( j = 0; j < numportals * 2; j++ )
813 Sys_Printf( "%6d active portals\n", num );
814 Sys_Printf( "%6d hint portals\n", hints );
823 void WriteFloat( FILE *f, vec_t v );
825 void WritePortals( char *portalpathfile ){
832 pf = fopen( portalpathfile, "w" );
834 Error( "Error opening %s", portalpathfile );
838 for ( j = 0; j < numportals * 2; j++ )
849 fprintf( pf, "%s\n", PORTALFILE );
850 fprintf( pf, "%i\n", 0 );
851 fprintf( pf, "%i\n", num ); // + numfaces);
852 fprintf( pf, "%i\n", 0 );
854 for ( j = 0; j < numportals * 2; j++ )
863 fprintf( pf,"%i %i %i ",w->numpoints, 0, 0 );
864 fprintf( pf, "%d ", p->hint );
865 for ( i = 0 ; i < w->numpoints ; i++ )
868 WriteFloat( pf, w->points[i][0] );
869 WriteFloat( pf, w->points[i][1] );
870 WriteFloat( pf, w->points[i][2] );
877 for (j = 0; j < numfaces; j++)
881 fprintf (pf,"%i %i %i ",w->numpoints, 0, 0);
883 for (i=0 ; i<w->numpoints ; i++)
886 WriteFloat (pf, w->points[i][0]);
887 WriteFloat (pf, w->points[i][1]);
888 WriteFloat (pf, w->points[i][2]);
902 void LoadPortals( char *name ){
913 if ( !strcmp( name,"-" ) ) {
918 f = fopen( name, "r" );
920 Error( "LoadPortals: couldn't read %s\n",name );
924 if ( fscanf( f,"%79s\n%i\n%i\n%i\n",magic, &portalclusters, &numportals, &numfaces ) != 4 ) {
925 Error( "LoadPortals: failed to read header" );
927 if ( strcmp( magic,PORTALFILE ) ) {
928 Error( "LoadPortals: not a portal file" );
931 Sys_Printf( "%6i portalclusters\n", portalclusters );
932 Sys_Printf( "%6i numportals\n", numportals );
933 Sys_Printf( "%6i numfaces\n", numfaces );
935 if ( numportals > MAX_PORTALS ) {
936 Error( "MAX_PORTALS" );
939 // these counts should take advantage of 64 bit systems automatically
940 leafbytes = ( ( portalclusters + 63 ) & ~63 ) >> 3;
941 leaflongs = leafbytes / sizeof( long );
943 portalbytes = ( ( numportals * 2 + 63 ) & ~63 ) >> 3;
944 portallongs = portalbytes / sizeof( long );
946 // each file portal is split into two memory portals
947 portals = safe_malloc0( 2 * numportals * sizeof( vportal_t ) );
949 leafs = safe_malloc0( portalclusters * sizeof( leaf_t ) );
951 for ( i = 0; i < portalclusters; i++ )
952 leafs[i].merged = -1;
954 numBSPVisBytes = VIS_HEADER_SIZE + portalclusters * leafbytes;
956 if ( numBSPVisBytes > MAX_MAP_VISIBILITY ) {
957 Error( "MAX_MAP_VISIBILITY exceeded" );
960 ( (int *)bspVisBytes )[0] = portalclusters;
961 ( (int *)bspVisBytes )[1] = leafbytes;
963 for ( i = 0, p = portals ; i < numportals ; i++ )
965 if ( fscanf( f, "%i %i %i ", &numpoints, &leafnums[0], &leafnums[1] ) != 3 ) {
966 Error( "LoadPortals: reading portal %i", i );
968 if ( numpoints > MAX_POINTS_ON_WINDING ) {
969 Error( "LoadPortals: portal %i has too many points", i );
971 if ( leafnums[0] > portalclusters
972 || leafnums[1] > portalclusters ) {
973 Error( "LoadPortals: reading portal %i", i );
975 if ( fscanf( f, "%i ", &flags ) != 1 ) {
976 Error( "LoadPortals: reading flags" );
979 w = p->winding = NewFixedWinding( numpoints );
980 w->numpoints = numpoints;
982 for ( j = 0 ; j < numpoints ; j++ )
987 // scanf into double, then assign to vec_t
988 // so we don't care what size vec_t is
989 if ( fscanf( f, "(%lf %lf %lf ) "
990 , &v[0], &v[1], &v[2] ) != 3 ) {
991 Error( "LoadPortals: reading portal %i", i );
993 for ( k = 0 ; k < 3 ; k++ )
994 w->points[j][k] = v[k];
996 if ( fscanf( f, "\n" ) != 0 ) {
997 // silence gcc warning
1001 PlaneFromWinding( w, &plane );
1003 // create forward portal
1004 l = &leafs[leafnums[0]];
1005 if ( l->numportals == MAX_PORTALS_ON_LEAF ) {
1006 Error( "Leaf with too many portals" );
1008 l->portals[l->numportals] = p;
1012 p->hint = ((flags & 1) != 0);
1013 p->sky = ((flags & 2) != 0);
1015 VectorSubtract( vec3_origin, plane.normal, p->plane.normal );
1016 p->plane.dist = -plane.dist;
1017 p->leaf = leafnums[1];
1018 SetPortalSphere( p );
1021 // create backwards portal
1022 l = &leafs[leafnums[1]];
1023 if ( l->numportals == MAX_PORTALS_ON_LEAF ) {
1024 Error( "Leaf with too many portals" );
1026 l->portals[l->numportals] = p;
1031 p->winding = NewFixedWinding( w->numpoints );
1032 p->winding->numpoints = w->numpoints;
1033 for ( j = 0 ; j < w->numpoints ; j++ )
1035 VectorCopy( w->points[w->numpoints - 1 - j], p->winding->points[j] );
1039 p->leaf = leafnums[0];
1040 SetPortalSphere( p );
1045 faces = safe_malloc0( 2 * numfaces * sizeof( vportal_t ) );
1047 faceleafs = safe_malloc0( portalclusters * sizeof( leaf_t ) );
1049 for ( i = 0, p = faces; i < numfaces; i++ )
1051 if ( fscanf( f, "%i %i ", &numpoints, &leafnums[0] ) != 2 ) {
1052 Error( "LoadPortals: reading portal %i", i );
1055 w = p->winding = NewFixedWinding( numpoints );
1056 w->numpoints = numpoints;
1058 for ( j = 0 ; j < numpoints ; j++ )
1063 // scanf into double, then assign to vec_t
1064 // so we don't care what size vec_t is
1065 if ( fscanf( f, "(%lf %lf %lf ) "
1066 , &v[0], &v[1], &v[2] ) != 3 ) {
1067 Error( "LoadPortals: reading portal %i", i );
1069 for ( k = 0 ; k < 3 ; k++ )
1070 w->points[j][k] = v[k];
1072 if ( fscanf( f, "\n" ) != 0 ) {
1073 // silence gcc warning
1077 PlaneFromWinding( w, &plane );
1079 l = &faceleafs[leafnums[0]];
1081 if ( l->numportals == MAX_PORTALS_ON_LEAF ) {
1082 Error( "Leaf with too many faces" );
1084 l->portals[l->numportals] = p;
1089 // normal pointing out of the leaf
1090 VectorSubtract( vec3_origin, plane.normal, p->plane.normal );
1091 p->plane.dist = -plane.dist;
1093 SetPortalSphere( p );
1107 int VisMain( int argc, char **argv ){
1109 char portalFilePath[ 1024 ];
1110 portalFilePath[0] = 0;
1114 Sys_Printf( "--- Vis ---\n" );
1116 /* process arguments */
1117 for ( i = 1 ; i < ( argc - 1 ) ; i++ )
1119 if ( !strcmp( argv[i], "-fast" ) ) {
1120 Sys_Printf( "fastvis = true\n" );
1123 else if ( !strcmp( argv[i], "-merge" ) ) {
1124 Sys_Printf( "merge = true\n" );
1127 else if ( !strcmp( argv[i], "-mergeportals" ) ) {
1128 Sys_Printf( "mergeportals = true\n" );
1129 mergevisportals = qtrue;
1131 else if ( !strcmp( argv[i], "-nopassage" ) ) {
1132 Sys_Printf( "nopassage = true\n" );
1133 noPassageVis = qtrue;
1135 else if ( !strcmp( argv[i], "-passageOnly" ) ) {
1136 Sys_Printf( "passageOnly = true\n" );
1137 passageVisOnly = qtrue;
1139 else if ( !strcmp( argv[i],"-nosort" ) ) {
1140 Sys_Printf( "nosort = true\n" );
1143 else if ( !strcmp( argv[i],"-saveprt" ) ) {
1144 Sys_Printf( "saveprt = true\n" );
1147 else if ( !strcmp( argv[ i ], "-v" ) ) {
1148 debugCluster = qtrue;
1149 Sys_Printf( "Extra verbose mode enabled\n" );
1151 else if ( !strcmp( argv[i],"-tmpin" ) ) {
1152 strcpy( inbase, "/tmp" );
1154 else if ( !strcmp( argv[i],"-tmpout" ) ) {
1155 strcpy( outbase, "/tmp" );
1158 /* ydnar: -hint to merge all but hint portals */
1159 else if ( !strcmp( argv[ i ], "-hint" ) ) {
1160 Sys_Printf( "hint = true\n" );
1164 else if ( !strcmp( argv[ i ], "-prtfile" ) )
1166 strcpy( portalFilePath, argv[i + 1] );
1170 Sys_Printf( "Use %s as portal file\n", portalFilePath );
1174 Sys_FPrintf( SYS_WRN, "WARNING: Unknown option \"%s\"\n", argv[ i ] );
1178 if ( i != argc - 1 ) {
1179 Error( "usage: vis [-threads #] [-fast] [-v] BSPFilePath" );
1184 sprintf( source, "%s%s", inbase, ExpandArg( argv[ i ] ) );
1185 StripExtension( source );
1186 strcat( source, ".bsp" );
1187 Sys_Printf( "Loading %s\n", source );
1188 LoadBSPFile( source );
1190 if ( game->texFile )
1192 // smokinguns-like tex file
1193 StripExtension( source );
1194 strcat( source, ".tex" );
1195 LoadSurfaceFlags( source );
1196 StripExtension( source );
1197 strcat( source, ".bsp" );
1200 /* load the portal file */
1201 if (!portalFilePath[0]) {
1202 sprintf( portalFilePath, "%s%s", inbase, ExpandArg( argv[ i ] ) );
1203 StripExtension( portalFilePath );
1204 strcat( portalFilePath, ".prt" );
1206 Sys_Printf( "Loading %s\n", portalFilePath );
1207 LoadPortals( portalFilePath );
1209 /* ydnar: exit if no portals, hence no vis */
1210 if ( numportals == 0 ) {
1211 Sys_Printf( "No portals means no vis, exiting.\n" );
1215 /* ydnar: for getting far plane */
1218 /* inject command line parameters */
1219 InjectCommandLine( argv, 0, argc - 1 );
1226 if ( mergevis || mergevisportals ) {
1230 CountActivePortals();
1231 /* WritePortals( "maps/hints.prs" );*/
1233 Sys_Printf( "visdatasize:%i\n", numBSPVisBytes );
1237 /* delete the prt file */
1239 remove( portalFilePath );
1242 if ( game->texFile )
1244 // smokinguns-like tex file
1245 StripExtension( source );
1246 WriteTexFile( source );
1247 DefaultExtension( source, ".bsp" );
1250 /* write the bsp file */
1251 Sys_Printf( "Writing %s\n", source );
1252 WriteBSPFile( source );