void CGameGibManager::AddGibToLRU( CBaseAnimating *pEntity ) { int i, next; if ( pEntity == NULL ) return; //Find stale gibs. for ( i = m_LRU.Head(); i < m_LRU.InvalidIndex(); i = next ) { next = m_LRU.Next(i); if ( m_LRU[i].Get() == NULL ) { m_LRU.Remove(i); } } // We're not tracking gibs at the moment if ( m_iCurrentMaxPieces <= 0 ) return; while ( m_LRU.Count() >= m_iCurrentMaxPieces ) { i = m_LRU.Head(); //TODO: Make this fade out instead of pop. UTIL_Remove( m_LRU[i] ); m_LRU.Remove(i); } m_LRU.AddToTail( pEntity ); m_iLastFrame = gpGlobals->framecount; }
// ----------------------------------------------------------------------------- // // Add/remove decals // ----------------------------------------------------------------------------- // DispDecalHandle_t CDispInfo::NotifyAddDecal( decal_t *pDecal ) { // FIXME: Add decal retirement... // if( m_Decals.Size() < MAX_DISP_DECALS ) // return; // Create a new decal, link it in DispDecalHandle_t h = s_DispDecals.Alloc( true ); // When linking, insert it in sorted order based on material enumeration ID // This will help us when rendering later int last = DISP_DECAL_HANDLE_INVALID; int i = m_FirstDecal; int enumerationId = pDecal->material->GetEnumerationID(); while( i != s_DispDecals.InvalidIndex() ) { int testId = s_DispDecals[i].m_pDecal->material->GetEnumerationID(); if (enumerationId <= testId) break; last = i; i = s_DispDecals.Next(i); } // NOTE: when the list is used in multimode, we can't use LinkBefore( i, INVALID_INDEX ), // since the Head and Tail of the linked list are meaningless... if ( last != DISP_DECAL_HANDLE_INVALID ) s_DispDecals.LinkAfter( last, h ); else { s_DispDecals.LinkBefore( m_FirstDecal, h ); m_FirstDecal = h; } CDispDecal *pDispDecal = &s_DispDecals[h]; pDispDecal->m_pDecal = pDecal; pDispDecal->m_FirstFragment = DISP_DECAL_FRAGMENT_HANDLE_INVALID; pDispDecal->m_nVerts = 0; pDispDecal->m_nTris = 0; // Setup a basis for it. CDecalVert *pOutVerts = NULL; R_SetupDecalClip( pOutVerts, pDispDecal->m_pDecal, MSurf_Plane( m_ParentSurfID ).normal, pDispDecal->m_pDecal->material, pDispDecal->m_TextureSpaceBasis, pDispDecal->m_DecalWorldScale ); // Recurse and precalculate which nodes this thing can touch. SetupDecalNodeIntersect( m_pPowerInfo->m_RootNode, 0, // node bit index into CDispDecal::m_NodeIntersects pDispDecal, 0 ); return h; }
BSPTreeDataHandle_t CBSPTreeData::NewHandle( int userId ) { BSPTreeDataHandle_t handle = m_Handles.AddToTail(); m_Handles[handle].m_UserId = userId; m_Handles[handle].m_LeafList = m_HandleLeafList.InvalidIndex(); return handle; }
//----------------------------------------------------------------------------- // Adds a handle to a leaf //----------------------------------------------------------------------------- void CBSPTreeData::AddHandleToLeaf( int leaf, BSPTreeDataHandle_t handle ) { // Got to a leaf baby! Add the handle to the leaf's list of elements unsigned short leafElement = m_LeafElements.Alloc( true ); if (m_Leaf[leaf].m_FirstElement != m_LeafElements.InvalidIndex() ) m_LeafElements.LinkBefore( m_Leaf[leaf].m_FirstElement, leafElement ); m_Leaf[leaf].m_FirstElement = leafElement; m_LeafElements[leafElement] = handle; // Insert the leaf into the handles's list of leaves unsigned short handleElement = m_HandleLeafList.Alloc( true ); if (m_Handles[handle].m_LeafList != m_HandleLeafList.InvalidIndex() ) m_HandleLeafList.LinkBefore( m_Handles[handle].m_LeafList, handleElement ); m_Handles[handle].m_LeafList = handleElement; m_HandleLeafList[handleElement].m_Leaf = leaf; m_HandleLeafList[handleElement].m_LeafElementIndex = leafElement; }
void CGroundLine::DrawAllGroundLines() { VPROF("CGroundLine::DrawAllGroundLines()"); unsigned short i; for( i = s_GroundLines.Head(); i != s_GroundLines.InvalidIndex(); i = s_GroundLines.Next(i) ) { s_GroundLines[i]->Draw(); } }
//----------------------------------------------------------------------------- // Purpose: // Input : *focus - //----------------------------------------------------------------------------- void CInputWin32::PanelDeleted(VPANEL focus) { HInputContext i; for (i = m_Contexts.Head(); i != m_Contexts.InvalidIndex(); i = m_Contexts.Next(i) ) { PanelDeleted( focus, m_Contexts[i] ); } PanelDeleted( focus, m_DefaultInputContext ); }
void CVGui::DestroyAllContexts( ) { HContext next; HContext i = m_Contexts.Head(); while (i != m_Contexts.InvalidIndex()) { next = m_Contexts.Next(i); DestroyContext( i ); i = next; } }
//----------------------------------------------------------------------------- // Enumerate elements in a particular leaf //----------------------------------------------------------------------------- int CBSPTreeData::CountElementsInLeaf( int leaf ) { int i; int nCount = 0; for( i = m_Leaf[leaf].m_FirstElement; i != m_LeafElements.InvalidIndex(); i = m_LeafElements.Next(i) ) { ++nCount; } return nCount; }
void CBSPTreeData::RemoveFromTree( BSPTreeDataHandle_t handle ) { // Iterate over the list of all leaves the handle is in unsigned short i = m_Handles[handle].m_LeafList; while (i != m_HandleLeafList.InvalidIndex()) { int leaf = m_HandleLeafList[i].m_Leaf; unsigned short leafElement = m_HandleLeafList[i].m_LeafElementIndex; // Unhook the handle from the leaf handle list if (leafElement == m_Leaf[leaf].m_FirstElement) m_Leaf[leaf].m_FirstElement = m_LeafElements.Next(leafElement); m_LeafElements.Free(leafElement); unsigned short prevNode = i; i = m_HandleLeafList.Next(i); m_HandleLeafList.Free(prevNode); } m_Handles[handle].m_LeafList = m_HandleLeafList.InvalidIndex(); }
void TimeoutJobIDs() { double flCurTime = Plat_FloatTime(); int iNext; for ( int i=g_JobMemories.Head(); i != g_JobMemories.InvalidIndex(); i=iNext ) { iNext = g_JobMemories.Next( i ); if ( (flCurTime - g_JobMemories[i].m_Time) > JOB_MEMORY_DURATION ) g_JobMemories.Remove( i ); } }
bool FindJobMemory( int id[4] ) { int iNext; for ( int i=g_JobMemories.Head(); i != g_JobMemories.InvalidIndex(); i=iNext ) { iNext = g_JobMemories.Next( i ); CJobMemory *pJob = &g_JobMemories[i]; if ( memcmp( pJob->m_ID, id, sizeof( pJob->m_ID ) ) == 0 ) return true; } return false; }
static bool EventCollidesWithRows( CUtlLinkedList< CChoreoEvent*, int >& list, CChoreoEvent *event, char *trackName, size_t trackNameLength ) { float st = event->GetStartTime(); float ed = event->GetEndTime(); for ( int i = list.Head(); i != list.InvalidIndex(); i = list.Next( i ) ) { CChoreoEvent *test = list[ i ]; float teststart = test->GetStartTime(); float testend = test->GetEndTime(); // See if spans overlap if ( teststart >= ed ) continue; if ( testend <= st ) continue; // Now see if they deal with the same flex controller int tc = event->GetNumFlexAnimationTracks(); for ( int track = 0; track < tc; ++track ) { CFlexAnimationTrack *t = event->GetFlexAnimationTrack( track ); if ( !t->IsTrackActive() ) { continue; } int sampleCountNormal = t->GetNumSamples( 0 ); int sampleCountBalance = 0; if ( t->IsComboType() ) { sampleCountBalance = t->GetNumSamples( 1 ); } if ( !sampleCountNormal && !sampleCountBalance ) continue; // Otherwise, see if the test track has this as an active track if ( IsFlexTrackBeingUsed( test, t->GetFlexControllerName() ) ) { Q_strncpy( trackName, t->GetFlexControllerName(), trackNameLength ); return true; } } return false; } return false; }
PackedEntity* CFrameSnapshotManager::GetPreviouslySentPacket( int iEntity, int iSerialNumber ) { PackedEntityHandle_t handle = m_pPackedData[iEntity]; if ( handle != m_PackedEntities.InvalidIndex() ) { // NOTE: We can't use the previously sent packet if there was a // serial number change.... if ( m_pSerialNumber[iEntity] == iSerialNumber ) { return &m_PackedEntities[handle]; } } return NULL; }
void CFrameSnapshotManager::DeleteFrameSnapshot( CFrameSnapshot* pSnapshot ) { // Decrement reference counts of all packed entities for (int i = 0; i < MAX_EDICTS; ++i) { if (pSnapshot->m_pPackedData[i] != m_PackedEntities.InvalidIndex()) { if (--m_PackedEntities[ pSnapshot->m_pPackedData[i] ].m_ReferenceCount <= 0) { DestroyPackedEntity( pSnapshot->m_pPackedData[i] ); } } } m_FrameSnapshots.Remove( pSnapshot->m_ListIndex ); delete pSnapshot; }
bool CFrameSnapshotManager::UsePreviouslySentPacket( CFrameSnapshot* pSnapshot, int entity, int entSerialNumber ) { PackedEntityHandle_t handle = m_pPackedData[entity]; if ( handle != m_PackedEntities.InvalidIndex() ) { // NOTE: We can't use the previously sent packet if there was a // serial number change.... if ( m_pSerialNumber[entity] == entSerialNumber ) { pSnapshot->m_pPackedData[entity] = handle; ++m_PackedEntities[handle].m_ReferenceCount; return true; } } return false; }
void CBSPTreeData::Init( ISpatialQuery* pBSPTree ) { Assert( pBSPTree ); m_pBSPTree = pBSPTree; m_Handles.EnsureCapacity( 1024 ); m_LeafElements.EnsureCapacity( 1024 ); m_HandleLeafList.EnsureCapacity( 1024 ); // Add all the leaves we'll need int leafCount = m_pBSPTree->LeafCount(); m_Leaf.EnsureCapacity( leafCount ); Leaf_t newLeaf; newLeaf.m_FirstElement = m_LeafElements.InvalidIndex(); while ( --leafCount >= 0 ) { m_Leaf.AddToTail( newLeaf ); } }
PackedEntity* CFrameSnapshotManager::CreatePackedEntity( CFrameSnapshot* pSnapshot, int entity ) { PackedEntityHandle_t handle = m_PackedEntities.AddToTail(); // Referenced twice: in the mru m_PackedEntities[handle].m_ReferenceCount = 2; pSnapshot->m_pPackedData[entity] = handle; // Add a reference into the global list of last entity packets seen... // and remove the reference to the last entity packet we saw if (m_pPackedData[entity] != m_PackedEntities.InvalidIndex()) { if (--m_PackedEntities[ m_pPackedData[entity] ].m_ReferenceCount <= 0) { DestroyPackedEntity( m_pPackedData[entity] ); } } m_pPackedData[entity] = handle; m_pSerialNumber[entity] = pSnapshot->m_Entities[entity].m_nSerialNumber; return &m_PackedEntities[handle]; }
//----------------------------------------------------------------------------- // Enumerate elements in a particular leaf //----------------------------------------------------------------------------- bool CBSPTreeData::EnumerateElementsInLeaf( int leaf, IBSPTreeDataEnumerator* pEnum, int context ) { #ifdef DBGFLAG_ASSERT // The enumeration method better damn well not change this list... int nCount = CountElementsInLeaf(leaf); #endif unsigned short idx = m_Leaf[leaf].m_FirstElement; while (idx != m_LeafElements.InvalidIndex()) { BSPTreeDataHandle_t handle = m_LeafElements[idx]; if (!pEnum->EnumerateElement( m_Handles[handle].m_UserId, context )) { Assert( CountElementsInLeaf(leaf) == nCount ); return false; } idx = m_LeafElements.Next(idx); } Assert( CountElementsInLeaf(leaf) == nCount ); return true; }
//----------------------------------------------------------------------------- // Is the element in any leaves at all? //----------------------------------------------------------------------------- bool CBSPTreeData::IsElementInTree( BSPTreeDataHandle_t handle ) const { return m_Handles[handle].m_LeafList != m_HandleLeafList.InvalidIndex(); }