/* ============== Load32BitImage Any of the return pointers can be NULL if you don't want them. ============== */ void Load32BitImage(const char *name, unsigned **pixels, int *width, int *height) { char ext[128]; byte *palette; byte *pixels8; byte *pixels32; int size; int i; int v; ExtractFileExtension(name, ext); if(!Q_stricmp(ext, "tga")) { LoadTGA(name, (byte **) pixels, width, height); } else { Load256Image(name, &pixels8, &palette, width, height); if(!pixels) { return; } size = *width * *height; pixels32 = safe_malloc(size * 4); *pixels = (unsigned *)pixels32; for(i = 0; i < size; i++) { v = pixels8[i]; pixels32[i * 4 + 0] = palette[v * 3 + 0]; pixels32[i * 4 + 1] = palette[v * 3 + 1]; pixels32[i * 4 + 2] = palette[v * 3 + 2]; pixels32[i * 4 + 3] = 0xff; } } }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int QuakeFileType(char *filename) { char ext[_MAX_PATH] = "."; ExtractFileExtension(filename, ext+1); return QuakeFileExtensionType(ext); } //end of the function QuakeFileTypeFromFileName
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void AASOuputFile( quakefile_t *qf, char *outputpath, char *filename ) { char ext[MAX_PATH]; // if ( strlen( outputpath ) ) { strcpy( filename, outputpath ); //append the bsp file base AppendPathSeperator( filename, MAX_PATH ); ExtractFileBase( qf->origname, &filename[strlen( filename )] ); // Ridah, add extension strcat( filename, aas_extension ); // done. //append .aas strcat( filename, ".aas" ); return; } //end if // ExtractFileExtension( qf->filename, ext ); if ( !stricmp( ext, "pk3" ) || !stricmp( ext, "pak" ) || !stricmp( ext, "sin" ) ) { strcpy( filename, qf->filename ); while ( strlen( filename ) && filename[strlen( filename ) - 1] != '\\' && filename[strlen( filename ) - 1] != '/' ) { filename[strlen( filename ) - 1] = '\0'; } //end while strcat( filename, "maps" ); if ( access( filename, 0x04 ) ) { CreatePath( filename ); } //append the bsp file base AppendPathSeperator( filename, MAX_PATH ); ExtractFileBase( qf->origname, &filename[strlen( filename )] ); // Ridah, add extension strcat( filename, aas_extension ); // done. //append .aas strcat( filename, ".aas" ); } //end if else { strcpy( filename, qf->filename ); while ( strlen( filename ) && filename[strlen( filename ) - 1] != '.' ) { filename[strlen( filename ) - 1] = '\0'; } //end while // Ridah, add extension strcat( filename, aas_extension ); // done. strcat( filename, "aas" ); } //end else } //end of the function AASOutputFile
/* ================ LoadAlphaMap ================ */ byte *LoadAlphaMap( int *num_layers, int *alphawidth, int *alphaheight ) { int *alphamap32; byte *alphamap; const char *alphamapname; char ext[ 128 ]; int width; int height; int layers; int size; int i; assert( alphawidth ); assert( alphaheight ); assert( num_layers ); layers = atoi( ValueForKey( mapent, "layers" ) ); if ( layers < 1 ) { Error ("SetTerrainTextures: invalid value for 'layers' (%d)", layers ); } alphamapname = ValueForKey( mapent, "alphamap" ); if ( !alphamapname[ 0 ] ) { Error ("LoadAlphaMap: No alphamap specified on terrain" ); } ExtractFileExtension( alphamapname, ext); if ( !Q_stricmp( ext, "tga" ) ) { Load32BitImage( ExpandGamePath( alphamapname ), &alphamap32, &width, &height ); size = width * height; alphamap = malloc( size ); for( i = 0; i < size; i++ ) { alphamap[ i ] = ( ( alphamap32[ i ] & 0xff ) * layers ) / 256; if ( alphamap[ i ] >= layers ) { alphamap[ i ] = layers - 1; } } } else { Load256Image( ExpandGamePath( alphamapname ), &alphamap, NULL, &width, &height ); size = width * height; for( i = 0; i < size; i++ ) { if ( alphamap[ i ] >= layers ) { alphamap[ i ] = layers - 1; } } } if ( ( width < 2 ) || ( height < 2 ) ) { Error ("LoadAlphaMap: alphamap width/height must be at least 2x2." ); } *num_layers = layers; *alphawidth = width; *alphaheight = height; return alphamap; }
int BSPInfo( int count, char **fileNames ) { int i; char source[ 1024 ], ext[ 64 ]; int size; FILE *f; /* dummy check */ if( count < 1 ) { Sys_Printf( "No files to dump info for.\n"); return -1; } /* enable info mode */ infoMode = qtrue; /* walk file list */ for( i = 0; i < count; i++ ) { Sys_Printf( "---------------------------------\n" ); /* mangle filename and get size */ strcpy( source, fileNames[ i ] ); ExtractFileExtension( source, ext ); if( !Q_stricmp( ext, "map" ) ) StripExtension( source ); DefaultExtension( source, ".bsp" ); f = fopen( source, "rb" ); if( f ) { size = Q_filelength (f); fclose( f ); } else size = 0; /* load the bsp file and print lump sizes */ Sys_Printf( "%s\n", source ); LoadBSPFile( source ); PrintBSPFileSizes(); /* print sizes */ Sys_Printf( "\n" ); Sys_Printf( " total %9d\n", size ); Sys_Printf( " %9d KB\n", size / 1024 ); Sys_Printf( " %9d MB\n", size / (1024 * 1024) ); Sys_Printf( "---------------------------------\n" ); } /* return count */ return i; }
/* ============== Save256Image Will save either an lbm or pcx, depending on extension. ============== */ void Save256Image(const char *name, byte * pixels, byte * palette, int width, int height) { char ext[128]; ExtractFileExtension(name, ext); if(!Q_stricmp(ext, "lbm")) { WriteLBMfile(name, pixels, width, height, palette); } else if(!Q_stricmp(ext, "pcx")) { WritePCXfile(name, pixels, width, height, palette); } else Error("%s doesn't have a known image extension", name); }
/* ============== Load256Image Will load either an lbm or pcx, depending on extension. Any of the return pointers can be NULL if you don't want them. ============== */ void Load256Image(const char *name, byte ** pixels, byte ** palette, int *width, int *height) { char ext[128]; ExtractFileExtension(name, ext); if(!Q_stricmp(ext, "lbm")) { LoadLBM(name, pixels, palette); if(width) *width = bmhd.w; if(height) *height = bmhd.h; } else if(!Q_stricmp(ext, "pcx")) { LoadPCX(name, pixels, palette, width, height); } else if(!Q_stricmp(ext, "bmp")) { LoadBMP(name, pixels, palette, width, height); } else Error("%s doesn't have a known image extension", name); }
UnicodeString ExtractFileExt(const UnicodeString & FileName) { UnicodeString Result = ExtractFileExtension(FileName, L'.'); return Result; }
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 ); }