Пример #1
0
CElement::~CElement ( void )
{
    // Get rid of the children elements
    ClearChildren ();
    SetParentObject ( NULL );

    // Remove ourselves from our element group
    if ( m_pElementGroup )
        m_pElementGroup->Remove ( this );

    // Delete our event manager
    delete m_pCustomData;
    delete m_pEventManager;

    // Unreference us from what's referencing us
    list < CPerPlayerEntity* > ::const_iterator iter = m_ElementReferenced.begin ();
    for ( ; iter != m_ElementReferenced.end (); iter++ )
    {
        if ( !(*iter)->m_ElementReferences.empty() ) (*iter)->m_ElementReferences.remove ( this );
    }

    RemoveAllCollisions ( true );

    // Null all camera elements referencing us
    list < CPlayerCamera* > ::const_iterator iterFollowingCameras = m_FollowingCameras.begin ();
    for ( ; iterFollowingCameras != m_FollowingCameras.end (); iterFollowingCameras++ )
    {
        (*iterFollowingCameras)->m_pTarget = NULL;
    }

    if ( m_pAttachedTo )
        m_pAttachedTo->RemoveAttachedElement ( this );

    list < CElement* > ::iterator iterAttached = m_AttachedElements.begin ();
    for ( ; iterAttached != m_AttachedElements.end () ; iterAttached++ )
    {
        // Make sure our attached element stores it's current position
        (*iterAttached)->GetPosition ();
        // Unlink it
        (*iterAttached)->m_pAttachedTo = NULL;
    }

    list < CPed * > ::iterator iterUsers = m_OriginSourceUsers.begin ();
    for ( ; iterUsers != m_OriginSourceUsers.end () ; iterUsers++ )
    {
        CPed* pPed = *iterUsers;
        if ( pPed->m_pContactElement == this )
            pPed->m_pContactElement = NULL;
    }

    // Deallocate our unique ID
    CElementIDs::PushUniqueID ( this );

    // Remove our reference from the element deleter
    g_pGame->GetElementDeleter ()->Unreference ( this );

    // Ensure nothing has inadvertently set a parent
    assert ( m_pParent == NULL );
}
Пример #2
0
CElement::~CElement ( void )
{
    // Get rid of the children elements
    ClearChildren ();
    SetParentObject ( NULL );

    // Remove ourselves from our element group
    if ( m_pElementGroup )
        m_pElementGroup->Remove ( this );

    // Delete our event manager
    delete m_pCustomData;
    delete m_pEventManager;

    // Unreference us from what's referencing us
    list < CPerPlayerEntity* > ::const_iterator iter = m_ElementReferenced.begin ();
    for ( ; iter != m_ElementReferenced.end (); iter++ )
    {
        (*iter)->m_ElementReferences.remove ( this );
    }

    RemoveAllCollisions ( true );

    // Null all camera elements referencing us
    std::list < CPlayerCamera* > cloneFollowingCameras = m_FollowingCameras;
    for ( std::list < CPlayerCamera* > ::const_iterator iter = cloneFollowingCameras.begin () ; iter != cloneFollowingCameras.end () ; iter++ )
    {
        (*iter)->SetTarget ( NULL );
    }

    if ( m_pAttachedTo )
        m_pAttachedTo->RemoveAttachedElement ( this );

    list < CElement* > ::iterator iterAttached = m_AttachedElements.begin ();
    for ( ; iterAttached != m_AttachedElements.end () ; iterAttached++ )
    {
        // Make sure our attached element stores it's current position
        (*iterAttached)->GetPosition ();
        // Unlink it
        (*iterAttached)->m_pAttachedTo = NULL;
    }

    list < CPed * > ::iterator iterUsers = m_OriginSourceUsers.begin ();
    for ( ; iterUsers != m_OriginSourceUsers.end () ; iterUsers++ )
    {
        CPed* pPed = *iterUsers;
        if ( pPed->m_pContactElement == this )
            pPed->m_pContactElement = NULL;
    }

    // Remove from spatial database
    GetSpatialDatabase ()->RemoveEntity ( this );

    if ( GetID() != INVALID_ELEMENT_ID && GetID() >= MAX_SERVER_ELEMENTS )
        CLogger::ErrorPrintf( "ERROR: Element ID is incorrect (%08x) (Type:%d)\n", GetID().Value(), GetType() );

    // Deallocate our unique ID
    CElementIDs::PushUniqueID ( this );

    // Remove our reference from the element deleter
    g_pGame->GetElementDeleter ()->Unreference ( this );

    // Ensure nothing has inadvertently set a parent
    assert ( m_pParent == NULL );

    CElementRefManager::OnElementDelete ( this );
    SAFE_RELEASE( m_pChildrenListSnapshot );
}