/* * BSP_Main */ int BSP_Main(void){ time_t start, end; char base[MAX_OSPATH]; int total_bsp_time; #ifdef _WIN32 char title[MAX_OSPATH]; sprintf(title, "Q2WMap [Compiling BSP]"); SetConsoleTitle(title); #endif Com_Print("\n----- BSP -----\n\n"); start = time(NULL); StripExtension(map_name, base); // clear the whole bsp structure memset(&d_bsp, 0, sizeof(d_bsp)); // delete portal and line files remove(va("%s.prt", base)); remove(va("%s.lin", base)); // if onlyents, just grab the entities and re-save if(onlyents){ LoadBSPFile(bsp_name); num_entities = 0; LoadMapFile(map_name); SetModelNumbers(); UnparseEntities(); WriteBSPFile(bsp_name); } else { // start from scratch LoadMapFile(map_name); SetModelNumbers(); ProcessModels(); } end = time(NULL); total_bsp_time = (int)(end - start); Com_Print("\nBSP Time: "); if(total_bsp_time > 59) Com_Print("%d Minutes ", total_bsp_time / 60); Com_Print("%d Seconds\n", total_bsp_time % 60); return 0; }
/* ================= ProcessFile ================= */ void ProcessFile (char *sourcebase, char *filename_bsp1) { if (!onlyents) { remove (filename_bsp); remove (filename_prt); remove (filename_pts); remove (filename_lin); remove (filename_lit); remove (filename_dlit); remove (filename_lights); } // load brushes and entities LoadMapFile (sourcebase); if (onlyents) { LoadBSPFile (filename_bsp); UpdateEntLump (); WriteBSPFile (filename_bsp, false); return; } // init the tables to be shared by all models BeginBSPFile (); // the clipping hulls will be written out to text files by forked processes CreateHulls (); UpdateEntLump (); WriteMiptex (); FinishBSPFile (); }
bool Maps::OpenMap(std::string fileName) { auto newMap = AddEmptyMap(); if ( newMap->LoadMapFile(fileName) ) { if ( newMap->CreateThis(getHandle(), fileName) ) { SetWindowText(newMap->getHandle(), fileName.c_str()); EnableMapping(); Focus(newMap); if ( newMap->isProtected() && newMap->hasPassword() ) chkd.enterPasswordWindow.CreateThis(chkd.getHandle()); else if ( newMap->isProtected() ) mb("Map is protected and will be opened as view only"); SetFocus(chkd.getHandle()); currentlyActiveMap->Scroll(true, true, false); currentlyActiveMap->Redraw(true); currentlyActiveMap->refreshScenario(); return true; } else Error("Failed to create MDI Child Window!"); } RemoveMap(newMap); return false; }
/* * @brief */ int32_t BSP_Main(void) { char base[MAX_OSPATH]; Com_Print("\n----- BSP -----\n\n"); const time_t start = time(NULL); StripExtension(map_name, base); // clear the whole bsp structure memset(&d_bsp, 0, sizeof(d_bsp)); // delete portal and line files remove(va("%s.prt", base)); remove(va("%s.lin", base)); // if onlyents, just grab the entities and re-save if (onlyents) { LoadBSPFile(bsp_name); num_entities = 0; LoadMapFile(map_name); SetModelNumbers(); UnparseEntities(); WriteBSPFile(bsp_name); } else { // start from scratch LoadMapFile(map_name); SetModelNumbers(); ProcessModels(); } const time_t end = time(NULL); const time_t duration = end - start; Com_Print("\nBSP Time: "); if (duration > 59) Com_Print("%d Minutes ", (int32_t) (duration / 60)); Com_Print("%d Seconds\n", (int32_t) (duration % 60)); return 0; }
/* ================= ProcessFile ================= */ void ProcessFile (char *sourcebase, char *bspfilename1) { // create filenames strcpy (bspfilename, bspfilename1); StripExtension (bspfilename); strcat (bspfilename, ".bsp"); strcpy (hullfilename, bspfilename1); StripExtension (hullfilename); strcat (hullfilename, ".h0"); strcpy (portfilename, bspfilename1); StripExtension (portfilename); strcat (portfilename, ".prt"); strcpy (pointfilename, bspfilename1); StripExtension (pointfilename); strcat (pointfilename, ".pts"); if (!onlyents) { remove (bspfilename); if (!usehulls) { hullfilename[strlen(hullfilename)-1] = '1'; remove (hullfilename); hullfilename[strlen(hullfilename)-1] = '2'; remove (hullfilename); } remove (portfilename); remove (pointfilename); } // load brushes and entities LoadMapFile (sourcebase); if (onlyents) { UpdateEntLump (); return; } // init the tables to be shared by all models BeginBSPFile (); // the clipping hulls will be written out to text files by forked processes CreateHulls (); ReadClipHull (1); ReadClipHull (2); WriteEntitiesToString(); FinishBSPFile (); }
/* ============ OnlyEnts ============ */ void OnlyEnts( void ) { char out[1024]; sprintf (out, "%s.bsp", source); LoadBSPFile (out); num_entities = 0; LoadMapFile (name); SetModelNumbers (); SetLightStyles (); UnparseEntities (); WriteBSPFile (out); }
void OnlyEnts( void ){ char out[ 1024 ]; char save_cmdline[1024], save_version[1024], save_gridsize[1024]; const char *p; /* note it */ Sys_Printf( "--- OnlyEnts ---\n" ); sprintf( out, "%s.bsp", source ); LoadBSPFile( out ); ParseEntities(); p = ValueForKey( &entities[0], "_q3map2_cmdline" ); strncpy( save_cmdline, p, sizeof( save_cmdline ) ); save_cmdline[sizeof( save_cmdline ) - 1] = 0; p = ValueForKey( &entities[0], "_q3map2_version" ); strncpy( save_version, p, sizeof( save_version ) ); save_version[sizeof( save_version ) - 1] = 0; p = ValueForKey( &entities[0], "gridsize" ); strncpy( save_gridsize, p, sizeof( save_gridsize ) ); save_gridsize[sizeof( save_gridsize ) - 1] = 0; numEntities = 0; LoadShaderInfo(); LoadMapFile( name, qfalse, qfalse ); SetModelNumbers(); SetLightStyles(); if ( *save_cmdline ) { SetKeyValue( &entities[0], "_q3map2_cmdline", save_cmdline ); } if ( *save_version ) { SetKeyValue( &entities[0], "_q3map2_version", save_version ); } if ( *save_gridsize ) { SetKeyValue( &entities[0], "gridsize", save_gridsize ); } numBSPEntities = numEntities; UnparseEntities(); WriteBSPFile( out ); }
/* ============ OnlyTextures ============ */ void OnlyTextures( void ) { // FIXME!!! char out[1024]; int i; Error( "-onlytextures isn't working now..." ); sprintf (out, "%s.bsp", source); LoadMapFile (name); LoadBSPFile (out); // replace all the drawsurface shader names for ( i = 0 ; i < numDrawSurfaces ; i++ ) { } WriteBSPFile (out); }
void OnlyEnts( void ){ char out[ 1024 ]; /* note it */ Sys_Printf( "--- OnlyEnts ---\n" ); sprintf( out, "%s.bsp", source ); LoadBSPFile( out ); numEntities = 0; LoadShaderInfo(); LoadMapFile( name, qfalse ); SetModelNumbers(); SetLightStyles(); numBSPEntities = numEntities; UnparseEntities(); WriteBSPFile( out ); }
/* ============ main ============ */ int main (int argc, char **argv) { int i; double start, end; char path[1024]; #ifndef FIXTEXONLY printf ("---- qbsp3 ----\n"); #else printf("---- Map Fix Texture Capitals ----\n"); #endif for (i=1 ; i<argc ; i++) { #ifndef FIXTEXONLY if (!strcmp(argv[i],"-threads")) { numthreads = atoi (argv[i+1]); i++; } else if (!strcmp(argv[i],"-glview")) { glview = true; } else if (!strcmp(argv[i], "-v")) { printf ("verbose = true\n"); verbose = true; } else if (!strcmp(argv[i], "-draw")) { printf ("drawflag = true\n"); drawflag = true; } else if (!strcmp(argv[i], "-noweld")) { printf ("noweld = true\n"); noweld = true; } else if (!strcmp(argv[i], "-nocsg")) { printf ("nocsg = true\n"); nocsg = true; } else if (!strcmp(argv[i], "-noshare")) { printf ("noshare = true\n"); noshare = true; } else if (!strcmp(argv[i], "-notjunc")) { printf ("notjunc = true\n"); notjunc = true; } else if (!strcmp(argv[i], "-nowater")) { printf ("nowater = true\n"); nowater = true; } else if (!strcmp(argv[i], "-noopt")) { printf ("noopt = true\n"); noopt = true; } else if (!strcmp(argv[i], "-noprune")) { printf ("noprune = true\n"); noprune = true; } else if (!strcmp(argv[i], "-nofill")) { printf ("nofill = true\n"); nofill = true; } else if (!strcmp(argv[i], "-nomerge")) { printf ("nomerge = true\n"); nomerge = true; } else if (!strcmp(argv[i], "-nosubdiv")) { printf ("nosubdiv = true\n"); nosubdiv = true; } else if (!strcmp(argv[i], "-nodetail")) { printf ("nodetail = true\n"); nodetail = true; } else if (!strcmp(argv[i], "-fulldetail")) { printf ("fulldetail = true\n"); fulldetail = true; } else if (!strcmp(argv[i], "-onlyents")) { printf ("onlyents = true\n"); onlyents = true; } //hypo else #endif if (!strcmp(argv[i], "-onlytextures")) { printf("onlytextures = true\n"); onlytextures = true; } //hypo end #ifndef FIXTEXONLY else if (!strcmp(argv[i], "-micro")) { microvolume = atof(argv[i+1]); printf ("microvolume = %f\n", microvolume); i++; } else if (!strcmp(argv[i], "-leaktest")) { printf ("leaktest = true\n"); leaktest = true; } else if (!strcmp(argv[i], "-verboseentities")) { printf ("verboseentities = true\n"); verboseentities = true; } else if (!strcmp(argv[i], "-chop")) { subdivide_size = atof(argv[i+1]); printf ("subdivide_size = %f\n", subdivide_size); i++; } else if (!strcmp(argv[i], "-block")) { block_xl = block_xh = atoi(argv[i+1]); block_yl = block_yh = atoi(argv[i+2]); printf ("block: %i,%i\n", block_xl, block_yl); i+=2; } else if (!strcmp(argv[i], "-blocks")) { block_xl = atoi(argv[i+1]); block_yl = atoi(argv[i+2]); block_xh = atoi(argv[i+3]); block_yh = atoi(argv[i+4]); printf ("blocks: %i,%i to %i,%i\n", block_xl, block_yl, block_xh, block_yh); i+=4; } else if (!strcmp (argv[i],"-tmpout")) { strcpy (outbase, "/tmp"); } #endif else if (argv[i][0] == '-') Error ("Unknown option \"%s\"", argv[i]); else break; } if (i != argc - 1) Error ("usage: qbsp3 [options] mapfile"); start = I_FloatTime (); ThreadSetDefault (); numthreads = 1; // multiple threads aren't helping... //hypo if (onlytextures) { strcpy(source, ExpandArg(argv[i])); StripExtension(source); mapHasCapitals = 0; } #ifndef FIXTEXONLY else //hypo end { SetQdirFromPath(argv[i]); 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])); DefaultExtension(name, ".map"); // might be .reg } #endif // // if onlyents, just grab the entites and resave // #ifndef FIXTEXONLY if (onlyents) { char out[1024]; sprintf (out, "%s.bsp", source); LoadBSPFile (out); num_entities = 0; LoadMapFile (name); SetModelNumbers (); SetLightStyles (); UnparseEntities (); WriteBSPFile (out); } //hypo write textures else #endif if (onlytextures) { char out[1024]; char mapFix[1024]; sprintf(out, "%s.bsp", source); LoadBSPFile(out); if (mapHasCapitals) { StripExtension(out); sprintf(mapFix, "%s_fix.bsp", out); printf("map has %i capitals. Writing... %s\n", mapHasCapitals, mapFix); WriteBSPFile(mapFix); } else printf("map is fine\n"); } //hypo end #ifndef FIXTEXONLY else { // // start from scratch // LoadMapFile (name); SetModelNumbers (); SetLightStyles (); ProcessModels (); } end = I_FloatTime (); printf ("%5.0f seconds elapsed\n", end-start); #endif return 0; }
int BspMain(int argc, char **argv) { int i; double start, end; char path[1024]; Sys_Printf("---- bsp ----\n"); for(i = 1; i < argc; i++) { 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")) { Sys_Printf("verbose = true\n"); verbose = qtrue; } else if(!strcmp(argv[i], "-draw")) { Sys_Printf("drawflag = true\n"); drawFlag = qtrue; } else if(!strcmp(argv[i], "-debugsurfaces")) { Sys_Printf("emitting debug surfaces\n"); debugSurfaces = qtrue; } else if(!strcmp(argv[i], "-nowater")) { Sys_Printf("nowater = true\n"); noliquids = qtrue; } else if(!strcmp(argv[i], "-nodetail")) { Sys_Printf("nodetail = true\n"); nodetail = qtrue; } else if(!strcmp(argv[i], "-fulldetail")) { Sys_Printf("fulldetail = true\n"); fulldetail = qtrue; } else if(!strcmp(argv[i], "-onlyents")) { Sys_Printf("onlyents = true\n"); onlyents = qtrue; } else if(!strcmp(argv[i], "-onlytextures")) { Sys_Printf("onlytextures = true\n"); // FIXME: make work again! onlytextures = qtrue; } else if(!strcmp(argv[i], "-micro")) { microvolume = atof(argv[i + 1]); Sys_Printf("microvolume = %f\n", microvolume); i++; } else if(!strcmp(argv[i], "-nofog")) { Sys_Printf("nofog = true\n"); nofog = qtrue; } else if(!strcmp(argv[i], "-nosubdivide")) { Sys_Printf("nosubdivide = true\n"); nosubdivide = qtrue; } else if(!strcmp(argv[i], "-leaktest")) { Sys_Printf("leaktest = true\n"); leaktest = qtrue; } else if(!strcmp(argv[i], "-nocurves")) { nocurves = qtrue; Sys_Printf("no curve brushes\n"); } else if(!strcmp(argv[i], "-nodoors")) { nodoors = qtrue; Sys_Printf("no door entities\n"); } else if(!strcmp(argv[i], "-notjunc")) { notjunc = qtrue; Sys_Printf("no tjunction fixing\n"); } else if(!strcmp(argv[i], "-expand")) { testExpand = qtrue; Sys_Printf("Writing expanded.map.\n"); } else if(!strcmp(argv[i], "-showseams")) { showseams = qtrue; Sys_Printf("Showing seams on terrain.\n"); } else if(!strcmp(argv[i], "-tmpout")) { strcpy(outbase, "/tmp"); } else if(!strcmp(argv[i], "-fakemap")) { fakemap = qtrue; Sys_Printf("will generate fakemap.map\n"); } else if(!strcmp(argv[i], "-samplesize")) { samplesize = atoi(argv[i + 1]); if(samplesize < 1) samplesize = 1; i++; Sys_Printf("lightmap sample size is %dx%d units\n", samplesize, samplesize); } else if(!strcmp(argv[i], "-connect")) { Broadcast_Setup(argv[++i]); } else if(argv[i][0] == '-') Error("Unknown option \"%s\"", argv[i]); else break; } if(i != argc - 1) { Error("usage: xmap -map2bsp [-<switch> [-<switch> ...]] <mapname.map>\n" "\n" "Switches:\n" " v = verbose output\n" " threads <X> = set number of threads to X\n" " nocurves = don't emit bezier surfaces\n" " nodoors = disable door entities\n" //" breadthfirst = breadth first bsp building\n" //" nobrushmerge = don't merge brushes\n" " noliquids = don't write liquids to map\n" //" nocsg = disables brush chopping\n" //" glview = output a GL view\n" " draw = enables mini BSP viewer\n" //" noweld = disables weld\n" //" noshare = disables sharing\n" " notjunc = disables juncs\n" " nowater = disables water brushes\n" //" noprune = disables node prunes\n" //" nomerge = disables face merging\n" " nofog = disables fogs\n" " nosubdivide = disables subdivision of draw surfaces\n" " nodetail = disables detail brushes\n" " fulldetail = enables full detail\n" " onlyents = only compile entities with bsp\n" " micro <volume>\n" " = sets the micro volume to the given float\n" " leaktest = perform a leak test\n" //" chop <subdivide_size>\n" //" = sets the subdivide size to the given float\n" " samplesize <N> = set the lightmap pixel size to NxN units\n"); } start = I_FloatTime(); ThreadSetDefault(); SetQdirFromPath(argv[i]); 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(); // shut down connection Broadcast_Shutdown(); return 0; } // if onlytextures, just grab the textures and resave if(onlytextures) { OnlyTextures(); // shut down connection Broadcast_Shutdown(); return 0; } // start from scratch LoadShaderInfo(); LoadMapFile(name); ProcessModels(); SetModelNumbers(); EndBSPFile(); end = I_FloatTime(); Sys_Printf("%5.0f seconds elapsed\n", end - start); // shut down connection Broadcast_Shutdown(); return 0; }
int RunVBSP( int argc, char **argv ) { int i; double start, end; char path[1024]; CommandLine()->CreateCmdLine( argc, argv ); MathLib_Init( 2.2f, 2.2f, 0.0f, OVERBRIGHT, false, false, false, false ); InstallSpewFunction(); SpewActivate( "developer", 1 ); CmdLib_InitFileSystem( argv[ argc-1 ] ); Q_StripExtension( ExpandArg( argv[ argc-1 ] ), source, sizeof( source ) ); Q_FileBase( source, mapbase, sizeof( mapbase ) ); strlwr( mapbase ); LoadCmdLineFromFile( argc, argv, mapbase, "vbsp" ); Msg( "Valve Software - vbsp.exe (%s)\n", __DATE__ ); for (i=1 ; i<argc ; i++) { if (!stricmp(argv[i],"-threads")) { numthreads = atoi (argv[i+1]); i++; } else if (!Q_stricmp(argv[i],"-glview")) { glview = true; } else if ( !Q_stricmp(argv[i], "-v") || !Q_stricmp(argv[i], "-verbose") ) { Msg("verbose = true\n"); verbose = true; } else if (!Q_stricmp(argv[i], "-noweld")) { Msg ("noweld = true\n"); noweld = true; } else if (!Q_stricmp(argv[i], "-nocsg")) { Msg ("nocsg = true\n"); nocsg = true; } else if (!Q_stricmp(argv[i], "-noshare")) { Msg ("noshare = true\n"); noshare = true; } else if (!Q_stricmp(argv[i], "-notjunc")) { Msg ("notjunc = true\n"); notjunc = true; } else if (!Q_stricmp(argv[i], "-nowater")) { Msg ("nowater = true\n"); nowater = true; } else if (!Q_stricmp(argv[i], "-noopt")) { Msg ("noopt = true\n"); noopt = true; } else if (!Q_stricmp(argv[i], "-noprune")) { Msg ("noprune = true\n"); noprune = true; } else if (!Q_stricmp(argv[i], "-nomerge")) { Msg ("nomerge = true\n"); nomerge = true; } else if (!Q_stricmp(argv[i], "-nomergewater")) { Msg ("nomergewater = true\n"); nomergewater = true; } else if (!Q_stricmp(argv[i], "-nosubdiv")) { Msg ("nosubdiv = true\n"); nosubdiv = true; } else if (!Q_stricmp(argv[i], "-nodetail")) { Msg ("nodetail = true\n"); nodetail = true; } else if (!Q_stricmp(argv[i], "-fulldetail")) { Msg ("fulldetail = true\n"); fulldetail = true; } else if (!Q_stricmp(argv[i], "-onlyents")) { Msg ("onlyents = true\n"); onlyents = true; } else if (!Q_stricmp(argv[i], "-onlyprops")) { Msg ("onlyprops = true\n"); onlyprops = true; } else if (!Q_stricmp(argv[i], "-micro")) { microvolume = atof(argv[i+1]); Msg ("microvolume = %f\n", microvolume); i++; } else if (!Q_stricmp(argv[i], "-leaktest")) { Msg ("leaktest = true\n"); leaktest = true; } else if (!Q_stricmp(argv[i], "-verboseentities")) { Msg ("verboseentities = true\n"); verboseentities = true; } else if (!Q_stricmp(argv[i], "-snapaxial")) { Msg ("snap axial = true\n"); g_snapAxialPlanes = true; } #if 0 else if (!Q_stricmp(argv[i], "-maxlightmapdim")) { g_maxLightmapDimension = atof(argv[i+1]); Msg ("g_maxLightmapDimension = %f\n", g_maxLightmapDimension); i++; } #endif else if (!Q_stricmp(argv[i], "-block")) { block_xl = block_xh = atoi(argv[i+1]); block_yl = block_yh = atoi(argv[i+2]); Msg ("block: %i,%i\n", block_xl, block_yl); i+=2; } else if (!Q_stricmp(argv[i], "-blocks")) { block_xl = atoi(argv[i+1]); block_yl = atoi(argv[i+2]); block_xh = atoi(argv[i+3]); block_yh = atoi(argv[i+4]); Msg ("blocks: %i,%i to %i,%i\n", block_xl, block_yl, block_xh, block_yh); i+=4; } else if ( !Q_stricmp( argv[i], "-dumpcollide" ) ) { Msg("Dumping collision models to collideXXX.txt\n" ); dumpcollide = true; } else if ( !Q_stricmp( argv[i], "-dumpstaticprop" ) ) { Msg("Dumping static props to staticpropXXX.txt\n" ); g_DumpStaticProps = true; } else if ( !Q_stricmp( argv[i], "-forceskyvis" ) ) { Msg("Enabled vis in 3d skybox\n" ); g_bSkyVis = true; } else if (!Q_stricmp (argv[i],"-tmpout")) { strcpy (outbase, "/tmp"); } #if 0 else if( !Q_stricmp( argv[i], "-defaultluxelsize" ) ) { g_defaultLuxelSize = atof( argv[i+1] ); i++; } #endif else if( !Q_stricmp( argv[i], "-luxelscale" ) ) { g_luxelScale = atof( argv[i+1] ); i++; } else if( !strcmp( argv[i], "-minluxelscale" ) ) { g_minLuxelScale = atof( argv[i+1] ); if (g_minLuxelScale < 1) g_minLuxelScale = 1; i++; } else if( !Q_stricmp( argv[i], "-dxlevel" ) ) { g_nDXLevel = atoi( argv[i+1] ); Msg( "DXLevel = %d\n", g_nDXLevel ); i++; } else if( !Q_stricmp( argv[i], "-bumpall" ) ) { g_BumpAll = true; } else if( !Q_stricmp( argv[i], "-low" ) ) { g_bLowPriority = true; } else if( !Q_stricmp( argv[i], "-lightifmissing" ) ) { g_bLightIfMissing = true; } else if ( !Q_stricmp( argv[i], CMDLINEOPTION_NOVCONFIG ) ) { } else if ( !Q_stricmp( argv[i], "-allowdebug" ) || !Q_stricmp( argv[i], "-steam" ) ) { // nothing to do here, but don't bail on this option } else if ( !Q_stricmp( argv[i], "-vproject" ) || !Q_stricmp( argv[i], "-game" ) ) { ++i; } else if ( !Q_stricmp( argv[i], "-keepstalezip" ) ) { g_bKeepStaleZip = true; } else if ( !Q_stricmp( argv[i], "-xbox" ) ) { // enable mandatory xbox extensions g_NodrawTriggers = true; g_DisableWaterLighting = true; } else if ( !Q_stricmp( argv[i], "-allowdetailcracks")) { g_bAllowDetailCracks = true; } else if ( !Q_stricmp( argv[i], "-novirtualmesh")) { g_bNoVirtualMesh = true; } else if ( !Q_stricmp( argv[i], "-replacematerials" ) ) { g_ReplaceMaterials = true; } else if ( !Q_stricmp(argv[i], "-nodrawtriggers") ) { g_NodrawTriggers = true; } else if ( !Q_stricmp( argv[i], "-FullMinidumps" ) ) { EnableFullMinidumps( true ); } else if (argv[i][0] == '-') { Warning("VBSP: Unknown option \"%s\"\n\n", argv[i]); i = 100000; // force it to print the usage break; } else break; } if (i != argc - 1) { PrintCommandLine( argc, argv ); Warning( "usage : vbsp [options...] mapfile\n" "example: vbsp -onlyents c:\\hl2\\hl2\\maps\\test\n" "\n" "Common options (use -v to see all options):\n" "\n" " -v (or -verbose): Turn on verbose output (also shows more command\n" " line options).\n" "\n" " -onlyents : This option causes vbsp only import the entities from the .vmf\n" " file. -onlyents won't reimport brush models.\n" " -onlyprops : Only update the static props and detail props.\n" " -glview : Writes .gl files in the current directory that can be viewed\n" " with glview.exe. If you use -tmpout, it will write the files\n" " into the \\tmp folder.\n" " -nodetail : Get rid of all detail geometry. The geometry left over is\n" " what affects visibility.\n" " -nowater : Get rid of water brushes.\n" " -low : Run as an idle-priority process.\n" "\n" " -vproject <directory> : Override the VPROJECT environment variable.\n" " -game <directory> : Same as -vproject.\n" "\n" ); if ( verbose ) { Warning( "Other options :\n" " -novconfig : Don't bring up graphical UI on vproject errors.\n" " -threads : Control the number of threads vbsp uses (defaults to the # of\n" " processors on your machine).\n" " -verboseentities: If -v is on, this disables verbose output for submodels.\n" " -noweld : Don't join face vertices together.\n" " -nocsg : Don't chop out intersecting brush areas.\n" " -noshare : Emit unique face edges instead of sharing them.\n" " -notjunc : Don't fixup t-junctions.\n" " -noopt : By default, vbsp removes the 'outer shell' of the map, which\n" " are all the faces you can't see because you can never get\n" " outside the map. -noopt disables this behaviour.\n" " -noprune : Don't prune neighboring solid nodes.\n" " -nomerge : Don't merge together chopped faces on nodes.\n" " -nomergewater: Don't merge together chopped faces on water.\n" " -nosubdiv : Don't subdivide faces for lightmapping.\n" " -micro <#> : vbsp will warn when brushes are output with a volume less\n" " than this number (default: 1.0).\n" " -fulldetail : Mark all detail geometry as normal geometry (so all detail\n" " geometry will affect visibility).\n" " -leaktest : Stop processing the map if a leak is detected. Whether or not\n" " this flag is set, a leak file will be written out at\n" " <vmf filename>.lin, and it can be imported into Hammer.\n" " -bumpall : Force all surfaces to be bump mapped.\n" " -snapaxial : Snap axial planes to integer coordinates.\n" " -block # # : Control the grid size mins that vbsp chops the level on.\n" " -blocks # # # # : Enter the mins and maxs for the grid size vbsp uses.\n" " -dumpstaticprops: Dump static props to staticprop*.txt\n" " -dumpcollide : Write files with collision info.\n" " -forceskyvis : Enable vis calculations in 3d skybox leaves\n" " -luxelscale # : Scale all lightmaps by this amount (default: 1.0).\n" " -minluxelscale #: No luxel scale will be lower than this amount (default: 1.0).\n" " -lightifmissing : Force lightmaps to be generated for all surfaces even if\n" " they don't need lightmaps.\n" " -keepstalezip : Keep the BSP's zip files intact but regenerate everything\n" " else.\n" " -virtualdispphysics : Use virtual (not precomputed) displacement collision models\n" " -xbox : Enable mandatory xbox options\n" " -x360 : Generate Xbox360 version of vsp\n" " -nox360 : Disable generation Xbox360 version of vsp (default)\n" " -replacematerials : Substitute materials according to materialsub.txt in content\\maps\n" " -FullMinidumps : Write large minidumps on crash.\n" ); } DeleteCmdLine( argc, argv ); CmdLib_Cleanup(); CmdLib_Exit( 1 ); } start = Plat_FloatTime(); // Run in the background? if( g_bLowPriority ) { SetLowPriority(); } if( ( g_nDXLevel != 0 ) && ( g_nDXLevel < 80 ) ) { g_BumpAll = false; } if( g_luxelScale == 1.0f ) { if ( g_nDXLevel == 70 ) { g_luxelScale = 4.0f; } } ThreadSetDefault (); numthreads = 1; // multiple threads aren't helping... // Setup the logfile. char logFile[512]; _snprintf( logFile, sizeof(logFile), "%s.log", source ); SetSpewFunctionLogFile( logFile ); LoadPhysicsDLL(); LoadSurfaceProperties(); #if 0 Msg( "qdir: %s This is the the path of the initial source file \n", qdir ); Msg( "gamedir: %s This is the base engine + mod-specific game dir (e.g. d:/tf2/mytfmod/) \n", gamedir ); Msg( "basegamedir: %s This is the base engine + base game directory (e.g. e:/hl2/hl2/, or d:/tf2/tf2/ )\n", basegamedir ); #endif sprintf( materialPath, "%smaterials", gamedir ); InitMaterialSystem( materialPath, CmdLib_GetFileSystemFactory() ); Msg( "materialPath: %s\n", materialPath ); // delete portal and line files sprintf (path, "%s.prt", source); remove (path); sprintf (path, "%s.lin", source); remove (path); strcpy (name, ExpandArg (argv[i])); const char *pszExtension = V_GetFileExtension( name ); if ( !pszExtension ) { V_SetExtension( name, ".vmm", sizeof( name ) ); if ( !FileExists( name ) ) { V_SetExtension( name, ".vmf", sizeof( name ) ); } } char platformBSPFileName[1024]; GetPlatformMapPath( source, platformBSPFileName, g_nDXLevel, 1024 ); // if we're combining materials, load the script file if ( g_ReplaceMaterials ) { LoadMaterialReplacementKeys( gamedir, mapbase ); } // // if onlyents, just grab the entites and resave // if (onlyents) { LoadBSPFile (platformBSPFileName); num_entities = 0; // Clear out the cubemap samples since they will be reparsed even with -onlyents g_nCubemapSamples = 0; // Mark as stale since the lighting could be screwed with new ents. AddBufferToPak( GetPakFile(), "stale.txt", "stale", strlen( "stale" ) + 1, false ); LoadMapFile (name); SetModelNumbers (); SetLightStyles (); // NOTE: If we ever precompute lighting for static props in // vrad, EmitStaticProps should be removed here // Emit static props found in the .vmf file EmitStaticProps(); // NOTE: Don't deal with detail props here, it blows away lighting // Recompute the skybox ComputeBoundsNoSkybox(); // Make sure that we have a water lod control eneity if we have water in the map. EnsurePresenceOfWaterLODControlEntity(); // Make sure the func_occluders have the appropriate data set FixupOnlyEntsOccluderEntities(); // Doing this here because stuff abov may filter out entities UnparseEntities (); WriteBSPFile (platformBSPFileName); } else if (onlyprops) { // In the only props case, deal with static + detail props only LoadBSPFile (platformBSPFileName); LoadMapFile(name); SetModelNumbers(); SetLightStyles(); // Emit static props found in the .vmf file EmitStaticProps(); // Place detail props found in .vmf and based on material properties LoadEmitDetailObjectDictionary( gamedir ); EmitDetailObjects(); WriteBSPFile (platformBSPFileName); } else { // // start from scratch // // Load just the file system from the bsp if( g_bKeepStaleZip && FileExists( platformBSPFileName ) ) { LoadBSPFile_FileSystemOnly (platformBSPFileName); // Mark as stale since the lighting could be screwed with new ents. AddBufferToPak( GetPakFile(), "stale.txt", "stale", strlen( "stale" ) + 1, false ); } LoadMapFile (name); WorldVertexTransitionFixup(); if( ( g_nDXLevel == 0 ) || ( g_nDXLevel >= 70 ) ) { Cubemap_FixupBrushSidesMaterials(); Cubemap_AttachDefaultCubemapToSpecularSides(); Cubemap_AddUnreferencedCubemaps(); } SetModelNumbers (); SetLightStyles (); LoadEmitDetailObjectDictionary( gamedir ); ProcessModels (); } end = Plat_FloatTime(); char str[512]; GetHourMinuteSecondsString( (int)( end - start ), str, sizeof( str ) ); Msg( "%s elapsed\n", str ); DeleteCmdLine( argc, argv ); ReleasePakFileLumps(); DeleteMaterialReplacementKeys(); ShutdownMaterialSystem(); CmdLib_Cleanup(); return 0; }
int ConvertMapToMap(int argc, char **argv) { int i; double start, end; char source[1024]; char name[1024]; char save[1024]; Sys_Printf("---- convert map to map ----\n"); for(i = 1; i < argc; i++) { if(!strcmp(argv[i], "-threads")) { numthreads = atoi(argv[i + 1]); i++; } else if(!strcmp(argv[i], "-v")) { Sys_Printf("verbose = true\n"); verbose = qtrue; } else if(!strcmp(argv[i], "-quake3")) { convertType = CONVERT_QUAKE3; Sys_Printf("converting from Quake3 to XreaL\n"); } else if(!strcmp(argv[i], "-quake4")) { convertType = CONVERT_QUAKE4; Sys_Printf("converting from Quake4 to XreaL\n"); } else if(!strcmp(argv[i], "-connect")) { Broadcast_Setup(argv[++i]); } else if(argv[i][0] == '-') Error("Unknown option \"%s\"", argv[i]); else break; } if(i != argc - 1) { Error("usage: xmap -map2map [-<switch> [-<switch> ...]] <mapname.map>\n" "\n" "Switches:\n" " v = verbose output\n" //" quake1 = convert from QuakeWorld to XreaL\n" //" quake2 = convert from Quake2 to XreaL\n" " quake3 = convert from Quake3 to XreaL\n" " quake4 = convert from Quake4 to XreaL\n"); } start = I_FloatTime(); ThreadSetDefault(); SetQdirFromPath(argv[i]); strcpy(source, ExpandArg(argv[i])); StripExtension(source); strcpy(name, ExpandArg(argv[i])); DefaultExtension(name, ".map"); // start from scratch LoadShaderInfo(); LoadMapFile(name); // strcpy(save, ExpandArg(argv[i])); StripExtension(save); strcat(save, "_converted"); DefaultExtension(save, ".map"); WriteMapFile(save); end = I_FloatTime(); Sys_Printf("%5.0f seconds elapsed\n", end - start); // shut down connection Broadcast_Shutdown(); return 0; }
int BSPMain( int argc, char **argv ) { int i; char path[ 1024 ], tempSource[ 1024 ]; qboolean onlyents = qfalse; /* note it */ Sys_Printf( "--- BSP ---\n" ); SetDrawSurfacesBuffer(); mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS ); memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS ); numMapDrawSurfs = 0; tempSource[ 0 ] = '\0'; /* set standard game flags */ maxSurfaceVerts = game->maxSurfaceVerts; maxSurfaceIndexes = game->maxSurfaceIndexes; emitFlares = game->emitFlares; /* process arguments */ for( i = 1; i < (argc - 1); i++ ) { if( !strcmp( argv[ i ], "-onlyents" ) ) { Sys_Printf( "Running entity-only compile\n" ); onlyents = qtrue; } else if( !strcmp( argv[ i ], "-tempname" ) ) strcpy( tempSource, argv[ ++i ] ); else if( !strcmp( argv[ i ], "-tmpout" ) ) strcpy( outbase, "/tmp" ); else if( !strcmp( argv[ i ], "-nowater" ) ) { Sys_Printf( "Disabling water\n" ); nowater = qtrue; } else if( !strcmp( argv[ i ], "-nodetail" ) ) { Sys_Printf( "Ignoring detail brushes\n") ; nodetail = qtrue; } else if( !strcmp( argv[ i ], "-fulldetail" ) ) { Sys_Printf( "Turning detail brushes into structural brushes\n" ); fulldetail = qtrue; } else if( !strcmp( argv[ i ], "-nofog" ) ) { Sys_Printf( "Fog volumes disabled\n" ); nofog = qtrue; } else if( !strcmp( argv[ i ], "-nosubdivide" ) ) { Sys_Printf( "Disabling brush face subdivision\n" ); nosubdivide = qtrue; } else if( !strcmp( argv[ i ], "-leaktest" ) ) { Sys_Printf( "Leaktest enabled\n" ); leaktest = qtrue; } else if( !strcmp( argv[ i ], "-verboseentities" ) ) { Sys_Printf( "Verbose entities enabled\n" ); verboseEntities = qtrue; } else if( !strcmp( argv[ i ], "-nocurves" ) ) { Sys_Printf( "Ignoring curved surfaces (patches)\n" ); noCurveBrushes = qtrue; } else if( !strcmp( argv[ i ], "-notjunc" ) ) { Sys_Printf( "T-junction fixing disabled\n" ); notjunc = qtrue; } else if( !strcmp( argv[ i ], "-fakemap" ) ) { Sys_Printf( "Generating fakemap.map\n" ); fakemap = qtrue; } else if( !strcmp( argv[ i ], "-samplesize" ) ) { sampleSize = atoi( argv[ i + 1 ] ); if( sampleSize < 1 ) sampleSize = 1; i++; Sys_Printf( "Lightmap sample size set to %dx%d units\n", sampleSize, sampleSize ); } else if( !strcmp( argv[ i ], "-custinfoparms") ) { Sys_Printf( "Custom info parms enabled\n" ); useCustomInfoParms = qtrue; } /* sof2 args */ else if( !strcmp( argv[ i ], "-rename" ) ) { Sys_Printf( "Appending _bsp suffix to misc_model shaders (SOF2)\n" ); renameModelShaders = qtrue; } /* ydnar args */ else if( !strcmp( argv[ i ], "-ne" ) ) { normalEpsilon = atof( argv[ i + 1 ] ); i++; Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon ); } else if( !strcmp( argv[ i ], "-de" ) ) { distanceEpsilon = atof( argv[ i + 1 ] ); i++; Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon ); } else if( !strcmp( argv[ i ], "-mv" ) ) { maxLMSurfaceVerts = atoi( argv[ i + 1 ] ); if( maxLMSurfaceVerts < 3 ) maxLMSurfaceVerts = 3; if( maxLMSurfaceVerts > maxSurfaceVerts ) maxSurfaceVerts = maxLMSurfaceVerts; i++; Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts ); } else if( !strcmp( argv[ i ], "-mi" ) ) { maxSurfaceIndexes = atoi( argv[ i + 1 ] ); if( maxSurfaceIndexes < 3 ) maxSurfaceIndexes = 3; i++; Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes ); } else if( !strcmp( argv[ i ], "-np" ) ) { npDegrees = atof( argv[ i + 1 ] ); if( npDegrees < 0.0f ) shadeAngleDegrees = 0.0f; else if( npDegrees > 0.0f ) Sys_Printf( "Forcing nonplanar surfaces with a breaking angle of %f degrees\n", npDegrees ); i++; } else if( !strcmp( argv[ i ], "-snap" ) ) { bevelSnap = atoi( argv[ i + 1 ]); if( bevelSnap < 0 ) bevelSnap = 0; i++; if( bevelSnap > 0 ) Sys_Printf( "Snapping brush bevel planes to %d units\n", bevelSnap ); } else if( !strcmp( argv[ i ], "-texrange" ) ) { texRange = atoi( argv[ i + 1 ]); if( texRange < 0 ) texRange = 0; i++; Sys_Printf( "Limiting per-surface texture range to %d texels\n", texRange ); } else if( !strcmp( argv[ i ], "-nohint" ) ) { Sys_Printf( "Hint brushes disabled\n" ); noHint = qtrue; } else if( !strcmp( argv[ i ], "-flat" ) ) { Sys_Printf( "Flatshading enabled\n" ); flat = qtrue; } else if( !strcmp( argv[ i ], "-meta" ) ) { Sys_Printf( "Creating meta surfaces from brush faces\n" ); meta = qtrue; } else if( !strcmp( argv[ i ], "-patchmeta" ) ) { Sys_Printf( "Creating meta surfaces from patches\n" ); patchMeta = qtrue; } else if( !strcmp( argv[ i ], "-flares" ) ) { Sys_Printf( "Flare surfaces enabled\n" ); emitFlares = qtrue; } else if( !strcmp( argv[ i ], "-noflares" ) ) { Sys_Printf( "Flare surfaces disabled\n" ); emitFlares = qfalse; } else if( !strcmp( argv[ i ], "-skyfix" ) ) { Sys_Printf( "GL_CLAMP sky fix/hack/workaround enabled\n" ); skyFixHack = qtrue; } else if( !strcmp( argv[ i ], "-debugsurfaces" ) ) { Sys_Printf( "emitting debug surfaces\n" ); debugSurfaces = qtrue; } else if( !strcmp( argv[ i ], "-debuginset" ) ) { Sys_Printf( "Debug surface triangle insetting enabled\n" ); debugInset = qtrue; } else if( !strcmp( argv[ i ], "-debugportals" ) ) { Sys_Printf( "Debug portal surfaces enabled\n" ); debugPortals = qtrue; } else if( !strcmp( argv[ i ], "-bsp" ) ) Sys_Printf( "-bsp argument unnecessary\n" ); else Sys_Printf( "WARNING: Unknown option \"%s\"\n", argv[ i ] ); } /* fixme: print more useful usage here */ if( i != (argc - 1) ) Error( "usage: q3map [options] mapfile" ); /* copy source name */ strcpy( source, ExpandArg( argv[ i ] ) ); StripExtension( source ); /* ydnar: set default sample size */ SetDefaultSampleSize( sampleSize ); /* delete portal, line and surface files */ sprintf( path, "%s.prt", source ); remove( path ); sprintf( path, "%s.lin", source ); remove( path ); //% sprintf( path, "%s.srf", source ); /* ydnar */ //% remove( path ); /* expand mapname */ 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; } /* load shaders */ 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, qfalse ); else LoadMapFile( name, qfalse ); /* ydnar: decal setup */ ProcessDecals(); /* ydnar: cloned brush model entities */ SetCloneModelNumbers(); /* process world and submodels */ ProcessModels(); /* set light styles from targetted light entities */ SetLightStyles(); /* finish and write bsp */ EndBSPFile(); /* remove temp map source file if appropriate */ if( strlen( tempSource ) > 0) remove( tempSource ); /* return to sender */ return 0; }
int main (int argc, char **argv) { int i, j; int hull; entity_t *ent; char source[1024]; char name[1024]; double start, end; printf( "qcsg.exe v2.8 (%s)\n", __DATE__ ); printf ("---- qcsg ----\n" ); for (i=1 ; i<argc ; i++) { if (!strcmp(argv[i],"-threads")) { numthreads = atoi (argv[i+1]); i++; } else if (!strcmp(argv[i],"-glview")) { glview = true; } else if (!strcmp(argv[i], "-v")) { printf ("verbose = true\n"); verbose = true; } else if (!strcmp(argv[i], "-draw")) { printf ("drawflag = true\n"); drawflag = true; } else if (!strcmp(argv[i], "-noclip")) { printf ("noclip = true\n"); noclip = true; } else if (!strcmp(argv[i], "-onlyents")) { printf ("onlyents = true\n"); onlyents = true; } else if (!strcmp(argv[i], "-nowadtextures")) { printf ("wadtextures = false\n"); wadtextures = false; } else if (!strcmp(argv[i], "-wadinclude")) { pszWadInclude[nWadInclude++] = strdup( argv[i + 1] ); i++; } else if( !strcmp( argv[ i ], "-proj" ) ) { strcpy( qproject, argv[ i + 1 ] ); i++; } else if (!strcmp(argv[i], "-hullfile")) { hullfile = true; strcpy( qhullfile, argv[i + 1] ); i++; } else if (argv[i][0] == '-') Error ("Unknown option \"%s\"", argv[i]); else break; } if (i != argc - 1) Error ("usage: qcsg [-nowadtextures] [-wadinclude <name>] [-draw] [-glview] [-noclip] [-onlyents] [-proj <name>] [-threads #] [-v] [-hullfile <name>] mapfile"); SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_ABOVE_NORMAL); start = I_FloatTime (); CheckHullFile( hullfile, qhullfile ); ThreadSetDefault (); SetQdirFromPath (argv[i]); strcpy (source, ExpandArg (argv[i])); COM_FixSlashes(source); StripExtension (source); strcpy (name, ExpandArg (argv[i])); DefaultExtension (name, ".map"); // might be .reg // // if onlyents, just grab the entites and resave // if (onlyents && !glview) { char out[1024]; int old_entities; sprintf (out, "%s.bsp", source); LoadBSPFile (out); // Get the new entity data from the map file LoadMapFile (name); // Write it all back out again. WriteBSP (source); end = I_FloatTime (); printf ("%5.0f seconds elapsed\n", end-start); return 0; } // // start from scratch // LoadMapFile (name); RunThreadsOnIndividual (nummapbrushes, true, CreateBrush); BoundWorld (); qprintf ("%5i map planes\n", nummapplanes); for (i=0 ; i<NUM_HULLS ; i++) { char name[1024]; if (glview) sprintf (name, "%s.gl%i",source, i); else sprintf (name, "%s.p%i",source, i); out[i] = fopen (name, "w"); if (!out[i]) Error ("Couldn't open %s",name); } ProcessModels (); qprintf ("%5i csg faces\n", c_csgfaces); qprintf ("%5i used faces\n", c_outfaces); qprintf ("%5i tiny faces\n", c_tiny); qprintf ("%5i tiny clips\n", c_tiny_clip); for (i=0 ; i<NUM_HULLS ; i++) fclose (out[i]); if (!glview) { EmitPlanes (); WriteBSP (source); } end = I_FloatTime (); printf ("%5.0f seconds elapsed\n", end-start); return 0; }
qbool VM_LoadBytecode( vm_t * vm, sys_callex_t syscall1 ) { char name[MAX_OSPATH]; byte *buff; vmHeader_t *header; qvm_t *qvm; char num[32]; int filesize; snprintf( name, sizeof( name ), "%s.qvm", vm->name ); Con_DPrintf( "VM_LoadBytecode: load %s\n", name ); buff = FS_LoadTempFile( name , &filesize ); if ( !buff ) return false; // add qvm crc to the serverinfo snprintf( num, sizeof(num), "%i", CRC_Block( ( byte * ) buff, filesize ) ); Info_SetValueForStarKey( svs.info, "*progs", num, MAX_SERVERINFO_STRING ); header = ( vmHeader_t * ) buff; header->vmMagic = LittleLong( header->vmMagic ); header->instructionCount = LittleLong( header->instructionCount ); header->codeOffset = LittleLong( header->codeOffset ); header->codeLength = LittleLong( header->codeLength ); header->dataOffset = LittleLong( header->dataOffset ); header->dataLength = LittleLong( header->dataLength ); header->litLength = LittleLong( header->litLength ); header->bssLength = LittleLong( header->bssLength ); // check file if ( header->vmMagic != VM_MAGIC || header->instructionCount <= 0 || header->codeLength <= 0 ) { return false; } // create vitrual machine if(vm->hInst) qvm = (qvm_t *)vm->hInst; else qvm = (qvm_t *) Q_malloc (sizeof (qvm_t)); qvm->len_cs = header->instructionCount + 1; //bad opcode padding. qvm->len_ds = header->dataOffset + header->litLength + header->bssLength; //align ds qvm->ds_mask = 1; while( qvm->ds_mask < qvm->len_ds) qvm->ds_mask<<=1; qvm->len_ds = qvm->ds_mask; qvm->ds_mask--; qvm->len_ss = 0x10000; // default by q3asm if ( qvm->len_ds < qvm->len_ss ) Sys_Error( "VM_LoadBytecode: stacksize greater than data segment" ); qvm->cs = ( qvm_instruction_t * ) Hunk_AllocName( qvm->len_cs * sizeof( qvm_instruction_t ), "qvmcode" ); qvm->ds = (byte *) Hunk_AllocName( qvm->len_ds, "qvmdata" ); qvm->ss = qvm->ds + qvm->len_ds - qvm->len_ss; // setup registers qvm->PC = 0; qvm->SP = 0; qvm->LP = qvm->len_ds - sizeof(int); qvm->cycles = 0; qvm->reenter = 0; qvm->syscall = syscall1; // load instructions { byte *src = buff + header->codeOffset; qvm_instruction_t *dst = qvm->cs; opcode_t op; int i; for ( i = 0; i < header->instructionCount; i++, dst++ ) { op = (opcode_t) *src++; dst->opcode = op; switch ( op ) { case OP_ARG: dst->parm._int = ( int ) *src++; break; case OP_ENTER: case OP_LEAVE: case OP_CONST: case OP_LOCAL: case OP_EQ: case OP_NE: case OP_LTI: case OP_LEI: case OP_GTI: case OP_GEI: case OP_LTU: case OP_LEU: case OP_GTU: case OP_GEU: case OP_EQF: case OP_NEF: case OP_LTF: case OP_LEF: case OP_GTF: case OP_GEF: case OP_BLOCK_COPY: dst->parm._int = LittleLong( *( int * ) src ); src += 4; break; default: dst->parm._int = 0; break; } } dst->opcode = OP_BREAK; dst->parm._int = 0; } // load data segment { int *src = ( int * ) ( buff + header->dataOffset ); int *dst = ( int * ) qvm->ds; int i; for ( i = 0; i < header->dataLength / 4; i++ ) *dst++ = LittleLong( *src++ ); memcpy( dst, src, header->litLength ); } LoadMapFile( qvm, vm->name ); vm->type = VM_BYTECODE; vm->hInst = qvm; return true; }
/* ================= ProcessFile ================= */ static void ProcessFile (char *sourcebase, char *bspfilename1) { int i; // FILE *FH; // char radfilename[1024]; // create filenames strcpy (bspfilename, bspfilename1); StripExtension (bspfilename); strcat (bspfilename, ".bsp"); strcpy (hullfilename, bspfilename1); StripExtension (hullfilename); strcat (hullfilename, ".h0"); strcpy (portfilename, bspfilename1); StripExtension (portfilename); strcat (portfilename, ".prt"); strcpy (pointfilename, bspfilename1); StripExtension (pointfilename); strcat (pointfilename, ".pts"); if (!onlyents) { remove (bspfilename); if (!usehulls && hullnum == 0) { hullfilename[strlen(hullfilename)-1] = '1'; remove (hullfilename); hullfilename[strlen(hullfilename)-1] = '2'; remove (hullfilename); hullfilename[strlen(hullfilename)-1] = '3'; remove (hullfilename); hullfilename[strlen(hullfilename)-1] = '4'; remove (hullfilename); hullfilename[strlen(hullfilename)-1] = '5'; remove (hullfilename); } remove (portfilename); remove (pointfilename); } // load brushes and entities LoadMapFile (sourcebase); if (onlyents) { UpdateEntLump (); return; } // init the tables to be shared by all models BeginBSPFile (); for (i = 0 ; i < MAX_MAP_CLIPNODES ; i++) LightValues[i] = -2; // the clipping hulls will be written out to text files by forked processes CreateHulls (); ReadClipHull (1); ReadClipHull (2); ReadClipHull (3); ReadClipHull (4); ReadClipHull (5); WriteEntitiesToString(); FinishBSPFile (); /* strcpy (radfilename, bspfilename1); StripExtension (radfilename); strcat (radfilename, ".rad"); FH = fopen(radfilename,"w"); for (i = 0 ; i < numfaces ; i++) fprintf(FH,"%d\n",LightValues[i]); fclose(FH); */ }
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; }
int ConvertBSPMain( int argc, char **argv ){ int i; int ( *convertFunc )( char * ); game_t *convertGame; char ext[1024]; char BSPFilePath [ 1024 ]; char surfaceFilePath [ 1024 ]; qboolean map_allowed, force_bsp, force_map; /* set default */ convertFunc = ConvertBSPToASE; convertGame = NULL; map_allowed = qfalse; force_bsp = qfalse; force_map = qfalse; /* arg checking */ if ( argc < 1 ) { Sys_Printf( "Usage: q3map -convert [-format <ase|obj|map_bp|map>] [-shadersasbitmap|-lightmapsastexcoord|-deluxemapsastexcoord] [-readbsp|-readmap [-meta|-patchmeta]] [-v] <mapname>\n" ); return 0; } /* process arguments */ for ( i = 1; i < ( argc - 1 ); i++ ) { /* -format map|ase|... */ if ( !strcmp( argv[ i ], "-format" ) ) { i++; if ( !Q_stricmp( argv[ i ], "ase" ) ) { convertFunc = ConvertBSPToASE; map_allowed = qfalse; } else if ( !Q_stricmp( argv[ i ], "obj" ) ) { convertFunc = ConvertBSPToOBJ; map_allowed = qfalse; } else if ( !Q_stricmp( argv[ i ], "map_bp" ) ) { convertFunc = ConvertBSPToMap_BP; map_allowed = qtrue; } else if ( !Q_stricmp( argv[ i ], "map" ) ) { convertFunc = ConvertBSPToMap; map_allowed = qtrue; } else { convertGame = GetGame( argv[ i ] ); map_allowed = qfalse; if ( convertGame == NULL ) { Sys_FPrintf( SYS_WRN, "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] ); } } } else if ( !strcmp( argv[ i ], "-ne" ) ) { normalEpsilon = atof( argv[ i + 1 ] ); i++; Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon ); } else if ( !strcmp( argv[ i ], "-de" ) ) { distanceEpsilon = atof( argv[ i + 1 ] ); i++; Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon ); } else if ( !strcmp( argv[ i ], "-shaderasbitmap" ) || !strcmp( argv[ i ], "-shadersasbitmap" ) ) { shadersAsBitmap = qtrue; } else if ( !strcmp( argv[ i ], "-lightmapastexcoord" ) || !strcmp( argv[ i ], "-lightmapsastexcoord" ) ) { lightmapsAsTexcoord = qtrue; } else if ( !strcmp( argv[ i ], "-deluxemapastexcoord" ) || !strcmp( argv[ i ], "-deluxemapsastexcoord" ) ) { lightmapsAsTexcoord = qtrue; deluxemap = qtrue; } else if ( !strcmp( argv[ i ], "-readbsp" ) ) { force_bsp = qtrue; } else if ( !strcmp( argv[ i ], "-readmap" ) ) { force_map = qtrue; } else if ( !strcmp( argv[ i ], "-meta" ) ) { meta = qtrue; } else if ( !strcmp( argv[ i ], "-patchmeta" ) ) { meta = qtrue; patchMeta = qtrue; } } LoadShaderInfo(); /* clean up map name */ strcpy( source, ExpandArg( argv[i] ) ); ExtractFileExtension( source, ext ); if ( !map_allowed && !force_map ) { force_bsp = qtrue; } if ( force_map || ( !force_bsp && !Q_stricmp( ext, "map" ) && map_allowed ) ) { if ( !map_allowed ) { Sys_FPrintf( SYS_WRN, "WARNING: the requested conversion should not be done from .map files. Compile a .bsp first.\n" ); } StripExtension( source ); DefaultExtension( source, ".map" ); Sys_Printf( "Loading %s\n", source ); LoadMapFile( source, qfalse, convertGame == NULL ); sprintf( BSPFilePath, "%s.bsp", source ); sprintf( surfaceFilePath, "%s.srf", source ); PseudoCompileBSP( convertGame != NULL, BSPFilePath, surfaceFilePath ); } else { StripExtension( source ); DefaultExtension( source, ".bsp" ); Sys_Printf( "Loading %s\n", source ); LoadBSPFile( source ); ParseEntities(); } /* bsp format convert? */ if ( convertGame != NULL ) { /* set global game */ game = convertGame; /* write bsp */ StripExtension( source ); DefaultExtension( source, "_c.bsp" ); Sys_Printf( "Writing %s\n", source ); WriteBSPFile( source ); /* return to sender */ return 0; } /* normal convert */ return convertFunc( source ); }