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)
47 VectorSubtract (w->points[2], w->points[1], v1);
48 VectorSubtract (w->points[0], w->points[1], v2);
49 CrossProduct (v2, v1, plane->normal);
50 VectorNormalize (plane->normal, plane->normal);
51 plane->dist = DotProduct (w->points[0], plane->normal);
57 returns a new fixed winding
58 ydnar: altered this a bit to reconcile multiply-defined winding_t
61 fixedWinding_t *NewFixedWinding( int points )
66 if (points > MAX_POINTS_ON_WINDING)
67 Error ("NewWinding: %i points", points);
69 size = (int)((size_t)((fixedWinding_t *)0)->points[points]);
70 w = safe_malloc (size);
84 for (i=0 ; i<l->numportals ; i++)
88 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]);
93 //=============================================================================
99 Sorts the portals from the least complex, so the later ones can reuse
100 the earlier information.
103 int PComp (const void *a, const void *b)
105 if ( (*(const vportal_t *const *)a)->nummightsee == (*(const vportal_t *const *)b)->nummightsee)
107 if ( (*(const vportal_t *const *)a)->nummightsee < (*(const vportal_t *const *)b)->nummightsee)
111 void SortPortals (void)
115 for (i=0 ; i<numportals*2 ; i++)
116 sorted_portals[i] = &portals[i];
120 qsort (sorted_portals, numportals*2, sizeof(sorted_portals[0]), PComp);
126 LeafVectorFromPortalVector
129 int LeafVectorFromPortalVector (byte *portalbits, byte *leafbits)
136 for (i=0 ; i<numportals*2 ; i++)
138 if (portalbits[i>>3] & (1<<(i&7)) )
141 leafbits[p->leaf>>3] |= (1<<(p->leaf&7));
145 for (j = 0; j < portalclusters; j++)
148 while (leafs[leafnum].merged >= 0)
149 leafnum = leafs[leafnum].merged;
150 //if the merged leaf is visible then the original leaf is visible
151 if (leafbits[leafnum>>3] & (1<<(leafnum&7)))
153 leafbits[j>>3] |= (1<<(j&7));
157 c_leafs = CountBits (leafbits, portalclusters);
167 Merges the portal visibility for a leaf
170 static int clustersizehistogram[MAX_MAP_LEAFS] = {0};
171 void ClusterMerge (int leafnum)
174 byte portalvector[MAX_PORTALS/8];
175 byte uncompressed[MAX_MAP_LEAFS/8];
177 int numvis, mergedleafnum;
181 // OR together all the portalvis bits
183 mergedleafnum = leafnum;
184 while(leafs[mergedleafnum].merged >= 0)
185 mergedleafnum = leafs[mergedleafnum].merged;
187 memset (portalvector, 0, portalbytes);
188 leaf = &leafs[mergedleafnum];
189 for (i = 0; i < leaf->numportals; i++)
191 p = leaf->portals[i];
195 if (p->status != stat_done)
196 Error ("portal not done");
197 for (j=0 ; j<portallongs ; j++)
198 ((long *)portalvector)[j] |= ((long *)p->portalvis)[j];
200 portalvector[pnum>>3] |= 1<<(pnum&7);
203 memset (uncompressed, 0, leafbytes);
205 uncompressed[mergedleafnum>>3] |= (1<<(mergedleafnum&7));
206 // convert portal bits to leaf bits
207 numvis = LeafVectorFromPortalVector (portalvector, uncompressed);
209 // if (uncompressed[leafnum>>3] & (1<<(leafnum&7)))
210 // Sys_Printf ("WARNING: Leaf portals saw into leaf\n");
212 // uncompressed[leafnum>>3] |= (1<<(leafnum&7));
214 numvis++; // count the leaf itself
216 //Sys_FPrintf (SYS_VRB,"cluster %4i : %4i visible\n", leafnum, numvis);
217 ++clustersizehistogram[numvis];
219 memcpy (bspVisBytes + VIS_HEADER_SIZE + leafnum*leafbytes, uncompressed, leafbytes);
227 void CalcPortalVis (void)
230 Sys_Printf("%6d portals out of %d", 0, numportals*2);
231 //get rid of the counter
232 RunThreadsOnIndividual (numportals*2, qfalse, PortalFlow);
234 RunThreadsOnIndividual (numportals*2, qtrue, PortalFlow);
244 void CalcPassageVis(void)
249 _printf("%6d portals out of %d", 0, numportals*2);
250 RunThreadsOnIndividual (numportals*2, qfalse, CreatePassages);
252 _printf("%6d portals out of %d", 0, numportals*2);
253 RunThreadsOnIndividual (numportals*2, qfalse, PassageFlow);
256 Sys_Printf( "\n--- CreatePassages (%d) ---\n", numportals * 2 );
257 RunThreadsOnIndividual( numportals*2, qtrue, CreatePassages );
259 Sys_Printf( "\n--- PassageFlow (%d) ---\n", numportals * 2 );
260 RunThreadsOnIndividual( numportals * 2, qtrue, PassageFlow );
269 void CalcPassagePortalVis(void)
274 Sys_Printf("%6d portals out of %d", 0, numportals*2);
275 RunThreadsOnIndividual (numportals*2, qfalse, CreatePassages);
277 Sys_Printf("%6d portals out of %d", 0, numportals*2);
278 RunThreadsOnIndividual (numportals*2, qfalse, PassagePortalFlow);
281 Sys_Printf( "\n--- CreatePassages (%d) ---\n", numportals * 2 );
282 RunThreadsOnIndividual( numportals * 2, qtrue, CreatePassages);
284 Sys_Printf( "\n--- PassagePortalFlow (%d) ---\n", numportals * 2 );
285 RunThreadsOnIndividual( numportals * 2, qtrue, PassagePortalFlow );
294 void CalcFastVis(void)
298 // fastvis just uses mightsee for a very loose bound
299 for (i=0 ; i<numportals*2 ; i++)
301 portals[i].portalvis = portals[i].portalflood;
302 portals[i].status = stat_done;
313 int i, minvis, maxvis;
315 double mu, sigma, totalvis, totalvis2;
318 /* ydnar: rr2do2's farplane code */
320 value = ValueForKey( &entities[ 0 ], "_farplanedist" ); /* proper '_' prefixed key */
321 if( value[ 0 ] == '\0' )
322 value = ValueForKey( &entities[ 0 ], "fogclip" ); /* wolf compatibility */
323 if( value[ 0 ] == '\0' )
324 value = ValueForKey( &entities[ 0 ], "distancecull" ); /* sof2 compatibility */
325 if( value[ 0 ] != '\0' )
327 farPlaneDist = atof( value );
328 if( farPlaneDist > 0.0f )
329 Sys_Printf( "farplane distance = %.1f\n", farPlaneDist );
336 Sys_Printf( "\n--- BasePortalVis (%d) ---\n", numportals * 2 );
337 RunThreadsOnIndividual( numportals * 2, qtrue, BasePortalVis );
339 // RunThreadsOnIndividual (numportals*2, qtrue, BetterPortalVis);
346 else if ( noPassageVis ) {
349 else if ( passageVisOnly ) {
353 CalcPassagePortalVis();
356 // assemble the leaf vis lists by oring and compressing the portal lists
358 Sys_Printf("creating leaf vis...\n");
359 for (i=0 ; i<portalclusters ; i++)
366 for(i = 0; i < MAX_MAP_LEAFS; ++i)
367 if(clustersizehistogram[i])
370 Sys_FPrintf(SYS_VRB, "%4i clusters have exactly %4i visible clusters\n", clustersizehistogram[i], i);
371 /* cast is to prevent integer overflow */
372 totalvis += ((double) i) * ((double) clustersizehistogram[i]);
373 totalvis2 += ((double) i) * ((double) i) * ((double) clustersizehistogram[i]);
380 mu = totalvis / portalclusters;
381 sigma = sqrt(totalvis2 / portalclusters - mu * mu);
383 Sys_Printf( "Total clusters: %i\n", portalclusters );
384 Sys_Printf( "Total visible clusters: %.0f\n", totalvis );
385 Sys_Printf( "Average clusters visible: %.2f (%.3f%%/total)\n", mu, mu / portalclusters * 100.0);
386 Sys_Printf( " Standard deviation: %.2f (%.3f%%/total, %.3f%%/avg)\n", sigma, sigma / portalclusters * 100.0, sigma / mu * 100.0);
387 Sys_Printf( " Minimum: %i (%.3f%%/total, %.3f%%/avg)\n", minvis, minvis / (double) portalclusters * 100.0, minvis / mu * 100.0);
388 Sys_Printf( " Maximum: %i (%.3f%%/total, %.3f%%/avg)\n", maxvis, maxvis / (double) portalclusters * 100.0, maxvis / mu * 100.0);
396 void SetPortalSphere (vportal_t *p)
404 VectorCopy (vec3_origin, total);
405 for (i=0 ; i<w->numpoints ; i++)
407 VectorAdd (total, w->points[i], total);
410 for (i=0 ; i<3 ; i++)
411 total[i] /= w->numpoints;
414 for (i=0 ; i<w->numpoints ; i++)
416 VectorSubtract (w->points[i], total, dist);
417 r = VectorLength (dist);
421 VectorCopy (total, p->origin);
427 Winding_PlanesConcave
430 #define WCONVEX_EPSILON 0.2
432 int Winding_PlanesConcave(fixedWinding_t *w1, fixedWinding_t *w2,
433 vec3_t normal1, vec3_t normal2,
434 float dist1, float dist2)
438 if (!w1 || !w2) return qfalse;
440 // check if one of the points of winding 1 is at the front of the plane of winding 2
441 for (i = 0; i < w1->numpoints; i++)
443 if (DotProduct(normal2, w1->points[i]) - dist2 > WCONVEX_EPSILON) return qtrue;
445 // check if one of the points of winding 2 is at the front of the plane of winding 1
446 for (i = 0; i < w2->numpoints; i++)
448 if (DotProduct(normal1, w2->points[i]) - dist1 > WCONVEX_EPSILON) return qtrue;
459 int TryMergeLeaves(int l1num, int l2num)
461 int i, j, k, n, numportals;
462 visPlane_t plane1, plane2;
465 vportal_t *portals[MAX_PORTALS_ON_LEAF];
467 for (k = 0; k < 2; k++)
469 if (k) l1 = &leafs[l1num];
470 else l1 = &faceleafs[l1num];
471 for (i = 0; i < l1->numportals; i++)
474 if (p1->leaf == l2num) continue;
475 for (n = 0; n < 2; n++)
477 if (n) l2 = &leafs[l2num];
478 else l2 = &faceleafs[l2num];
479 for (j = 0; j < l2->numportals; j++)
482 if (p2->leaf == l1num) continue;
486 if (Winding_PlanesConcave(p1->winding, p2->winding, plane1.normal, plane2.normal, plane1.dist, plane2.dist))
492 for (k = 0; k < 2; k++)
501 l1 = &faceleafs[l1num];
502 l2 = &faceleafs[l2num];
505 //the leaves can be merged now
506 for (i = 0; i < l1->numportals; i++)
509 if (p1->leaf == l2num)
514 portals[numportals++] = p1;
516 for (j = 0; j < l2->numportals; j++)
519 if (p2->leaf == l1num)
524 portals[numportals++] = p2;
526 for (i = 0; i < numportals; i++)
528 l2->portals[i] = portals[i];
530 l2->numportals = numportals;
541 void UpdatePortals(void)
546 for (i = 0; i < numportals * 2; i++)
551 while(leafs[p->leaf].merged >= 0)
552 p->leaf = leafs[p->leaf].merged;
560 try to merge leaves but don't merge through hint splitters
563 void MergeLeaves(void)
565 int i, j, nummerges, totalnummerges;
573 for (i = 0; i < portalclusters; i++)
576 //if this leaf is merged already
578 /* ydnar: vmods: merge all non-hint portals */
579 if( leaf->merged >= 0 && hint == qfalse )
583 for (j = 0; j < leaf->numportals; j++)
585 p = leaf->portals[j];
589 //never merge through hint portals
592 if (TryMergeLeaves(i, p->leaf))
600 totalnummerges += nummerges;
602 Sys_Printf("%6d leaves merged\n", totalnummerges);
610 #define CONTINUOUS_EPSILON 0.005
612 fixedWinding_t *TryMergeWinding (fixedWinding_t *f1, fixedWinding_t *f2, vec3_t planenormal)
614 vec_t *p1, *p2, *p3, *p4, *back;
615 fixedWinding_t *newf;
617 vec3_t normal, delta;
619 qboolean keep1, keep2;
623 // find a common edge
625 p1 = p2 = NULL; // stop compiler warning
628 for (i = 0; i < f1->numpoints; i++)
631 p2 = f1->points[(i+1) % f1->numpoints];
632 for (j = 0; j < f2->numpoints; j++)
635 p4 = f2->points[(j+1) % f2->numpoints];
636 for (k = 0; k < 3; k++)
638 if (fabs(p1[k] - p4[k]) > 0.1)//EQUAL_EPSILON) //ME
640 if (fabs(p2[k] - p3[k]) > 0.1)//EQUAL_EPSILON) //ME
646 if (j < f2->numpoints)
650 if (i == f1->numpoints)
651 return NULL; // no matching edges
654 // check slope of connected lines
655 // if the slopes are colinear, the point can be removed
657 back = f1->points[(i+f1->numpoints-1)%f1->numpoints];
658 VectorSubtract (p1, back, delta);
659 CrossProduct (planenormal, delta, normal);
660 VectorNormalize (normal, normal);
662 back = f2->points[(j+2)%f2->numpoints];
663 VectorSubtract (back, p1, delta);
664 dot = DotProduct (delta, normal);
665 if (dot > CONTINUOUS_EPSILON)
666 return NULL; // not a convex polygon
667 keep1 = (qboolean)(dot < -CONTINUOUS_EPSILON);
669 back = f1->points[(i+2)%f1->numpoints];
670 VectorSubtract (back, p2, delta);
671 CrossProduct (planenormal, delta, normal);
672 VectorNormalize (normal, normal);
674 back = f2->points[(j+f2->numpoints-1)%f2->numpoints];
675 VectorSubtract (back, p2, delta);
676 dot = DotProduct (delta, normal);
677 if (dot > CONTINUOUS_EPSILON)
678 return NULL; // not a convex polygon
679 keep2 = (qboolean)(dot < -CONTINUOUS_EPSILON);
682 // build the new polygon
684 newf = NewFixedWinding (f1->numpoints + f2->numpoints);
686 // copy first polygon
687 for (k=(i+1)%f1->numpoints ; k != i ; k=(k+1)%f1->numpoints)
689 if (k==(i+1)%f1->numpoints && !keep2)
692 VectorCopy (f1->points[k], newf->points[newf->numpoints]);
696 // copy second polygon
697 for (l= (j+1)%f2->numpoints ; l != j ; l=(l+1)%f2->numpoints)
699 if (l==(j+1)%f2->numpoints && !keep1)
701 VectorCopy (f2->points[l], newf->points[newf->numpoints]);
713 void MergeLeafPortals(void)
715 int i, j, k, nummerges, hintsmerged;
722 for (i = 0; i < portalclusters; i++)
725 if (leaf->merged >= 0) continue;
726 for (j = 0; j < leaf->numportals; j++)
728 p1 = leaf->portals[j];
731 for (k = j+1; k < leaf->numportals; k++)
733 p2 = leaf->portals[k];
736 if (p1->leaf == p2->leaf)
738 w = TryMergeWinding(p1->winding, p2->winding, p1->plane.normal);
741 free( p1->winding ); //% FreeWinding(p1->winding);
743 if (p1->hint && p2->hint)
745 p1->hint |= p2->hint;
754 if (k < leaf->numportals)
758 Sys_Printf("%6d portals merged\n", nummerges);
759 Sys_Printf("%6d hint portals merged\n", hintsmerged);
768 int CountActivePortals(void)
775 for (j = 0; j < numportals * 2; j++)
784 Sys_Printf("%6d active portals\n", num);
785 Sys_Printf("%6d hint portals\n", hints);
794 void WriteFloat (FILE *f, vec_t v);
796 void WritePortals(char *filename)
804 pf = fopen (filename, "w");
806 Error ("Error opening %s", filename);
809 for (j = 0; j < numportals * 2; j++)
819 fprintf (pf, "%s\n", PORTALFILE);
820 fprintf (pf, "%i\n", 0);
821 fprintf (pf, "%i\n", num);// + numfaces);
822 fprintf (pf, "%i\n", 0);
824 for (j = 0; j < numportals * 2; j++)
832 fprintf (pf,"%i %i %i ",w->numpoints, 0, 0);
833 fprintf (pf, "%d ", p->hint);
834 for (i=0 ; i<w->numpoints ; i++)
837 WriteFloat (pf, w->points[i][0]);
838 WriteFloat (pf, w->points[i][1]);
839 WriteFloat (pf, w->points[i][2]);
846 for (j = 0; j < numfaces; j++)
850 fprintf (pf,"%i %i %i ",w->numpoints, 0, 0);
852 for (i=0 ; i<w->numpoints ; i++)
855 WriteFloat (pf, w->points[i][0]);
856 WriteFloat (pf, w->points[i][1]);
857 WriteFloat (pf, w->points[i][2]);
871 void LoadPortals (char *name)
883 if (!strcmp(name,"-"))
887 f = fopen(name, "r");
889 Error ("LoadPortals: couldn't read %s\n",name);
892 if (fscanf (f,"%79s\n%i\n%i\n%i\n",magic, &portalclusters, &numportals, &numfaces) != 4)
893 Error ("LoadPortals: failed to read header");
894 if (strcmp(magic,PORTALFILE))
895 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");
904 // these counts should take advantage of 64 bit systems automatically
905 leafbytes = ((portalclusters+63)&~63)>>3;
906 leaflongs = leafbytes/sizeof(long);
908 portalbytes = ((numportals*2+63)&~63)>>3;
909 portallongs = portalbytes/sizeof(long);
911 // each file portal is split into two memory portals
912 portals = safe_malloc(2*numportals*sizeof(vportal_t));
913 memset (portals, 0, 2*numportals*sizeof(vportal_t));
915 leafs = safe_malloc(portalclusters*sizeof(leaf_t));
916 memset (leafs, 0, portalclusters*sizeof(leaf_t));
918 for (i = 0; i < portalclusters; i++)
919 leafs[i].merged = -1;
921 numBSPVisBytes = VIS_HEADER_SIZE + portalclusters*leafbytes;
923 if (numBSPVisBytes > MAX_MAP_VISIBILITY)
924 Error("MAX_MAP_VISIBILITY exceeded");
926 ((int *)bspVisBytes)[0] = portalclusters;
927 ((int *)bspVisBytes)[1] = leafbytes;
929 for (i=0, p=portals ; i<numportals ; i++)
931 if (fscanf (f, "%i %i %i ", &numpoints, &leafnums[0], &leafnums[1]) != 3)
932 Error ("LoadPortals: reading portal %i", i);
933 if (numpoints > MAX_POINTS_ON_WINDING)
934 Error ("LoadPortals: portal %i has too many points", i);
935 if (leafnums[0] > portalclusters
936 || leafnums[1] > portalclusters)
937 Error ("LoadPortals: reading portal %i", i);
938 if (fscanf (f, "%i ", &hint) != 1)
939 Error ("LoadPortals: reading hint state");
941 w = p->winding = NewFixedWinding (numpoints);
942 w->numpoints = numpoints;
944 for (j=0 ; j<numpoints ; j++)
949 // scanf into double, then assign to vec_t
950 // so we don't care what size vec_t is
951 if (fscanf (f, "(%lf %lf %lf ) "
952 , &v[0], &v[1], &v[2]) != 3)
953 Error ("LoadPortals: reading portal %i", i);
954 for (k=0 ; k<3 ; k++)
955 w->points[j][k] = v[k];
957 if(fscanf (f, "\n") != 0)
959 // silence gcc warning
963 PlaneFromWinding (w, &plane);
965 // create forward portal
966 l = &leafs[leafnums[0]];
967 if (l->numportals == MAX_PORTALS_ON_LEAF)
968 Error ("Leaf with too many portals");
969 l->portals[l->numportals] = p;
975 VectorSubtract (vec3_origin, plane.normal, p->plane.normal);
976 p->plane.dist = -plane.dist;
977 p->leaf = leafnums[1];
981 // create backwards portal
982 l = &leafs[leafnums[1]];
983 if (l->numportals == MAX_PORTALS_ON_LEAF)
984 Error ("Leaf with too many portals");
985 l->portals[l->numportals] = p;
990 p->winding = NewFixedWinding(w->numpoints);
991 p->winding->numpoints = w->numpoints;
992 for (j=0 ; j<w->numpoints ; j++)
994 VectorCopy (w->points[w->numpoints-1-j], p->winding->points[j]);
998 p->leaf = leafnums[0];
1004 faces = safe_malloc(2*numfaces*sizeof(vportal_t));
1005 memset (faces, 0, 2*numfaces*sizeof(vportal_t));
1007 faceleafs = safe_malloc(portalclusters*sizeof(leaf_t));
1008 memset(faceleafs, 0, portalclusters*sizeof(leaf_t));
1010 for (i = 0, p = faces; i < numfaces; i++)
1012 if (fscanf (f, "%i %i ", &numpoints, &leafnums[0]) != 2)
1013 Error ("LoadPortals: reading portal %i", i);
1015 w = p->winding = NewFixedWinding (numpoints);
1016 w->numpoints = numpoints;
1018 for (j=0 ; j<numpoints ; j++)
1023 // scanf into double, then assign to vec_t
1024 // so we don't care what size vec_t is
1025 if (fscanf (f, "(%lf %lf %lf ) "
1026 , &v[0], &v[1], &v[2]) != 3)
1027 Error ("LoadPortals: reading portal %i", i);
1028 for (k=0 ; k<3 ; k++)
1029 w->points[j][k] = v[k];
1031 if(fscanf (f, "\n") != 0)
1033 // silence gcc warning
1037 PlaneFromWinding (w, &plane);
1039 l = &faceleafs[leafnums[0]];
1041 if (l->numportals == MAX_PORTALS_ON_LEAF)
1042 Error ("Leaf with too many faces");
1043 l->portals[l->numportals] = p;
1048 // normal pointing out of the leaf
1049 VectorSubtract (vec3_origin, plane.normal, p->plane.normal);
1050 p->plane.dist = -plane.dist;
1052 SetPortalSphere (p);
1066 int VisMain (int argc, char **argv)
1068 char portalfile[1024];
1073 Sys_Printf( "--- Vis ---\n" );
1075 /* process arguments */
1076 for (i=1 ; i < (argc - 1) ; i++)
1078 if (!strcmp(argv[i], "-fast")) {
1079 Sys_Printf ("fastvis = true\n");
1081 } else if (!strcmp(argv[i], "-merge")) {
1082 Sys_Printf ("merge = true\n");
1084 } else if (!strcmp(argv[i], "-mergeportals")) {
1085 Sys_Printf ("mergeportals = true\n");
1086 mergevisportals = qtrue;
1087 } else if (!strcmp(argv[i], "-nopassage")) {
1088 Sys_Printf ("nopassage = true\n");
1089 noPassageVis = qtrue;
1090 } else if (!strcmp(argv[i], "-passageOnly")) {
1091 Sys_Printf ("passageOnly = true\n");
1092 passageVisOnly = qtrue;
1093 } else if (!strcmp (argv[i],"-nosort")) {
1094 Sys_Printf ("nosort = true\n");
1096 } else if (!strcmp (argv[i],"-saveprt")) {
1097 Sys_Printf ("saveprt = true\n");
1099 } else if( !strcmp( argv[ i ], "-v" ) ) {
1100 debugCluster = qtrue;
1101 Sys_Printf( "Extra verbous mode enabled\n" );
1102 } else if (!strcmp (argv[i],"-tmpin")) {
1103 strcpy (inbase, "/tmp");
1104 } else if (!strcmp (argv[i],"-tmpout")) {
1105 strcpy (outbase, "/tmp");
1109 /* ydnar: -hint to merge all but hint portals */
1110 else if( !strcmp( argv[ i ], "-hint" ) )
1112 Sys_Printf( "hint = true\n" );
1119 Sys_Printf( "WARNING: Unknown option \"%s\"\n", argv[ i ] );
1124 Error( "usage: vis [-threads #] [-level 0-4] [-fast] [-v] bspfile" );
1128 sprintf( source, "%s%s", inbase, ExpandArg( argv[ i ] ) );
1129 StripExtension( source );
1130 strcat( source, ".bsp" );
1131 Sys_Printf( "Loading %s\n", source );
1132 LoadBSPFile( source );
1134 /* load the portal file */
1135 sprintf( portalfile, "%s%s", inbase, ExpandArg( argv[ i ] ) );
1136 StripExtension( portalfile );
1137 strcat( portalfile, ".prt" );
1138 Sys_Printf( "Loading %s\n", portalfile );
1139 LoadPortals( portalfile );
1141 /* ydnar: exit if no portals, hence no vis */
1142 if( numportals == 0 )
1144 Sys_Printf( "No portals means no vis, exiting.\n" );
1148 /* ydnar: for getting far plane */
1151 /* inject command line parameters */
1152 InjectCommandLine(argv, 0, argc - 1);
1158 if( mergevis || mergevisportals )
1161 CountActivePortals();
1162 /* WritePortals( "maps/hints.prs" );*/
1164 Sys_Printf( "visdatasize:%i\n", numBSPVisBytes );
1168 /* delete the prt file */
1170 remove( portalfile );
1172 /* write the bsp file */
1173 Sys_Printf( "Writing %s\n", source );
1174 WriteBSPFile( source );