Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better array #3440

Merged
merged 3 commits into from
Aug 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 18 additions & 26 deletions cocos2dx/base_nodes/CCNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ void Node::detachChild(Node *child, bool doCleanup)
void Node::insertChild(Node* child, int z)
{
_reorderChildDirty = true;
ccArrayAppendObjectWithResize(_children->data, child);
_children->addObject(child);
child->_setZOrder(z);
}

Expand All @@ -713,23 +713,24 @@ void Node::sortAllChildren()
{
if (_reorderChildDirty)
{
int i,j,length = _children->data->num;
Node ** x = (Node**)_children->data->arr;
Node *tempItem;
int i,j,length = _children->count();

// insertion sort
for(i=1; i<length; i++)
{
tempItem = x[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 && ( tempItem->_ZOrder < x[j]->_ZOrder || ( tempItem->_ZOrder== x[j]->_ZOrder && tempItem->_orderOfArrival < x[j]->_orderOfArrival ) ) )
while(j>=0 && ( tempI->_ZOrder < tempJ->_ZOrder || ( tempI->_ZOrder == tempJ->_ZOrder && tempI->_orderOfArrival < tempJ->_orderOfArrival ) ) )
{
x[j+1] = x[j];
_children->fastSetObject( tempJ, j+1 );
j = j-1;
if(j>=0)
tempJ = static_cast<Node*>( _children->getObjectAtIndex(j) );
}
x[j+1] = tempItem;
_children->fastSetObject(tempI, j+1);
}

//don't need to check children recursively, that's done in visit of each child
Expand Down Expand Up @@ -762,39 +763,30 @@ void Node::visit()
}

this->transform();

Node* pNode = NULL;
unsigned int i = 0;

if(_children && _children->count() > 0)
{
sortAllChildren();
// draw children zOrder < 0
ccArray *arrayData = _children->data;
for( ; i < arrayData->num; i++ )
for( ; i < _children->count(); i++ )
{
pNode = (Node*) arrayData->arr[i];
auto node = static_cast<Node*>( _children->getObjectAtIndex(i) );

if ( pNode && pNode->_ZOrder < 0 )
{
pNode->visit();
}
if ( node && node->_ZOrder < 0 )
node->visit();
else
{
break;
}
}
// self draw
this->draw();

for( ; i < arrayData->num; i++ )
for( ; i < _children->count(); i++ )
{
pNode = (Node*) arrayData->arr[i];
if (pNode)
{
pNode->visit();
}
}
auto node = static_cast<Node*>( _children->getObjectAtIndex(i) );
if (node)
node->visit();
}
}
else
{
Expand Down
Loading