// // This method handles parsing a single file, it can be called // many times if a wildcard path was passed to InitParser. // Input: pszFilePath - FS path to a KeyValue file for parsing. // bWildcard - Is this file the only one to be parsed? or will more come... // bool CScriptParser::ParseFile( const char *pszFilePath ) { // Load the file into a buffer (null-terminated) char *buffer = (char*) UTIL_LoadFileForMe( pszFilePath, NULL ); if ( !buffer ) return false; // If we are encrypted, decrypt us const char *fileName = Q_UnqualifiedFileName( pszFilePath ); if( CompareExtensions( fileName, GetEncryptedEXT() ) ) UTIL_DecodeICE( (unsigned char*)buffer, Q_strlen(buffer), g_pGameRules->GetEncryptionKey() ); // Remove the extension char fileNameNoExt[64]; Q_StripExtension( fileName, fileNameNoExt, 64 ); KeyValues *pKV = new KeyValues( fileNameNoExt ); if( !pKV->LoadFromBuffer( fileNameNoExt, buffer ) ) { pKV->deleteThis(); delete [] buffer; return false; } Parse( pKV, fileNameNoExt ); pKV->deleteThis(); delete[] buffer; return true; }
bool LoadVTXFile( char const* pModelName, const studiohdr_t *pStudioHdr, CUtlBuffer& buf ) { char filename[MAX_PATH]; // construct filename Q_StripExtension( pModelName, filename, sizeof( filename ) ); strcat( filename, g_bXBox ? ".xbox.vtx" : ".dx80.vtx" ); if ( !LoadFile( filename, buf ) ) { Warning( "Error! Unable to load file \"%s\"\n", filename ); return false; } OptimizedModel::FileHeader_t* pVtxHdr = (OptimizedModel::FileHeader_t *)buf.Base(); // Check that it's valid if ( pVtxHdr->version != OPTIMIZED_MODEL_FILE_VERSION ) { Warning( "Error! Invalid VTX file version: %d, expected %d \"%s\"\n", pVtxHdr->version, OPTIMIZED_MODEL_FILE_VERSION, filename ); return false; } if ( pVtxHdr->checkSum != pStudioHdr->checksum ) { Warning( "Error! Invalid VTX file checksum: %d, expected %d \"%s\"\n", pVtxHdr->checkSum, pStudioHdr->checksum, filename ); return false; } return true; }
void EstrangedMenuScrollerLoadGame::AddSavedGames() { ClearItems(); const char *SAVE_PATH = "./SAVE/"; FileFindHandle_t fh; char path[256]; Q_snprintf(path, sizeof(path), "%s*.sav", SAVE_PATH); char const *fn = g_pFullFileSystem->FindFirstEx(path, "MOD", &fh); if (!fn) return; char save_name[64]; do { Q_StripExtension(fn, save_name, sizeof(save_name)); AddItem(new vgui::Button(NULL, "", save_name, this, save_name)); fn = g_pFullFileSystem->FindNext(fh); } while(fn); g_pFullFileSystem->FindClose(fh); }
// Precache all wave files referenced in wave or rndwave keys virtual void LevelInitPreEntity() { char mapname[ 256 ]; #if !defined( CLIENT_DLL ) StartLog(); Q_snprintf( mapname, sizeof( mapname ), "maps/%s", STRING( gpGlobals->mapname ) ); #else Q_strncpy( mapname, engine->GetLevelName(), sizeof( mapname ) ); #endif Q_FixSlashes( mapname ); Q_strlower( mapname ); // Load in any map specific overrides char scriptfile[ 512 ]; Q_StripExtension( mapname, scriptfile, sizeof( scriptfile ) ); Q_strncat( scriptfile, "_level_sounds.txt", sizeof( scriptfile ), COPY_ALL_CHARACTERS ); if ( filesystem->FileExists( scriptfile, "GAME" ) ) { soundemitterbase->AddSoundOverrides( scriptfile ); } #if !defined( CLIENT_DLL ) for ( int i=soundemitterbase->First(); i != soundemitterbase->InvalidIndex(); i=soundemitterbase->Next( i ) ) { CSoundParametersInternal *pParams = soundemitterbase->InternalGetParametersForSound( i ); if ( pParams->ShouldPreload() ) { InternalPrecacheWaves( i ); } } #endif }
void CRoomTemplate::SetFullName( const char *pFullName ) { Q_strncpy( m_FullName, pFullName, MAX_PATH ); Q_StripExtension( m_FullName, m_FullName, MAX_PATH ); Q_FixSlashes( m_FullName ); Q_ExtractFilePath( m_FullName, m_SubFolder, MAX_PATH ); Q_AppendSlash( m_SubFolder, MAX_PATH ); Q_strncpy( m_TemplateName, m_FullName + Q_strlen( m_SubFolder ), MAX_PATH ); }
//----------------------------------------------------------------------------- // Build list of all VTFs //----------------------------------------------------------------------------- void CheckVTFInDirectoryRecursive( const char *pRoot, const char *pDirectory, CUtlVector< VTFInfo_t > &vtf ) { #define BUF_SIZE 1024 char buf[BUF_SIZE]; WIN32_FIND_DATA wfd; HANDLE findHandle; sprintf( buf, "%s/%s/*.vtf", pRoot, pDirectory ); findHandle = FindFirstFile( buf, &wfd ); if ( findHandle != INVALID_HANDLE_VALUE ) { do { int i = vtf.AddToTail( ); char buf[MAX_PATH]; char buf2[MAX_PATH]; Q_snprintf( buf, MAX_PATH, "%s/%s", pDirectory, wfd.cFileName ); Q_FixSlashes( buf ); Q_StripExtension( buf, buf2, sizeof(buf2) ); Assert( !Q_strnicmp( buf2, "materials\\", 10 ) ); vtf[i].m_VTFName = &buf2[10]; vtf[i].m_bFoundInVMT = false; } while ( FindNextFile ( findHandle, &wfd ) ); FindClose ( findHandle ); } // do subdirectories sprintf( buf, "%s/%s/*.*", pRoot, pDirectory ); findHandle = FindFirstFile( buf, &wfd ); if ( findHandle != INVALID_HANDLE_VALUE ) { do { if( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { if( ( strcmp( wfd.cFileName, ".." ) == 0 ) || ( strcmp( wfd.cFileName, "." ) == 0 ) ) { continue; } char buf[MAX_PATH]; Q_snprintf( buf, MAX_PATH, "%s/%s", pDirectory, wfd.cFileName ); CheckVTFInDirectoryRecursive( pRoot, buf, vtf ); } } while ( FindNextFile ( findHandle, &wfd ) ); FindClose ( findHandle ); } #undef BUF_SIZE }
//----------------------------------------------------------------------------- // Purpose: Writes out a new .dem file based on the existing dem file with new camera positions saved into the dem file // Note: The new file is named filename_smooth.dem // Input : *filename - // smoothing - //----------------------------------------------------------------------------- void SaveSmoothingInfo( char const *filename, CSmoothingContext& smoothing ) { // Nothing to do int c = smoothing.smooth.Count(); if ( !c ) return; IBaseFileSystem *fs = g_pFileSystem; FileHandle_t infile, outfile; infile = fs->Open( filename, "rb", "GAME" ); if ( infile == FILESYSTEM_INVALID_HANDLE ) return; int filesize = fs->Size( infile ); char outfilename[ 512 ]; Q_StripExtension( filename, outfilename, sizeof( outfilename ) ); Q_strncat( outfilename, "_smooth", sizeof(outfilename), COPY_ALL_CHARACTERS ); Q_DefaultExtension( outfilename, ".dem", sizeof( outfilename ) ); outfile = fs->Open( outfilename, "wb", "GAME" ); if ( outfile == FILESYSTEM_INVALID_HANDLE ) { fs->Close( infile ); return; } int i; // The basic algorithm is to seek to each sample and "overwrite" it during copy with the new data... int lastwritepos = 0; for ( i = 0; i < c; i++ ) { demosmoothing_t *p = &smoothing.smooth[ i ]; int copyamount = p->file_offset - lastwritepos; COM_CopyFileChunk( outfile, infile, copyamount ); fs->Seek( infile, p->file_offset, FILESYSTEM_SEEK_HEAD ); // wacky hacky overwriting fs->Write( &p->info, sizeof( democmdinfo_t ), outfile ); lastwritepos = fs->Tell( outfile ); fs->Seek( infile, p->file_offset + sizeof( democmdinfo_t ), FILESYSTEM_SEEK_HEAD ); } // Copy the final bit of data, if any... int final = filesize - lastwritepos; COM_CopyFileChunk( outfile, infile, final ); fs->Close( outfile ); fs->Close( infile ); }
int GetMissionIndex( IASW_Mission_Chooser_Source *pSource, const char *szMapName ) { int nMissions = pSource->GetNumMissions( true ); for ( int i = 0; i < nMissions; i++ ) { ASW_Mission_Chooser_Mission* pMission = pSource->GetMission( i, true ); char pTemp[64]; Q_StripExtension( pMission->m_szMissionName, pTemp, sizeof(pTemp) ); if ( !Q_stricmp( pTemp, szMapName ) ) { return i; } } return -1; }
bool CampaignContainsMission( KeyValues *pCampaignKeys, const char *szMissionName ) { char szMissionStripped[256]; Q_StripExtension( szMissionName, szMissionStripped, sizeof( szMissionStripped ) ); for ( KeyValues *pMissionKey = pCampaignKeys->GetFirstSubKey(); pMissionKey; pMissionKey = pMissionKey->GetNextKey() ) { if ( !Q_stricmp( pMissionKey->GetName(), "MISSION" ) ) { const char *szMapName = pMissionKey->GetString( "MapName", "none" ); if ( !Q_stricmp( szMapName, szMissionStripped ) ) return true; } } return false; }
IFaceposerModels::CFacePoserModel::CFacePoserModel( char const *modelfile, StudioModel *model ) { m_pModel = model; m_szActorName[ 0 ] = 0; m_szShortName[ 0 ] = 0; strcpy( m_szModelFileName, modelfile ); Q_FixSlashes( m_szModelFileName ); CStudioHdr *hdr = model->GetStudioHdr(); if ( hdr ) { Q_StripExtension( hdr->pszName(), m_szShortName, sizeof( m_szShortName ) ); } m_bVisibileIn3DView = false; m_bFirstBitmapLoad = true; LoadBitmaps(); }
int main( int argc, char **argv ) { SpewOutputFunc( VTF2TGAOutputFunc ); CommandLine()->CreateCmdLine( argc, argv ); MathLib_Init( 2.2f, 2.2f, 0.0f, 1.0f, false, false, false, false ); InitDefaultFileSystem(); const char *pVTFFileName = CommandLine()->ParmValue( "-i" ); const char *pTGAFileName = CommandLine()->ParmValue( "-o" ); bool bGenerateMipLevels = CommandLine()->CheckParm( "-mip" ) != NULL; if ( !pVTFFileName ) { Usage(); } if ( !pTGAFileName ) { pTGAFileName = pVTFFileName; } char pCurrentDirectory[MAX_PATH]; if ( _getcwd( pCurrentDirectory, sizeof(pCurrentDirectory) ) == NULL ) { fprintf( stderr, "Unable to get the current directory\n" ); return -1; } Q_StripTrailingSlash( pCurrentDirectory ); char pBuf[MAX_PATH]; if ( !Q_IsAbsolutePath( pTGAFileName ) ) { Q_snprintf( pBuf, sizeof(pBuf), "%s\\%s", pCurrentDirectory, pTGAFileName ); } else { Q_strncpy( pBuf, pTGAFileName, sizeof(pBuf) ); } Q_FixSlashes( pBuf ); char pOutFileNameBase[MAX_PATH]; Q_StripExtension( pBuf, pOutFileNameBase, MAX_PATH ); char pActualVTFFileName[MAX_PATH]; Q_strncpy( pActualVTFFileName, pVTFFileName, MAX_PATH ); if ( !Q_strstr( pActualVTFFileName, ".vtf" ) ) { Q_strcat( pActualVTFFileName, ".vtf", MAX_PATH ); } FILE *vtfFp = fopen( pActualVTFFileName, "rb" ); if( !vtfFp ) { Error( "Can't open %s\n", pActualVTFFileName ); exit( -1 ); } fseek( vtfFp, 0, SEEK_END ); int srcVTFLength = ftell( vtfFp ); fseek( vtfFp, 0, SEEK_SET ); CUtlBuffer buf; buf.EnsureCapacity( srcVTFLength ); int nBytesRead = fread( buf.Base(), 1, srcVTFLength, vtfFp ); fclose( vtfFp ); buf.SeekPut( CUtlBuffer::SEEK_HEAD, nBytesRead ); IVTFTexture *pTex = CreateVTFTexture(); if (!pTex->Unserialize( buf )) { Error( "*** Error reading in .VTF file %s\n", pActualVTFFileName ); exit(-1); } Msg( "vtf width: %d\n", pTex->Width() ); Msg( "vtf height: %d\n", pTex->Height() ); Msg( "vtf numFrames: %d\n", pTex->FrameCount() ); Msg( "TEXTUREFLAGS_POINTSAMPLE=%s\n", ( pTex->Flags() & TEXTUREFLAGS_POINTSAMPLE ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_TRILINEAR=%s\n", ( pTex->Flags() & TEXTUREFLAGS_TRILINEAR ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_CLAMPS=%s\n", ( pTex->Flags() & TEXTUREFLAGS_CLAMPS ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_CLAMPT=%s\n", ( pTex->Flags() & TEXTUREFLAGS_CLAMPT ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_CLAMPU=%s\n", ( pTex->Flags() & TEXTUREFLAGS_CLAMPU ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_BORDER=%s\n", ( pTex->Flags() & TEXTUREFLAGS_BORDER ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_ANISOTROPIC=%s\n", ( pTex->Flags() & TEXTUREFLAGS_ANISOTROPIC ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_HINT_DXT5=%s\n", ( pTex->Flags() & TEXTUREFLAGS_HINT_DXT5 ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_SRGB=%s\n", ( pTex->Flags() & TEXTUREFLAGS_SRGB ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_NORMAL=%s\n", ( pTex->Flags() & TEXTUREFLAGS_NORMAL ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_NOMIP=%s\n", ( pTex->Flags() & TEXTUREFLAGS_NOMIP ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_NOLOD=%s\n", ( pTex->Flags() & TEXTUREFLAGS_NOLOD ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_ALL_MIPS=%s\n", ( pTex->Flags() & TEXTUREFLAGS_ALL_MIPS ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_PROCEDURAL=%s\n", ( pTex->Flags() & TEXTUREFLAGS_PROCEDURAL ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_ONEBITALPHA=%s\n", ( pTex->Flags() & TEXTUREFLAGS_ONEBITALPHA ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_EIGHTBITALPHA=%s\n", ( pTex->Flags() & TEXTUREFLAGS_EIGHTBITALPHA ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_ENVMAP=%s\n", ( pTex->Flags() & TEXTUREFLAGS_ENVMAP ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_RENDERTARGET=%s\n", ( pTex->Flags() & TEXTUREFLAGS_RENDERTARGET ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_DEPTHRENDERTARGET=%s\n", ( pTex->Flags() & TEXTUREFLAGS_DEPTHRENDERTARGET ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_NODEBUGOVERRIDE=%s\n", ( pTex->Flags() & TEXTUREFLAGS_NODEBUGOVERRIDE ) ? "true" : "false" ); Msg( "TEXTUREFLAGS_SINGLECOPY=%s\n", ( pTex->Flags() & TEXTUREFLAGS_SINGLECOPY ) ? "true" : "false" ); Vector vecReflectivity = pTex->Reflectivity(); Msg( "vtf reflectivity: %f %f %f\n", vecReflectivity[0], vecReflectivity[1], vecReflectivity[2] ); Msg( "transparency: " ); if( pTex->Flags() & TEXTUREFLAGS_EIGHTBITALPHA ) { Msg( "eightbitalpha\n" ); } else if( pTex->Flags() & TEXTUREFLAGS_ONEBITALPHA ) { Msg( "onebitalpha\n" ); } else { Msg( "noalpha\n" ); } ImageFormat srcFormat = pTex->Format(); Msg( "vtf format: %s\n", ImageLoader::GetName( srcFormat ) ); int iTGANameLen = Q_strlen( pOutFileNameBase ); int iFaceCount = pTex->FaceCount(); int nFrameCount = pTex->FrameCount(); bool bIsCubeMap = pTex->IsCubeMap(); int iLastMipLevel = bGenerateMipLevels ? pTex->MipCount() - 1 : 0; for( int iFrame = 0; iFrame < nFrameCount; ++iFrame ) { for ( int iMipLevel = 0; iMipLevel <= iLastMipLevel; ++iMipLevel ) { int iWidth, iHeight, iDepth; pTex->ComputeMipLevelDimensions( iMipLevel, &iWidth, &iHeight, &iDepth ); for (int iCubeFace = 0; iCubeFace < iFaceCount; ++iCubeFace) { for ( int z = 0; z < iDepth; ++z ) { // Construct output filename char *pTempNameBuf = (char *)stackalloc( iTGANameLen + 13 ); Q_strncpy( pTempNameBuf, pOutFileNameBase, iTGANameLen + 1 ); char *pExt = Q_strrchr( pTempNameBuf, '.' ); if ( pExt ) { pExt = 0; } if ( bIsCubeMap ) { Assert( pTex->Depth() == 1 ); // shouldn't this be 1 instead of 0? static const char *pCubeFaceName[7] = { "rt", "lf", "bk", "ft", "up", "dn", "sph" }; Q_strcat( pTempNameBuf, pCubeFaceName[iCubeFace], iTGANameLen + 13 ); } if ( nFrameCount > 1 ) { char pTemp[4]; Q_snprintf( pTemp, 4, "%03d", iFrame ); Q_strcat( pTempNameBuf, pTemp, iTGANameLen + 13 ); } if ( iLastMipLevel != 0 ) { char pTemp[8]; Q_snprintf( pTemp, 8, "_mip%d", iMipLevel ); Q_strcat( pTempNameBuf, pTemp, iTGANameLen + 13 ); } if ( pTex->Depth() > 1 ) { char pTemp[6]; Q_snprintf( pTemp, 6, "_z%03d", z ); Q_strcat( pTempNameBuf, pTemp, iTGANameLen + 13 ); } if( srcFormat == IMAGE_FORMAT_RGBA16161616F ) { Q_strcat( pTempNameBuf, ".pfm", iTGANameLen + 13 ); } else { Q_strcat( pTempNameBuf, ".tga", iTGANameLen + 13 ); } unsigned char *pSrcImage = pTex->ImageData( iFrame, iCubeFace, iMipLevel, 0, 0, z ); ImageFormat dstFormat; if( srcFormat == IMAGE_FORMAT_RGBA16161616F ) { dstFormat = IMAGE_FORMAT_RGB323232F; } else { if( ImageLoader::IsTransparent( srcFormat ) || (srcFormat == IMAGE_FORMAT_ATI1N ) || (srcFormat == IMAGE_FORMAT_ATI2N )) { dstFormat = IMAGE_FORMAT_BGRA8888; } else { dstFormat = IMAGE_FORMAT_BGR888; } } // dstFormat = IMAGE_FORMAT_RGBA8888; // dstFormat = IMAGE_FORMAT_RGB888; // dstFormat = IMAGE_FORMAT_BGRA8888; // dstFormat = IMAGE_FORMAT_BGR888; // dstFormat = IMAGE_FORMAT_BGRA5551; // dstFormat = IMAGE_FORMAT_BGR565; // dstFormat = IMAGE_FORMAT_BGRA4444; // printf( "dstFormat: %s\n", ImageLoader::GetName( dstFormat ) ); unsigned char *pDstImage = new unsigned char[ImageLoader::GetMemRequired( iWidth, iHeight, 1, dstFormat, false )]; if( !ImageLoader::ConvertImageFormat( pSrcImage, srcFormat, pDstImage, dstFormat, iWidth, iHeight, 0, 0 ) ) { Error( "Error converting from %s to %s\n", ImageLoader::GetName( srcFormat ), ImageLoader::GetName( dstFormat ) ); exit( -1 ); } if( dstFormat != IMAGE_FORMAT_RGB323232F ) { if( ImageLoader::IsTransparent( dstFormat ) && ( dstFormat != IMAGE_FORMAT_RGBA8888 ) ) { unsigned char *tmpImage = pDstImage; pDstImage = new unsigned char[ImageLoader::GetMemRequired( iWidth, iHeight, 1, IMAGE_FORMAT_RGBA8888, false )]; if( !ImageLoader::ConvertImageFormat( tmpImage, dstFormat, pDstImage, IMAGE_FORMAT_RGBA8888, iWidth, iHeight, 0, 0 ) ) { Error( "Error converting from %s to %s\n", ImageLoader::GetName( dstFormat ), ImageLoader::GetName( IMAGE_FORMAT_RGBA8888 ) ); } dstFormat = IMAGE_FORMAT_RGBA8888; } else if( !ImageLoader::IsTransparent( dstFormat ) && ( dstFormat != IMAGE_FORMAT_RGB888 ) ) { unsigned char *tmpImage = pDstImage; pDstImage = new unsigned char[ImageLoader::GetMemRequired( iWidth, iHeight, 1, IMAGE_FORMAT_RGB888, false )]; if( !ImageLoader::ConvertImageFormat( tmpImage, dstFormat, pDstImage, IMAGE_FORMAT_RGB888, iWidth, iHeight, 0, 0 ) ) { Error( "Error converting from %s to %s\n", ImageLoader::GetName( dstFormat ), ImageLoader::GetName( IMAGE_FORMAT_RGB888 ) ); } dstFormat = IMAGE_FORMAT_RGB888; } CUtlBuffer outBuffer; TGAWriter::WriteToBuffer( pDstImage, outBuffer, iWidth, iHeight, dstFormat, dstFormat ); if ( !g_pFullFileSystem->WriteFile( pTempNameBuf, NULL, outBuffer ) ) { fprintf( stderr, "unable to write %s\n", pTempNameBuf ); } } else { PFMWrite( ( float * )pDstImage, pTempNameBuf, iWidth, iHeight ); } } } } } // leak leak leak leak leak, leak leak, leak leak (Blue Danube) return 0; }
void SpewPerfStats( studiohdr_t *pStudioHdr, const char *pFilename, unsigned int flags ) { char fileName[260]; vertexFileHeader_t *pNewVvdHdr; vertexFileHeader_t *pVvdHdr = 0; OptimizedModel::FileHeader_t *pVtxHdr = 0; studiohwdata_t studioHWData; int vvdSize = 0; const char *prefix[] = {".dx80.vtx", ".dx90.vtx", ".sw.vtx"}; s_pSavedSpewFunc = NULL; if( !( flags & SPEWPERFSTATS_SHOWSTUDIORENDERWARNINGS ) ) { s_pSavedSpewFunc = GetSpewOutputFunc(); SpewOutputFunc( NullSpewOutputFunc ); } // no stats on these if (!pStudioHdr->numbodyparts) return; // Need to update the render config to spew perf stats. UpdateStudioRenderConfig(); // persist the vvd data Q_StripExtension( pFilename, fileName, sizeof( fileName ) ); strcat( fileName, ".vvd" ); if (FileExists( fileName )) { vvdSize = LoadFile( fileName, (void**)&pVvdHdr ); } else { MdlError( "Could not open '%s'\n", fileName ); } // validate header if (pVvdHdr->id != MODEL_VERTEX_FILE_ID) { MdlError( "Bad id for '%s' (got %d expected %d)\n", fileName, pVvdHdr->id, MODEL_VERTEX_FILE_ID); } if (pVvdHdr->version != MODEL_VERTEX_FILE_VERSION) { MdlError( "Bad version for '%s' (got %d expected %d)\n", fileName, pVvdHdr->version, MODEL_VERTEX_FILE_VERSION); } if (pVvdHdr->checksum != pStudioHdr->checksum) { MdlError( "Bad checksum for '%s' (got %d expected %d)\n", fileName, pVvdHdr->checksum, pStudioHdr->checksum); } if (pVvdHdr->numFixups) { // need to perform mesh relocation fixups // allocate a new copy pNewVvdHdr = (vertexFileHeader_t *)malloc( vvdSize ); if (!pNewVvdHdr) { MdlError( "Error allocating %d bytes for Vertex File '%s'\n", vvdSize, fileName ); } Studio_LoadVertexes( pVvdHdr, pNewVvdHdr, 0, true ); // discard original free( pVvdHdr ); pVvdHdr = pNewVvdHdr; } // iterate all ???.vtx files for (int j=0; j<sizeof(prefix)/sizeof(prefix[0]); j++) { // make vtx filename Q_StripExtension( pFilename, fileName, sizeof( fileName ) ); strcat( fileName, prefix[j] ); // persist the vtx data if (FileExists(fileName)) { LoadFile( fileName, (void**)&pVtxHdr ); } else { MdlError( "Could not open '%s'\n", fileName ); } // validate header if (pVtxHdr->version != OPTIMIZED_MODEL_FILE_VERSION) { MdlError( "Bad version for '%s' (got %d expected %d)\n", fileName, pVtxHdr->version, OPTIMIZED_MODEL_FILE_VERSION ); } if (pVtxHdr->checkSum != pStudioHdr->checksum) { MdlError( "Bad checksum for '%s' (got %d expected %d)\n", fileName, pVtxHdr->checkSum, pStudioHdr->checksum ); } // studio render will request these through cache interface pStudioHdr->pVertexBase = (void *)pVvdHdr; pStudioHdr->pIndexBase = (void *)pVtxHdr; g_pStudioRender->LoadModel( pStudioHdr, pVtxHdr, &studioHWData ); if( flags & SPEWPERFSTATS_SHOWPERF ) { if( flags & SPEWPERFSTATS_SPREADSHEET ) { printf( "%s,%s,%d,", fileName, prefix[j], studioHWData.m_NumLODs - studioHWData.m_RootLOD ); } else { printf( "\n" ); printf( "Performance Stats: %s\n", fileName ); printf( "------------------\n" ); } } int i; if( flags & SPEWPERFSTATS_SHOWPERF ) { for( i = studioHWData.m_RootLOD; i < studioHWData.m_NumLODs; i++ ) { DrawModelInfo_t drawModelInfo; drawModelInfo.m_Skin = 0; drawModelInfo.m_Body = 0; drawModelInfo.m_HitboxSet = 0; drawModelInfo.m_pClientEntity = 0; drawModelInfo.m_pColorMeshes = 0; drawModelInfo.m_pStudioHdr = pStudioHdr; drawModelInfo.m_pHardwareData = &studioHWData; CUtlBuffer statsOutput( 0, 0, CUtlBuffer::TEXT_BUFFER ); if( !( flags & SPEWPERFSTATS_SPREADSHEET ) ) { printf( "LOD:%d\n", i ); } drawModelInfo.m_Lod = i; DrawModelResults_t results; g_pStudioRender->GetPerfStats( &results, drawModelInfo, &statsOutput ); if( flags & SPEWPERFSTATS_SPREADSHEET ) { printf( "%d,%d,%d,", results.m_ActualTriCount, results.m_NumBatches, results.m_NumMaterials ); } else { printf( " actual tris:%d\n", ( int )results.m_ActualTriCount ); printf( " texture memory bytes: %d (only valid in a rendering app)\n", ( int )results.m_TextureMemoryBytes ); printf( ( char * )statsOutput.Base() ); } } if( flags & SPEWPERFSTATS_SPREADSHEET ) { printf( "\n" ); } } g_pStudioRender->UnloadModel( &studioHWData ); free(pVtxHdr); } if (pVvdHdr) free(pVvdHdr); if( !( flags & SPEWPERFSTATS_SHOWSTUDIORENDERWARNINGS ) ) { SpewOutputFunc( s_pSavedSpewFunc ); } }
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; }
bool CEngineSprite::Init( const char *pName ) { m_VideoMaterial = NULL; for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[ i ] = NULL; } m_width = m_height = m_numFrames = 1; Assert( g_pVideo != NULL ); if ( g_pVideo != NULL && g_pVideo->LocateVideoSystemForPlayingFile( pName ) != VideoSystem::NONE ) { m_VideoMaterial = g_pVideo->CreateVideoMaterial( pName, pName, "GAME", VideoPlaybackFlags::DEFAULT_MATERIAL_OPTIONS, VideoSystem::DETERMINE_FROM_FILE_EXTENSION, false ); if ( m_VideoMaterial == NULL ) return false; IMaterial *pMaterial = m_VideoMaterial->GetMaterial(); m_VideoMaterial->GetVideoImageSize( &m_width, &m_height ); m_numFrames = m_VideoMaterial->GetFrameCount(); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = pMaterial; pMaterial->IncrementReferenceCount(); } } else { char pTemp[MAX_PATH]; char pMaterialName[MAX_PATH]; char pMaterialPath[MAX_PATH]; Q_StripExtension( pName, pTemp, sizeof(pTemp) ); Q_strlower( pTemp ); Q_FixSlashes( pTemp, '/' ); // Check to see if this is a UNC-specified material name bool bIsUNC = pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/'; if ( !bIsUNC ) { Q_strncpy( pMaterialName, "materials/", sizeof(pMaterialName) ); Q_strncat( pMaterialName, pTemp, sizeof(pMaterialName), COPY_ALL_CHARACTERS ); } else { Q_strncpy( pMaterialName, pTemp, sizeof(pMaterialName) ); } Q_strncpy( pMaterialPath, pMaterialName, sizeof(pMaterialPath) ); Q_SetExtension( pMaterialPath, ".vmt", sizeof(pMaterialPath) ); KeyValues *kv = new KeyValues( "vmt" ); if ( !kv->LoadFromFile( g_pFullFileSystem, pMaterialPath, "GAME" ) ) { Warning( "Unable to load sprite material %s!\n", pMaterialPath ); return false; } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) { m_material[i] = NULL; continue; } Q_snprintf( pMaterialPath, sizeof(pMaterialPath), "%s_rendermode_%d", pMaterialName, i ); KeyValues *pMaterialKV = kv->MakeCopy(); pMaterialKV->SetInt( "$spriteRenderMode", i ); m_material[i] = g_pMaterialSystem->FindProceduralMaterial( pMaterialPath, TEXTURE_GROUP_CLIENT_EFFECTS, pMaterialKV ); m_material[ i ]->IncrementReferenceCount(); } kv->deleteThis(); m_width = m_material[0]->GetMappingWidth(); m_height = m_material[0]->GetMappingHeight(); m_numFrames = m_material[0]->GetNumAnimationFrames(); } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) continue; if ( !m_material[i] ) return false; } IMaterialVar *orientationVar = m_material[0]->FindVarFast( "$spriteorientation", &spriteOrientationCache ); m_orientation = orientationVar ? orientationVar->GetIntValue() : C_SpriteRenderer::SPR_VP_PARALLEL_UPRIGHT; IMaterialVar *originVar = m_material[0]->FindVarFast( "$spriteorigin", &spriteOriginCache ); Vector origin, originVarValue; if( !originVar || ( originVar->GetType() != MATERIAL_VAR_TYPE_VECTOR ) ) { origin[0] = -m_width * 0.5f; origin[1] = m_height * 0.5f; } else { originVar->GetVecValue( &originVarValue[0], 3 ); origin[0] = -m_width * originVarValue[0]; origin[1] = m_height * originVarValue[1]; } up = origin[1]; down = origin[1] - m_height; left = origin[0]; right = m_width + origin[0]; return true; }
int main( int argc, char **argv ) { if( argc < 2 ) { Usage(); } MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f ); InitDefaultFileSystem(); int i = 1; while( i < argc ) { if( stricmp( argv[i], "-quiet" ) == 0 ) { i++; g_Quiet = true; g_NoPause = true; // no point in pausing if we aren't going to print anything out. } if( stricmp( argv[i], "-nopause" ) == 0 ) { i++; g_NoPause = true; } else { break; } } char pCurrentDirectory[MAX_PATH]; if ( _getcwd( pCurrentDirectory, sizeof(pCurrentDirectory) ) == NULL ) { fprintf( stderr, "Unable to get the current directory\n" ); return -1; } Q_FixSlashes( pCurrentDirectory ); Q_StripTrailingSlash( pCurrentDirectory ); for( ; i < argc; i++ ) { static char normalFileNameWithoutExtension[1024]; char *pFileName; if ( !Q_IsAbsolutePath( argv[i] ) ) { Q_snprintf( normalFileNameWithoutExtension, sizeof(normalFileNameWithoutExtension), "%s\\%s", pCurrentDirectory, argv[i] ); pFileName = normalFileNameWithoutExtension; } else { pFileName = argv[i]; } if( !g_Quiet ) { printf( "file: %s\n", pFileName ); } float bumpScale = -1.0f; int startFrame = -1; int endFrame = -1; LoadConfigFile( pFileName, &bumpScale, &startFrame, &endFrame ); if( bumpScale == -1.0f ) { fprintf( stderr, "Must specify \"bumpscale\" in config file\n" ); Pause(); continue; } if( ( startFrame == -1 && endFrame != -1 ) || ( startFrame != -1 && endFrame == -1 ) ) { fprintf( stderr, "ERROR: If you use startframe, you must use endframe, and vice versa.\n" ); Pause(); continue; } if( !g_Quiet ) { printf( "\tbumpscale: %f\n", bumpScale ); } Q_StripExtension( pFileName, normalFileNameWithoutExtension, sizeof( normalFileNameWithoutExtension ) ); ProcessFiles( normalFileNameWithoutExtension, startFrame, endFrame, bumpScale ); } return 0; }
void IFaceposerModels::CFacePoserModel::ReconcileAnimationBitmaps() { // iterate files in directory and see if each checksum is valid and if not delete the .bmp char path[ 512 ]; Q_snprintf( path, sizeof( path ), "expressions/%s/animation/*.bmp", GetShortModelName() ); FileFindHandle_t hFindFile; char const *fn = filesystem->FindFirstEx( path, "MOD", &hFindFile ); g_pProgressDialog->Start( CFmtStr( "%s - Reconcile Animation Thumbnails", GetShortModelName() ), "", true ); CUtlVector< CUtlString > workList; if ( fn ) { while ( fn ) { // Don't do anything with directories if ( !filesystem->FindIsDirectory( hFindFile ) ) { CUtlString s = fn; workList.AddToTail( s ); } fn = filesystem->FindNext( hFindFile ); } filesystem->FindClose( hFindFile ); } CUtlRBTree< CRC32_t > tree( 0, 0, DefLessFunc( CRC32_t ) ); BuildValidChecksums( tree ); for ( int i = 0 ; i < workList.Count(); ++i ) { char testname[ 256 ]; Q_StripExtension( workList[ i ].String(), testname, sizeof( testname ) ); g_pProgressDialog->UpdateText( "%s", testname ); g_pProgressDialog->Update( (float)i / (float)workList.Count() ); CRC32_t check; Q_hextobinary( testname, Q_strlen( testname ), (byte *)&check, sizeof( check ) ); if ( tree.Find( check ) == tree.InvalidIndex() ) { Q_snprintf( testname, sizeof( testname ), "expressions/%s/animation/%s", GetShortModelName(), fn ); char fullpath[ 512 ]; filesystem->RelativePathToFullPath( testname, "MOD", fullpath, sizeof( fullpath ) ); // Delete it Con_ErrorPrintf( "Removing unused bitmap file %s\n", fullpath ); _unlink( fullpath ); } if ( g_pProgressDialog->IsCancelled() ) { Msg( "Cancelled\n" ); break; } } g_pProgressDialog->Finish(); }
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; }
bool CSmokeStack::KeyValue( const char *szKeyName, const char *szValue ) { if( stricmp( szKeyName, "Wind" ) == 0 ) { sscanf( szValue, "%f %f %f", &m_vWind.GetForModify().x, &m_vWind.GetForModify().y, &m_vWind.GetForModify().z ); return true; } else if( stricmp( szKeyName, "WindAngle" ) == 0 ) { m_WindAngle = atoi( szValue ); RecalcWindVector(); return true; } else if( stricmp( szKeyName, "WindSpeed" ) == 0 ) { m_WindSpeed = atoi( szValue ); RecalcWindVector(); return true; } else if ( stricmp( szKeyName, "SmokeMaterial" ) == 0 ) { // Make sure we have a vmt extension. if ( Q_stristr( szValue, ".vmt" ) ) { m_strMaterialModel = AllocPooledString( szValue ); } else { char str[512]; Q_snprintf( str, sizeof( str ), "%s.vmt", szValue ); m_strMaterialModel = AllocPooledString( str ); } const char *pName = STRING( m_strMaterialModel ); char szStrippedName[512]; m_iMaterialModel = PrecacheModel( pName ); Q_StripExtension( pName, szStrippedName, Q_strlen(pName)+1 ); int iLength = Q_strlen( szStrippedName ); szStrippedName[iLength-1] = '\0'; int iCount = 1; char str[512]; Q_snprintf( str, sizeof( str ), "%s%d.vmt", szStrippedName, iCount ); while ( filesystem->FileExists( UTIL_VarArgs( "materials/%s", str ) ) ) { PrecacheModel( str ); iCount++; Q_snprintf( str, sizeof( str ), "%s%d.vmt", szStrippedName, iCount ); } return true; } else { return BaseClass::KeyValue( szKeyName, szValue ); } }
//-------------------------------------------------------------------------------------------------------------- void DownloadCache::PersistToDisk( const RequestContext *rc ) { if ( !m_cache ) return; if ( rc && rc->data && rc->nBytesTotal ) { char gamePath[MAX_PATH]; if ( rc->bIsBZ2 ) { Q_StripExtension( rc->gamePath, gamePath, sizeof( gamePath ) ); } else { Q_strncpy( gamePath, rc->gamePath, sizeof( gamePath ) ); } if ( !g_pFileSystem->FileExists( gamePath ) ) { // Create the subdirs char * tmpDir = CloneString( gamePath ); COM_CreatePath( tmpDir ); delete[] tmpDir; bool success = false; if ( rc->bIsBZ2 ) { success = DecompressBZipToDisk( gamePath, rc->gamePath, reinterpret_cast< char * >(rc->data), rc->nBytesTotal ); } else { FileHandle_t fp = g_pFileSystem->Open( gamePath, "wb" ); if ( fp ) { g_pFileSystem->Write( rc->data, rc->nBytesTotal, fp ); g_pFileSystem->Close( fp ); success = true; } } if ( success ) { // write succeeded. remove any old data from the cache. char cachePath[_MAX_PATH]; GetCacheFilename( rc, cachePath ); if ( cachePath[0] ) { g_pFileSystem->RemoveFile( cachePath, NULL ); } BuildKeyNames( rc->gamePath ); KeyValues *kv = m_cache->FindKey( m_cachefileKey, false ); if ( kv ) { m_cache->RemoveSubKey( kv ); } kv = m_cache->FindKey( m_timestampKey, false ); if ( kv ) { m_cache->RemoveSubKey( kv ); } } } } m_cache->SaveToFile( g_pFileSystem, CacheFilename, NULL ); }
//----------------------------------------------------------------------------- // Saves/loads from file //----------------------------------------------------------------------------- bool CVcdBlockDoc::LoadFromFile( const char *pFileName ) { Assert( !m_hVMFRoot.Get() ); Assert( !m_hEditRoot.Get() ); CAppDisableUndoScopeGuard guard( "CVcdBlockDoc::LoadFromFile", NOTIFY_CHANGE_OTHER ); SetDirty( false ); if ( !pFileName[0] ) return false; // Construct VMF file name from the BSP const char *pGame = Q_stristr( pFileName, "\\game\\" ); if ( !pGame ) { pGame = Q_stristr( pFileName, "\\content\\" ); if ( !pGame ) return false; } // Compute the map name const char *pMaps = Q_stristr( pFileName, "\\maps\\" ); if ( !pMaps ) return false; // Build map name char mapname[ 256 ]; Q_StripExtension( pFileName, mapname, sizeof(mapname) ); char *pszFileName = (char*)Q_UnqualifiedFileName(mapname); int nLen = (int)( (size_t)pGame - (size_t)pFileName ) + 1; Q_strncpy( m_pVMFFileName, pFileName, nLen ); Q_strncat( m_pVMFFileName, "\\content\\", sizeof(m_pVMFFileName) ); Q_strncat( m_pVMFFileName, pGame + 6, sizeof(m_pVMFFileName) ); Q_SetExtension( m_pVMFFileName, ".vmf", sizeof(m_pVMFFileName) ); // Make sure new entities start with ids at 0 CDmeVMFEntity::SetNextEntityId( 0 ); // Build the Edit file name Q_StripExtension( m_pVMFFileName, m_pEditFileName, sizeof(m_pEditFileName) ); Q_strncat( m_pEditFileName, ".vle", sizeof( m_pEditFileName ) ); // Store the BSP file name Q_strncpy( m_pBSPFileName, pFileName, sizeof( m_pBSPFileName ) ); // Set the txt file name. // If we loaded a .bsp, clear out what we're doing // load the Edits file into memory, assign it as our "root" CDmElement *pEdit = NULL; if ( !V_stricmp( Q_GetFileExtension( pFileName ), "vle" ) ) { if ( g_pDataModel->RestoreFromFile( m_pEditFileName, NULL, "vmf", &pEdit ) != DMFILEID_INVALID ) { // If we successfully read the file in, ask it for the max hammer id //int nMaxHammerId = pVMF->GetAttributeValue<int>( "maxHammerId" ); //CDmeVMFEntity::SetNextEntityId( nMaxHammerId + 1 ); m_hEditRoot = pEdit; SetDirty( false ); } } if (pEdit == NULL) { if ( g_pFileSystem->FileExists( m_pEditFileName ) ) { char pBuf[1024]; Q_snprintf( pBuf, sizeof(pBuf), "File %s already exists!\n", m_pEditFileName ); m_pEditFileName[0] = 0; vgui::MessageBox *pMessageBox = new vgui::MessageBox( "Unable to overwrite file!\n", pBuf, g_pVcdBlockTool ); pMessageBox->DoModal( ); return false; } DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( m_pEditFileName ); m_hEditRoot = CreateElement<CDmElement>( "root", fileid ); m_hEditRoot->AddAttribute( "entities", AT_ELEMENT_ARRAY ); g_pDataModel->SetFileRoot( fileid, m_hEditRoot ); SetDirty( true ); } guard.Release(); // tell the engine to actually load the map char cmd[ 256 ]; Q_snprintf( cmd, sizeof( cmd ), "disconnect; map %s\n", pszFileName ); enginetools->Command( cmd ); enginetools->Execute( ); return true; }
//----------------------------------------------------------------------------- // Load the VMF file, merge in all the edits, write it back out //----------------------------------------------------------------------------- bool CVcdBlockDoc::CopyEditsToVMF( ) { const CDmrElementArray<CDmElement> entityList = GetEntityList(); CDmElement *pVMF = NULL; DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( m_pVMFFileName ); if ( g_pDataModel->RestoreFromFile( m_pVMFFileName, NULL, "vmf", &pVMF ) == DMFILEID_INVALID ) { // needs some kind of error message return false; } CDmrElementArray<CDmElement> vmfEntities( pVMF, "entities" ); int nVMFCount = vmfEntities.Count(); for (int i = 0; i < nVMFCount; i++) { CDmElement *pVMFEntity = vmfEntities[i]; char classname[256]; pVMFEntity->GetValueAsString( "classname", classname, sizeof( classname ) ); if ( Q_stricmp( "info_target", classname ) ) continue; int nHammerID = atoi( pVMFEntity->GetName() ); // find a match. int nCount = entityList.Count(); for (int j = 0; j < nCount; j++) { CDmeVMFEntity *pEntity = CastElement<CDmeVMFEntity>( entityList[j] ); if ( pEntity->IsDirty() && pEntity->GetEntityId() == nHammerID) { char text[256]; pEntity->GetValueAsString( "targetname", text, sizeof( text ) ); pVMFEntity->SetValueFromString( "targetname", text ); pEntity->GetValueAsString( "origin", text, sizeof( text ) ); pVMFEntity->SetValueFromString( "origin", text ); pEntity->GetValueAsString( "angles", text, sizeof( text ) ); pVMFEntity->SetValueFromString( "angles", text ); pEntity->MarkDirty(false); } } } // add the new entities int nCount = entityList.Count(); for (int j = 0; j < nCount; j++) { CDmeVMFEntity *pEntity = CastElement<CDmeVMFEntity>( entityList[j] ); if ( pEntity->IsDirty()) { CDmElement *pVMFEntity = CreateElement<CDmElement>( pEntity->GetName(), fileid ); char text[256]; pEntity->GetValueAsString( "classname", text, sizeof( text ) ); pVMFEntity->SetValue( "classname", text ); pEntity->GetValueAsString( "targetname", text, sizeof( text ) ); pVMFEntity->SetValue( "targetname", text ); pEntity->GetValueAsString( "origin", text, sizeof( text ) ); pVMFEntity->SetValue( "origin", text ); pEntity->GetValueAsString( "angles", text, sizeof( text ) ); pVMFEntity->SetValue( "angles", text ); vmfEntities.AddToTail( pVMFEntity ); pEntity->MarkDirty(false); } } // currently, don't overwrite the vmf, not sure if this is serializing correctly yet char tmpname[ 256 ]; Q_StripExtension( m_pVMFFileName, tmpname, sizeof(tmpname) ); Q_SetExtension( tmpname, ".vme", sizeof(tmpname) ); if (!g_pDataModel->SaveToFile( tmpname, NULL, "keyvalues", "vmf", pVMF )) { // needs some kind of error message return false; } /* // If we successfully read the file in, ask it for the max hammer id int nMaxHammerId = pVMF->GetAttributeValue<int>( "maxHammerId" ); CDmeVMFEntity::SetNextEntityId( nMaxHammerId + 1 ); m_hVMFRoot = pVMF; */ return true; }
void WritePHXFile( const char *pName, const phyfile_t &file ) { if ( file.header.size != sizeof(file.header) || file.collide.solidCount <= 0 ) return; CUtlBuffer out; char outName[1024]; Q_snprintf( outName, sizeof(outName), "%s", pName ); Q_SetExtension( outName, ".phx", sizeof(outName) ); simplifyparams_t params; params.Defaults(); params.tolerance = (file.collide.solidCount > 1) ? 4.0f : 2.0f; // single solids constraint to AABB for placement help params.addAABBToSimplifiedHull = (file.collide.solidCount == 1) ? true : false; params.mergeConvexElements = true; params.mergeConvexTolerance = 0.025f; Q_FixSlashes(outName); Q_strlower(outName); char *pSearch = Q_strstr( outName,"models\\" ); if ( pSearch ) { char keyname[1024]; pSearch += strlen("models\\"); Q_StripExtension( pSearch, keyname, sizeof(keyname) ); OverrideDefaultsForModel( keyname, params ); } out.Put( &file.header, sizeof(file.header) ); int outSize = 0; bool bStoreSolidNames = file.collide.solidCount > 1 ? true : false; bStoreSolidNames = bStoreSolidNames || HasMultipleBones(outName); vcollide_t *pNewCollide = ConvertVCollideToPHX( &file.collide, params, &outSize, false, bStoreSolidNames); g_TotalOut += file.fileSize; for ( int i = 0; i < pNewCollide->solidCount; i++ ) { int collideSize = physcollision->CollideSize( pNewCollide->solids[i] ); out.PutInt( collideSize ); char *pMem = new char[collideSize]; physcollision->CollideWrite( pMem, pNewCollide->solids[i] ); out.Put( pMem, collideSize ); delete[] pMem; } if (!g_bQuiet) { Msg("%s Compressed %d (%d text) to %d (%d text)\n", outName, file.fileSize, file.collide.descSize, out.TellPut(), pNewCollide->descSize ); } out.Put( pNewCollide->pKeyValues, pNewCollide->descSize ); g_TotalCompress += out.TellPut(); #if 0 //Msg("OLD:\n-----------------------------------\n%s\n", file.collide.pKeyValues ); CPackedPhysicsDescription *pPacked = physcollision->CreatePackedDesc( pNewCollide->pKeyValues, pNewCollide->descSize ); Msg("NEW:\n-----------------------------------\n" ); for ( int i = 0; i < pPacked->m_solidCount; i++ ) { solid_t solid; pPacked->GetSolid( &solid, i ); Msg("index %d\n", solid.index ); Msg("name %s\n", solid.name ); Msg("mass %.2f\n", solid.params.mass ); Msg("surfaceprop %s\n", solid.surfaceprop); Msg("damping %.2f\n", solid.params.damping ); Msg("rotdamping %.2f\n", solid.params.rotdamping ); Msg("drag %.2f\n", solid.params.dragCoefficient ); Msg("inertia %.2f\n", solid.params.inertia ); Msg("volume %.2f\n", solid.params.volume ); } #endif DestroyPHX( pNewCollide ); if ( !g_pFullFileSystem->WriteFile( outName, NULL, out ) ) Warning("Can't write file: %s\n", outName ); }
bool CEngineSprite::Init( const char *pName ) { m_hAVIMaterial = AVIMATERIAL_INVALID; m_hBIKMaterial = BIKMATERIAL_INVALID; m_width = m_height = m_numFrames = 1; const char *pExt = Q_GetFileExtension( pName ); bool bIsAVI = pExt && !Q_stricmp( pExt, "avi" ); #if !defined( _X360 ) || defined( BINK_ENABLED_FOR_X360 ) bool bIsBIK = pExt && !Q_stricmp( pExt, "bik" ); #endif if ( bIsAVI && IsPC() ) { m_hAVIMaterial = avi->CreateAVIMaterial( pName, pName, "GAME" ); if ( m_hAVIMaterial == AVIMATERIAL_INVALID ) return false; IMaterial *pMaterial = avi->GetMaterial( m_hAVIMaterial ); avi->GetFrameSize( m_hAVIMaterial, &m_width, &m_height ); m_numFrames = avi->GetFrameCount( m_hAVIMaterial ); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = pMaterial; pMaterial->IncrementReferenceCount(); } } #if !defined( _X360 ) || defined( BINK_ENABLED_FOR_X360 ) else if ( bIsBIK ) { m_hBIKMaterial = bik->CreateMaterial( pName, pName, "GAME" ); if ( m_hBIKMaterial == BIKMATERIAL_INVALID ) return false; IMaterial *pMaterial = bik->GetMaterial( m_hBIKMaterial ); bik->GetFrameSize( m_hBIKMaterial, &m_width, &m_height ); m_numFrames = bik->GetFrameCount( m_hBIKMaterial ); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = pMaterial; pMaterial->IncrementReferenceCount(); } } #endif else { char pTemp[MAX_PATH]; char pMaterialName[MAX_PATH]; char pMaterialPath[MAX_PATH]; Q_StripExtension( pName, pTemp, sizeof(pTemp) ); Q_strlower( pTemp ); Q_FixSlashes( pTemp, '/' ); // Check to see if this is a UNC-specified material name bool bIsUNC = pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/'; if ( !bIsUNC ) { Q_strncpy( pMaterialName, "materials/", sizeof(pMaterialName) ); Q_strncat( pMaterialName, pTemp, sizeof(pMaterialName), COPY_ALL_CHARACTERS ); } else { Q_strncpy( pMaterialName, pTemp, sizeof(pMaterialName) ); } Q_strncpy( pMaterialPath, pMaterialName, sizeof(pMaterialPath) ); Q_SetExtension( pMaterialPath, ".vmt", sizeof(pMaterialPath) ); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = NULL; } KeyValues *kv = new KeyValues( "vmt" ); if ( !kv->LoadFromFile( g_pFullFileSystem, pMaterialPath, "GAME" ) ) { Warning( "Unable to load sprite material %s!\n", pMaterialPath ); return false; } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) { continue; } // strip possible materials/ Q_snprintf( pMaterialPath, sizeof(pMaterialPath), "%s_rendermode_%d", pMaterialName + ( bIsUNC ? 0 : 10 ), i ); KeyValues *pMaterialKV = kv->MakeCopy(); pMaterialKV->SetInt( "$spriteRenderMode", i ); m_material[i] = g_pMaterialSystem->FindProceduralMaterial( pMaterialPath, TEXTURE_GROUP_CLIENT_EFFECTS, pMaterialKV ); m_material[i]->IncrementReferenceCount(); } kv->deleteThis(); m_width = m_material[0]->GetMappingWidth(); m_height = m_material[0]->GetMappingHeight(); m_numFrames = m_material[0]->GetNumAnimationFrames(); } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) continue; if ( !m_material[i] ) return false; } IMaterialVar *orientationVar = m_material[0]->FindVarFast( "$spriteorientation", &spriteOrientationCache ); m_orientation = orientationVar ? orientationVar->GetIntValue() : C_SpriteRenderer::SPR_VP_PARALLEL_UPRIGHT; IMaterialVar *originVar = m_material[0]->FindVarFast( "$spriteorigin", &spriteOriginCache ); Vector origin, originVarValue; if( !originVar || ( originVar->GetType() != MATERIAL_VAR_TYPE_VECTOR ) ) { origin[0] = -m_width * 0.5f; origin[1] = m_height * 0.5f; } else { originVar->GetVecValue( &originVarValue[0], 3 ); origin[0] = -m_width * originVarValue[0]; origin[1] = m_height * originVarValue[1]; } up = origin[1]; down = origin[1] - m_height; left = origin[0]; right = m_width + origin[0]; return true; }
void SpewPerfStats( studiohdr_t *pStudioHdr, const char *pFilename ) { char fileName[260]; vertexFileHeader_t *pNewVvdHdr; vertexFileHeader_t *pVvdHdr; OptimizedModel::FileHeader_t *pVtxHdr; DrawModelInfo_t drawModelInfo; studiohwdata_t studioHWData; int vvdSize; const char *prefix[] = {".dx80.vtx", ".dx90.vtx", ".sw.vtx", ".xbox.vtx"}; if (!pStudioHdr->numbodyparts) { // no stats on these return; } // Need to load up StudioRender.dll to spew perf stats. InitStudioRender(); // persist the vvd data Q_StripExtension( pFilename, fileName, sizeof( fileName ) ); strcat( fileName, ".vvd" ); if (FileExists( fileName )) { vvdSize = LoadFile( fileName, (void**)&pVvdHdr ); } else { MdlError( "Could not open '%s'\n", fileName ); } // validate header if (pVvdHdr->id != MODEL_VERTEX_FILE_ID) { MdlError( "Bad id for '%s' (got %d expected %d)\n", fileName, pVvdHdr->id, MODEL_VERTEX_FILE_ID); } if (pVvdHdr->version != MODEL_VERTEX_FILE_VERSION) { MdlError( "Bad version for '%s' (got %d expected %d)\n", fileName, pVvdHdr->version, MODEL_VERTEX_FILE_VERSION); } if (pVvdHdr->checksum != pStudioHdr->checksum) { MdlError( "Bad checksum for '%s' (got %d expected %d)\n", fileName, pVvdHdr->checksum, pStudioHdr->checksum); } if (pVvdHdr->numFixups) { // need to perform mesh relocation fixups // allocate a new copy pNewVvdHdr = (vertexFileHeader_t *)malloc( vvdSize ); if (!pNewVvdHdr) { MdlError( "Error allocating %d bytes for Vertex File '%s'\n", vvdSize, fileName ); } Studio_LoadVertexes( pVvdHdr, pNewVvdHdr, 0, true ); // discard original free( pVvdHdr ); pVvdHdr = pNewVvdHdr; } // iterate all ???.vtx files for (int j=0; j<sizeof(prefix)/sizeof(prefix[0]); j++) { // make vtx filename Q_StripExtension( pFilename, fileName, sizeof( fileName ) ); strcat( fileName, prefix[j] ); printf( "\n" ); printf( "Performance Stats: %s\n", fileName ); printf( "------------------\n" ); // persist the vtx data if (FileExists(fileName)) { LoadFile( fileName, (void**)&pVtxHdr ); } else { MdlError( "Could not open '%s'\n", fileName ); } // validate header if (pVtxHdr->version != OPTIMIZED_MODEL_FILE_VERSION) { MdlError( "Bad version for '%s' (got %d expected %d)\n", fileName, pVtxHdr->version, OPTIMIZED_MODEL_FILE_VERSION ); } if (pVtxHdr->checkSum != pStudioHdr->checksum) { MdlError( "Bad checksum for '%s' (got %d expected %d)\n", fileName, pVtxHdr->checkSum, pStudioHdr->checksum ); } // studio render will request these through cache interface pStudioHdr->pVertexBase = (void *)pVvdHdr; pStudioHdr->pIndexBase = (void *)pVtxHdr; g_pStudioRender->LoadModel( pStudioHdr, pVtxHdr, &studioHWData ); memset( &drawModelInfo, 0, sizeof( DrawModelInfo_t ) ); drawModelInfo.m_pStudioHdr = pStudioHdr; drawModelInfo.m_pHardwareData = &studioHWData; int i; for( i = studioHWData.m_RootLOD; i < studioHWData.m_NumLODs; i++ ) { CUtlBuffer statsOutput( 0, 0, true /* text */ ); printf( "LOD: %d\n", i ); drawModelInfo.m_Lod = i; g_pStudioRender->GetPerfStats( drawModelInfo, &statsOutput ); printf( "\tactual tris: %d\n", ( int )drawModelInfo.m_ActualTriCount ); printf( "\ttexture memory bytes: %d\n", ( int )drawModelInfo.m_TextureMemoryBytes ); printf( ( char * )statsOutput.Base() ); } g_pStudioRender->UnloadModel( &studioHWData ); free(pVtxHdr); } if (pVvdHdr) free(pVvdHdr); }
const mstudio_modelvertexdata_t *mstudiomodel_t::GetVertexData() { char fileName[MAX_PATH]; FileHandle_t fileHandle; vertexFileHeader_t *pVvdHdr; Assert( g_pActiveStudioHdr ); if ( g_pActiveStudioHdr->pVertexBase ) { vertexdata.pVertexData = (byte *)g_pActiveStudioHdr->pVertexBase + ((vertexFileHeader_t *)g_pActiveStudioHdr->pVertexBase)->vertexDataStart; vertexdata.pTangentData = (byte *)g_pActiveStudioHdr->pVertexBase + ((vertexFileHeader_t *)g_pActiveStudioHdr->pVertexBase)->tangentDataStart; return &vertexdata; } // mandatory callback to make requested data resident // load and persist the vertex file strcpy( fileName, "models/" ); strcat( fileName, g_pActiveStudioHdr->pszName() ); Q_StripExtension( fileName, fileName, sizeof( fileName ) ); strcat( fileName, ".vvd" ); // load the model fileHandle = g_pFileSystem->Open( fileName, "rb" ); if ( !fileHandle ) { Error( "Unable to load vertex data \"%s\"\n", fileName ); } // Get the file size int size = g_pFileSystem->Size( fileHandle ); if (size == 0) { g_pFileSystem->Close( fileHandle ); Error( "Bad size for vertex data \"%s\"\n", fileName ); } pVvdHdr = (vertexFileHeader_t *)malloc(size); g_pFileSystem->Read( pVvdHdr, size, fileHandle ); g_pFileSystem->Close( fileHandle ); // check header if (pVvdHdr->id != MODEL_VERTEX_FILE_ID) { Error("Error Vertex File %s id %d should be %d\n", fileName, pVvdHdr->id, MODEL_VERTEX_FILE_ID); } if (pVvdHdr->version != MODEL_VERTEX_FILE_VERSION) { Error("Error Vertex File %s version %d should be %d\n", fileName, pVvdHdr->version, MODEL_VERTEX_FILE_VERSION); } if (pVvdHdr->checksum != g_pActiveStudioHdr->checksum) { Error("Error Vertex File %s checksum %d should be %d\n", fileName, pVvdHdr->checksum, g_pActiveStudioHdr->checksum); } g_pActiveStudioHdr->pVertexBase = (void*)pVvdHdr; vertexdata.pVertexData = (byte *)pVvdHdr + pVvdHdr->vertexDataStart; vertexdata.pTangentData = (byte *)pVvdHdr + pVvdHdr->tangentDataStart; return &vertexdata; }