//----------------------------------------------------------------------------- // Fixes up all elements //----------------------------------------------------------------------------- void CImportSFMV6::BuildList( CDmElement *pElement, CUtlRBTree< CDmElement *, int >& list ) { if ( !pElement ) return; if ( list.Find( pElement ) != list.InvalidIndex() ) return; list.Insert( pElement ); // Descend to bottom of tree, then do fixup coming back up the tree for ( CDmAttribute *pAttribute = pElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() ) { if ( pAttribute->GetType() == AT_ELEMENT ) { CDmElement *pElement = pAttribute->GetValueElement<CDmElement>( ); BuildList( pElement, list ); continue; } if ( pAttribute->GetType() == AT_ELEMENT_ARRAY ) { CDmrElementArray<> array( pAttribute ); int nCount = array.Count(); for ( int i = 0; i < nCount; ++i ) { CDmElement *pChild = array[ i ]; BuildList( pChild, list ); } continue; } } }
void CClientTools::DetachFromEntity( EntitySearchResult entityToDetach ) { C_BaseEntity *ent = reinterpret_cast< C_BaseEntity * >( entityToDetach ); Assert( ent ); if ( !ent ) return; HTOOLHANDLE handle = ent->GetToolHandle(); ent->SetToolHandle( (HTOOLHANDLE)0 ); if ( handle == (HTOOLHANDLE)0 ) { Assert( 0 ); return; } int idx = m_Handles.Find( HToolEntry_t( handle ) ); if ( idx == m_Handles.InvalidIndex() ) { Assert( 0 ); return; } m_Handles.RemoveAt( idx ); m_ActiveHandles.FindAndRemove( handle ); }
//----------------------------------------------------------------------------- // Purpose: returns the next index, or INVALID_STRING_INDEX if no more strings available //----------------------------------------------------------------------------- StringIndex_t CLocalizedStringTable::GetNextStringIndex(StringIndex_t index) { StringIndex_t idx = m_Lookup.NextInorder(index); if (idx == m_Lookup.InvalidIndex()) return INVALID_STRING_INDEX; return idx; }
void CPhysicsListenerCollision::event_friction_pair_created( IVP_Friction_Core_Pair *pair ) { corepair_t test(pair); unsigned short index = m_pairList.Find( test ); if ( m_pairList.IsValidIndex( index ) ) { corepair_t &save = m_pairList.Element(index); // found this one already, update the time if ( save.lastImpactTime.get_seconds() > pair->last_impact_time_pair.get_seconds() ) { pair->last_impact_time_pair = save.lastImpactTime; } else { save.lastImpactTime = pair->last_impact_time_pair; } } else { if ( m_pairList.Count() < 16 ) { m_pairList.Insert( test ); } } }
void CClientTools::OnRemoveEntity( C_BaseEntity *ent ) { if ( !ent ) { Assert( 0 ); return; } HTOOLHANDLE handle = ent->GetToolHandle(); ent->SetToolHandle( (HTOOLHANDLE)0 ); if ( handle == (HTOOLHANDLE)0 ) { Assert( 0 ); return; } int idx = m_Handles.Find( HToolEntry_t( handle ) ); if ( idx == m_Handles.InvalidIndex() ) { Assert( 0 ); return; } // Send deletion message to tool interface if ( m_bInRecordingMode ) { KeyValues *kv = new KeyValues( "deleted" ); ToolFramework_PostToolMessage( handle, kv ); kv->deleteThis(); } m_Handles.RemoveAt( idx ); m_ActiveHandles.FindAndRemove( handle ); }
bool CChoreoChannel::GetSortedCombinedEventList( char const *cctoken, CUtlRBTree< CChoreoEvent * >& events ) { events.RemoveAll(); int i; // Sort items int c = GetNumEvents(); for ( i = 0; i < c; i++ ) { CChoreoEvent *e = GetEvent( i ); Assert( e ); if ( e->GetType() != CChoreoEvent::SPEAK ) continue; if ( e->GetCloseCaptionType() == CChoreoEvent::CC_DISABLED ) continue; // A master with no slaves is not a combined event if ( e->GetCloseCaptionType() == CChoreoEvent::CC_MASTER && e->GetNumSlaves() == 0 ) continue; char const *token = e->GetCloseCaptionToken(); if ( Q_stricmp( token, cctoken ) ) continue; events.Insert( e ); } return ( events.Count() > 0 ) ? true : false; }
int CCombatCharVisCache::LookupVisibility( const CBaseCombatCharacter *pChar1, CBaseCombatCharacter *pChar2 ) { VisCacheEntry_t cacheEntry; if ( pChar1 < pChar2 ) { cacheEntry.m_hEntity1 = pChar1; cacheEntry.m_hEntity2 = pChar2; } else { cacheEntry.m_hEntity1 = pChar2; cacheEntry.m_hEntity2 = pChar1; } int iCache = m_VisCache.Find( cacheEntry ); if ( iCache == m_VisCache.InvalidIndex() ) { if ( m_VisCache.Count() == m_VisCache.InvalidIndex() ) return VIS_CACHE_INVALID; iCache = m_VisCache.Insert( cacheEntry ); m_VisCache[iCache].m_flTime = gpGlobals->curtime - 2.0f * VIS_CACHE_ENTRY_LIFE; } return ( pChar1 < pChar2 ) ? iCache : - iCache - 1; }
//----------------------------------------------------------------------------- // Purpose: // Input : handle - // Output : C_BaseEntity //----------------------------------------------------------------------------- C_BaseEntity *CClientTools::LookupEntity( HTOOLHANDLE handle ) { int idx = m_Handles.Find( HToolEntry_t( handle ) ); if ( idx == m_Handles.InvalidIndex() ) return NULL; return m_Handles[ idx ].m_hEntity; }
bool CClientTools::ShouldRecord( HTOOLHANDLE handle ) { int idx = m_Handles.Find( HToolEntry_t( handle ) ); if ( idx == m_Handles.InvalidIndex() ) return false; HToolEntry_t &entry = m_Handles[ idx ]; return entry.m_hEntity && entry.m_hEntity->ShouldRecordInTools(); }
AISquadEnemyInfo_t *CAI_Squad::FindEnemyInfo( CBaseEntity *pEnemy ) { int i; if ( gpGlobals->curtime > m_flEnemyInfoCleanupTime ) { if ( m_EnemyInfos.Count() ) { m_pLastFoundEnemyInfo = NULL; CUtlRBTree<CBaseEntity *> activeEnemies; SetDefLessFunc( activeEnemies ); // Gather up the set of active enemies for ( i = 0; i < m_SquadMembers.Count(); i++ ) { CBaseEntity *pMemberEnemy = m_SquadMembers[i]->GetEnemy(); if ( pMemberEnemy && activeEnemies.Find( pMemberEnemy ) == activeEnemies.InvalidIndex() ) { activeEnemies.Insert( pMemberEnemy ); } } // Remove the records for deleted or unused enemies for ( i = m_EnemyInfos.Count() - 1; i >= 0; --i ) { if ( m_EnemyInfos[i].hEnemy == NULL || activeEnemies.Find( m_EnemyInfos[i].hEnemy ) == activeEnemies.InvalidIndex() ) { m_EnemyInfos.FastRemove( i ); } } } m_flEnemyInfoCleanupTime = gpGlobals->curtime + 30; } if ( m_pLastFoundEnemyInfo && m_pLastFoundEnemyInfo->hEnemy == pEnemy ) return m_pLastFoundEnemyInfo; for ( i = 0; i < m_EnemyInfos.Count(); i++ ) { if ( m_EnemyInfos[i].hEnemy == pEnemy ) { m_pLastFoundEnemyInfo = &m_EnemyInfos[i]; return &m_EnemyInfos[i]; } } m_pLastFoundEnemyInfo = NULL; i = m_EnemyInfos.AddToTail(); m_EnemyInfos[i].hEnemy = pEnemy; m_pLastFoundEnemyInfo = &m_EnemyInfos[i]; return &m_EnemyInfos[i]; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CClientTools::SetRecording( HTOOLHANDLE handle, bool recording ) { int idx = m_Handles.Find( HToolEntry_t( handle ) ); if ( idx == m_Handles.InvalidIndex() ) return; HToolEntry_t &entry = m_Handles[ idx ]; if ( entry.m_hEntity ) { entry.m_hEntity->SetToolRecording( recording ); } }
Vector CClientTools::GetAbsOrigin( HTOOLHANDLE handle ) { int idx = m_Handles.Find( HToolEntry_t( handle ) ); if ( idx == m_Handles.InvalidIndex() ) return vec3_origin; HToolEntry_t &entry = m_Handles[ idx ]; if ( entry.m_hEntity ) { return entry.m_hEntity->GetAbsOrigin(); } Assert( 0 ); return vec3_origin; }
QAngle CClientTools::GetAbsAngles( HTOOLHANDLE handle ) { int idx = m_Handles.Find( HToolEntry_t( handle ) ); if ( idx == m_Handles.InvalidIndex() ) return vec3_angle; HToolEntry_t &entry = m_Handles[ idx ]; if ( entry.m_hEntity ) { return entry.m_hEntity->GetAbsAngles(); } Assert( 0 ); return vec3_angle; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- const char* CClientTools::GetClassname( HTOOLHANDLE handle ) { int idx = m_Handles.Find( HToolEntry_t( handle ) ); if ( idx == m_Handles.InvalidIndex() ) return NULL; HToolEntry_t &entry = m_Handles[ idx ]; if ( entry.m_hEntity ) { return STRING( entry.m_hEntity->GetClassname() ); } Assert( 0 ); return NULL; }
EntitySearchResult CClientTools::GetEntity( HTOOLHANDLE handle ) { int idx = m_Handles.Find( HToolEntry_t( handle ) ); if ( idx == m_Handles.InvalidIndex() ) return reinterpret_cast< EntitySearchResult >( NULL ); HToolEntry_t *slot = &m_Handles[ idx ]; Assert( slot ); if ( slot == NULL ) return reinterpret_cast< EntitySearchResult >( NULL ); C_BaseEntity *ent = slot->m_hEntity.Get(); return reinterpret_cast< EntitySearchResult >( ent ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- int CClientTools::GetModelIndex( HTOOLHANDLE handle ) { int idx = m_Handles.Find( HToolEntry_t( handle ) ); if ( idx == m_Handles.InvalidIndex() ) return NULL; HToolEntry_t &entry = m_Handles[ idx ]; if ( entry.m_hEntity ) { return entry.m_hEntity->GetModelIndex(); } Assert( 0 ); return 0; }
//----------------------------------------------------------------------------- // Purpose: Takes the texinfo_t referenced by the .vmt and the computed depth for the // surface and looks up or creates a texdata/texinfo for the mangled one-off water .vmt file // Input : *pBaseInfo - // depth - // Output : int //----------------------------------------------------------------------------- int FindOrCreateWaterTexInfo( texinfo_t *pBaseInfo, float depth ) { char fullname[ 512 ]; char materialname[ 512 ]; // Get the base texture/material name char const *name = TexDataStringTable_GetString( GetTexData( pBaseInfo->texdata )->nameStringTableID ); GetWaterTextureName( mapbase, name, (int)depth, fullname ); // See if we already have an entry for this depth WaterTexInfo lookup; lookup.m_FullName = fullname; int idx = g_WaterTexInfos.Find( lookup ); // If so, return the existing entry texinfo index if ( idx != g_WaterTexInfos.InvalidIndex() ) { return g_WaterTexInfos[ idx ].m_nTexInfo; } // Otherwise, fill in the rest of the data lookup.m_nWaterDepth = (int)depth; // Remember the current material name sprintf( materialname, "%s", name ); strlwr( materialname ); lookup.m_MaterialName = materialname; texinfo_t ti; // Make a copy ti = *pBaseInfo; // Create a texdata that is based on the underlying existing entry ti.texdata = FindAliasedTexData( fullname, GetTexData( pBaseInfo->texdata ) ); // Find or create a new index lookup.m_nTexInfo = FindOrCreateTexInfo( ti ); // Add the new texinfo to the RB tree idx = g_WaterTexInfos.Insert( lookup ); // Msg( "created texinfo for %s\n", lookup.m_FullName.String() ); // Go ahead and create the new vmt file. EmitWaterMaterialFile( &g_WaterTexInfos[idx] ); // Return the new texinfo return g_WaterTexInfos[ idx ].m_nTexInfo; }
//----------------------------------------------------------------------------- // Finds and/or creates a symbol based on the string //----------------------------------------------------------------------------- void CLocalizedStringTable::AddString(char const *pString, wchar_t *pValue, const char *fileName) { if (!pString) return; wchar_t *str = Find(pString); // it's already in the table if (str) return; // didn't find, insert the string into the vector. int len = strlen(pString) + 1; int stridx = m_Names.AddMultipleToTail( len ); memcpy( &m_Names[stridx], pString, len * sizeof(char) ); len = wcslen(pValue) + 1; int valueidx = m_Values.AddMultipleToTail( len ); memcpy( &m_Values[valueidx], pValue, len * sizeof(wchar_t) ); localizedstring_t stringMapItem; stringMapItem.nameIndex = stridx; stringMapItem.valueIndex = valueidx; if (fileName) { stringMapItem.filename = fileName; } else { stringMapItem.filename = m_CurrentFile; } m_Lookup.Insert( stringMapItem ); }
//----------------------------------------------------------------------------- // Remove all symbols in the table. //----------------------------------------------------------------------------- void CLocalizedStringTable::RemoveAll() { m_Lookup.RemoveAll(); m_Names.RemoveAll(); m_Values.RemoveAll(); m_LocalizationFiles.RemoveAll(); }
//----------------------------------------------------------------------------- // Delete a managed image //----------------------------------------------------------------------------- void CSchemeManager::DeleteImage( const char *pImageName ) { if ( !pImageName ) return; // set up to search for the bitmap CachedBitmapHandle_t searchBitmap; searchBitmap.bitmap = NULL; s_pszSearchString = pImageName; int i = m_Bitmaps.Find( searchBitmap ); if ( m_Bitmaps.IsValidIndex( i ) ) { delete m_Bitmaps[i].bitmap; m_Bitmaps.RemoveAt( i ); } }
//----------------------------------------------------------------------------- // Use this to turn on/off the presence of an underlying game entity //----------------------------------------------------------------------------- void CClientTools::SetEnabled( HTOOLHANDLE handle, bool enabled ) { int idx = m_Handles.Find( HToolEntry_t( handle ) ); if ( idx == m_Handles.InvalidIndex() ) return; HToolEntry_t *slot = &m_Handles[ idx ]; Assert( slot ); if ( slot == NULL ) return; C_BaseEntity *ent = slot->m_hEntity.Get(); if ( ent == NULL || ent->entindex() == 0 ) return; // Don't disable/enable the "world" ent->EnableInToolView( enabled ); }
char const* CUtlSymbolTable::String( CUtlSymbol id ) const { if (!id.IsValid()) return ""; Assert( m_Lookup.IsValidIndex((UtlSymId_t)id) ); return StringFromIndex( m_Lookup[id] ); }
void CAI_GoalEntity::InputUpdateActors( inputdata_t &inputdata ) { int i; CUtlRBTree<CAI_BaseNPC *> prevActors; CUtlRBTree<CAI_BaseNPC *>::IndexType_t index; SetDefLessFunc( prevActors ); PruneActors(); for ( i = 0; i < m_actors.Count(); i++ ) { prevActors.Insert( m_actors[i] ); } ResolveNames(); for ( i = 0; i < m_actors.Count(); i++ ) { index = prevActors.Find( m_actors[i] ); if ( index == prevActors.InvalidIndex() ) { if ( m_flags & ACTIVE ) EnableGoal( m_actors[i] ); } else prevActors.Remove( m_actors[i] ); } for ( index = prevActors.FirstInorder(); index != prevActors.InvalidIndex(); index = prevActors.NextInorder( index ) ) { if ( m_flags & ACTIVE ) DisableGoal( prevActors[ index ] ); } }
void CUtlSymbolTable::RemoveAll() { m_Lookup.RemoveAll(); for ( int i=0; i < m_StringPools.Count(); i++ ) free( m_StringPools[i] ); m_StringPools.RemoveAll(); }
void AddNewTranslation( const char *pOriginalMaterialName, const char *pNewMaterialName ) { NameTranslationLookup_t newEntry; newEntry.m_OriginalFileName = s_SymbolTable.AddString( pOriginalMaterialName ); newEntry.m_PatchFileName = s_SymbolTable.AddString( pNewMaterialName ); s_MapPatchedMatToOriginalMat.Insert( newEntry ); }
//----------------------------------------------------------------------------- // Purpose: Recursively determine directory tree //----------------------------------------------------------------------------- static void RecurseFileTree_r( const char *pBasePath, const char *pDirPath, int depth, CUtlVector< CUtlString > &dirList, bool bIsModPath ) { if ( depth >= 2 ) { // too much unecessary detail return; } // ignore path roots, only interested in subdirs const char *pSubName = pDirPath + strlen( pBasePath ); if ( pSubName[0] ) { GamePath_t gamePath; gamePath.pathName = pSubName; gamePath.bIsModPath = bIsModPath; int iIndex = g_PathTable.Find( gamePath ); if ( iIndex == g_PathTable.InvalidIndex() ) { g_PathTable.Insert( gamePath ); } } // recurse from source directory, get directories only CUtlVector< CUtlString > fileList; int dirCount = GetFileList( pDirPath, "\\", fileList ); if ( !dirCount ) { // add directory name to search tree int j = dirList.AddToTail(); dirList[j].Set( pDirPath ); return; } for ( int i=0; i<dirCount; i++ ) { // form new path name, recurse into RecurseFileTree_r( pBasePath, fileList[i].String(), depth+1, dirList, bIsModPath ); } int j = dirList.AddToTail(); dirList[j].Set( pDirPath ); }
//----------------------------------------------------------------------------- // Make sure the details are compiled with static prop //----------------------------------------------------------------------------- static bool IsModelValid( const char* pModelName ) { StaticPropLookup_t lookup; lookup.m_ModelName = pModelName; int i = s_StaticPropLookup.Find( lookup ); if (i != s_StaticPropLookup.InvalidIndex() ) return s_StaticPropLookup[i].m_IsValid; CUtlBuffer buf; lookup.m_IsValid = LoadStudioModel( pModelName, "detail_prop", buf ); if (!lookup.m_IsValid) { Warning("Error loading studio model \"%s\"!\n", pModelName ); } s_StaticPropLookup.Insert( lookup ); return lookup.m_IsValid; }
void RemoveFromWhiteList( char const *path ) { vprint( 2, "-\t'%s'\n", path ); char dir[ 512 ]; Q_strncpy( dir, path, sizeof( dir ) ); // Get the base filename from the path _strlwr( dir ); Q_FixSlashes( dir ); CUtlVector< FileEntry > files; char *lastslash = strrchr( dir, '\\' ); if ( lastslash == 0 ) { BuildFileListWildcard( 1, files, "", dir, 0 ); } else { char *wild = lastslash + 1; *lastslash = 0; BuildFileListWildcard( 1, files, dir, wild, 0 ); } int c = files.Count(); for ( int i = 0; i < c; ++i ) { UnusedContent::CUtlSymbol sym = files[ i ].sym; int idx = g_WhiteList.Find( sym ); if ( idx != g_WhiteList.InvalidIndex() ) { g_WhiteList.RemoveAt( idx ); ++wl_removed; } } }
//----------------------------------------------------------------------------- // Purpose: returns a pointer to an image //----------------------------------------------------------------------------- IImage *CSchemeManager::GetImage(const char *imageName, bool hardwareFiltered) { if ( !imageName || strlen(imageName) <= 0 ) // frame icons and the like are in the scheme file and may not be defined, so if this is null then fail silently { return NULL; } // set up to search for the bitmap CachedBitmapHandle_t searchBitmap; searchBitmap.bitmap = NULL; // Prepend 'vgui/'. Resource files try to load images assuming they live in the vgui directory. // Used to do this in Bitmap::Bitmap, moved so that the s_pszSearchString is searching for the // filename with 'vgui/' already added. char szFileName[256]; if ( Q_stristr( imageName, ".pic" ) ) { Q_snprintf( szFileName, sizeof(szFileName), "%s", imageName ); } else { Q_snprintf( szFileName, sizeof(szFileName), "vgui/%s", imageName ); } s_pszSearchString = szFileName; int i = m_Bitmaps.Find(searchBitmap); if (m_Bitmaps.IsValidIndex(i)) { return m_Bitmaps[i].bitmap; } // couldn't find the image, try and load it CachedBitmapHandle_t bitmap = { new Bitmap(szFileName, hardwareFiltered) }; m_Bitmaps.Insert(bitmap); return bitmap.bitmap; }
CUtlSymbol CUtlSymbolTable::Find( char const* pString ) { if (!pString) return CUtlSymbol(); // Store a special context used to help with insertion g_LessCtx.m_pUserString = pString; g_LessCtx.m_pTable = this; // Passing this special invalid symbol makes the comparison function // use the string passed in the context UtlSymId_t idx = m_Lookup.Find( INVALID_STRING_INDEX ); return CUtlSymbol( idx ); }