From 7d04254855a3413eb6fec27ed47b9d26315047df Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 26 Mar 2012 22:37:09 +0800 Subject: [PATCH] issue #1056: Updated some files. --- .../particle_nodes/CCParticleSystemQuad.cpp | 2 +- cocos2dx/sprite_nodes/CCSprite.cpp | 8 +++---- cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp | 17 ++++++++------ cocos2dx/textures/CCTextureAtlas.cpp | 22 +++++++++++++------ 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp index 614520c976..3e9ca3a23d 100644 --- a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp @@ -304,7 +304,7 @@ void CCParticleSystemQuad::draw() /* FIXME: It will cause crash on some devices if the last parameter is zero. I'm not familiar with opengles, but my change works. --By James Chen. */ - glDrawElements(GL_TRIANGLES, (GLsizei) m_uParticleIdx*6, GL_UNSIGNED_SHORT, 0/*m_pIndices*/ /*0*/); + glDrawElements(GL_TRIANGLES, (GLsizei) m_uParticleIdx*6, GL_UNSIGNED_SHORT, m_pIndices /*0*/); glBindVertexArray( 0 ); diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index be525711d9..ab46d075ea 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -735,11 +735,11 @@ void CCSprite::setReorderChildDirtyRecursively(void) if ( ! m_bReorderChildDirty ) { m_bReorderChildDirty = true; - CCNode* node = (CCNode*) m_pParent; - while (node && node != m_pobBatchNode) + CCNode* pNode = (CCNode*)m_pParent; + while (pNode && pNode != m_pobBatchNode) { - ((CCSprite*)node)->setReorderChildDirtyRecursively(); - node=node->getParent(); + ((CCSprite*)pNode)->setReorderChildDirtyRecursively(); + pNode=pNode->getParent(); } } } diff --git a/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp b/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp index fc614a214f..3ae01380d1 100644 --- a/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp +++ b/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp @@ -292,12 +292,13 @@ void CCSpriteBatchNode::sortAllChildren() void CCSpriteBatchNode::updateAtlasIndex(CCSprite* sprite, int* curIndex) { - CCArray *array = sprite->getChildren(); - if (array == NULL) + unsigned int count = 0; + CCArray* pArray = sprite->getChildren(); + if (pArray != NULL) { - return; + count = pArray->count(); } - unsigned int count = array->count(); + int oldIndex = 0; if( count == 0 ) @@ -314,7 +315,7 @@ void CCSpriteBatchNode::updateAtlasIndex(CCSprite* sprite, int* curIndex) { bool needNewIndex=true; - if (((CCSprite*) (array->data->arr[0]))->getZOrder() >= 0) + if (((CCSprite*) (pArray->data->arr[0]))->getZOrder() >= 0) { //all children are in front of the parent oldIndex = sprite->getAtlasIndex(); @@ -330,7 +331,7 @@ void CCSpriteBatchNode::updateAtlasIndex(CCSprite* sprite, int* curIndex) } CCObject* pObj = NULL; - CCARRAY_FOREACH(array,pObj) + CCARRAY_FOREACH(pArray,pObj) { CCSprite* child = (CCSprite*)pObj; if (needNewIndex && child->getZOrder() >= 0) @@ -355,7 +356,7 @@ void CCSpriteBatchNode::updateAtlasIndex(CCSprite* sprite, int* curIndex) sprite->setAtlasIndex(*curIndex); sprite->setOrderOfArrival(0); if (oldIndex!=*curIndex) { - this->swap(oldIndex, *curIndex); + swap(oldIndex, *curIndex); } (*curIndex)++; } @@ -391,7 +392,9 @@ void CCSpriteBatchNode::draw(void) // Optimization: Fast Dispatch if( m_pobTextureAtlas->getTotalQuads() == 0 ) + { return; + } CC_NODE_DRAW_SETUP(); diff --git a/cocos2dx/textures/CCTextureAtlas.cpp b/cocos2dx/textures/CCTextureAtlas.cpp index 03f24afc2c..5ed1bd3a12 100644 --- a/cocos2dx/textures/CCTextureAtlas.cpp +++ b/cocos2dx/textures/CCTextureAtlas.cpp @@ -303,7 +303,8 @@ void CCTextureAtlas::insertQuad(ccV3F_C4B_T2F_Quad *quad, unsigned int index) unsigned int remaining = (m_uTotalQuads-1) - index; // last object doesn't need to be moved - if( remaining > 0) { + if( remaining > 0) + { // texture coordinates memmove( &m_pQuads[index+1],&m_pQuads[index], sizeof(m_pQuads[0]) * remaining ); } @@ -328,9 +329,10 @@ void CCTextureAtlas::insertQuads(ccV3F_C4B_T2F_Quad* quads, unsigned int index, // last object doesn't need to be moved if( remaining > 0) + { // tex coordinates memmove( &m_pQuads[index+amount],&m_pQuads[index], sizeof(m_pQuads[0]) * remaining ); - + } unsigned int max = index + amount; @@ -351,14 +353,16 @@ void CCTextureAtlas::insertQuadFromIndex(unsigned int oldIndex, unsigned int new CCAssert( oldIndex >= 0 && oldIndex < m_uTotalQuads, "insertQuadFromIndex:atIndex: Invalid index"); if( oldIndex == newIndex ) + { return; - + } // because it is ambigious in iphone, so we implement abs ourself // unsigned int howMany = abs( oldIndex - newIndex); unsigned int howMany = (oldIndex - newIndex) > 0 ? (oldIndex - newIndex) : (newIndex - oldIndex); unsigned int dst = oldIndex; unsigned int src = oldIndex + 1; - if( oldIndex > newIndex) { + if( oldIndex > newIndex) + { dst = newIndex+1; src = newIndex; } @@ -381,7 +385,8 @@ void CCTextureAtlas::removeQuadAtIndex(unsigned int index) // last object doesn't need to be moved - if( remaining ) { + if( remaining ) + { // texture coordinates memmove( &m_pQuads[index],&m_pQuads[index+1], sizeof(m_pQuads[0]) * remaining ); } @@ -402,7 +407,9 @@ void CCTextureAtlas::removeQuadsAtIndex(unsigned int index, unsigned int amount) m_uTotalQuads -= amount; if ( remaining ) + { memmove( &m_pQuads[index], &m_pQuads[index+amount], sizeof(m_pQuads[0]) * remaining ); + } m_bDirty = true; } @@ -416,8 +423,9 @@ void CCTextureAtlas::removeAllQuads() bool CCTextureAtlas::resizeCapacity(unsigned int newCapacity) { if( newCapacity == m_uCapacity ) + { return true; - + } // update capacity and totolQuads m_uTotalQuads = MIN(m_uTotalQuads, newCapacity); m_uCapacity = newCapacity; @@ -562,7 +570,7 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start) #if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP glDrawElements(GL_TRIANGLE_STRIP, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (m_pIndices)/*(start*6*sizeof(m_pIndices[0]))*/ ); #else - glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) 0/*(m_pIndices)*//*(start*6*sizeof(m_pIndices[0]))*/ ); + glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (m_pIndices)/*(start*6*sizeof(m_pIndices[0]))*/ ); #endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP