void CCompiledKeyValuesWriter::WriteFiles( CUtlBuffer &buf ) { int c = m_Files.Count(); buf.PutInt( c ); for ( int i = 0; i < c; ++i ) { KVFile_t &file = m_Files[ i ]; buf.PutShort( file.filename ); buf.PutShort( file.firstElement ); buf.PutShort( file.numElements ); } }
void CCompiledKeyValuesWriter::WriteData( CUtlBuffer& buf ) { int c = m_Data.Count(); buf.PutInt( c ); for ( int i = 0; i < c; ++i ) { KVInfo_t &info = m_Data[ i ]; buf.PutShort( info.key ); buf.PutShort( info.value ); buf.PutShort( info.GetParent() ); buf.PutChar( info.IsSubTree() ? 1 : 0 ); } }
bool CBaseGameStats::SaveToFileNOW( bool bForceSyncWrite /* = false */ ) { if ( !StatsTrackingIsFullyEnabled() ) return false; // this code path is only for old format stats. Products that use new format take a different path. if ( !gamestats->UseOldFormat() ) return false; CUtlBuffer buf; buf.PutShort( GAMESTATS_FILE_VERSION ); buf.Put( s_szPseudoUniqueID, 16 ); if( ShouldTrackStandardStats() ) m_BasicStats.SaveToBuffer( buf ); else buf.PutInt( GAMESTATS_STANDARD_NOT_SAVED ); gamestats->AppendCustomDataToSaveBuffer( buf ); char fullpath[ 512 ] = { 0 }; if ( filesystem->FileExists( GetStatSaveFileName(), GAMESTATS_PATHID ) ) { filesystem->RelativePathToFullPath( GetStatSaveFileName(), GAMESTATS_PATHID, fullpath, sizeof( fullpath ) ); } else { // filename is local to game dir for Steam, so we need to prepend game dir for regular file save char gamePath[256]; engine->GetGameDir( gamePath, 256 ); Q_StripTrailingSlash( gamePath ); Q_snprintf( fullpath, sizeof( fullpath ), "%s/%s", gamePath, GetStatSaveFileName() ); Q_strlower( fullpath ); Q_FixSlashes( fullpath ); } // StatsLog( "SaveToFileNOW '%s'\n", fullpath ); if( CBGSDriver.m_bShuttingDown || bForceSyncWrite ) //write synchronously { filesystem->WriteFile( fullpath, GAMESTATS_PATHID, buf ); StatsLog( "Shut down wrote to '%s'\n", fullpath ); } else { // Allocate memory for async system to use (and free afterward!!!) size_t nBufferSize = buf.TellPut(); void *pMem = malloc(nBufferSize); CUtlBuffer statsBuffer( pMem, nBufferSize ); statsBuffer.Put( buf.Base(), nBufferSize ); // Write data async filesystem->AsyncWrite( fullpath, statsBuffer.Base(), statsBuffer.TellPut(), true, false ); } return true; }
void CModelSoundsCache::Save( CUtlBuffer& buf ) { buf.PutShort( sounds.Count() ); for ( int i = 0; i < sounds.Count(); ++i ) { buf.PutString( GetSoundName( i ) ); } }
// This is a compressed save of just the data needed to drive phonemes in the engine (no word / sentence text, etc ) //----------------------------------------------------------------------------- // Purpose: // Input : buf - //----------------------------------------------------------------------------- void CSentence::CacheSaveToBuffer( CUtlBuffer& buf ) { Assert( !buf.IsText() ); Assert( m_bIsCached ); buf.PutChar( CACHED_SENTENCE_VERSION ); int i; unsigned short pcount = GetRuntimePhonemeCount(); buf.PutShort( pcount ); for ( i = 0; i < pcount; ++i ) { const CBasePhonemeTag *phoneme = GetRuntimePhoneme( i ); Assert( phoneme ); buf.PutShort( phoneme->GetPhonemeCode() ); buf.PutFloat( phoneme->GetStartTime() ); buf.PutFloat( phoneme->GetEndTime() ); } // Now save out emphasis samples int c = m_EmphasisSamples.Count(); Assert( c <= 32767 ); buf.PutShort( c ); for ( i = 0; i < c; i++ ) { CEmphasisSample *sample = &m_EmphasisSamples[ i ]; Assert( sample ); buf.PutFloat( sample->time ); short scaledValue = clamp( (short)( sample->value * 32767 ), 0, 32767 ); buf.PutShort( scaledValue ); } // And voice duck buf.PutChar( GetVoiceDuck() ? 1 : 0 ); }
void CSceneCache::Save( CUtlBuffer& buf ) { buf.PutUnsignedInt( msecs ); unsigned short c = GetSoundCount(); buf.PutShort( c ); Assert( sounds.Count() <= 65536 ); for ( int i = 0; i < c; ++i ) { buf.PutString( GetSoundName( i ) ); } }
void CChoreoChannel::SaveToBuffer( CUtlBuffer& buf, CChoreoScene *pScene, IChoreoStringPool *pStringPool ) { buf.PutShort( pStringPool->FindOrAddString( GetName() ) ); int c = GetNumEvents(); Assert( c <= 255 ); buf.PutUnsignedChar( c ); for ( int i = 0; i < c; i++ ) { CChoreoEvent *e = GetEvent( i ); Assert( e ); e->SaveToBuffer( buf, pScene, pStringPool ); } buf.PutChar( GetActive() ? 1 : 0 ); }
void BasicGameStats_t::SaveToBuffer( CUtlBuffer& buf ) { buf.PutInt( m_nSecondsToCompleteGame ); m_Summary.SaveToBuffer( buf ); int c = m_MapTotals.Count(); buf.PutInt( c ); for ( int i = m_MapTotals.First(); i != m_MapTotals.InvalidIndex(); i = m_MapTotals.Next( i ) ) { char const *name = m_MapTotals.GetElementName( i ); BasicGameStatsRecord_t &rec = m_MapTotals[ i ]; buf.PutString( name ); rec.SaveToBuffer( buf ); } buf.PutChar( (char)m_nHL2ChaptureUnlocked ); buf.PutChar( m_bSteam ? 1 : 0 ); buf.PutChar( m_bCyberCafe ? 1 : 0 ); buf.PutShort( (short)m_nDXLevel ); }
void CNetworkStringTable::WriteStringTable( CUtlBuffer& buf ) { int numstrings = GetNumStrings(); buf.PutInt( numstrings ); for ( int i = 0 ; i < numstrings; i++ ) { buf.PutString( GetString( i ) ); int userDataSize; const void *pUserData = GetStringUserData( i, &userDataSize ); if ( userDataSize > 0 ) { buf.PutChar( 1 ); buf.PutShort( (short)userDataSize ); buf.Put( pUserData, userDataSize ); } else { buf.PutChar( 0 ); } } }
void CChoreoActor::SaveToBuffer( CUtlBuffer& buf, CChoreoScene *pScene ) { int i, c; buf.PutString( GetName() ); c = GetNumChannels(); buf.PutShort( c ); for ( i = 0; i < c; i++ ) { CChoreoChannel *channel = GetChannel( i ); Assert( channel ); channel->SaveToBuffer( buf, pScene ); } /* if ( Q_strlen( a->GetFacePoserModelName() ) > 0 ) { FilePrintf( buf, level + 1, "faceposermodel \"%s\"\n", a->GetFacePoserModelName() ); } */ buf.PutChar( GetActive() ? 1 : 0 ); }
// This is a compressed save of just the data needed to drive phonemes in the engine (no word / sentence text, etc ) //----------------------------------------------------------------------------- // Purpose: // Input : buf - //----------------------------------------------------------------------------- void CSentence::CacheSaveToBuffer( CUtlBuffer& buf, int version ) { Assert( !buf.IsText() ); Assert( m_bIsCached ); int i; unsigned short pcount = GetRuntimePhonemeCount(); // header if ( version == CACHED_SENTENCE_VERSION_ALIGNED ) { buf.PutChar( version ); buf.PutChar( 0 ); buf.PutChar( 0 ); buf.PutChar( 0 ); buf.PutInt( pcount ); } else { buf.PutChar( version ); buf.PutShort( pcount ); } // phoneme if ( version == CACHED_SENTENCE_VERSION_ALIGNED ) { for ( i = 0; i < pcount; ++i ) { const CBasePhonemeTag *phoneme = GetRuntimePhoneme( i ); Assert( phoneme ); buf.PutInt( phoneme->GetPhonemeCode() ); buf.PutFloat( phoneme->GetStartTime() ); buf.PutFloat( phoneme->GetEndTime() ); } } else { for ( i = 0; i < pcount; ++i ) { const CBasePhonemeTag *phoneme = GetRuntimePhoneme( i ); Assert( phoneme ); buf.PutShort( phoneme->GetPhonemeCode() ); buf.PutFloat( phoneme->GetStartTime() ); buf.PutFloat( phoneme->GetEndTime() ); } } // emphasis samples and voice duck int c = m_EmphasisSamples.Count(); Assert( c <= 32767 ); if ( version == CACHED_SENTENCE_VERSION_ALIGNED ) { buf.PutInt( c ); for ( i = 0; i < c; i++ ) { CEmphasisSample *sample = &m_EmphasisSamples[i]; Assert( sample ); buf.PutFloat( sample->time ); buf.PutFloat( sample->value ); } buf.PutInt( GetVoiceDuck() ? 1 : 0 ); } else { buf.PutShort( c ); for ( i = 0; i < c; i++ ) { CEmphasisSample *sample = &m_EmphasisSamples[i]; Assert( sample ); buf.PutFloat( sample->time ); short scaledValue = clamp( (short)( sample->value * 32767 ), (short)0, (short)32767 ); buf.PutShort( scaledValue ); } buf.PutChar( GetVoiceDuck() ? 1 : 0 ); } }
void Disp_BuildVirtualMesh( int contentsMask ) { CUtlVector<CPhysCollide *> virtualMeshes; virtualMeshes.EnsureCount( g_CoreDispInfos.Count() ); for ( int i = 0; i < g_CoreDispInfos.Count(); i++ ) { CCoreDispInfo *pDispInfo = g_CoreDispInfos[ i ]; mapdispinfo_t *pMapDisp = &mapdispinfo[ i ]; virtualMeshes[i] = NULL; // not solid for this pass if ( !(pMapDisp->contents & contentsMask) ) continue; // Build a triangle list. This shares the tesselation code with the engine. CUtlVector<unsigned short> indices; CVBSPTesselateHelper helper; helper.m_pIndices = &indices; helper.m_pActiveVerts = pDispInfo->GetAllowedVerts().Base(); helper.m_pPowerInfo = pDispInfo->GetPowerInfo(); ::TesselateDisplacement( &helper ); // validate the collision data if ( 1 ) { int triCount = indices.Count() / 3; for ( int j = 0; j < triCount; j++ ) { int index = j * 3; Vector v0 = pDispInfo->GetVert( indices[index+0] ); Vector v1 = pDispInfo->GetVert( indices[index+1] ); Vector v2 = pDispInfo->GetVert( indices[index+2] ); if ( v0 == v1 || v1 == v2 || v2 == v0 ) { Warning( "Displacement %d has bad geometry near %.2f %.2f %.2f\n", i, v0.x, v0.y, v0.z ); texinfo_t *pTexInfo = &texinfo[pMapDisp->face.texinfo]; dtexdata_t *pTexData = GetTexData( pTexInfo->texdata ); const char *pMatName = TexDataStringTable_GetString( pTexData->nameStringTableID ); Error( "Can't compile displacement physics, exiting. Texture is %s\n", pMatName ); } } } CDispMeshEvent meshHandler( indices.Base(), indices.Count(), pDispInfo ); virtualmeshparams_t params; params.buildOuterHull = true; params.pMeshEventHandler = &meshHandler; params.userData = &meshHandler; virtualMeshes[i] = physcollision->CreateVirtualMesh( params ); } unsigned int totalSize = 0; CUtlBuffer buf; dphysdisp_t header; header.numDisplacements = g_CoreDispInfos.Count(); buf.PutObjects( &header ); CUtlVector<char> dispBuf; for ( int i = 0; i < header.numDisplacements; i++ ) { if ( virtualMeshes[i] ) { unsigned int testSize = physcollision->CollideSize( virtualMeshes[i] ); totalSize += testSize; buf.PutShort( testSize ); } else { buf.PutShort( -1 ); } } for ( int i = 0; i < header.numDisplacements; i++ ) { if ( virtualMeshes[i] ) { unsigned int testSize = physcollision->CollideSize( virtualMeshes[i] ); dispBuf.RemoveAll(); dispBuf.EnsureCount(testSize); unsigned int outSize = physcollision->CollideWrite( dispBuf.Base(), virtualMeshes[i], false ); Assert( outSize == testSize ); buf.Put( dispBuf.Base(), outSize ); } } g_PhysDispSize = totalSize + sizeof(dphysdisp_t) + (sizeof(unsigned short) * header.numDisplacements); Assert( buf.TellMaxPut() == g_PhysDispSize ); g_PhysDispSize = buf.TellMaxPut(); g_pPhysDisp = new byte[g_PhysDispSize]; Q_memcpy( g_pPhysDisp, buf.Base(), g_PhysDispSize ); }