bool AStar::Save(IFileSystem *filesystem, const char *Filename) { CUtlBuffer buf; AStarNode *Node; NodeList_t Links; int TotalNumLinks = 0; int NodeTotal = Nodes.Count(); ////////////////////////////////////////////// // Nodes buf.PutInt(NodeTotal); for(int i = 0; i < NodeTotal; i++) { Node = Nodes[i]; buf.PutFloat(Node->GetPos().x); buf.PutFloat(Node->GetPos().y); buf.PutFloat(Node->GetPos().z); TotalNumLinks += Node->GetLinks().Count(); } ////////////////////////////////////////////// ////////////////////////////////////////////// // Links buf.PutInt(TotalNumLinks); for(int i = 0; i < NodeTotal; i++) { Node = Nodes[i]; Links = Node->GetLinks(); for(int li = 0; li < Links.Count(); li++) { buf.PutInt(Node->GetID()); buf.PutInt(Links[li]->GetID()); } } ////////////////////////////////////////////// ////////////////////////////////////////////// // Write File FileHandle_t fh = filesystem->Open(Filename, "wb"); if(!fh) { return false; } filesystem->Write(buf.Base(), buf.TellPut(), fh); filesystem->Close(fh); ////////////////////////////////////////////// return true; }
bool Serialize( CUtlBuffer &buf, const QAngle &src ) { if ( buf.IsText() ) { SerializeFloats( buf, 3, src.Base() ); } else { buf.PutFloat( src.x ); buf.PutFloat( src.y ); buf.PutFloat( src.z ); } return buf.IsValid(); }
bool Serialize( CUtlBuffer &buf, const Quaternion &src ) { if ( buf.IsText() ) { SerializeFloats( buf, 4, &src.x ); } else { buf.PutFloat( src.x ); buf.PutFloat( src.y ); buf.PutFloat( src.z ); buf.PutFloat( src.w ); } return buf.IsValid(); }
/** * Save a navigation area to the opened binary stream */ void CNavArea::Save( CUtlBuffer &fileBuffer, unsigned int version ) const { // save ID fileBuffer.PutUnsignedInt( m_id ); // save attribute flags fileBuffer.PutInt( m_attributeFlags ); // save extent of area fileBuffer.Put( &m_nwCorner, 3*sizeof(float) ); fileBuffer.Put( &m_seCorner, 3*sizeof(float) ); // save heights of implicit corners fileBuffer.PutFloat( m_neZ ); fileBuffer.PutFloat( m_swZ ); // save connections to adjacent areas // in the enum order NORTH, EAST, SOUTH, WEST for( int d=0; d<NUM_DIRECTIONS; d++ ) { // save number of connections for this direction unsigned int count = m_connect[d].Count(); fileBuffer.PutUnsignedInt( count ); FOR_EACH_VEC( m_connect[d], it ) { NavConnect connect = m_connect[d][ it ]; fileBuffer.PutUnsignedInt( connect.area->m_id ); } }
// 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 ); }
bool Serialize( CUtlBuffer &buf, const float &src ) { if ( buf.IsText() ) { SerializeFloat( buf, src ); } else { buf.PutFloat( src ); } return buf.IsValid(); }
void CMomRunStats::Serialize(CUtlBuffer &writer) { writer.PutUnsignedChar(m_iTotalZones); for (int i = 0; i < m_iTotalZones + 1; ++i) { //Jumps/Strafes writer.PutUnsignedInt(m_iZoneJumps[i]); writer.PutUnsignedInt(m_iZoneStrafes[i]); //Sync writer.PutFloat(m_flZoneStrafeSyncAvg[i]); writer.PutFloat(m_flZoneStrafeSync2Avg[i]); //Time writer.PutUnsignedInt(m_iZoneEnterTick[i]); writer.PutUnsignedInt(m_iZoneTicks[i]); //Velocity writer.PutFloat(m_flZoneVelocityMax3D[i]); writer.PutFloat(m_flZoneVelocityMax2D[i]); writer.PutFloat(m_flZoneVelocityAvg3D[i]); writer.PutFloat(m_flZoneVelocityAvg2D[i]); writer.PutFloat(m_flZoneEnterSpeed3D[i]); writer.PutFloat(m_flZoneEnterSpeed2D[i]); writer.PutFloat(m_flZoneExitSpeed3D[i]); writer.PutFloat(m_flZoneExitSpeed2D[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, 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 ); } }
bool KeyValues::WriteAsBinary(CUtlBuffer &buffer) { if (buffer.IsText()) return false; if (!buffer.IsValid()) return false; for (KeyValues *dat = this; dat != NULL; dat = dat->m_pPeer) { buffer.PutUnsignedChar(dat->m_iDataType); buffer.PutString(dat->GetName()); switch (dat->m_iDataType) { case TYPE_NONE: { dat->m_pSub->WriteAsBinary(buffer); break; } case TYPE_STRING: { if (dat->m_sValue && *(dat->m_sValue)) { buffer.PutString(dat->m_sValue); } else { buffer.PutString(""); } break; } case TYPE_WSTRING: { Assert(!"TYPE_WSTRING"); break; } case TYPE_INT: { buffer.PutInt(dat->m_iValue); break; } case TYPE_UINT64: { buffer.PutDouble(*((double *)dat->m_sValue)); break; } case TYPE_FLOAT: { buffer.PutFloat(dat->m_flValue); break; } case TYPE_COLOR: { buffer.PutUnsignedChar(dat->m_Color[0]); buffer.PutUnsignedChar(dat->m_Color[1]); buffer.PutUnsignedChar(dat->m_Color[2]); buffer.PutUnsignedChar(dat->m_Color[3]); break; } case TYPE_PTR: { buffer.PutUnsignedInt((int)dat->m_pValue); } default: { break; } } } buffer.PutUnsignedChar(TYPE_NUMTYPES); return buffer.IsValid(); }