Ejemplo n.º 1
0
void CMapEventManager::GetHandles ( CLuaMain* pLuaMain, const char* szName, lua_State* luaVM )
{
    unsigned int uiIndex = 0;
    EventsIterPair itPair = m_EventsMap.equal_range ( szName );
    for ( EventsIter iter = itPair.first ; iter != itPair.second ; ++iter )
    {
        CMapEvent* pMapEvent = iter->second;

        // Is it not being destroyed?
        if ( !pMapEvent->IsBeingDestroyed () )
        {
            // Same lua main?
            if ( pMapEvent->GetVM () == pLuaMain )
            {
                // Same name?
                dassert ( strcmp ( pMapEvent->GetName (), szName ) == 0 );
                {
                    lua_pushnumber ( luaVM, ++uiIndex );
                    lua_getref ( luaVM, pMapEvent->GetLuaFunction ().ToInt() );
                    lua_settable ( luaVM, -3 );
                }
            }
        }
    }
}
Ejemplo n.º 2
0
bool CMapEventManager::HandleExists ( CLuaMain* pLuaMain, const char* szName, const CLuaFunctionRef& iLuaFunction )
{
    // Return true if we find an event which matches the handle
    EventsIterPair itPair = m_EventsMap.equal_range ( szName );
    for ( EventsIter iter = itPair.first ; iter != itPair.second ; ++iter )
    {
        CMapEvent* pMapEvent = iter->second;

        // Is it not being destroyed?
        if ( !pMapEvent->IsBeingDestroyed () )
        {
            // Same lua main?
            if ( pMapEvent->GetVM () == pLuaMain )
            {
                // Same name?
                dassert ( strcmp ( pMapEvent->GetName (), szName ) == 0 );
                {
                    // Same lua function?
                    if ( pMapEvent->GetLuaFunction () == iLuaFunction )
                    {
                        // It exists
                        return true;
                    }
                }
            }
        }
    }

    // Doesn't exist
    return false;
}
Ejemplo n.º 3
0
bool CMapEventManager::HandleExists ( CLuaMain* pLuaMain, const char* szName, int iLuaFunction )
{
    // Return true if we find an event which matches the handle
    list < CMapEvent* > ::const_iterator iter = m_Events.begin ();
    for ( ; iter != m_Events.end (); iter++ )
    {
        CMapEvent* pMapEvent = *iter;

        // Is it not being destroyed?
        if ( !pMapEvent->IsBeingDestroyed () )
        {
            // Same lua main?
            if ( pMapEvent->GetVM () == pLuaMain )
            {
                // Same name?
                if ( strcmp ( pMapEvent->GetName (), szName ) == 0 )
                {
                    // Same lua function?
                    if ( pMapEvent->GetLuaFunction () == iLuaFunction )
                    {
                        // It exists
                        return true;
                    }
                }
            }
        }
    }

    // Doesn't exist
    return false;
}
Ejemplo n.º 4
0
bool CMapEventManager::Delete ( CLuaMain* pLuaMain, const char* szName, const CLuaFunctionRef& iLuaFunction )
{
    // Delete all the events with matching names
    bool bRemovedSomeone = false;

    EventsIter iter = m_EventsMap.begin ();
    while ( iter != m_EventsMap.end () )
    {
        CMapEvent* pMapEvent = iter->second;

        // Matching VM?
        if ( pLuaMain == pMapEvent->GetVM () )
        {
            // If name supplied, check name and function
            if ( !szName || ( ( strcmp ( pMapEvent->GetName (), szName ) == 0 ) && ( pMapEvent->GetLuaFunction () == iLuaFunction ) ) )
            {
                // Not alredy being destroyed?
                if ( !pMapEvent->IsBeingDestroyed () )
                {
                    // Are we in an event handler?
                    if ( m_bIteratingList )
                    {
                        // Put it in the trashcan
                        pMapEvent->SetBeingDestroyed ( true );
                        m_TrashCan.push_back ( pMapEvent );

                        // Remember that we deleted something
                        bRemovedSomeone = true;
                    }
                    else
                    {
                        // Delete the object
                        delete pMapEvent;

                        // Remove from list and remember that we deleted something
                        m_EventsMap.erase ( iter++ );
                        bRemovedSomeone = true;
                        continue;
                    }
                }
            }
        }

        // Increment iterator
        ++iter;
    }

    m_bHasEvents = !m_EventsMap.empty ();

    // Return whether we actually destroyed someone or not
    return bRemovedSomeone;
}
Ejemplo n.º 5
0
bool CMapEventManager::Delete ( CLuaMain* pLuaMain, const char* szName, int iLuaFunction )
{
    // Delete all the events with matching names
    bool bRemovedSomeone = false;
    CMapEvent* pMapEvent = NULL;
    list < CMapEvent* > ::iterator iter = m_Events.begin ();
    while ( iter != m_Events.end () )
    {
        pMapEvent = *iter;

        // Matching VM and name?
        if ( pLuaMain == pMapEvent->GetVM () &&
             strcmp ( pMapEvent->GetName (), szName ) == 0 )
        {
            // Same lua function?
            if ( pMapEvent->GetLuaFunction () == iLuaFunction )
            {
                // Not alredy being destroyed?
                if ( !pMapEvent->IsBeingDestroyed () )
                {
                    // Are we in an event handler?
                    if ( m_bIteratingList )
                    {
                        // Put it in the trashcan
                        pMapEvent->SetBeingDestroyed ( true );
                        m_TrashCan.push_back ( *iter );

                        // Remember that we deleted something
                        bRemovedSomeone = true;
                    }
                    else
                    {
                        // Delete the object
                        delete pMapEvent;

                        // Remove from list and remember that we deleted something
                        iter = m_Events.erase ( iter );
                        bRemovedSomeone = true;
                        continue;
                    }
                }
            }
        }

        // Increment iterator
        iter++;
    }

    // Return whether we actually destroyed someone or not
    return bRemovedSomeone;
}