CChoreoScene *C_SceneEntity::LoadScene( const char *filename ) { char loadfile[ 512 ]; Q_strncpy( loadfile, filename, sizeof( loadfile ) ); Q_SetExtension( loadfile, ".vcd", sizeof( loadfile ) ); Q_FixSlashes( loadfile ); char *buffer = NULL; size_t bufsize = scenefilecache->GetSceneBufferSize( loadfile ); if ( bufsize <= 0 ) return NULL; buffer = new char[ bufsize ]; if ( !scenefilecache->GetSceneData( filename, (byte *)buffer, bufsize ) ) { delete[] buffer; return NULL; } g_TokenProcessor.SetBuffer( buffer ); CChoreoScene *scene = ChoreoLoadScene( loadfile, this, &g_TokenProcessor, Scene_Printf ); delete[] buffer; return scene; }
//----------------------------------------------------------------------------- // Create binary compiled version of VCD. Stores to a dictionary for later // post processing //----------------------------------------------------------------------------- bool CreateTargetFile_VCD( const char *pSourceName, const char *pTargetName, bool bWriteToZip, bool bLittleEndian ) { CUtlBuffer sourceBuf; if ( !scriptlib->ReadFileToBuffer( pSourceName, sourceBuf ) ) { return false; } CRC32_t crcSource; CRC32_Init( &crcSource ); CRC32_ProcessBuffer( &crcSource, sourceBuf.Base(), sourceBuf.TellMaxPut() ); CRC32_Final( &crcSource ); ParseFromMemory( (char *)sourceBuf.Base(), sourceBuf.TellMaxPut() ); CChoreoScene *pChoreoScene = ChoreoLoadScene( pSourceName, NULL, &g_SceneTokenProcessor, Msg ); if ( !pChoreoScene ) { return false; } int iScene = g_SceneFiles.AddToTail(); g_SceneFiles[iScene].fileName.Set( pSourceName ); // Walk all events looking for SPEAK events CChoreoEvent *pEvent; for ( int i = 0; i < pChoreoScene->GetNumEvents(); ++i ) { pEvent = pChoreoScene->GetEvent( i ); FindSoundsInEvent( pEvent, g_SceneFiles[iScene].soundList ); } // calc duration g_SceneFiles[iScene].msecs = (unsigned int)( pChoreoScene->FindStopTime() * 1000.0f + 0.5f ); // compile to binary buffer g_SceneFiles[iScene].compiledBuffer.SetBigEndian( !bLittleEndian ); pChoreoScene->SaveToBinaryBuffer( g_SceneFiles[iScene].compiledBuffer, crcSource, &g_ChoreoStringPool ); unsigned int compressedSize; unsigned char *pCompressedBuffer = LZMA_Compress( (unsigned char *)g_SceneFiles[iScene].compiledBuffer.Base(), g_SceneFiles[iScene].compiledBuffer.TellMaxPut(), &compressedSize ); if ( pCompressedBuffer ) { // replace the compiled buffer with the compressed version g_SceneFiles[iScene].compiledBuffer.Purge(); g_SceneFiles[iScene].compiledBuffer.EnsureCapacity( compressedSize ); g_SceneFiles[iScene].compiledBuffer.Put( pCompressedBuffer, compressedSize ); free( pCompressedBuffer ); } delete pChoreoScene; return true; }
CChoreoScene* HammerLoadScene( const char *pFilename ) { if ( g_pFullFileSystem->FileExists( pFilename ) ) { LoadScriptFile( (char*)pFilename ); CChoreoScene *scene = ChoreoLoadScene( pFilename, NULL, &g_TokenProcessor, Msg ); return scene; } return NULL; }
//----------------------------------------------------------------------------- // Purpose: // Input : *filename - // Output : CChoreoScene //----------------------------------------------------------------------------- CChoreoScene *CVCDFile::LoadScene( char const *filename ) { if ( SceneManager_FullpathFileExists( va( "%s/%s", SceneManager_GetGameDirectory(), (char *)filename ) ) ) { LoadScriptFile( va( "%s/%s", SceneManager_GetGameDirectory(), (char *)filename ) ); CChoreoScene *scene = ChoreoLoadScene( this, &g_TokenProcessor, Con_Printf ); return scene; } return NULL; }
CChoreoScene *C_SceneEntity::LoadScene( const char *filename ) { char loadfile[ 512 ]; Q_strncpy( loadfile, filename, sizeof( loadfile ) ); Q_SetExtension( loadfile, ".vcd", sizeof( loadfile ) ); Q_FixSlashes( loadfile ); char *pBuffer = NULL; size_t bufsize = scenefilecache->GetSceneBufferSize( loadfile ); if ( bufsize <= 0 ) return NULL; pBuffer = new char[ bufsize ]; if ( !scenefilecache->GetSceneData( filename, (byte *)pBuffer, bufsize ) ) { delete[] pBuffer; return NULL; } CChoreoScene *pScene; if ( IsBufferBinaryVCD( pBuffer, bufsize ) ) { pScene = new CChoreoScene( this ); CUtlBuffer buf( pBuffer, bufsize, CUtlBuffer::READ_ONLY ); if ( !pScene->RestoreFromBinaryBuffer( buf, loadfile, &g_ChoreoStringPool ) ) { Warning( "Unable to restore binary scene '%s'\n", loadfile ); delete pScene; pScene = NULL; } else { pScene->SetPrintFunc( Scene_Printf ); pScene->SetEventCallbackInterface( this ); } } else { g_TokenProcessor.SetBuffer( pBuffer ); pScene = ChoreoLoadScene( loadfile, this, &g_TokenProcessor, Scene_Printf ); } delete[] pBuffer; return pScene; }
void ProcessVCD( CUtlDict< VCDList, int >& database, CUtlSymbol& vcdname ) { // vprint( 0, "Processing '%s'\n", g_Analysis.symbols.String( vcdname ) ); // Load the .vcd char fullname[ 512 ]; Q_snprintf( fullname, sizeof( fullname ), "%s", g_Analysis.symbols.String( vcdname ) ); LoadScriptFile( fullname ); CChoreoScene *scene = ChoreoLoadScene( fullname, NULL, &g_TokenProcessor, Con_Printf ); if ( scene ) { bool first = true; // Now iterate the events looking for speak events int c = scene->GetNumEvents(); for ( int i = 0; i < c; i++ ) { CChoreoEvent *e = scene->GetEvent( i ); if ( e->GetType() == CChoreoEvent::MOVETO ) { SpewMoveto( first, fullname, e ); first = false; } if ( e->GetType() != CChoreoEvent::SPEAK ) continue; // Look up sound in sound emitter system char const *wavename = soundemitter->GetWavFileForSound( e->GetParameters(), NULL ); if ( !wavename || !wavename[ 0 ] ) { continue; } char fullwavename[ 512 ]; Q_snprintf( fullwavename, sizeof( fullwavename ), "%ssound\\%s", gamedir, wavename ); Q_FixSlashes( fullwavename ); // Now add to proper slot VCDList *entry = NULL; // Add vcd to database int slot = database.Find( fullwavename ); if ( slot == database.InvalidIndex() ) { VCDList nullEntry; slot = database.Insert( fullwavename, nullEntry ); } entry = &database[ slot ]; if ( entry->vcds.Find( vcdname ) == entry->vcds.InvalidIndex() ) { entry->vcds.AddToTail( vcdname ); } } if ( vcdonly ) { CheckForOverlappingFlexTracks( scene ); } } delete scene; }