コード例 #1
0
ファイル: CCSpriteBatchNode.cpp プロジェクト: 289/DouPo
//override sortAllChildren
void SpriteBatchNode::sortAllChildren()
{
    if (_reorderChildDirty)
    {
        std::sort(std::begin(_children), std::end(_children), nodeComparisonLess);

        //sorted now check all children
        if (!_children.empty())
        {
            //first sort all children recursively based on zOrder
            for(const auto &child: _children) {
                child->sortAllChildren();
            }

            ssize_t index=0;

            //fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
            // and at the same time reorder descendants and the quads to the right index
            for(const auto &child: _children) {
                Sprite* sp = static_cast<Sprite*>(child);
                updateAtlasIndex(sp, &index);
            }
        }

        _reorderChildDirty=false;
    }
}
コード例 #2
0
ファイル: CCSpriteBatchNode.cpp プロジェクト: Ratel13/HXGame
//override sortAllChildren
void SpriteBatchNode::sortAllChildren()
{
    if (_reorderChildDirty)
    {
        int i = 0,j = 0,length = _children->count();

        // insertion sort
        for(i=1; i<length; i++)
        {
            j = i-1;
            auto tempI = static_cast<Node*>( _children->getObjectAtIndex(i) );
            auto tempJ = static_cast<Node*>( _children->getObjectAtIndex(j) );

            //continue moving element downwards while zOrder is smaller or when zOrder is the same but mutatedIndex is smaller
            while(j>=0 && ( tempI->getZOrder() < tempJ->getZOrder() ||
                           ( tempI->getZOrder() == tempJ->getZOrder() &&
                            tempI->getOrderOfArrival() < tempJ->getOrderOfArrival() ) ) )
            {
                _children->fastSetObject( tempJ, j+1 );
                j = j-1;
                if(j>=0)
                    tempJ = static_cast<Node*>( _children->getObjectAtIndex(j) );
            }
            _children->fastSetObject(tempI, j+1);
        }

        //sorted now check all children
        if (_children->count() > 0)
        {
            //first sort all children recursively based on zOrder
            arrayMakeObjectsPerformSelector(_children, sortAllChildren, Sprite*);

            int index=0;

            Object* pObj = NULL;
            //fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
            // and at the same time reorder descendants and the quads to the right index
            CCARRAY_FOREACH(_children, pObj)
            {
                Sprite* child = static_cast<Sprite*>(pObj);
                updateAtlasIndex(child, &index);
            }
        }
コード例 #3
0
ファイル: CABatchView.cpp プロジェクト: Brian1900/CrossApp
void CABatchView::sortAllSubview()
{
    if (m_bReorderChildDirty)
    {
        std::sort(m_obSubviews.begin(), m_obSubviews.end(), compareSubviewZOrder);
        
        if (!m_obSubviews.empty())
        {
            CAVector<CAView*>::iterator itr;
            
            for (itr=m_obSubviews.begin(); itr!=m_obSubviews.end(); itr++)
                if(m_bRunning) (*itr)->sortAllSubviews();
            
            int index=0;
            for (itr=m_obSubviews.begin(); itr!=m_obSubviews.end(); itr++)
                updateAtlasIndex(*itr, &index);
        }
        m_bReorderChildDirty=false;
    }
}
コード例 #4
0
//override sortAllChildren
void CCSpriteBatchNode::sortAllChildren()
{
    if (m_bReorderChildDirty)
    {
        int i = 0,j = 0,length = m_pChildren->data->num;
        CCNode ** x = (CCNode**)m_pChildren->data->arr;
        CCNode *tempItem = NULL;

        //insertion sort
        for(i=1; i<length; i++)
        {
            tempItem = x[i];
            j = i-1;

            //continue moving element downwards while zOrder is smaller or when zOrder is the same but orderOfArrival is smaller
            while(j>=0 && ( tempItem->getZOrder() < x[j]->getZOrder() || ( tempItem->getZOrder() == x[j]->getZOrder() && tempItem->getOrderOfArrival() < x[j]->getOrderOfArrival() ) ) )
            {
                x[j+1] = x[j];
                j--;
            }

            x[j+1] = tempItem;
        }

        //sorted now check all children
        if (m_pChildren->count() > 0)
        {
            //first sort all children recursively based on zOrder
            arrayMakeObjectsPerformSelector(m_pChildren, sortAllChildren, CCSprite*);

            int index=0;

            CCObject* pObj = NULL;
            //fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
            // and at the same time reorder descendants and the quads to the right index
            CCARRAY_FOREACH(m_pChildren, pObj)
            {
                CCSprite* pChild = (CCSprite*)pObj;
                updateAtlasIndex(pChild, &index);
            }
        }
コード例 #5
0
ファイル: CABatchView.cpp プロジェクト: AojiaoZero/CrossApp
void CABatchView::sortAllSubview()
{
    if (m_bReorderChildDirty)
    {
        int i = 0,j = 0,length = m_pSubviews->data->num;
        CAView ** x = (CAView**)m_pSubviews->data->arr;
        CAView *tempItem = NULL;

        for(i=1; i<length; i++)
        {
            tempItem = x[i];
            j = i-1;


            while(j>=0 && ( tempItem->getZOrder() < x[j]->getZOrder() || ( tempItem->getZOrder() == x[j]->getZOrder() && tempItem->getOrderOfArrival() < x[j]->getOrderOfArrival() ) ) )
            {
                x[j+1] = x[j];
                j--;
            }

            x[j+1] = tempItem;
        }

        if (m_pSubviews->count() > 0)
        {
            arrayMakeObjectsPerformSelector(m_pSubviews, sortAllSubviews, CAView*);

            int index=0;

            CAObject* pObj = NULL;
            CCARRAY_FOREACH(m_pSubviews, pObj)
            {
                CAView* pChild = (CAView*)pObj;
                updateAtlasIndex(pChild, &index);
            }
        }
コード例 #6
0
ファイル: CABatchView.cpp プロジェクト: Brian1900/CrossApp
void CABatchView::updateAtlasIndex(CAView* view, int* curIndex)
{
    const CAVector<CAView*> pVector = view->getSubviews();
    unsigned int count = (unsigned int)pVector.size();

    int oldIndex = 0;

    if( count == 0 )
    {
        oldIndex = view->getAtlasIndex();
        view->setAtlasIndex(*curIndex);
        view->setOrderOfArrival(0);
        if (oldIndex != *curIndex)
        {
            swap(oldIndex, *curIndex);
        }
        (*curIndex)++;
    }
    else
    {
        bool needNewIndex = true;

        if (pVector.front()->getZOrder() >= 0)
        {
            oldIndex = view->getAtlasIndex();
            view->setAtlasIndex(*curIndex);
            view->setOrderOfArrival(0);
            if (oldIndex != *curIndex)
            {
                swap(oldIndex, *curIndex);
            }
            (*curIndex)++;
            
            needNewIndex = false;
        }
        
        CAVector<CAView*>::const_iterator itr;
        for (itr=pVector.begin(); itr!=pVector.end(); itr++)
        {
            CAView* subview = *itr;
            if (needNewIndex && subview->getZOrder() >= 0)
            {
                oldIndex = view->getAtlasIndex();
                view->setAtlasIndex(*curIndex);
                view->setOrderOfArrival(0);
                if (oldIndex != *curIndex)
                {
                    this->swap(oldIndex, *curIndex);
                }
                (*curIndex)++;
                needNewIndex = false;
                
            }
            
            updateAtlasIndex(subview, curIndex);
        }

        if (needNewIndex)
        {
            oldIndex = view->getAtlasIndex();
            view->setAtlasIndex(*curIndex);
            view->setOrderOfArrival(0);
            if (oldIndex!=*curIndex)
            {
                swap(oldIndex, *curIndex);
            }
            (*curIndex)++;
        }
    }
}
コード例 #7
0
ファイル: CCSpriteBatchNode.cpp プロジェクト: 289/DouPo
void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, ssize_t* curIndex)
{
    auto& array = sprite->getChildren();
    auto count = array.size();
    
    ssize_t oldIndex = 0;

    if( count == 0 )
    {
        oldIndex = sprite->getAtlasIndex();
        sprite->setAtlasIndex(*curIndex);
        sprite->setOrderOfArrival(0);
        if (oldIndex != *curIndex){
            swap(oldIndex, *curIndex);
        }
        (*curIndex)++;
    }
    else
    {
        bool needNewIndex=true;

        if (array.at(0)->getLocalZOrder() >= 0)
        {
            //all children are in front of the parent
            oldIndex = sprite->getAtlasIndex();
            sprite->setAtlasIndex(*curIndex);
            sprite->setOrderOfArrival(0);
            if (oldIndex != *curIndex)
            {
                swap(oldIndex, *curIndex);
            }
            (*curIndex)++;

            needNewIndex = false;
        }

        for(const auto &child: array) {
            Sprite* sp = static_cast<Sprite*>(child);
            if (needNewIndex && sp->getLocalZOrder() >= 0)
            {
                oldIndex = sprite->getAtlasIndex();
                sprite->setAtlasIndex(*curIndex);
                sprite->setOrderOfArrival(0);
                if (oldIndex != *curIndex) {
                    this->swap(oldIndex, *curIndex);
                }
                (*curIndex)++;
                needNewIndex = false;
            }
            
            updateAtlasIndex(sp, curIndex);
        }

        if (needNewIndex)
        {//all children have a zOrder < 0)
            oldIndex = sprite->getAtlasIndex();
            sprite->setAtlasIndex(*curIndex);
            sprite->setOrderOfArrival(0);
            if (oldIndex != *curIndex) {
                swap(oldIndex, *curIndex);
            }
            (*curIndex)++;
        }
    }
}