Exemple #1
0
int main (int argc, char **argv) {
	int		i;
	double		start, end;
	char		path[1024];

	_printf ("Q3Map v1.0s (c) 1999 Id Software Inc.\n");
  	_printf ("OMmap (su44) - v0.1\n");

	if ( argc < 2 ) {
		Error ("usage: q3map [options] mapfile");
	}

	// check for general program options
	if (!strcmp(argv[1], "-info")) {
		Bspinfo( argc - 2, argv + 2 );
		return 0;
	}
	if (!strcmp(argv[1], "-light")) {
		LightMain( argc - 1, argv + 1 );
		return 0;
	}
	if (!strcmp(argv[1], "-vlight")) {
		VLightMain( argc - 1, argv + 1 );
		return 0;
	}
	if (!strcmp(argv[1], "-vsound")) {
		VSoundMain( argc - 1, argv + 1 );
		return 0;
	}
	if (!strcmp(argv[1], "-vis")) {
		VisMain( argc - 1, argv + 1 );
		return 0;
	}

	// do a bsp if nothing else was specified

	_printf ("---- q3map ----\n");

  tempsource[0] = '\0';

	for (i=1 ; i<argc ; i++)
	{
		if (!strcmp(argv[i],"-tempname"))
    {
      strcpy(tempsource, argv[++i]);
    }
		else if (!strcmp(argv[i],"-threads"))
		{
			numthreads = atoi (argv[i+1]);
			i++;
		}
		else if (!strcmp(argv[i],"-glview"))
		{
			glview = qtrue;
		}
		else if (!strcmp(argv[i], "-v"))
		{
			_printf ("verbose = true\n");
			verbose = qtrue;
		}
		else if (!strcmp(argv[i], "-draw"))
		{
			_printf ("drawflag = true\n");
			drawflag = qtrue;
		}
		else if (!strcmp(argv[i], "-nowater"))
		{
			_printf ("nowater = true\n");
			nowater = qtrue;
		}
		else if (!strcmp(argv[i], "-noopt"))
		{
			_printf ("noopt = true\n");
			noopt = qtrue;
		}
		else if (!strcmp(argv[i], "-nofill"))
		{
			_printf ("nofill = true\n");
			nofill = qtrue;
		}
		else if (!strcmp(argv[i], "-nodetail"))
		{
			_printf ("nodetail = true\n");
			nodetail = qtrue;
		}
		else if (!strcmp(argv[i], "-fulldetail"))
		{
			_printf ("fulldetail = true\n");
			fulldetail = qtrue;
		}
		else if (!strcmp(argv[i], "-onlyents"))
		{
			_printf ("onlyents = true\n");
			onlyents = qtrue;
		}
		else if (!strcmp(argv[i], "-onlytextures"))
		{
			_printf ("onlytextures = true\n");	// FIXME: make work again!
			onlytextures = qtrue;
		}
		else if (!strcmp(argv[i], "-micro"))
		{
			microvolume = atof(argv[i+1]);
			_printf ("microvolume = %f\n", microvolume);
			i++;
		}
		else if (!strcmp(argv[i], "-nofog"))
		{
			_printf ("nofog = true\n");
			nofog = qtrue;
		}
		else if (!strcmp(argv[i], "-nosubdivide"))
		{
			_printf ("nosubdivide = true\n");
			nosubdivide = qtrue;
		}
		else if (!strcmp(argv[i], "-leaktest"))
		{
			_printf ("leaktest = true\n");
			leaktest = qtrue;
		}
		else if (!strcmp(argv[i], "-verboseentities"))
		{
			_printf ("verboseentities = true\n");
			verboseentities = qtrue;
		}
		else if (!strcmp(argv[i], "-nocurves"))
		{
			noCurveBrushes = qtrue;
			_printf ("no curve brushes\n");
		}
		else if (!strcmp(argv[i], "-notjunc"))
		{
			notjunc = qtrue;
			_printf ("no tjunction fixing\n");
		}
		else if (!strcmp(argv[i], "-expand"))
		{
			testExpand = qtrue;
			_printf ("Writing expanded.map.\n");
		}
		else if (!strcmp(argv[i], "-showseams"))
		{
			showseams = qtrue;
			_printf ("Showing seams on terrain.\n");
		}
		else if (!strcmp (argv[i],"-tmpout"))
		{
			strcpy (outbase, "/tmp");
		}
		else if (!strcmp (argv[i],"-fakemap"))
		{
			fakemap = qtrue;
			_printf( "will generate fakemap.map\n");
		}
		else if (!strcmp(argv[i], "-samplesize"))
		{
			samplesize = atoi(argv[i+1]);
			if (samplesize < 1) samplesize = 1;
			i++;
			_printf("lightmap sample size is %dx%d units\n", samplesize, samplesize);
		}
		else if (argv[i][0] == '-')
			Error ("Unknown option \"%s\"", argv[i]);
		else
			break;
	}

	if (i != argc - 1)
		Error ("usage: q3map [options] mapfile");

	start = I_FloatTime ();

	ThreadSetDefault ();
	//numthreads = 1;		// multiple threads aren't helping because of heavy malloc use
	SetQdirFromPath (argv[i]);

#ifdef _WIN32
  InitPakFile(gamedir, NULL);
#endif

	strcpy (source, ExpandArg (argv[i]));
	StripExtension (source);

	// delete portal and line files
	sprintf (path, "%s.prt", source);
	remove (path);
	sprintf (path, "%s.lin", source);
	remove (path);

	strcpy (name, ExpandArg (argv[i]));	
	if ( strcmp(name + strlen(name) - 4, ".reg" ) ) {
		// if we are doing a full map, delete the last saved region map
		sprintf (path, "%s.reg", source);
		remove (path);

		DefaultExtension (name, ".map");	// might be .reg
	}

	//
	// if onlyents, just grab the entites and resave
	//
	if ( onlyents ) {
		OnlyEnts();
		return 0;
	}

	//
	// if onlytextures, just grab the textures and resave
	//
	if ( onlytextures ) {
		OnlyTextures();
		return 0;
	}

	//
	// start from scratch
	//
	LoadShaderInfo();

  // load original file from temp spot in case it was renamed by the editor on the way in
  if (strlen(tempsource) > 0) {
	  LoadMapFile (tempsource);
  } else {
	  LoadMapFile (name);
  }

	SetModelNumbers ();
	SetLightStyles ();

	ProcessModels ();

	EndBSPFile();

	end = I_FloatTime ();
	_printf ("%5.0f seconds elapsed\n", end-start);

  // remove temp name if appropriate
  if (strlen(tempsource) > 0) {
    remove(tempsource);
  }

	return 0;
}
Exemple #2
0
// reads all pak files from a dir
void InitDirectory(const char* directory, ArchiveModules& archiveModules)
{
  int j;

  g_numForbiddenDirs = 0;
  StringTokeniser st(GlobalRadiant().getGameDescriptionKeyValue("forbidden_paths"), " ");
  for(j = 0; j < VFS_MAXDIRS; ++j)
  {
    const char *t = st.getToken();
    if(string_empty(t))
      break;
    strncpy(g_strForbiddenDirs[g_numForbiddenDirs], t, PATH_MAX);
    g_strForbiddenDirs[g_numForbiddenDirs][PATH_MAX] = '\0';
    ++g_numForbiddenDirs;
  }

  for(j = 0; j < g_numForbiddenDirs; ++j)
  {
    char* dbuf = g_strdup(directory);
    if(*dbuf && dbuf[strlen(dbuf)-1] == '/')
      dbuf[strlen(dbuf)-1] = 0;
    const char *p = strrchr(dbuf, '/');
    p = (p ? (p+1) : dbuf);
    if(matchpattern(p, g_strForbiddenDirs[j], TRUE))
    {
      g_free(dbuf);
      break;
    }
    g_free(dbuf);
  }
  if(j < g_numForbiddenDirs)
  {
    printf("Directory %s matched by forbidden dirs, removed\n", directory);
    return;
  }

  if (g_numDirs == VFS_MAXDIRS)
    return;

  strncpy(g_strDirs[g_numDirs], directory, PATH_MAX);
  g_strDirs[g_numDirs][PATH_MAX] = '\0';
  FixDOSName (g_strDirs[g_numDirs]);
  AddSlash (g_strDirs[g_numDirs]);

  const char* path = g_strDirs[g_numDirs];
  
  g_numDirs++;

  {
    archive_entry_t entry;
    entry.name = path;
    entry.archive = OpenArchive(path);
    entry.is_pakfile = false;
    g_archives.push_back(entry);
  }

  if (g_bUsePak)
  {
    GDir* dir = g_dir_open (path, 0, 0);

    if (dir != 0)
    {
			globalOutputStream() << "vfs directory: " << path << "\n";

      const char* ignore_prefix = "";
      const char* override_prefix = "";

      {
        // See if we are in "sp" or "mp" mapping mode
        const char* gamemode = gamemode_get();

		    if (strcmp (gamemode, "sp") == 0)
        {
				  ignore_prefix = "mp_";
          override_prefix = "sp_";
        }
		    else if (strcmp (gamemode, "mp") == 0)
        {
				  ignore_prefix = "sp_";
          override_prefix = "mp_";
        }
      }

      Archives archives;
      Archives archivesOverride;
      for(;;)
      {
        const char* name = g_dir_read_name(dir);
        if(name == 0)
          break;

        for(j = 0; j < g_numForbiddenDirs; ++j)
        {
          const char *p = strrchr(name, '/');
          p = (p ? (p+1) : name);
          if(matchpattern(p, g_strForbiddenDirs[j], TRUE))
            break;
        }
	if(j < g_numForbiddenDirs)
	  continue;

        const char *ext = strrchr (name, '.');

	if(ext && !string_compare_nocase_upper(ext, ".pk3dir"))
	{
	  if (g_numDirs == VFS_MAXDIRS)
	    continue;
	  snprintf(g_strDirs[g_numDirs], PATH_MAX, "%s%s/", path, name);
	  g_strDirs[g_numDirs][PATH_MAX] = '\0';
	  FixDOSName (g_strDirs[g_numDirs]);
	  AddSlash (g_strDirs[g_numDirs]);
	  g_numDirs++;

	  {
	    archive_entry_t entry;
	    entry.name = g_strDirs[g_numDirs-1];
	    entry.archive = OpenArchive(g_strDirs[g_numDirs-1]);
	    entry.is_pakfile = false;
	    g_archives.push_back(entry);
	  }
	}

        if ((ext == 0) || *(++ext) == '\0' || GetArchiveTable(archiveModules, ext) == 0)
          continue;

        // using the same kludge as in engine to ensure consistency
				if(!string_empty(ignore_prefix) && strncmp(name, ignore_prefix, strlen(ignore_prefix)) == 0)
				{
					continue;
				}
				if(!string_empty(override_prefix) && strncmp(name, override_prefix, strlen(override_prefix)) == 0)
        {
          archivesOverride.insert(name);
					continue;
        }

        archives.insert(name);
      }

      g_dir_close (dir);

			// add the entries to the vfs
      for(Archives::iterator i = archivesOverride.begin(); i != archivesOverride.end(); ++i)
			{
        char filename[PATH_MAX];
        strcpy(filename, path);
        strcat(filename, (*i).c_str());
        InitPakFile(archiveModules, filename);
			}
      for(Archives::iterator i = archives.begin(); i != archives.end(); ++i)
			{
        char filename[PATH_MAX];
        strcpy(filename, path);
        strcat(filename, (*i).c_str());
        InitPakFile(archiveModules, filename);
			}
    }
    else
    {
      globalErrorStream() << "vfs directory not found: " << path << "\n";
    }
  }
}