Ejemplo n.º 1
0
static CCScriptEventListenersForEvent* getListeners(Node* pNode, int evt)
{
    CCScriptEventListenersForEvent *listeners = pNode->getScriptEventDispatcher()->getAllScriptEventListeners();
    if (!listeners) return nullptr;
    long sz = listeners->size();
    if (sz<1) return nullptr;
    CCScriptEventListenersForEvent* pls = new CCScriptEventListenersForEvent(sz);
//    pls->reserve(sz);
    if (!pls) return nullptr;
    
    CCScriptHandlePair *p;
    auto it=listeners->begin();
    for (; it!=listeners->end(); ++it) {
        p = (*it);
        if (p->event==evt) {
            pls->pushBack(*it);
        }
    }

    return pls;
}
void CCScriptEventDispatcher::cleanRemovedEvents()
{
    if (!m_scriptEventListeners) return;

    CCScriptEventListenersForEvent eventsRemoved;
    CCScriptHandlePair *p;
    auto it = m_scriptEventListeners->begin();
    for (; it != m_scriptEventListeners->end(); ++it)
    {
        p = *it;
        if (p->removed)
        {
            eventsRemoved.pushBack(p);
        }
    }
    it = eventsRemoved.begin();
    for (; it!=eventsRemoved.end(); ++it)
    {
        p = *it;
        m_scriptEventListeners->eraseObject(p);
    }
    eventsRemoved.clear();
}