CClientEntity::~CClientEntity() { // Remove collision properties while ( !m_notCollidableWith.empty() ) SetCollidableWith( m_notCollidableWith.front(), true ); // Reset our index in the element array if ( m_ID != INVALID_ELEMENT_ID ) { CElementIDs::SetElement ( m_ID, NULL ); // Got a clientside ID? Push it back on our stack so we don't run out of client id's if ( IsLocalEntity () ) { CElementIDs::PushClientID ( m_ID ); } } if ( m_pAttachedToEntity ) { m_pAttachedToEntity->RemoveAttachedEntity ( this ); } for ( attachments_t::iterator iter = m_AttachedEntities.begin() ; iter != m_AttachedEntities.end(); ++iter ) { CClientEntity* pAttachedEntity = *iter; if ( pAttachedEntity ) { pAttachedEntity->m_pAttachedToEntity = NULL; } } RemoveAllCollisions ( true ); if ( m_pEventManager ) { delete m_pEventManager; m_pEventManager = NULL; } if ( m_pElementGroup ) { m_pElementGroup->Remove ( this ); } list < CClientPed* > ::iterator iterUsers = m_OriginSourceUsers.begin (); for ( ; iterUsers != m_OriginSourceUsers.end () ; iterUsers++ ) { CClientPed* pModel = *iterUsers; if ( pModel->m_interp.pTargetOriginSource == this ) { pModel->m_interp.pTargetOriginSource = NULL; pModel->m_interp.bHadOriginSource = true; } } m_OriginSourceUsers.clear (); // Unlink our contacts list < CClientPed * > ::iterator iterContacts = m_Contacts.begin (); for ( ; iterContacts != m_Contacts.end () ; iterContacts++ ) { CClientPed * pModel = *iterContacts; if ( pModel->GetCurrentContactEntity () == this ) { pModel->SetCurrentContactEntity ( NULL ); } } m_Contacts.clear (); // Remove from spatial database if ( !g_pClientGame->IsBeingDeleted () ) GetClientSpatialDatabase ()->RemoveEntity ( this ); // Ensure intrusive list nodes have been isolated assert ( m_FromRootNode.m_pOuterItem == this && !m_FromRootNode.m_pPrev && !m_FromRootNode.m_pNext ); if ( !g_pClientGame->IsBeingDeleted () ) CClientEntityRefManager::OnEntityDelete ( this ); }
CClientEntity::~CClientEntity ( void ) { #ifdef MTA_DEBUG --iCount; #endif // Make sure we won't get deleted later by the element deleter if we've been requested so if ( m_bBeingDeleted ) { g_pClientGame->GetElementDeleter ()->Unreference ( this ); } // Remove from parent ClearChildren (); SetParent ( NULL ); // Reset our index in the element array if ( m_ID != INVALID_ELEMENT_ID ) { CElementIDs::SetElement ( m_ID, NULL ); // Got a clientside ID? Push it back on our stack so we don't run out of client id's if ( IsLocalEntity () ) { CElementIDs::PushClientID ( m_ID ); } } // Remove our custom data if ( m_pCustomData ) { delete m_pCustomData; } if ( m_pAttachedToEntity ) { m_pAttachedToEntity->RemoveAttachedEntity ( this ); } for ( list < CClientEntity* >::iterator iter = m_AttachedEntities.begin () ; iter != m_AttachedEntities.end () ; ++iter ) { CClientEntity* pAttachedEntity = *iter; if ( pAttachedEntity ) { pAttachedEntity->m_pAttachedToEntity = NULL; } } RemoveAllCollisions ( true ); if ( m_pEventManager ) { delete m_pEventManager; m_pEventManager = NULL; } if ( m_pElementGroup ) { m_pElementGroup->Remove ( this ); } if ( m_OriginSourceUsers.size () > 0 ) { list < CClientPed* > ::iterator iterUsers = m_OriginSourceUsers.begin (); for ( ; iterUsers != m_OriginSourceUsers.end () ; iterUsers++ ) { CClientPed* pModel = *iterUsers; if ( pModel->m_interp.pTargetOriginSource == this ) { pModel->m_interp.pTargetOriginSource = NULL; pModel->m_interp.bHadOriginSource = true; } } m_OriginSourceUsers.clear (); } // Unlink our contacts list < CClientPed * > ::iterator iterContacts = m_Contacts.begin (); for ( ; iterContacts != m_Contacts.end () ; iterContacts++ ) { CClientPed * pModel = *iterContacts; if ( pModel->GetCurrentContactEntity () == this ) { pModel->SetCurrentContactEntity ( NULL ); } } m_Contacts.clear (); // Unlink disabled-collisions while ( !m_DisabledCollisions.empty () ) { CClientEntity * pEntity = m_DisabledCollisions.begin ()->first; SetCollidableWith ( pEntity, true ); } // Ensure not referenced in the disabled collisions list assert ( !MapContains ( g_pClientGame->m_AllDisabledCollisions, this ) ); // Ensure nothing has inadvertently set a parent assert ( m_pParent == NULL ); }
CClientEntity::~CClientEntity ( void ) { // Make sure we won't get deleted later by the element deleter if we've been requested so if ( m_bBeingDeleted ) { g_pClientGame->GetElementDeleter ()->Unreference ( this ); } // Remove from parent ClearChildren (); SetParent ( NULL ); // Reset our index in the element array if ( m_ID != INVALID_ELEMENT_ID ) { CElementIDs::SetElement ( m_ID, NULL ); // Got a clientside ID? Push it back on our stack so we don't run out of client id's if ( IsLocalEntity () ) { CElementIDs::PushClientID ( m_ID ); } } // Remove our custom data if ( m_pCustomData ) { delete m_pCustomData; } // Detach from everything AttachTo( NULL ); while( m_AttachedEntities.size() ) { CClientEntity* pAttachedEntity = m_AttachedEntities.back(); pAttachedEntity->AttachTo( NULL ); } m_bDisallowAttaching = true; assert( !m_pAttachedToEntity && m_AttachedEntities.empty() ); RemoveAllCollisions (); if ( m_pEventManager ) { delete m_pEventManager; m_pEventManager = NULL; } if ( m_pElementGroup ) { m_pElementGroup->Remove ( this ); } if ( m_OriginSourceUsers.size () > 0 ) { list < CClientPed* > ::iterator iterUsers = m_OriginSourceUsers.begin (); for ( ; iterUsers != m_OriginSourceUsers.end () ; iterUsers++ ) { CClientPed* pModel = *iterUsers; if ( pModel->m_interp.pTargetOriginSource == this ) { pModel->m_interp.pTargetOriginSource = NULL; pModel->m_interp.bHadOriginSource = true; } } m_OriginSourceUsers.clear (); } // Unlink our contacts list < CClientPed * > ::iterator iterContacts = m_Contacts.begin (); for ( ; iterContacts != m_Contacts.end () ; iterContacts++ ) { CClientPed * pModel = *iterContacts; if ( pModel->GetCurrentContactEntity () == this ) { pModel->SetCurrentContactEntity ( NULL ); } } m_Contacts.clear (); // Unlink disabled-collisions while ( !m_DisabledCollisions.empty () ) { CClientEntity * pEntity = m_DisabledCollisions.begin ()->first; SetCollidableWith ( pEntity, true ); } // Remove from spatial database if ( !g_pClientGame->IsBeingDeleted () ) GetClientSpatialDatabase ()->RemoveEntity ( this ); // Ensure not referenced in the disabled collisions list assert ( !MapContains ( g_pClientGame->m_AllDisabledCollisions, this ) ); // Ensure nothing has inadvertently set a parent assert ( m_pParent == NULL ); if ( !g_pClientGame->IsBeingDeleted () ) CClientEntityRefManager::OnEntityDelete ( this ); g_pClientGame->GetGameEntityXRefManager ()->OnClientEntityDelete ( this ); SAFE_RELEASE( m_pChildrenListSnapshot ); g_pCore->GetGraphics ()->GetRenderItemManager ()->RemoveClientEntityRefs ( this ); g_pCore->UpdateDummyProgress(); }