fixed #428, Use CCArray instead of CCMutableArray as the parameter type of CCNode::m_pChildren.

This commit is contained in:
natural-law 2011-04-21 14:46:15 +08:00
parent adbf349116
commit 5d2ac1fc0c
26 changed files with 830 additions and 543 deletions

View File

@ -1 +1 @@
564b1b0ff02bf8c6185be8446b8ea8e156db7f6a
4b1a0a89eeffc4ac07d3adecd95b38b431f8cd5c

View File

@ -73,6 +73,7 @@ sprite_nodes/CCSpriteBatchNode.cpp \
sprite_nodes/CCSpriteFrame.cpp \
sprite_nodes/CCSpriteFrameCache.cpp \
sprite_nodes/CCSpriteSheet.cpp \
support/CCArray.cpp \
support/CCProfiling.cpp \
support/CCPointExtension.cpp \
support/TransformUtils.cpp \

View File

@ -84,17 +84,17 @@ CCNode::~CCNode()
CC_SAFE_RELEASE(m_pGrid);
if(m_pChildren && m_pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for( it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
if (*it)
{
(*it)->m_pParent = NULL;
}
}
CCObject* child;
CCARRAY_FOREACH(m_pChildren, child)
{
CCNode* pChild = (CCNode*) child;
if (pChild)
{
pChild->m_pParent = NULL;
}
}
}
// children
@ -102,21 +102,19 @@ CCNode::~CCNode()
}
void CCNode::arrayMakeObjectsPerformSelector(CCMutableArray<CCNode*> * pArray, callbackFunc func)
void CCNode::arrayMakeObjectsPerformSelector(CCArray* pArray, callbackFunc func)
{
if(pArray && pArray->count() > 0)
{
CCNode* pNode;
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for( it = pArray->begin(); it != pArray->end(); it++)
{
pNode = (*it);
if(pNode && func)
{
(pNode->*func)();
}
}
CCObject* child;
CCARRAY_FOREACH(m_pChildren, child)
{
CCNode* pNode = (CCNode*) child;
if(pNode && func)
{
(pNode->*func)();
}
}
}
}
@ -264,7 +262,7 @@ CCPoint CCNode::getPositionInPixels()
}
/// children getter
CCMutableArray<CCNode*> * CCNode::getChildren()
CCArray* CCNode::getChildren()
{
return m_pChildren;
}
@ -493,7 +491,8 @@ char * CCNode::description()
// lazy allocs
void CCNode::childrenAlloc(void)
{
m_pChildren = new CCMutableArray<CCNode*>(4);
m_pChildren = CCArray::arrayWithCapacity(4);
m_pChildren->retain();
}
CCNode* CCNode::getChildByTag(int aTag)
@ -502,11 +501,10 @@ CCNode* CCNode::getChildByTag(int aTag)
if(m_pChildren && m_pChildren->count() > 0)
{
CCNode* pNode;
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for( it = m_pChildren->begin(); it != m_pChildren->end(); it++)
{
pNode = (*it);
CCObject* child;
CCARRAY_FOREACH(m_pChildren, child)
{
CCNode* pNode = (CCNode*) child;
if(pNode && pNode->m_nTag == aTag)
return pNode;
}
@ -597,11 +595,10 @@ void CCNode::removeAllChildrenWithCleanup(bool cleanup)
// not using detachChild improves speed here
if ( m_pChildren && m_pChildren->count() > 0 )
{
CCNode * pNode;
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for ( it = m_pChildren->begin(); it!= m_pChildren->end(); it++ )
CCObject* child;
CCARRAY_FOREACH(m_pChildren, child)
{
pNode = *it;
CCNode* pNode = (CCNode*) child;
if (pNode)
{
// IMPORTANT:
@ -654,22 +651,20 @@ void CCNode::detachChild(CCNode *child, bool doCleanup)
void CCNode::insertChild(CCNode* child, int z)
{
unsigned int index = 0;
CCNode* a = m_pChildren->getLastObject();
CCNode* a = (CCNode*) m_pChildren->lastObject();
if (!a || a->getZOrder() <= z)
{
m_pChildren->addObject(child);
}
else
{
CCNode* pNode;
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for( it = m_pChildren->begin(); it != m_pChildren->end(); it++)
CCObject* pObject;
CCARRAY_FOREACH(m_pChildren, pObject)
{
pNode = (*it);
if ( pNode && pNode->m_nZOrder > z )
CCNode* pNode = (CCNode*) pObject;
if ( pNode && (pNode->m_nZOrder > z ))
{
m_pChildren->insertObjectAtIndex(child, index);
m_pChildren->insertObject(child, index);
break;
}
index++;
@ -715,15 +710,16 @@ void CCNode::visit()
this->transform();
CCNode* pNode;
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
CCNode* pNode = NULL;
unsigned int i = 0;
if(m_pChildren && m_pChildren->count() > 0)
{
// draw children zOrder < 0
for( it = m_pChildren->begin(); it != m_pChildren->end(); it++)
{
pNode = (*it);
ccArray *arrayData = m_pChildren->data;
for( ; i < arrayData->num; i++ )
{
pNode = (CCNode*) arrayData->arr[i];
if ( pNode && pNode->m_nZOrder < 0 )
{
@ -742,9 +738,10 @@ void CCNode::visit()
// draw children zOrder >= 0
if (m_pChildren && m_pChildren->count() > 0)
{
for ( ; it!=m_pChildren->end(); it++ )
{
pNode = (*it);
ccArray *arrayData = m_pChildren->data;
for( ; i < arrayData->num; i++ )
{
pNode = (CCNode*) arrayData->arr[i];
if (pNode)
{
pNode->visit();

View File

@ -0,0 +1,82 @@
/****************************************************************************
Copyright (c) 2010 Abstraction Works. http://www.abstractionworks.com
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCARRAY_H__
#define __CCARRAY_H__
#include "support/data_support/ccCArray.h"
/** @def CCARRAY_FOREACH
A convience macro to iterate over a CCArray using. It is faster than the "fast enumeration" interface.
@since v0.99.4
*/
#define CCARRAY_FOREACH(__array__, __object__) \
if (__array__ && __array__->data->num > 0) \
for(CCObject** arr = __array__->data->arr, **end = __array__->data->arr + __array__->data->num-1; \
arr <= end && ((__object__ = *arr) != NULL/* || true*/); \
arr++)
namespace cocos2d
{
class CC_DLL CCArray : public CCObject
{
public:
~CCArray();
static CCArray* array();
static CCArray* arrayWithCapacity(unsigned int capacity);
static CCArray* arrayWithArray(CCArray* otherArray);
bool init();
bool initWithCapacity(unsigned int capacity);
bool initWithArray(CCArray* otherArray);
unsigned int count();
unsigned int capacity();
unsigned int indexOfObject(CCObject* object);
CCObject* objectAtIndex(unsigned int index);
CCObject* lastObject();
CCObject* randomObject();
bool containsObject(CCObject* object);
void addObject(CCObject* object);
void addObjectsFromArray(CCArray* otherArray);
void insertObject(CCObject* object, unsigned int index);
void removeLastObject();
void removeObject(CCObject* object);
void removeObjectAtIndex(unsigned int index);
void removeObjectsInArray(CCArray* otherArray);
void removeAllObjects();
void fastRemoveObject(CCObject* object);
void fastRemoveObjectAtIndex(unsigned int index);
public:
ccArray* data;
};
}
#endif // __CCARRAY_H__

View File

@ -29,7 +29,7 @@ THE SOFTWARE.
#include "ccMacros.h"
#include "CCAffineTransform.h"
#include "CCMutableArray.h"
#include "CCArray.h"
#include "selector_protocol.h"
#include "CCGL.h"
@ -140,7 +140,7 @@ namespace cocos2d {
CC_PROPERTY(CCPoint, m_tPosition, Position)
CC_PROPERTY(CCPoint, m_tPositionInPixels, PositionInPixels)
CC_PROPERTY_READONLY(CCMutableArray<CCNode *> *, m_pChildren, Children)
CC_PROPERTY_READONLY(CCArray*, m_pChildren, Children)
/** A CCCamera object that lets you move the node using a gluLookAt
*/
@ -229,7 +229,7 @@ namespace cocos2d {
typedef void (CCNode::*callbackFunc)(void);
void arrayMakeObjectsPerformSelector(CCMutableArray<CCNode*> * pArray, callbackFunc func);
void arrayMakeObjectsPerformSelector(CCArray* pArray, callbackFunc func);
CCPoint convertToWindowSpace(CCPoint nodePoint);

View File

@ -71,7 +71,7 @@ namespace cocos2d
}
}
inline CCMutableArray<CCSprite*>* getDescendants(void) { return m_pobDescendants; }
inline CCArray* getDescendants(void) { return m_pobDescendants; }
/** creates a CCSpriteBatchNode with a texture2d and a default capacity of 29 children.
The capacity will be increased in 33% in runtime if it run out of space.
@ -182,7 +182,7 @@ namespace cocos2d
ccBlendFunc m_blendFunc;
// all descendants: chlidren, gran children, etc...
CCMutableArray<CCSprite*>* m_pobDescendants;
CCArray* m_pobDescendants;
};
}

View File

@ -542,12 +542,15 @@ namespace cocos2d{
if (m_pChildren && m_pChildren->count() != 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for(it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
(*it)->setIsVisible(false);
}
}
CCObject* child;
CCARRAY_FOREACH(m_pChildren, child)
{
CCNode* pNode = (CCNode*) child;
if (pNode)
{
pNode->setIsVisible(false);
}
} }
this->createFontChars();
}
@ -567,12 +570,15 @@ namespace cocos2d{
m_tColor = var;
if (m_pChildren && m_pChildren->count() != 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for(it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
((CCSprite*)(*it))->setColor(m_tColor);
}
}
CCObject* child;
CCARRAY_FOREACH(m_pChildren, child)
{
CCSprite* pNode = (CCSprite*) child;
if (pNode)
{
pNode->setColor(m_tColor);
}
} }
}
ccColor3B CCLabelBMFont::getColor()
{
@ -584,16 +590,19 @@ namespace cocos2d{
if (m_pChildren && m_pChildren->count() != 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for(it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
CCRGBAProtocol *pRGBAProtocol = (*it)->convertToRGBAProtocol();
if (pRGBAProtocol)
{
pRGBAProtocol->setOpacity(m_cOpacity);
}
}
}
CCObject* child;
CCARRAY_FOREACH(m_pChildren, child)
{
CCNode* pNode = (CCNode*) child;
if (pNode)
{
CCRGBAProtocol *pRGBAProtocol = pNode->convertToRGBAProtocol();
if (pRGBAProtocol)
{
pRGBAProtocol->setOpacity(m_cOpacity);
}
}
} }
}
GLubyte CCLabelBMFont::getOpacity()
{
@ -604,16 +613,19 @@ namespace cocos2d{
m_bIsOpacityModifyRGB = var;
if (m_pChildren && m_pChildren->count() != 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for(it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
CCRGBAProtocol *pRGBAProtocol = (*it)->convertToRGBAProtocol();
if (pRGBAProtocol)
{
pRGBAProtocol->setIsOpacityModifyRGB(m_bIsOpacityModifyRGB);
}
}
}
CCObject* child;
CCARRAY_FOREACH(m_pChildren, child)
{
CCNode* pNode = (CCNode*) child;
if (pNode)
{
CCRGBAProtocol *pRGBAProtocol = pNode->convertToRGBAProtocol();
if (pRGBAProtocol)
{
pRGBAProtocol->setIsOpacityModifyRGB(m_bIsOpacityModifyRGB);
}
}
} }
}
bool CCLabelBMFont::getIsOpacityModifyRGB()
{

View File

@ -220,32 +220,30 @@ namespace cocos2d{
float height = -padding;
if (m_pChildren && m_pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
if (!(*it))
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pChild = (CCNode*) pObject;
if (pChild)
{
break;
height += pChild->getContentSize().height * pChild->getScaleY() + padding;
}
height += (*it)->getContentSize().height * (*it)->getScaleY() + padding;
}
}
}
float y = height / 2.0f;
if (m_pChildren && m_pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
if (!(*it))
{
break;
}
(*it)->setPosition(ccp(0, y - (*it)->getContentSize().height * (*it)->getScaleY() / 2.0f));
y -= (*it)->getContentSize().height * (*it)->getScaleY() + padding;
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pChild = (CCNode*) pObject;
if (pChild)
{
pChild->setPosition(ccp(0, y - pChild->getContentSize().height * pChild->getScaleY() / 2.0f));
y -= pChild->getContentSize().height * pChild->getScaleY() + padding;
}
}
}
}
@ -260,32 +258,30 @@ namespace cocos2d{
float width = -padding;
if (m_pChildren && m_pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
if (!(*it))
{
break;
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pChild = (CCNode*) pObject;
if (pChild)
{
width += pChild->getContentSize().width * pChild->getScaleX() + padding;
}
width += (*it)->getContentSize().width * (*it)->getScaleX() + padding;
}
}
}
float x = -width / 2.0f;
if (m_pChildren && m_pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
if (!(*it))
{
break;
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pChild = (CCNode*) pObject;
if (pChild)
{
pChild->setPosition(ccp(x + pChild->getContentSize().width * pChild->getScaleX() / 2.0f, 0));
x += pChild->getContentSize().width * pChild->getScaleX() + padding;
}
(*it)->setPosition(ccp(x + (*it)->getContentSize().width * (*it)->getScaleX() / 2.0f, 0));
x += (*it)->getContentSize().width * (*it)->getScaleX() + padding;
}
}
}
}
@ -316,34 +312,32 @@ namespace cocos2d{
if (m_pChildren && m_pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
// if it has no value, break
if (! *it)
{
break;
}
assert(row < rows.size());
rowColumns = rows[row];
// can not have zero columns on a row
assert(rowColumns);
float tmp = (*it)->getContentSize().height;
rowHeight = (unsigned int)((rowHeight >= tmp || isnan(tmp)) ? rowHeight : tmp);
++columnsOccupied;
if (columnsOccupied >= rowColumns)
{
height += rowHeight + 5;
columnsOccupied = 0;
rowHeight = 0;
++row;
}
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pChild = (CCNode*) pObject;
if (pChild)
{
assert(row < rows.size());
rowColumns = rows[row];
// can not have zero columns on a row
assert(rowColumns);
float tmp = pChild->getContentSize().height;
rowHeight = (unsigned int)((rowHeight >= tmp || isnan(tmp)) ? rowHeight : tmp);
++columnsOccupied;
if (columnsOccupied >= rowColumns)
{
height += rowHeight + 5;
columnsOccupied = 0;
rowHeight = 0;
++row;
}
}
}
}
// check if too many rows/columns for available menu items
@ -360,40 +354,39 @@ namespace cocos2d{
if (m_pChildren && m_pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
if (! *it)
{
break;
}
if (rowColumns == 0)
{
rowColumns = rows[row];
w = winSize.width / (1 + rowColumns);
x = w;
}
float tmp = (*it)->getContentSize().height;
rowHeight = (unsigned int)((rowHeight >= tmp || isnan(tmp)) ? rowHeight : tmp);
(*it)->setPosition(ccp(x - winSize.width / 2,
y - (*it)->getContentSize().height / 2));
x += w + 10;
++columnsOccupied;
if (columnsOccupied >= rowColumns)
{
y -= rowHeight + 5;
columnsOccupied = 0;
rowColumns = 0;
rowHeight = 0;
++row;
}
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pChild = (CCNode*) pObject;
if (pChild)
{
if (rowColumns == 0)
{
rowColumns = rows[row];
w = winSize.width / (1 + rowColumns);
x = w;
}
float tmp = pChild->getContentSize().height;
rowHeight = (unsigned int)((rowHeight >= tmp || isnan(tmp)) ? rowHeight : tmp);
pChild->setPosition(ccp(x - winSize.width / 2,
y - pChild->getContentSize().height / 2));
x += w + 10;
++columnsOccupied;
if (columnsOccupied >= rowColumns)
{
y -= rowHeight + 5;
columnsOccupied = 0;
rowColumns = 0;
rowHeight = 0;
++row;
}
}
}
}
}
@ -428,40 +421,39 @@ namespace cocos2d{
if (m_pChildren && m_pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
if (! *it)
{
break;
}
// check if too many menu items for the amount of rows/columns
assert(column < columns.size());
columnRows = columns[column];
// can't have zero rows on a column
assert(columnRows);
// columnWidth = fmaxf(columnWidth, [item contentSize].width);
float tmp = (*it)->getContentSize().width;
columnWidth = (unsigned int)((columnWidth >= tmp || isnan(tmp)) ? columnWidth : tmp);
columnHeight += (int)((*it)->getContentSize().height + 5);
++rowsOccupied;
if (rowsOccupied >= columnRows)
{
columnWidths.push_back(columnWidth);
columnHeights.push_back(columnHeight);
width += columnWidth + 10;
rowsOccupied = 0;
columnWidth = 0;
columnHeight = -5;
++column;
}
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pChild = (CCNode*) pObject;
if (pChild)
{
// check if too many menu items for the amount of rows/columns
assert(column < columns.size());
columnRows = columns[column];
// can't have zero rows on a column
assert(columnRows);
// columnWidth = fmaxf(columnWidth, [item contentSize].width);
float tmp = pChild->getContentSize().width;
columnWidth = (unsigned int)((columnWidth >= tmp || isnan(tmp)) ? columnWidth : tmp);
columnHeight += (int)(pChild->getContentSize().height + 5);
++rowsOccupied;
if (rowsOccupied >= columnRows)
{
columnWidths.push_back(columnWidth);
columnHeights.push_back(columnHeight);
width += columnWidth + 10;
rowsOccupied = 0;
columnWidth = 0;
columnHeight = -5;
++column;
}
}
}
}
// check if too many rows/columns for available menu items.
@ -477,39 +469,38 @@ namespace cocos2d{
if (m_pChildren && m_pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
if (! *it)
{
break;
}
if (columnRows == 0)
{
columnRows = columns[column];
y = (float) columnHeights[column];
}
// columnWidth = fmaxf(columnWidth, [item contentSize].width);
float tmp = (*it)->getContentSize().width;
columnWidth = (unsigned int)((columnWidth >= tmp || isnan(tmp)) ? columnWidth : tmp);
(*it)->setPosition(ccp(x + columnWidths[column] / 2,
y - winSize.height / 2));
y -= (*it)->getContentSize().height + 10;
++rowsOccupied;
if (rowsOccupied >= columnRows)
{
x += columnWidth + 5;
rowsOccupied = 0;
columnRows = 0;
columnWidth = 0;
++column;
}
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pChild = (CCNode*) pObject;
if (pChild)
{
if (columnRows == 0)
{
columnRows = columns[column];
y = (float) columnHeights[column];
}
// columnWidth = fmaxf(columnWidth, [item contentSize].width);
float tmp = pChild->getContentSize().width;
columnWidth = (unsigned int)((columnWidth >= tmp || isnan(tmp)) ? columnWidth : tmp);
pChild->setPosition(ccp(x + columnWidths[column] / 2,
y - winSize.height / 2));
y -= pChild->getContentSize().height + 10;
++rowsOccupied;
if (rowsOccupied >= columnRows)
{
x += columnWidth + 5;
rowsOccupied = 0;
columnRows = 0;
columnWidth = 0;
++column;
}
}
}
}
}
@ -522,20 +513,19 @@ namespace cocos2d{
if (m_pChildren && m_pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
if (! *it)
{
break;
}
CCRGBAProtocol *pRGBAProtocol = (*it)->convertToRGBAProtocol();
if (pRGBAProtocol)
{
pRGBAProtocol->setOpacity(m_cOpacity);
}
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pChild = (CCNode*) pObject;
if (pChild)
{
CCRGBAProtocol *pRGBAProtocol = pChild->convertToRGBAProtocol();
if (pRGBAProtocol)
{
pRGBAProtocol->setOpacity(m_cOpacity);
}
}
}
}
}
@ -550,20 +540,19 @@ namespace cocos2d{
if (m_pChildren && m_pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
if (! *it)
{
break;
}
CCRGBAProtocol *pRGBAProtocol = (*it)->convertToRGBAProtocol();
if (pRGBAProtocol)
{
pRGBAProtocol->setColor(m_tColor);
}
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pChild = (CCNode*) pObject;
if (pChild)
{
CCRGBAProtocol *pRGBAProtocol = pChild->convertToRGBAProtocol();
if (pRGBAProtocol)
{
pRGBAProtocol->setColor(m_tColor);
}
}
}
}
}
@ -579,28 +568,22 @@ namespace cocos2d{
if (m_pChildren && m_pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
if (! *it)
{
break;
}
// ignore invisible and disabled items: issue #779, #866
if ((*it)->getIsVisible() && ((CCMenuItem*)(*it))->getIsEnabled())
{
CCPoint local = (*it)->convertToNodeSpace(touchLocation);
CCRect r = ((CCMenuItem*)(*it))->rect();
r.origin = CCPointZero;
if (CCRect::CCRectContainsPoint(r, local))
{
return (CCMenuItem*)(*it);
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pChild = (CCNode*) pObject;
if (pChild && pChild->getIsVisible() && ((CCMenuItem*)pChild)->getIsEnabled())
{
CCPoint local = pChild->convertToNodeSpace(touchLocation);
CCRect r = ((CCMenuItem*)pChild)->rect();
r.origin = CCPointZero;
if (CCRect::CCRectContainsPoint(r, local))
{
return (CCMenuItem*)pChild;
}
}
}
}
}
}

View File

@ -375,6 +375,10 @@
RelativePath="..\include\CCApplication.h"
>
</File>
<File
RelativePath="..\include\CCArray.h"
>
</File>
<File
RelativePath="..\include\CCAtlasNode.h"
>
@ -879,6 +883,10 @@
RelativePath="..\support\base64.h"
>
</File>
<File
RelativePath="..\support\CCArray.cpp"
>
</File>
<File
RelativePath="..\support\CCPointExtension.cpp"
>

View File

@ -101,6 +101,7 @@ OBJECTS = \
$(OBJECTS_DIR)/CCSpriteFrameCache.o \
$(OBJECTS_DIR)/CCSpriteSheet.o \
$(OBJECTS_DIR)/base64.o \
$(OBJECTS_DIR)/CCArray.o \
$(OBJECTS_DIR)/CCPointExtension.o \
$(OBJECTS_DIR)/CCProfiling.o \
$(OBJECTS_DIR)/ccUtils.o \
@ -345,6 +346,9 @@ $(OBJECTS_DIR)/CCSpriteSheet.o : ../sprite_nodes/CCSpriteSheet.cpp
$(OBJECTS_DIR)/base64.o : ../support/base64.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/base64.o ../support/base64.cpp
$(OBJECTS_DIR)/CCArray.o : ../support/CCArray.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCArray.o ../support/CCArray.cpp
$(OBJECTS_DIR)/CCPointExtension.o : ../support/CCPointExtension.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCPointExtension.o ../support/CCPointExtension.cpp

View File

@ -336,6 +336,10 @@
RelativePath="..\include\CCApplication.h"
>
</File>
<File
RelativePath="..\include\CCArray.h"
>
</File>
<File
RelativePath="..\include\CCAtlasNode.h"
>
@ -720,6 +724,10 @@
RelativePath="..\support\base64.h"
>
</File>
<File
RelativePath="..\support\CCArray.cpp"
>
</File>
<File
RelativePath="..\support\CCPointExtension.cpp"
>

View File

@ -766,14 +766,15 @@ void CCSprite::removeAllChildrenWithCleanup(bool bCleanup)
{
if (m_bUsesBatchNode)
{
CCSprite *pChild;
CCMutableArray<CCNode*>::CCMutableArrayIterator iter;
for (iter = m_pChildren->begin(); iter != m_pChildren->end(); ++iter)
{
pChild = (CCSprite*)(*iter);
CC_BREAK_IF(! pChild);
m_pobBatchNode->removeSpriteFromAtlas(pChild);
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
m_pobBatchNode->removeSpriteFromAtlas(pChild);
}
}
}
CCNode::removeAllChildrenWithCleanup(bCleanup);
@ -792,14 +793,15 @@ void CCSprite::setDirtyRecursively(bool bValue)
// recursively set dirty
if (m_bHasChildren)
{
CCSprite *pChild;
CCMutableArray<CCNode*>::CCMutableArrayIterator iter;
for (iter = m_pChildren->begin(); iter != m_pChildren->end(); ++iter)
{
pChild = (CCSprite*)(*iter);
CC_BREAK_IF(! pChild);
pChild->setDirtyRecursively(true);
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
pChild->setDirtyRecursively(true);
}
}
}
}

View File

@ -110,8 +110,10 @@ namespace cocos2d
updateBlendFunc();
// no lazy alloc in this node
m_pChildren = new CCMutableArray<CCNode*>();
m_pobDescendants = new CCMutableArray<CCSprite*>();
m_pChildren = CCArray::array();
m_pobDescendants = CCArray::array();
m_pChildren->retain();
m_pobDescendants->retain();
return true;
}
@ -249,7 +251,7 @@ namespace cocos2d
void CCSpriteBatchNode::removeChildAtIndex(unsigned int uIndex, bool bDoCleanup)
{
removeChild((CCSprite*)(m_pChildren->getObjectAtIndex(uIndex)), bDoCleanup);
removeChild((CCSprite*)(m_pChildren->objectAtIndex(uIndex)), bDoCleanup);
}
void CCSpriteBatchNode::removeAllChildrenWithCleanup(bool bCleanup)
@ -257,19 +259,15 @@ namespace cocos2d
// Invalidate atlas index. issue #569
if (m_pChildren && m_pChildren->count() > 0)
{
CCSprite *pSprite;
CCMutableArray<CCNode*>::CCMutableArrayIterator iter;
for (iter = m_pChildren->begin(); iter != m_pChildren->end(); ++iter)
{
pSprite = (CCSprite*)(*iter);
if (! pSprite)
{
break;
}
pSprite->useSelfRender();
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
pChild->useSelfRender();
}
}
}
CCNode::removeAllChildrenWithCleanup(bCleanup);
@ -289,33 +287,29 @@ namespace cocos2d
if (m_pobDescendants && m_pobDescendants->count() > 0)
{
CCSprite *pSprite;
CCMutableArray<CCSprite*>::CCMutableArrayIterator iter;
for (iter = m_pobDescendants->begin(); iter != m_pobDescendants->end(); ++iter)
{
pSprite = *iter;
if (! pSprite)
{
break;
}
// fast dispatch
pSprite->updateTransform();
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
// fast dispatch
pChild->updateTransform();
#if CC_SPRITEBATCHNODE_DEBUG_DRAW
// issue #528
CCRect rect = pSprite->boundingBox();
CCPoint vertices[4]={
ccp(rect.origin.x,rect.origin.y),
ccp(rect.origin.x+rect.size.width,rect.origin.y),
ccp(rect.origin.x+rect.size.width,rect.origin.y+rect.size.height),
ccp(rect.origin.x,rect.origin.y+rect.size.height),
};
ccDrawPoly(vertices, 4, true);
// issue #528
CCRect rect = pChild->boundingBox();
CCPoint vertices[4]={
ccp(rect.origin.x,rect.origin.y),
ccp(rect.origin.x+rect.size.width,rect.origin.y),
ccp(rect.origin.x+rect.size.width,rect.origin.y+rect.size.height),
ccp(rect.origin.x,rect.origin.y+rect.size.height),
};
ccDrawPoly(vertices, 4, true);
#endif // CC_SPRITEBATCHNODE_DEBUG_DRAW
}
}
}
}
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
@ -354,26 +348,19 @@ namespace cocos2d
unsigned int CCSpriteBatchNode::rebuildIndexInOrder(CCSprite *pobParent, unsigned int uIndex)
{
CCMutableArray<CCNode*> *pChildren = pobParent->getChildren();
CCArray *pChildren = pobParent->getChildren();
if (pChildren && pChildren->count() > 0)
{
CCSprite *pSprite;
CCMutableArray<CCNode*>::CCMutableArrayIterator iter;
for (iter = pChildren->begin(); iter != pChildren->end(); ++iter)
{
pSprite = (CCSprite*)(*iter);
if (! pSprite)
{
break;
}
if (pSprite->getZOrder() < 0)
{
uIndex = rebuildIndexInOrder(pSprite, uIndex);
}
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild && (pChild->getZOrder() < 0))
{
uIndex = rebuildIndexInOrder(pChild, uIndex);
}
}
}
// ignore self (batch node)
@ -385,22 +372,15 @@ namespace cocos2d
if (pChildren && pChildren->count() > 0)
{
CCSprite *pSprite;
CCMutableArray<CCNode*>::CCMutableArrayIterator iter;
for (iter = pChildren->begin(); iter != pChildren->end(); ++iter)
{
pSprite = (CCSprite*)(*iter);
if (! pSprite)
{
break;
}
if (pSprite->getZOrder() >= 0)
{
uIndex = rebuildIndexInOrder(pSprite, uIndex);
}
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild && (pChild->getZOrder() >= 0))
{
uIndex = rebuildIndexInOrder(pChild, uIndex);
}
}
}
return uIndex;
@ -408,7 +388,7 @@ namespace cocos2d
unsigned int CCSpriteBatchNode::highestAtlasIndexInChild(CCSprite *pSprite)
{
CCMutableArray<CCNode*> *pChildren = pSprite->getChildren();
CCArray *pChildren = pSprite->getChildren();
if (! pChildren || pChildren->count() == 0)
{
@ -416,13 +396,13 @@ namespace cocos2d
}
else
{
return highestAtlasIndexInChild((CCSprite*)(pChildren->getLastObject()));
return highestAtlasIndexInChild((CCSprite*)(pChildren->lastObject()));
}
}
unsigned int CCSpriteBatchNode::lowestAtlasIndexInChild(CCSprite *pSprite)
{
CCMutableArray<CCNode*> *pChildren = pSprite->getChildren();
CCArray *pChildren = pSprite->getChildren();
if (! pChildren || pChildren->count() == 0)
{
@ -430,21 +410,21 @@ namespace cocos2d
}
else
{
return lowestAtlasIndexInChild((CCSprite*)(pChildren->getObjectAtIndex(0)));
return lowestAtlasIndexInChild((CCSprite*)(pChildren->objectAtIndex(0)));
}
}
unsigned int CCSpriteBatchNode::atlasIndexForChild(CCSprite *pobSprite, int nZ)
{
CCMutableArray<CCNode*> *pBrothers = pobSprite->getParent()->getChildren();
unsigned int uChildIndex = pBrothers->getIndexOfObject(pobSprite);
CCArray *pBrothers = pobSprite->getParent()->getChildren();
unsigned int uChildIndex = pBrothers->indexOfObject(pobSprite);
// ignore parent Z if parent is spriteSheet
bool bIgnoreParent = (CCSpriteBatchNode*)(pobSprite->getParent()) == this;
CCSprite *pPrevious = NULL;
if (uChildIndex > 0)
{
pPrevious = (CCSprite*)(pBrothers->getObjectAtIndex(uChildIndex - 1));
pPrevious = (CCSprite*)(pBrothers->objectAtIndex(uChildIndex - 1));
}
// first child of the sprite sheet
@ -509,47 +489,42 @@ namespace cocos2d
ccV3F_C4B_T2F_Quad quad = pobSprite->getQuad();
m_pobTextureAtlas->insertQuad(&quad, uIndex);
m_pobDescendants->insertObjectAtIndex(pobSprite, uIndex);
m_pobDescendants->insertObject(pobSprite, uIndex);
// update indices
unsigned int i = 0;
if (m_pobDescendants && m_pobDescendants->count() > 0)
{
CCMutableArray<CCSprite*>::CCMutableArrayIterator iter;
for (iter = m_pobDescendants->begin(); iter != m_pobDescendants->end(); ++iter)
{
if (! *iter)
{
break;
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
if (i > uIndex)
{
pChild->setAtlasIndex(pChild->getAtlasIndex() + 1);
}
if (i > uIndex)
{
(*iter)->setAtlasIndex((*iter)->getAtlasIndex() + 1);
}
++i;
}
++i;
}
}
}
// add children recursively
CCMutableArray<CCNode*> *pChildren = pobSprite->getChildren();
CCArray *pChildren = pobSprite->getChildren();
if (pChildren && pChildren->count() > 0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator iterNode;
CCSprite *pSprite;
for (iterNode = pChildren->begin(); iterNode != pChildren->end(); ++iterNode)
{
pSprite = (CCSprite*)(*iterNode);
if (! pSprite)
{
break;
}
unsigned int uIndex = atlasIndexForChild(pSprite, pSprite->getZOrder());
insertChild(pSprite, uIndex);
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
unsigned int uIndex = atlasIndexForChild(pChild, pChild->getZOrder());
insertChild(pChild, uIndex);
}
}
}
}
@ -561,7 +536,7 @@ namespace cocos2d
// Cleanup sprite. It might be reused (issue #569)
pobSprite->useSelfRender();
unsigned int uIndex = m_pobDescendants->getIndexOfObject(pobSprite);
unsigned int uIndex = m_pobDescendants->indexOfObject(pobSprite);
if (uIndex != -1)
{
m_pobDescendants->removeObjectAtIndex(uIndex);
@ -571,28 +546,24 @@ namespace cocos2d
for(; uIndex < count; ++uIndex)
{
CCSprite* s = (CCSprite*)(m_pobDescendants->getObjectAtIndex(uIndex));
CCSprite* s = (CCSprite*)(m_pobDescendants->objectAtIndex(uIndex));
s->setAtlasIndex( s->getAtlasIndex() - 1 );
}
}
// remove children recursively
CCMutableArray<CCNode*> *pChildren = pobSprite->getChildren();
CCArray *pChildren = pobSprite->getChildren();
if (pChildren && pChildren->count() > 0)
{
CCSprite *pSprite;
CCMutableArray<CCNode*>::CCMutableArrayIterator iter;
for (iter = pChildren->begin(); iter != pChildren->end(); ++iter)
{
pSprite = (CCSprite*)(*iter);
if (! pSprite)
{
break;
}
removeSpriteFromAtlas(pSprite);
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
removeSpriteFromAtlas(pChild);
}
}
}
}
@ -667,18 +638,17 @@ namespace cocos2d
int i=0;
if (m_pobDescendants && m_pobDescendants->count() > 0)
{
CCMutableArray<CCSprite*>::CCMutableArrayIterator iter;
for (iter = m_pobDescendants->begin(); iter != m_pobDescendants->end(); ++iter)
{
// fast dispatch
if (!(*iter) || (*iter)->getAtlasIndex() >=z)
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild && (pChild->getAtlasIndex() >= z))
{
break;
++i;
}
++i;
}
}
m_pobDescendants->insertObjectAtIndex(child, i);
m_pobDescendants->insertObject(child, i);
// IMPORTANT: Call super, and not self. Avoid adding it to the texture atlas array
CCNode::addChild(child, z, aTag);

View File

@ -0,0 +1,202 @@
/****************************************************************************
Copyright (c) 2010 Abstraction Works. http://www.abstractionworks.com
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCArray.h"
namespace cocos2d
{
CCArray* CCArray::array()
{
CCArray* pArray = new CCArray();
if (pArray && pArray->init())
{
pArray->autorelease();
}
else
{
CC_SAFE_DELETE(pArray);
}
return pArray;
}
CCArray* CCArray::arrayWithCapacity(unsigned int capacity)
{
CCArray* pArray = new CCArray();
if (pArray && pArray->initWithCapacity(capacity))
{
pArray->autorelease();
}
else
{
CC_SAFE_DELETE(pArray);
}
return pArray;
}
CCArray* CCArray::arrayWithArray(CCArray* otherArray)
{
CCArray* pArray = new CCArray();
if (pArray && pArray->initWithArray(otherArray))
{
pArray->autorelease();
}
else
{
CC_SAFE_DELETE(pArray);
}
return pArray;
}
bool CCArray::init()
{
return initWithCapacity(1);
}
bool CCArray::initWithCapacity(unsigned int capacity)
{
data = ccArrayNew(capacity);
return true;
}
bool CCArray::initWithArray(CCArray* otherArray)
{
bool bRet = false;
do
{
CC_BREAK_IF(! initWithCapacity(otherArray->data->num));
addObjectsFromArray(otherArray);
bRet = true;
} while (0);
return bRet;
}
unsigned int CCArray::count()
{
return data->num;
}
unsigned int CCArray::capacity()
{
return data->max;
}
unsigned int CCArray::indexOfObject(CCObject* object)
{
return ccArrayGetIndexOfObject(data, object);
}
CCObject* CCArray::objectAtIndex(unsigned int index)
{
CCAssert(index < data->num, "index out of range in objectAtIndex()");
return data->arr[index];
}
CCObject* CCArray::lastObject()
{
if( data->num > 0 )
return data->arr[data->num-1];
return NULL;
}
CCObject* CCArray::randomObject()
{
if(data->num==0) return NULL;
return data->arr[(int)(data->num*CCRANDOM_0_1())];
}
bool CCArray::containsObject(CCObject* object)
{
return ccArrayContainsObject(data, object);
}
void CCArray::addObject(CCObject* object)
{
ccArrayAppendObjectWithResize(data, object);
}
void CCArray::addObjectsFromArray(CCArray* otherArray)
{
ccArrayAppendArrayWithResize(data, otherArray->data);
}
void CCArray::insertObject(CCObject* object, unsigned int index)
{
ccArrayInsertObjectAtIndex(data, object, index);
}
void CCArray::removeLastObject()
{
CCAssert(data->num, "no objects added");
ccArrayRemoveObjectAtIndex(data, data->num-1);
}
void CCArray::removeObject(CCObject* object)
{
ccArrayRemoveObject(data, object);
}
void CCArray::removeObjectAtIndex(unsigned int index)
{
ccArrayRemoveObjectAtIndex(data, index);
}
void CCArray::removeObjectsInArray(CCArray* otherArray)
{
ccArrayRemoveArray(data, otherArray->data);
}
void CCArray::removeAllObjects()
{
ccArrayRemoveAllObjects(data);
}
void CCArray::fastRemoveObjectAtIndex(unsigned int index)
{
ccArrayFastRemoveObjectAtIndex(data, index);
}
void CCArray::fastRemoveObject(CCObject* object)
{
ccArrayFastRemoveObject(data, object);
}
CCArray::~CCArray()
{
ccArrayFree(data);
}
}

View File

@ -41,8 +41,8 @@ THE SOFTWARE.
#include <stdlib.h>
#include <string.h>
#include "CCMutableArray.h"
#include "CCObject.h"
#include "ccMacros.h"
namespace cocos2d {
@ -158,6 +158,21 @@ static inline void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr)
ccArrayAppendArray(arr, plusArr);
}
static inline void ccArrayInsertObjectAtIndex(ccArray *arr, CCObject* object, unsigned int index)
{
CCAssert(index<=arr->num, "Invalid index. Out of bounds");
ccArrayEnsureExtraCapacity(arr, 1);
int remaining = arr->num - index;
if( remaining > 0)
memmove(&arr->arr[index+1], &arr->arr[index], sizeof(CCObject*) * remaining );
object->retain();
arr->arr[index] = object;
arr->num++;
}
/** Removes all objects from arr */
static inline void ccArrayRemoveAllObjects(ccArray *arr)
{
@ -192,6 +207,13 @@ static inline void ccArrayFastRemoveObjectAtIndex(ccArray *arr, unsigned int ind
arr->arr[index] = arr->arr[last];
}
static inline void ccArrayFastRemoveObject(ccArray *arr, CCObject* object)
{
unsigned int index = ccArrayGetIndexOfObject(arr, object);
if (index != -1)
ccArrayFastRemoveObjectAtIndex(arr, index);
}
/** Searches for the first occurance of object and removes it. If object is not
found the function has no effect. */
static inline void ccArrayRemoveObject(ccArray *arr, CCObject* object)

View File

@ -291,20 +291,19 @@ namespace cocos2d {
// update possible children
if (m_pChildren && m_pChildren->count()>0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
CCSprite *pSprite = NULL;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
pSprite = (CCSprite*)(*it);
if (pSprite)
{
unsigned int ai = pSprite->getAtlasIndex();
if ( ai >= indexForZ )
{
pSprite->setAtlasIndex(ai+1);
}
}
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
unsigned int ai = pChild->getAtlasIndex();
if ( ai >= indexForZ )
{
pChild->setAtlasIndex(ai+1);
}
}
}
}
m_pTiles[z] = gid;
return m_pReusedTile;
@ -495,20 +494,19 @@ namespace cocos2d {
// update possible children
if (m_pChildren && m_pChildren->count()>0)
{
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
CCSprite *pSprite = NULL;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{
pSprite = (CCSprite*)(*it);
if (pSprite)
{
unsigned int ai = pSprite->getAtlasIndex();
if ( ai >= atlasIndex )
{
pSprite->setAtlasIndex(ai-1);
}
}
}
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
unsigned int ai = pChild->getAtlasIndex();
if ( ai >= atlasIndex )
{
pChild->setAtlasIndex(ai-1);
}
}
}
}
}
}

View File

@ -1 +1 @@
dc7539c2ee19df2be260115613d46d73e062fa72
b69284f836d8fbe8a1494cda6f723f02f0fc67ea

View File

@ -1 +1 @@
55f9260dfa6b4d5f66ed3a42697a1896c779c8d5
db9df4d8057e9b2d6debaa04e51ba2dacc74b35b

View File

@ -1 +1 @@
e61a9910ad0fd7301987ddd8664ed44b731a837d
89cf804b6d8b2ea5f52b32c4b454b034b2251797

View File

@ -1 +1 @@
38bdb35f5d331e4f326831460ce303bfed7e29bd
e7dda511c80c56d286471fa6602e12ac60e02863

View File

@ -75,15 +75,14 @@ MenuLayer1::MenuLayer1()
int i=0;
CCNode* child;
CCMutableArray<CCNode*> * pArray = menu->getChildren();
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for(it = pArray->begin(); it != pArray->end(); it++)
CCArray * pArray = menu->getChildren();
CCObject* pObject = NULL;
CCARRAY_FOREACH(pArray, pObject)
{
if(*it == NULL)
if(pObject == NULL)
break;
child = (CCNode*)(*it);
child = (CCNode*)pObject;
CCPoint dstPoint = child->getPosition();
int offset = (int) (s.width/2 + 50);

View File

@ -7,7 +7,7 @@ enum {
kTagBase = 20000,
TEST_COUNT = 5,
TEST_COUNT = 4,
};
enum {
@ -210,11 +210,11 @@ void IterateSpriteSheetFastEnum::update(ccTime dt)
//CCProfilingBeginTimingBlock(_profilingTimer);
// iterate using fast enumeration protocol
CCMutableArray<CCNode*>* pChildren = batchNode->getChildren();
CCMutableArray<CCNode*>::CCMutableArrayIterator iter;
for(iter = pChildren->begin(); iter != pChildren->end(); ++iter)
CCArray* pChildren = batchNode->getChildren();
CCObject* pObject = NULL;
CCARRAY_FOREACH(pChildren, pObject)
{
CCSprite* pSprite = (CCSprite*)(*iter);
CCSprite* pSprite = (CCSprite*) pObject;
pSprite->setIsVisible(false);
}
@ -239,11 +239,11 @@ std::string IterateSpriteSheetFastEnum::subtitle()
void IterateSpriteSheetCArray::update(ccTime dt)
{
// iterate using fast enumeration protocol
CCMutableArray<CCNode*>* pChildren = batchNode->getChildren();
CCMutableArray<CCNode*>::CCMutableArrayIterator iter;
for(iter = pChildren->begin(); iter != pChildren->end(); ++iter)
CCArray* pChildren = batchNode->getChildren();
CCObject* pObject = NULL;
CCARRAY_FOREACH(pChildren, pObject)
{
CCSprite* pSprite = (CCSprite*)(*iter);
CCSprite* pSprite = (CCSprite*)pObject;
pSprite->setIsVisible(false);
} }
@ -314,14 +314,14 @@ void AddSpriteSheet::update(ccTime dt)
if( totalToAdd > 0 )
{
std::vector<CCSprite *> sprites;
CCArray* sprites = CCArray::arrayWithCapacity(totalToAdd);
int *zs = new int[totalToAdd];
// Don't include the sprite creation time and random as part of the profiling
for(int i=0; i<totalToAdd; i++)
{
CCSprite* pSprite = CCSprite::spriteWithTexture(batchNode->getTexture(), CCRectMake(0,0,32,32));
sprites.push_back(pSprite);
sprites->addObject(pSprite);
zs[i] = CCRANDOM_MINUS1_1() * 50;
}
@ -329,7 +329,7 @@ void AddSpriteSheet::update(ccTime dt)
// CCProfilingBeginTimingBlock(_profilingTimer);
for( int i=0; i < totalToAdd;i++ )
{
batchNode->addChild((CCSprite *)(sprites[i]), zs[i], kTagBase+i);
batchNode->addChild((CCNode*) (sprites->objectAtIndex(i)), zs[i], kTagBase+i);
}
// [batchNode sortAllChildren];
// CCProfilingEndTimingBlock(_profilingTimer);
@ -369,19 +369,19 @@ void RemoveSpriteSheet::update(ccTime dt)
if( totalToAdd > 0 )
{
std::vector<CCSprite *> sprites;
CCArray* sprites = CCArray::arrayWithCapacity(totalToAdd);
// Don't include the sprite creation time as part of the profiling
for(int i=0;i<totalToAdd;i++)
{
CCSprite* pSprite = CCSprite::spriteWithTexture(batchNode->getTexture(), CCRectMake(0,0,32,32));
sprites.push_back(pSprite);
sprites->addObject(pSprite);
}
// add them with random Z (very important!)
for( int i=0; i < totalToAdd;i++ )
{
batchNode->addChild((CCSprite *)(sprites[i]), CCRANDOM_MINUS1_1() * 50, kTagBase+i);
batchNode->addChild((CCNode*) (sprites->objectAtIndex(i)), CCRANDOM_MINUS1_1() * 50, kTagBase+i);
}
// remove them
@ -418,19 +418,19 @@ void ReorderSpriteSheet::update(ccTime dt)
if( totalToAdd > 0 )
{
std::vector<CCSprite *> sprites;
CCArray* sprites = CCArray::arrayWithCapacity(totalToAdd);
// Don't include the sprite creation time as part of the profiling
for(int i=0;i<totalToAdd;i++)
{
CCSprite* pSprite = CCSprite::spriteWithTexture(batchNode->getTexture(), CCRectMake(0,0,32,32));
sprites.push_back(pSprite);
sprites->addObject(pSprite);
}
// add them with random Z (very important!)
for( int i=0; i < totalToAdd;i++ )
{
batchNode->addChild((CCSprite *)(sprites[i]), CCRANDOM_MINUS1_1() * 50, kTagBase+i);
batchNode->addChild((CCNode*) (sprites->objectAtIndex(i)), CCRANDOM_MINUS1_1() * 50, kTagBase+i);
}
// [batchNode sortAllChildren];
@ -439,7 +439,8 @@ void ReorderSpriteSheet::update(ccTime dt)
//CCProfilingBeginTimingBlock(_profilingTimer);
for( int i=0;i < totalToAdd;i++)
{
batchNode->reorderChild(batchNode->getChildren()->getObjectAtIndex(i), CCRANDOM_MINUS1_1() * 50);
CCNode* pNode = (CCNode*) (batchNode->getChildren()->objectAtIndex(i));
batchNode->reorderChild(pNode, CCRANDOM_MINUS1_1() * 50);
}
// [batchNode sortAllChildren];
//CCProfilingEndTimingBlock(_profilingTimer);
@ -464,7 +465,7 @@ std::string ReorderSpriteSheet::subtitle()
void runNodeChildrenTest()
{
IterateSpriteSheet* pScene = new IterateSpriteSheetFastEnum();
IterateSpriteSheet* pScene = new IterateSpriteSheetCArray();
pScene->initWithQuantityOfNodes(kNodesIncrease);
CCDirector::sharedDirector()->replaceScene(pScene);

View File

@ -10,7 +10,7 @@ enum {
enum {
kTagInfoLayer = 1,
kTagMainLayer = 2,
kTagMenuLayer = 1000,
kTagMenuLayer = (kMaxNodes + 1000),
};
static int s_nSpriteCurCase = 0;

View File

@ -446,13 +446,12 @@ void SchedulerUpdate::onEnter()
void SchedulerUpdate::removeUpdates(ccTime dt)
{
CCMutableArray<CCNode*> * children = getChildren();
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
CCArray* children = getChildren();
CCNode* pNode;
for (it = children->begin(); it != children->end(); it++)
CCObject* pObject;
CCARRAY_FOREACH(children, pObject)
{
pNode = (CCNode*)(*it);
pNode = (CCNode*)pObject;
if (! pNode)
{

View File

@ -1 +1 @@
9e16647d99e1705b6436f4764cfacc6a478d3715
225b2feefddaa0d61cec8c434664bc2738986082

View File

@ -124,12 +124,12 @@ TMXOrthoTest::TMXOrthoTest()
CCSize s = map->getContentSize();
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
CCMutableArray<CCNode*> * pChildrenArray = map->getChildren();
CCArray * pChildrenArray = map->getChildren();
CCSpriteBatchNode* child = NULL;
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for( it = pChildrenArray->begin(); it != pChildrenArray->end(); it++)
CCObject* pObject = NULL;
CCARRAY_FOREACH(pChildrenArray, pObject)
{
child = (CCSpriteBatchNode*)(*it);
child = (CCSpriteBatchNode*)pObject;
if(!child)
break;
@ -173,12 +173,12 @@ TMXOrthoTest2::TMXOrthoTest2()
CCSize s = map->getContentSize();
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
CCMutableArray<CCNode*> * pChildrenArray = map->getChildren();
CCArray* pChildrenArray = map->getChildren();
CCSpriteBatchNode* child = NULL;
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for( it = pChildrenArray->begin(); it != pChildrenArray->end(); it++)
CCObject* pObject = NULL;
CCARRAY_FOREACH(pChildrenArray, pObject)
{
child = (CCSpriteBatchNode*)(*it);
child = (CCSpriteBatchNode*)pObject;
if(!child)
break;
@ -207,12 +207,12 @@ TMXOrthoTest3::TMXOrthoTest3()
CCSize s = map->getContentSize();
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
CCMutableArray<CCNode*> * pChildrenArray = map->getChildren();
CCArray* pChildrenArray = map->getChildren();
CCSpriteBatchNode* child = NULL;
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for( it = pChildrenArray->begin(); it != pChildrenArray->end(); it++)
CCObject* pObject = NULL;
CCARRAY_FOREACH(pChildrenArray, pObject)
{
child = (CCSpriteBatchNode*)(*it);
child = (CCSpriteBatchNode*)pObject;
if(!child)
break;
@ -242,12 +242,12 @@ TMXOrthoTest4::TMXOrthoTest4()
CCSize s1 = map->getContentSize();
////----UXLOG("ContentSize: %f, %f", s1.width,s1.height);
CCMutableArray<CCNode*> * pChildrenArray = map->getChildren();
CCArray* pChildrenArray = map->getChildren();
CCSpriteBatchNode* child = NULL;
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for( it = pChildrenArray->begin(); it != pChildrenArray->end(); it++)
CCObject* pObject = NULL;
CCARRAY_FOREACH(pChildrenArray, pObject)
{
child = (CCSpriteBatchNode*)(*it);
child = (CCSpriteBatchNode*)pObject;
if(!child)
break;
@ -547,12 +547,12 @@ TMXUncompressedTest::TMXUncompressedTest()
map->runAction(CCMoveTo::actionWithDuration(1.0f, ccp( -ms.width * ts.width/2, -ms.height * ts.height/2 ) ));
// testing release map
CCMutableArray<CCNode*> * pChildrenArray = map->getChildren();
CCArray* pChildrenArray = map->getChildren();
CCTMXLayer* layer;
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for( it = pChildrenArray->begin(); it != pChildrenArray->end(); it++)
CCObject* pObject = NULL;
CCARRAY_FOREACH(pChildrenArray, pObject)
{
layer= (CCTMXLayer*)(*it);
layer= (CCTMXLayer*)pObject;
if(!layer)
break;
@ -1122,13 +1122,12 @@ TMXBug987::TMXBug987()
CCSize s1 = map->getContentSize();
CCLOG("ContentSize: %f, %f", s1.width,s1.height);
CCMutableArray<CCNode*>* childs = map->getChildren();
CCTMXLayer* pNode;
CCMutableArray<CCNode*>::CCMutableArrayIterator it;
for(it = childs->begin(); it != childs->end(); it++)
CCArray* childs = map->getChildren();
CCTMXLayer* pNode;
CCObject* pObject = NULL;
CCARRAY_FOREACH(childs, pObject)
{
pNode = (CCTMXLayer*)(*it);
pNode = (CCTMXLayer*) pObject;
CC_BREAK_IF(!pNode);
pNode->getTexture()->setAntiAliasTexParameters();
}