Example #1
0
int
main (int argc, char **argv)
{
	double      start, stop;
	dstring_t  *portalfile = dstring_new ();
	QFile      *f;

	start = Sys_DoubleTime ();

	this_program = argv[0];

	DecodeArgs (argc, argv);

	if (!options.bspfile) {
		usage (1);
		Sys_Error ("%s: no bsp file specified.", this_program);
	}

	QFS_SetExtension (options.bspfile, ".bsp");

	f = Qopen (options.bspfile->str, "rb");
	if (!f)
		Sys_Error ("couldn't open %s for reading.", options.bspfile->str);
	bsp = LoadBSPFile (f, Qfilesize (f));
	Qclose (f);

	visdata = dstring_new ();

	dstring_copystr (portalfile, options.bspfile->str);
	QFS_SetExtension (portalfile, ".prt");
	LoadPortals (portalfile->str);

	uncompressed = calloc (bitbytes_l, portalclusters);

	CalcVis ();

	if (options.verbosity >= 0)
		printf ("c_chains: %i%s\n", c_chains,
				options.threads > 1 ? " (not reliable)" :"");

	BSP_AddVisibility (bsp, (byte *) visdata->str, visdata->size);
	if (options.verbosity >= 0)
		printf ("visdatasize:%ld  compressed from %ld\n",
				(long) bsp->visdatasize, (long) originalvismapsize);

	CalcAmbientSounds ();

	f = Qopen (options.bspfile->str, "wb");
	if (!f)
		Sys_Error ("couldn't open %s for writing.", options.bspfile->str);
	WriteBSPFile (bsp, f);
	Qclose (f);

	stop = Sys_DoubleTime ();

	if (options.verbosity >= 0)
		printf ("%5.1f seconds elapsed\n", stop - start);

	return 0;
}
Example #2
0
/*
   ===========
   main
   ===========
 */
int VIS_Main(){
	char portalfile[1024];
	char source[1024];
	char name[1024];
	double start, end;
	int total_vis_time;

	Sys_Printf( "\n----- VIS ----\n\n" );

	//if (i != argc - 1)
	//	Error ("usage: vis [-threads #] [-level 0-4] [-fast] [-v] bspfile");

	start = I_FloatTime();

	ThreadSetDefault();

	SetQdirFromPath( mapname );
	strcpy( source, ExpandArg( mapname ) );
	StripExtension( source );
	DefaultExtension( source, ".bsp" );

	sprintf( name, "%s%s", inbase, source );
	Sys_Printf( "reading %s\n", name );
	LoadBSPFile( name );
	if ( numnodes == 0 || numfaces == 0 ) {
		Error( "Empty map" );
	}

	sprintf( portalfile, "%s%s", inbase, ExpandArg( mapname ) );
	StripExtension( portalfile );
	strcat( portalfile, ".prt" );

	Sys_Printf( "reading %s\n", portalfile );
	LoadPortals( portalfile );

	CalcVis();

	CalcPHS();

	visdatasize = vismap_p - dvisdata;
	Sys_Printf( "visdatasize:%i  compressed from %i\n", visdatasize, originalvismapsize * 2 );

	sprintf( name, "%s%s", outbase, source );
	Sys_Printf( "writing %s\n", name );
	WriteBSPFile( name );

	end = I_FloatTime();
	total_vis_time = (int) ( end - start );
	Sys_Printf( "\nVIS Time: " );
	if ( total_vis_time > 59 ) {
		Sys_Printf( "%d Minutes ", total_vis_time / 60 );
	}
	Sys_Printf( "%d Seconds\n", total_vis_time % 60 );


	return 0;
}
Example #3
0
/*
 * @brief
 */
int32_t VIS_Main(void) {
	char portal_file[MAX_OSPATH];

	Com_Print("\n----- VIS -----\n\n");

	const time_t start = time(NULL);

	LoadBSPFile(bsp_name);

	if (d_bsp.num_nodes == 0 || d_bsp.num_faces == 0)
		Com_Error(ERR_FATAL, "Empty map\n");

	StripExtension(map_name, portal_file);
	strcat(portal_file, ".prt");

	LoadPortals(portal_file);

	CalcVis();

	CalcPHS();

	d_bsp.vis_data_size = map_vis.pointer - d_bsp.vis_data;
	Com_Print("VIS data: %d bytes (compressed from %u bytes)\n", d_bsp.vis_data_size,
			(uint32_t) (map_vis.uncompressed_size * 2));

	WriteBSPFile(bsp_name);

	const time_t end = time(NULL);
	const time_t duration = end - start;
	Com_Print("\nVIS Time: ");
	if (duration > 59)
		Com_Print("%d Minutes ", (int32_t) (duration / 60));
	Com_Print("%d Seconds\n", (int32_t) (duration % 60));

	return 0;
}
Example #4
0
/*
===========
main
===========
*/
int main (int argc, char **argv)
{
	char	portalfile[1024];
	char		source[1024];
	int		i;
	double		start, end;
		
	printf ("vis.exe v1.3 (%s)\n", __DATE__);
	printf ("---- vis ----\n");

	verbose = false;
	for (i=1 ; i<argc ; i++)
	{
		if (!strcmp(argv[i],"-threads"))
		{
			numthreads = atoi (argv[i+1]);
			i++;
		}
		else if (!strcmp(argv[i], "-fast"))
		{
			printf ("fastvis = true\n");
			fastvis = true;
		}
		else if (!strcmp(argv[i], "-v"))
		{
			printf ("verbose = true\n");
			verbose = true;
		}
		else if (argv[i][0] == '-')
			Error ("Unknown option \"%s\"", argv[i]);
		else
			break;
	}

	if (i != argc - 1)
		Error ("usage: vis [-threads #] [-level 0-4] [-fast] [-v] bspfile");

	start = I_FloatTime ();
	
	ThreadSetDefault ();

	printf ("%i thread(s)\n", numthreads);

	strcpy (source, argv[i]);
	StripExtension (source);
	DefaultExtension (source, ".bsp");

	LoadBSPFile (source);
	
	strcpy (portalfile, argv[i]);
	StripExtension (portalfile);
	strcat (portalfile, ".prt");
	
	LoadPortals (portalfile);
	
	uncompressed = malloc(bitbytes*portalleafs);
	memset (uncompressed, 0, bitbytes*portalleafs);

	CalcVis ();

	qprintf ("c_chains: %i\n",c_chains);
	
	visdatasize = vismap_p - dvisdata;	
	printf ("visdatasize:%i  compressed from %i\n", visdatasize, originalvismapsize);
	
	CalcAmbientSounds ();

	WriteBSPFile (source);	
	
//	unlink (portalfile);

	end = I_FloatTime ();
	printf ("%5.1f seconds elapsed\n", end-start);
	
	free(uncompressed);

	return 0;
}
Example #5
0
/*
===========
VisMain
===========
*/
int VisMain(int argc, char **argv)
{
	char            portalfile[1024];
	int             i;


	/* note it */
	Sys_Printf("--- Vis ---\n");

	/* process arguments */
	for(i = 1; i < (argc - 1); i++)
	{
		if(!strcmp(argv[i], "-fast"))
		{
			Sys_Printf("fastvis = true\n");
			fastvis = qtrue;
		}
		else if(!strcmp(argv[i], "-merge"))
		{
			Sys_Printf("merge = true\n");
			mergevis = qtrue;
		}
		else if(!strcmp(argv[i], "-mergeportals"))
		{
			Sys_Printf("mergeportals = true\n");
			mergevisportals = qtrue;
		}
		else if(!strcmp(argv[i], "-nopassage"))
		{
			Sys_Printf("nopassage = true\n");
			noPassageVis = qtrue;
		}
		else if(!strcmp(argv[i], "-passageOnly"))
		{
			Sys_Printf("passageOnly = true\n");
			passageVisOnly = qtrue;
		}
		else if(!strcmp(argv[i], "-nosort"))
		{
			Sys_Printf("nosort = true\n");
			nosort = qtrue;
		}
		else if(!strcmp(argv[i], "-v"))
		{
			debugCluster = qtrue;
			Sys_Printf("Extra verbose mode enabled\n");
		}
		else if(!strcmp(argv[i], "-tmpin"))
		{
			strcpy(inbase, "/tmp");
		}
		else if(!strcmp(argv[i], "-tmpout"))
		{
			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
		{
			Sys_Printf("WARNING: Unknown option \"%s\"\n", argv[i]);
		}
	}

	if(i != argc - 1)
		Error("usage: vis [-threads #] [-level 0-4] [-fast] [-v] bspfile");


	/* load the bsp */
	sprintf(source, "%s%s", inbase, ExpandArg(argv[i]));
	StripExtension(source);
	strcat(source, ".bsp");
	Sys_Printf("Loading %s\n", source);
	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);

	/* ydnar: exit if no portals, hence no vis */
	if(numportals == 0)
	{
		Sys_Printf("No portals means no vis, exiting.\n");
		return 0;
	}

	/* ydnar: for getting far plane */
	ParseEntities();

	/* inject command line parameters */
	InjectCommandLine(argv, 0, argc - 1);
	UnparseEntities();

	if(mergevis)
		MergeLeaves();

	if(mergevis || mergevisportals)
		MergeLeafPortals();

	CountActivePortals();
	/* WritePortals( "maps/hints.prs" ); */

	Sys_Printf("visdatasize:%i\n", numBSPVisBytes);

	CalcVis();

	/* write the bsp file */
	Sys_Printf("Writing %s\n", source);
	WriteBSPFile(source);

	return 0;
}
Example #6
0
File: vis.c Project: qbism/super8
/*
===========
Vis_Main
===========
*/
int Vis_Main( int argc, char **argv )
{
    int			i;
    double		start, end;

    printf ("---- vis ----\n");

    fastvis = false;
    verbose = false;
    rvis = true;
    noambientslime = true;
    noreuse = false;
    farplane = 0;

    if (ismcbsp)
        noambient = true;

    for (i=1 ; i<argc ; i++)
    {
        if (!strcmp(argv[i], "-norvis"))
        {
            rvis = false;
            printf ("rvis optimization disabled\n");
        }
        else if (!strcmp(argv[i], "-fast"))
        {
            printf ("fastvis = true\n");
            fastvis = true;
        }
        else if (!strcmp(argv[i], "-level"))
        {
            testlevel = atoi(argv[i+1]);
            printf ("testlevel = %i\n", testlevel);
            i++;
        }
        else if (!strcmp(argv[i], "-v"))
        {
            printf ("verbose = true\n");
            verbose = true;
        }
        else if (!strcmp(argv[i], "-noreuse"))
        {
            printf ("vis rows reusage disabled\n");
            noreuse = true;
        }
        else if (!strcmp(argv[i], "-noambient"))
        {
            noambient = true;
            printf ("all ambient sounds disabled\n");
        }
        else if (!strcmp(argv[i], "-noambientwater"))
        {
            noambientwater = true;
            printf ("ambient water sounds disabled\n");
        }
        else if (!strcmp(argv[i], "-ambientslime"))
        {
            noambientslime = false;
            printf ("ambient slime sounds enabled\n");
        }
        else if (!strcmp(argv[i], "-noambientlava"))
        {
            noambientlava = true;
            printf ("ambient lava sounds disabled\n");
        }
        else if (!strcmp(argv[i], "-noambientsky"))
        {
            noambientsky = true;
            printf ("ambient sky sounds disabled\n");
        }
        else if (!strcmp(argv[i], "-farplane"))
        {
            farplane = atoi (argv[i+1]);
            printf ("farplane = %f\n", farplane);
            i++;
        }
        else if (argv[i][0] == '-')
            Error ("Unknown option \"%s\"", argv[i]);
        else
            break;
    }

    if (i != argc - 1)
    {
        Error ("%s",
               "usage: hmap2 -vis [options] bspfile\n"
               "Compiles visibility data in a .bsp, needs a .prt file\n"
               "\n"
               "What the options do:\n"
               "-level 0-4      quality, default 4\n"
               "-fast           fast but bad quality vis\n"
               "-v              verbose\n"
               "-norvis         disable rvis optimization, 0.001% better quality and 30% slower\n"
               "-ambientslime   do not convert slime channel to water (requires engine support)\n"
               "-noambient      disable ambient sounds (water bubbling, wind, etc)\n"
               "-noambientwater disable ambient water sounds (water)\n"
               "-noambientslime disable ambient slime sounds (water, or -ambientslime)\n"
               "-noambientlava  disable ambient lava sounds (unused by quake)\n"
               "-noambientsky   disable ambient sky sounds (wind)\n"
               "-noreuse        disable merging of identical vis data (less compression)\n"
               "-farplane       limit visible distance (warning: not a good idea without fog)\n"
              );
    }

    // init memory
    Q_InitMem ();

    start = I_DoubleTime ();

    LoadBSPFile (filename_bsp);
    LoadPortals (filename_prt);

    uncompressed = qmalloc(bitlongs*portalleafs*sizeof(long));
    memset (uncompressed, 0, bitlongs*portalleafs*sizeof(long));

//	CalcPassages ();

    CalcVis ();

    printf ("row size: %i\n",bitbytes);
    printf ("c_reused: %i\n",c_reused);
    printf ("c_chains: %i\n",c_chains);

    visdatasize = vismap_p - dvisdata;
    printf ("reused bytes: %i\n",c_reused*bitbytes);
    printf ("visdatasize:%i compressed from %i\n", visdatasize, originalvismapsize);

    if (!noambient)
        CalcAmbientSounds ();

    WriteBSPFile (filename_bsp, false);

//	unlink (portalfile);

    end = I_DoubleTime ();
    printf ("%5.2f seconds elapsed\n\n", end-start);

    // print memory stats
    Q_PrintMem ();

    // free allocated memory
    Q_ShutdownMem ();

    return 0;
}
Example #7
0
/*
===========
main
===========
*/
int main (int argc, char **argv)
{
	char	portalfile[1024];
	char		source[1024];
	char		name[1024];
	int		i;
	double		start, end;
		
	printf ("---- vis ----\n");

	verbose = false;
	for (i=1 ; i<argc ; i++)
	{
		if (!strcmp(argv[i],"-threads"))
		{
			numthreads = atoi (argv[i+1]);
			i++;
		}
		else if (!strcmp(argv[i], "-fast"))
		{
			printf ("fastvis = true\n");
			fastvis = true;
		}
		else if (!strcmp(argv[i], "-level"))
		{
			testlevel = atoi(argv[i+1]);
			printf ("testlevel = %i\n", testlevel);
			i++;
		}
		else if (!strcmp(argv[i], "-v"))
		{
			printf ("verbose = true\n");
			verbose = true;
		}
		else if (!strcmp (argv[i],"-nosort"))
		{
			printf ("nosort = true\n");
			nosort = true;
		}
		else if (!strcmp (argv[i],"-tmpin"))
			strcpy (inbase, "/tmp");
		else if (!strcmp (argv[i],"-tmpout"))
			strcpy (outbase, "/tmp");
		else if (argv[i][0] == '-')
			Error ("Unknown option \"%s\"", argv[i]);
		else
			break;
	}

	if (i != argc - 1)
		Error ("usage: vis [-threads #] [-level 0-4] [-fast] [-v] bspfile");

	start = I_FloatTime ();
	
	ThreadSetDefault ();

	strcpy (source, argv[i]);
	StripExtension (source);
	DefaultExtension (source, ".bsp");

	sprintf (name, "%s%s", inbase, source);
	printf ("reading %s\n", name);
	LoadBSPFile (name);
	if (numnodes == 0 || numfaces == 0)
		Error ("Empty map");

	sprintf (portalfile, "%s%s", inbase, ExpandArg(argv[i]));
	StripExtension (portalfile);
	strcat (portalfile, ".prt");
	
	printf ("reading %s\n", portalfile);
	LoadPortals (portalfile);
	
	CalcVis ();

	CalcPHS ();

	visdatasize = vismap_p - dvisdata;	
	printf ("visdatasize:%i  compressed from %i\n", visdatasize, originalvismapsize*2);

	sprintf (name, "%s%s", outbase, source);
	printf ("writing %s\n", name);
	WriteBSPFile (name);	
	
	end = I_FloatTime ();
	printf ("%5.1f seconds elapsed\n", end-start);

	return 0;
}
Example #8
0
File: map.c Project: fielder/fenton
int
Map_Load (const char *name)
{
	int direxists;

	map_error = NULL;
	memset (&loadmap, 0, sizeof(loadmap));

	if (Data_IsDir(name, &direxists) && direxists)
	{
		loaddir = name;
		Get = GetFromDir;
	}
	else
	{
		/* no directory with the map name; try a pak */

		const char *ext = ".pak";
		char path[2048];

		if (strlen(name) > (sizeof(path) - strlen(ext) - 1))
			return Error("map name too long");
		strcpy (path, name);
		strcat (path, ext);
		if ((loadpak = Pak_Open(path)) == NULL)
			return Error("unable to open \"%s\"", path);

		Get = GetFromPak;
	}

	if (!LoadPlanes())
		goto failed;
	if (!LoadVertices())
		goto failed;
	if (!LoadEdges())
		goto failed;
	if (!LoadEdgeLoops())
		goto failed;
	if (!LoadSurfaces())
		goto failed;
	if (!LoadPortals())
		goto failed;
	if (!LoadNodes())
		goto failed;
	if (!LoadLeafs())
		goto failed;
	if (!LoadTextures())
		goto failed;

	/* success; get rid of current map & switch over */

	Map_Unload ();
	map = loadmap;
	memset (&loadmap, 0, sizeof(loadmap));

	Get = NULL;
	loadpak = Pak_Close (loadpak);
	loaddir = NULL;

	return 1;

failed:
	/* failure; keep the currently-loaded map running */

	FreeMap (&loadmap);

	Get = NULL;
	loadpak = Pak_Close (loadpak);
	loaddir = NULL;

	return 0;
}
Example #9
0
int RunVVis( int argc, char **argv )
{
    char	portalfile[1024];
    char		source[1024];
    double		start, end;


    Msg( "Valve Software - vvis.exe (%s)\n", __DATE__ );

    verbose = false;

    Q_StripExtension( argv[ argc - 1 ], source, sizeof( source ) );
    CmdLib_InitFileSystem( argv[ argc - 1 ] );

    Q_FileBase( source, source, sizeof( source ) );

    LoadCmdLineFromFile( argc, argv, source, "vvis" );
    int i = ParseCommandLine( argc, argv );

    // This part is just for VMPI. VMPI's file system needs the basedir in front of all filenames,
    // so we prepend qdir here.
    strcpy( source, ExpandPath( source ) );

    if (i != argc - 1)
    {
        PrintUsage( argc, argv );
        DeleteCmdLine( argc, argv );
        CmdLib_Exit( 1 );
    }

    start = Plat_FloatTime();


    if (!g_bUseMPI)
    {
        // Setup the logfile.
        char logFile[512];
        _snprintf( logFile, sizeof(logFile), "%s.log", source );
        SetSpewFunctionLogFile( logFile );
    }

    // Run in the background?
    if( g_bLowPriority )
    {
        SetLowPriority();
    }

    ThreadSetDefault ();

    char	targetPath[1024];
    GetPlatformMapPath( source, targetPath, 0, 1024 );
    Msg ("reading %s\n", targetPath);
    LoadBSPFile (targetPath);
    if (numnodes == 0 || numfaces == 0)
        Error ("Empty map");
    ParseEntities ();

    // Check the VMF for a vis radius
    if (!g_bUseRadius)
    {
        float flRadius = DetermineVisRadius( );
        if (flRadius > 0.0f)
        {
            g_bUseRadius = true;
            g_VisRadius = flRadius * flRadius;
        }
    }

    if ( g_bUseRadius )
    {
        MarkLeavesAsRadial();
    }

    if ( inbase[0] == 0 )
    {
        strcpy( portalfile, source );
    }
    else
    {
        sprintf ( portalfile, "%s%s", inbase, argv[i] );
        Q_StripExtension( portalfile, portalfile, sizeof( portalfile ) );
    }
    strcat (portalfile, ".prt");

    Msg ("reading %s\n", portalfile);
    LoadPortals (portalfile);

    CalcVis ();
    CalcPAS ();

    // We need a mapping from cluster to leaves, since the PVS
    // deals with clusters for both CalcVisibleFogVolumes and
    BuildClusterTable();

    CalcVisibleFogVolumes();
    CalcDistanceFromLeavesToWater();

    visdatasize = vismap_p - dvisdata;
    Msg ("visdatasize:%i  compressed from %i\n", visdatasize, originalvismapsize*2);

    Msg ("writing %s\n", targetPath);
    WriteBSPFile (targetPath);

    end = Plat_FloatTime();

    char str[512];
    GetHourMinuteSecondsString( (int)( end - start ), str, sizeof( str ) );
    Msg( "%s elapsed\n", str );

    DeleteCmdLine( argc, argv );
    CmdLib_Cleanup();
    return 0;
}
Example #10
0
/*
===========
Vis_Main
===========
*/
int Vis_Main (int argc, char **argv)
{
	char	portalfile[1024];
	char	source[1024];
	char	name[1024];
	int		i;
	double	start, end;
	int		total_vis_time;
		
	Con_Print("---- VIS ----\n");

	verbose = false;
	for (i=1 ; i<argc ; i++)
	{
		if (!strcmp(argv[i], "-fast"))
		{
			Con_Print("fastvis = true\n");
			fastvis = true;
		}
		else if (!strcmp(argv[i], "-level"))
		{
			testlevel = atoi(argv[i+1]);
			Con_Print("testlevel = %i\n", testlevel);
			i++;
		}
		else if (!strcmp(argv[i], "-v"))
		{
			Con_Print("verbose = true\n");
			verbose = true;
		}
		else if (!strcmp (argv[i],"-nosort"))
		{
			Con_Print("nosort = true\n");
			nosort = true;
		}
		else if (!strcmp (argv[i],"-tmpin"))
			strcpy (inbase, "/tmp");
		else if (!strcmp (argv[i],"-tmpout"))
			strcpy (outbase, "/tmp");
		else if (argv[i][0] == '-')
			Con_Error("Unknown option \"%s\"\n", argv[i]);
		else
			break;
	}

	if (i != argc - 1)
		Con_Error("usage: q2map -vis [-level 0-4] [-fast] [-v] bspfile\n");

	start = I_FloatTime ();

	SetQdirFromPath (argv[i]);

	strcpy (source, ExpandArg(argv[i]));
	StripExtension (source);
	DefaultExtension (source, ".bsp");

	sprintf (name, "%s%s", inbase, source);
	Con_Print("reading %s\n", name);
	LoadBSPFile (name);
	if (numnodes == 0 || numfaces == 0)
		Con_Error("Empty map\n");

	sprintf (portalfile, "%s%s", inbase, ExpandArg(argv[i]));
	StripExtension (portalfile);
	strcat (portalfile, ".prt");
	
	Con_Print("reading %s\n", portalfile);
	LoadPortals (portalfile);
	
	CalcVis ();

	CalcPHS ();

	visdatasize = vismap_p - dvisdata;
	Con_Print("visdatasize:%i  compressed from %i\n", visdatasize, originalvismapsize*2);

	sprintf (name, "%s%s", outbase, source);
	Con_Print("writing %s\n", name);
	WriteBSPFile (name);	
	
	end = I_FloatTime ();
	total_vis_time = (int) ( end - start );
	Con_Print("\nVIS Time: ");
	if ( total_vis_time > 59 ) {
		Con_Print( "%d minutes ", total_vis_time / 60 );
	}
	Con_Print( "%d seconds\n", total_vis_time % 60 );

	return 0;
}
Example #11
0
/*
  ===========
  main
  ===========
*/
int
main(int argc, char **argv)
{
    bspdata_t bspdata;
    bsp2_t *const bsp = &bspdata.data.bsp2;
    int32_t loadversion;
    int i;

    init_log("vis.log");
    logprint("---- vis / TyrUtils " stringify(TYRUTILS_VERSION) " ----\n");

    LowerProcessPriority();
    numthreads = GetDefaultThreads();

    for (i = 1; i < argc; i++) {
        if (!strcmp(argv[i], "-threads")) {
            numthreads = atoi(argv[i + 1]);
            i++;
        } else if (!strcmp(argv[i], "-fast")) {
            logprint("fastvis = true\n");
            fastvis = true;
        } else if (!strcmp(argv[i], "-level")) {
            testlevel = atoi(argv[i + 1]);
            i++;
        } else if (!strcmp(argv[i], "-v")) {
            logprint("verbose = true\n");
            verbose = 1;
        } else if (!strcmp(argv[i], "-vv")) {
            logprint("verbose = extra\n");
            verbose = 2;
        } else if (!strcmp(argv[i], "-noambientsky")) {
            logprint("ambient sky sounds disabled\n");
            ambientsky = false;
        } else if (!strcmp(argv[i], "-noambientwater")) {
            logprint("ambient water sounds disabled\n");
            ambientwater = false;
        } else if (!strcmp(argv[i], "-noambientslime")) {
            logprint("ambient slime sounds disabled\n");
            ambientslime = false;
        } else if (!strcmp(argv[i], "-noambientlava")) {
            logprint("ambient lava sounds disabled\n");
            ambientlava = false;
        } else if (!strcmp(argv[i], "-noambient")) {
            logprint("ambient sound calculation disabled\n");
            ambientsky = false;
            ambientwater = false;
            ambientslime = false;
            ambientlava = false;
        } else if (argv[i][0] == '-')
            Error("Unknown option \"%s\"", argv[i]);
        else
            break;
    }

    if (i != argc - 1) {
        printf("usage: vis [-threads #] [-level 0-4] [-fast] [-v|-vv] "
               "[-credits] bspfile\n");
        exit(1);
    }

    logprint("running with %d threads\n", numthreads);
    logprint("testlevel = %i\n", testlevel);

    stateinterval = 300; /* 5 minutes */
    starttime = statetime = I_FloatTime();

    strcpy(sourcefile, argv[i]);
    StripExtension(sourcefile);
    DefaultExtension(sourcefile, ".bsp");

    LoadBSPFile(sourcefile, &bspdata);

    loadversion = bspdata.version;
    if (loadversion != BSP2VERSION)
        ConvertBSPFormat(BSP2VERSION, &bspdata);

    strcpy(portalfile, argv[i]);
    StripExtension(portalfile);
    strcat(portalfile, ".prt");

    LoadPortals(portalfile, bsp);

    strcpy(statefile, sourcefile);
    StripExtension(statefile);
    DefaultExtension(statefile, ".vis");

    strcpy(statetmpfile, sourcefile);
    StripExtension(statetmpfile);
    DefaultExtension(statetmpfile, ".vi0");

    uncompressed = malloc(leafbytes_real * portalleafs_real);
    memset(uncompressed, 0, leafbytes_real * portalleafs_real);

//    CalcPassages ();

    CalcVis(bsp);

    logprint("c_noclip: %i\n", c_noclip);
    logprint("c_chains: %lu\n", c_chains);

    bsp->visdatasize = vismap_p - bsp->dvisdata;
    logprint("visdatasize:%i  compressed from %i\n",
             bsp->visdatasize, originalvismapsize);

    CalcAmbientSounds(bsp);

    /* Convert data format back if necessary */
    if (loadversion != BSP2VERSION)
        ConvertBSPFormat(loadversion, &bspdata);

    WriteBSPFile(sourcefile, &bspdata);

//    unlink (portalfile);

    endtime = I_FloatTime();
    logprint("%5.1f seconds elapsed\n", endtime - starttime);

    close_log();

    return 0;
}