]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/vis.c
q3map2: fix prt loading for vis computation when using -prtfile
[xonotic/netradiant.git] / tools / quake3 / q3map2 / vis.c
index fb560d511311c911499c1719e50ed63376cb1757..73a22c8a77bf398ab7e36629c750bac25fdd762b 100644 (file)
@@ -210,7 +210,7 @@ void ClusterMerge( int leafnum ){
 
        numvis++;       // count the leaf itself
 
-       //Sys_FPrintf (SYS_VRB,"cluster %4i : %4i visible\n", leafnum, numvis);
+       //Sys_FPrintf( SYS_VRB,"cluster %4i : %4i visible\n", leafnum, numvis );
        ++clustersizehistogram[numvis];
 
        memcpy( bspVisBytes + VIS_HEADER_SIZE + leafnum * leafbytes, uncompressed, leafbytes );
@@ -812,16 +812,16 @@ int CountActivePortals( void ){
  */
 void WriteFloat( FILE *f, vec_t v );
 
-void WritePortals( char *filename ){
+void WritePortals( char *portalpathfile ){
        int i, j, num;
        FILE *pf;
        vportal_t *p;
        fixedWinding_t *w;
 
        // write the file
-       pf = fopen( filename, "w" );
+       pf = fopen( portalpathfile, "w" );
        if ( !pf ) {
-               Error( "Error opening %s", filename );
+               Error( "Error opening %s", portalpathfile );
        }
 
        num = 0;
@@ -890,7 +890,7 @@ void WritePortals( char *filename ){
    ============
  */
 void LoadPortals( char *name ){
-       int i, j, hint;
+       int i, j, flags;
        vportal_t   *p;
        leaf_t      *l;
        char magic[80];
@@ -964,8 +964,8 @@ void LoadPortals( char *name ){
                         || leafnums[1] > portalclusters ) {
                        Error( "LoadPortals: reading portal %i", i );
                }
-               if ( fscanf( f, "%i ", &hint ) != 1 ) {
-                       Error( "LoadPortals: reading hint state" );
+               if ( fscanf( f, "%i ", &flags ) != 1 ) {
+                       Error( "LoadPortals: reading flags" );
                }
 
                w = p->winding = NewFixedWinding( numpoints );
@@ -1001,7 +1001,8 @@ void LoadPortals( char *name ){
                l->numportals++;
 
                p->num = i + 1;
-               p->hint = hint;
+               p->hint = ((flags & 1) != 0);
+               p->sky = ((flags & 2) != 0);
                p->winding = w;
                VectorSubtract( vec3_origin, plane.normal, p->plane.normal );
                p->plane.dist = -plane.dist;
@@ -1098,8 +1099,9 @@ void LoadPortals( char *name ){
    ===========
  */
 int VisMain( int argc, char **argv ){
-       char portalfile[1024];
        int i;
+       char portalFilePath[ 1024 ];
+       portalFilePath[0] = 0;
 
 
        /* note it */
@@ -1147,22 +1149,26 @@ int VisMain( int argc, char **argv ){
                        strcpy( outbase, "/tmp" );
                }
 
-
                /* ydnar: -hint to merge all but hint portals */
                else if ( !strcmp( argv[ i ], "-hint" ) ) {
                        Sys_Printf( "hint = true\n" );
                        hint = qtrue;
                        mergevis = qtrue;
                }
-
-               else
+               else if ( !strcmp( argv[ i ], "-prtfile" ) )
                {
-                       Sys_Printf( "WARNING: Unknown option \"%s\"\n", argv[ i ] );
+                       strcpy( portalFilePath, argv[i + 1] );
+                       i++;
+                       Sys_Printf( "Use %s as portal file\n", portalFilePath );
+               }
+
+               else{
+                       Sys_FPrintf( SYS_WRN, "WARNING: Unknown option \"%s\"\n", argv[ i ] );
                }
        }
 
        if ( i != argc - 1 ) {
-               Error( "usage: vis [-threads #] [-level 0-4] [-fast] [-v] bspfile" );
+               Error( "usage: vis [-threads #] [-level 0-4] [-fast] [-v] BSPFilePath" );
        }
 
 
@@ -1174,11 +1180,13 @@ int VisMain( int argc, char **argv ){
        LoadBSPFile( source );
 
        /* load the portal file */
-       sprintf( portalfile, "%s%s", inbase, ExpandArg( argv[ i ] ) );
-       StripExtension( portalfile );
-       strcat( portalfile, ".prt" );
-       Sys_Printf( "Loading %s\n", portalfile );
-       LoadPortals( portalfile );
+       if (!portalFilePath[0]) {
+               sprintf( portalFilePath, "%s%s", inbase, ExpandArg( argv[ i ] ) );
+               StripExtension( portalFilePath );
+               strcat( portalFilePath, ".prt" );
+       }
+       Sys_Printf( "Loading %s\n", portalFilePath );
+       LoadPortals( portalFilePath );
 
        /* ydnar: exit if no portals, hence no vis */
        if ( numportals == 0 ) {
@@ -1210,7 +1218,7 @@ int VisMain( int argc, char **argv ){
 
        /* delete the prt file */
        if ( !saveprt ) {
-               remove( portalfile );
+               remove( portalFilePath );
        }
 
        /* write the bsp file */