issue #2790: Vector::makeObjectsPerformCallback —> Vector::forEach

This commit is contained in:
James Chen 2013-11-28 18:23:06 +08:00
Родитель d4d864216b
Коммит 1d5984b29a
23 изменённых файлов: 180 добавлений и 150 удалений

Просмотреть файл

@ -40,7 +40,7 @@ static void setProgram(Node *n, GLProgram *p)
{
n->setShaderProgram(p);
n->getChildren().makeObjectsPerformCallback([p](Node* child){
n->getChildren().forEach([p](Node* child){
setProgram(child, p);
});
}

Просмотреть файл

@ -250,7 +250,7 @@ void Label::alignText()
int strLen = cc_wcslen(_currentUTF16String);
_children.makeObjectsPerformCallback([this, &strLen](Node* child){
_children.forEach([this, &strLen](Node* child){
if (child)
{
int tag = child->getTag();
@ -592,7 +592,7 @@ void Label::setOpacityModifyRGB(bool isOpacityModifyRGB)
{
_isOpacityModifyRGB = isOpacityModifyRGB;
_children.makeObjectsPerformCallback([this](Node* child){
_children.forEach([this](Node* child){
if (child)
{
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(child);
@ -634,7 +634,7 @@ void Label::updateDisplayedOpacity(GLubyte parentOpacity)
{
_displayedOpacity = _realOpacity * parentOpacity/255.0;
_children.makeObjectsPerformCallback([this](Node* child){
_children.forEach([this](Node* child){
Sprite *item = static_cast<Sprite*>( child );
item->updateDisplayedOpacity(_displayedOpacity);
});
@ -700,7 +700,7 @@ void Label::updateDisplayedColor(const Color3B& parentColor)
_displayedColor.g = _realColor.g * parentColor.g/255.0;
_displayedColor.b = _realColor.b * parentColor.b/255.0;
_children.makeObjectsPerformCallback([this](Node* child){
_children.forEach([this](Node* child){
Sprite *item = static_cast<Sprite*>( child );
item->updateDisplayedColor(_displayedColor);
});

Просмотреть файл

@ -746,7 +746,7 @@ void LabelBMFont::setString(unsigned short *newString, bool needUpdateLabel)
CC_SAFE_DELETE_ARRAY(tmp);
}
_children.makeObjectsPerformCallback([](Node* child){
_children.forEach([](Node* child){
child->setVisible(false);
});
@ -822,7 +822,7 @@ void LabelBMFont::setOpacity(GLubyte opacity)
void LabelBMFont::setOpacityModifyRGB(bool var)
{
_isOpacityModifyRGB = var;
_children.makeObjectsPerformCallback([this](Node* child){
_children.forEach([this](Node* child){
if (child)
{
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(child);
@ -842,7 +842,7 @@ void LabelBMFont::updateDisplayedOpacity(GLubyte parentOpacity)
{
_displayedOpacity = _realOpacity * parentOpacity/255.0f;
_children.makeObjectsPerformCallback([this](Node* child){
_children.forEach([this](Node* child){
Sprite *item = static_cast<Sprite*>( child );
item->updateDisplayedOpacity(_displayedOpacity);
});
@ -854,7 +854,7 @@ void LabelBMFont::updateDisplayedColor(const Color3B& parentColor)
_displayedColor.g = _realColor.g * parentColor.g/255.0f;
_displayedColor.b = _realColor.b * parentColor.b/255.0f;
_children.makeObjectsPerformCallback([this](Node* child){
_children.forEach([this](Node* child){
Sprite *item = static_cast<Sprite*>( child );
item->updateDisplayedColor(_displayedColor);
});

Просмотреть файл

@ -499,7 +499,7 @@ void LayerRGBA::updateDisplayedOpacity(GLubyte parentOpacity)
if (_cascadeOpacityEnabled)
{
_children.makeObjectsPerformCallback([this](Node* obj){
_children.forEach([this](Node* obj){
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
if (item)
{
@ -517,7 +517,7 @@ void LayerRGBA::updateDisplayedColor(const Color3B& parentColor)
if (_cascadeColorEnabled)
{
_children.makeObjectsPerformCallback([this](Node* obj){
_children.forEach([this](Node* obj){
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
if (item)
{

Просмотреть файл

@ -303,7 +303,7 @@ void Menu::alignItemsVerticallyWithPadding(float padding)
{
float height = -padding;
_children.makeObjectsPerformCallback([&](Node* child){
_children.forEach([&](Node* child){
if (child)
{
height += child->getContentSize().height * child->getScaleY() + padding;
@ -312,7 +312,7 @@ void Menu::alignItemsVerticallyWithPadding(float padding)
float y = height / 2.0f;
_children.makeObjectsPerformCallback([&](Node* child){
_children.forEach([&](Node* child){
if (child)
{
child->setPosition(Point(0, y - child->getContentSize().height * child->getScaleY() / 2.0f));
@ -329,7 +329,7 @@ void Menu::alignItemsHorizontally(void)
void Menu::alignItemsHorizontallyWithPadding(float padding)
{
float width = -padding;
_children.makeObjectsPerformCallback([&](Node* child){
_children.forEach([&](Node* child){
if (child)
{
width += child->getContentSize().width * child->getScaleX() + padding;
@ -338,7 +338,7 @@ void Menu::alignItemsHorizontallyWithPadding(float padding)
float x = -width / 2.0f;
_children.makeObjectsPerformCallback([&](Node* child){
_children.forEach([&](Node* child){
if (child)
{
child->setPosition(Point(x + child->getContentSize().width * child->getScaleX() / 2.0f, 0));
@ -379,7 +379,7 @@ void Menu::alignItemsInColumnsWithArray(Array* rowsArray)
unsigned int columnsOccupied = 0;
unsigned int rowColumns;
_children.makeObjectsPerformCallback([&](Node* child){
_children.forEach([&](Node* child){
if (child)
{
CCASSERT(row < rows.size(), "");
@ -415,7 +415,7 @@ void Menu::alignItemsInColumnsWithArray(Array* rowsArray)
float x = 0.0;
float y = (float)(height / 2);
_children.makeObjectsPerformCallback([&](Node* child){
_children.forEach([&](Node* child){
if (child)
{
if (child)
@ -485,7 +485,7 @@ void Menu::alignItemsInRowsWithArray(Array* columnArray)
unsigned int rowsOccupied = 0;
unsigned int columnRows;
_children.makeObjectsPerformCallback([&](Node* child){
_children.forEach([&](Node* child){
if (child)
{
// check if too many menu items for the amount of rows/columns
@ -527,7 +527,7 @@ void Menu::alignItemsInRowsWithArray(Array* columnArray)
float x = (float)(-width / 2);
float y = 0.0;
_children.makeObjectsPerformCallback([&](Node* child){
_children.forEach([&](Node* child){
if (child)
{
if (columnRows == 0)
@ -562,7 +562,7 @@ MenuItem* Menu::itemForTouch(Touch *touch)
{
Point touchLocation = touch->getLocation();
if (_children.count() > 0)
if (!_children.empty())
{
for (auto iter = _children.rcbegin(); iter != _children.rcend(); ++iter)
{

Просмотреть файл

@ -575,7 +575,7 @@ void Node::cleanup()
}
// timers
_children.makeObjectsPerformCallback([](Node* child){
_children.forEach([](Node* child){
child->cleanup();
});
}
@ -613,7 +613,7 @@ void Node::addChild(Node *child, int zOrder, int tag)
CCASSERT( child != NULL, "Argument must be non-nil");
CCASSERT( child->_parent == NULL, "child already added. It can't be added again");
if (_children.count() == 0)
if (_children.empty())
{
this->childrenAlloc();
}
@ -678,7 +678,7 @@ void Node::removeFromParentAndCleanup(bool cleanup)
void Node::removeChild(Node* child, bool cleanup /* = true */)
{
// explicit nil handling
if (_children.count() == 0)
if (_children.empty())
{
return;
}
@ -712,7 +712,7 @@ void Node::removeAllChildren()
void Node::removeAllChildrenWithCleanup(bool cleanup)
{
// not using detachChild improves speed here
if ( _children.count() > 0 )
if (!_children.empty())
{
for (auto& child : _children)
{
@ -854,7 +854,7 @@ void Node::visit()
this->transform();
int i = 0;
if(_children.count() > 0)
if(!_children.empty())
{
sortAllChildren();
// draw children zOrder < 0
@ -940,7 +940,7 @@ void Node::onEnter()
{
_isTransitionFinished = false;
_children.makeObjectsPerformCallback([](Node* child){
_children.forEach([](Node* child){
child->onEnter();
});
@ -961,7 +961,7 @@ void Node::onEnterTransitionDidFinish()
{
_isTransitionFinished = true;
_children.makeObjectsPerformCallback([](Node* child){
_children.forEach([](Node* child){
child->onEnterTransitionDidFinish();
});
@ -976,7 +976,7 @@ void Node::onEnterTransitionDidFinish()
void Node::onExitTransitionDidStart()
{
_children.makeObjectsPerformCallback([](Node* child){
_children.forEach([](Node* child){
child->onExitTransitionDidStart();
});
@ -1002,7 +1002,7 @@ void Node::onExit()
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
}
_children.makeObjectsPerformCallback([](Node* child){
_children.forEach([](Node* child){
child->onExit();
});
}
@ -1352,7 +1352,7 @@ bool Node::updatePhysicsTransform()
void Node::updateTransform()
{
// Recursively iterate over children
_children.makeObjectsPerformCallback([](Node* child){
_children.forEach([](Node* child){
child->updateTransform();
});
}
@ -1463,7 +1463,7 @@ void NodeRGBA::updateDisplayedOpacity(GLubyte parentOpacity)
if (_cascadeOpacityEnabled)
{
_children.makeObjectsPerformCallback([this](Node* child){
_children.forEach([this](Node* child){
RGBAProtocol* item = dynamic_cast<RGBAProtocol*>(child);
if (item)
{
@ -1518,7 +1518,7 @@ void NodeRGBA::updateDisplayedColor(const Color3B& parentColor)
if (_cascadeColorEnabled)
{
_children.makeObjectsPerformCallback([this](Node* child){
_children.forEach([this](Node* child){
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(child);
if (item)
{

Просмотреть файл

@ -169,7 +169,7 @@ void ParticleBatchNode::addChild(Node * aChild, int zOrder, int tag)
ParticleSystem* child = static_cast<ParticleSystem*>(aChild);
CCASSERT( child->getTexture()->getName() == _textureAtlas->getTexture()->getName(), "CCParticleSystem is not using the same texture id");
// If this is the 1st children, then copy blending function
if( _children.count() == 0 )
if (_children.empty())
{
setBlendFunc(child->getBlendFunc());
}
@ -242,7 +242,7 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder)
}
// no reordering if only 1 child
if( _children.count() > 1)
if (!_children.empty())
{
long newIndex = 0, oldIndex = 0;
@ -383,7 +383,7 @@ void ParticleBatchNode::removeChildAtIndex(unsigned int index, bool doCleanup)
void ParticleBatchNode::removeAllChildrenWithCleanup(bool doCleanup)
{
_children.makeObjectsPerformCallback([](Node* child){
_children.forEach([](Node* child){
static_cast<ParticleSystem*>(child)->setBatchNode(nullptr);
});
@ -464,7 +464,7 @@ void ParticleBatchNode::updateAllAtlasIndexes()
{
unsigned int index = 0;
_children.makeObjectsPerformCallback([&index](Node* child){
_children.forEach([&index](Node* child){
ParticleSystem* partiSys = static_cast<ParticleSystem*>(child);
partiSys->setAtlasIndex(index);
index += partiSys->getTotalParticles();

Просмотреть файл

@ -528,7 +528,7 @@ void RenderTexture::draw()
//! make sure all children are drawn
sortAllChildren();
_children.makeObjectsPerformCallback([this](Node* child){
_children.forEach([this](Node* child){
if (child != _sprite)
{
child->visit();

Просмотреть файл

@ -140,7 +140,7 @@ void Scene::addChildToPhysicsWorld(Node* child)
_physicsWorld->addBody(node->getPhysicsBody());
}
node->getChildren().makeObjectsPerformCallback([addToPhysicsWorldFunc](Node* n){
node->getChildren().forEach([addToPhysicsWorldFunc](Node* n){
addToPhysicsWorldFunc(n);
});
};

Просмотреть файл

@ -726,7 +726,7 @@ void Sprite::removeAllChildrenWithCleanup(bool cleanup)
{
if (_batchNode)
{
_children.makeObjectsPerformCallback([this](Node* child){
_children.forEach([this](Node* child){
Sprite* sprite = dynamic_cast<Sprite*>(child);
if (sprite)
{
@ -772,7 +772,7 @@ void Sprite::sortAllChildren()
if ( _batchNode)
{
_children.makeObjectsPerformCallback([](Node* child){
_children.forEach([](Node* child){
child->sortAllChildren();
});
}
@ -809,7 +809,7 @@ void Sprite::setDirtyRecursively(bool bValue)
// recursively set dirty
if (_hasChildren)
{
_children.makeObjectsPerformCallback([](Node* child){
_children.forEach([](Node* child){
Sprite* sp = dynamic_cast<Sprite*>(child);
if (sp)
{

Просмотреть файл

@ -267,10 +267,10 @@ void SpriteBatchNode::sortAllChildren()
#endif
//sorted now check all children
if (_children.count() > 0)
if (!_children.empty())
{
//first sort all children recursively based on zOrder
_children.makeObjectsPerformCallback([](Node* child){
_children.forEach([](Node* child){
child->sortAllChildren();
});
@ -278,7 +278,7 @@ void SpriteBatchNode::sortAllChildren()
//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
_children.makeObjectsPerformCallback([this, &index](Node* child){
_children.forEach([this, &index](Node* child){
Sprite* sp = static_cast<Sprite*>(child);
updateAtlasIndex(sp, &index);
});
@ -324,7 +324,7 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
needNewIndex = false;
}
array.makeObjectsPerformCallback([&](Node* child){
array.forEach([&](Node* child){
Sprite* sp = static_cast<Sprite*>(child);
if (needNewIndex && sp->getZOrder() >= 0)
{
@ -390,7 +390,7 @@ void SpriteBatchNode::draw(void)
CC_NODE_DRAW_SETUP();
_children.makeObjectsPerformCallback([](Node* child){
_children.forEach([](Node* child){
child->updateTransform();
});
@ -426,7 +426,7 @@ int SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, int index)
auto children = parent->getChildren();
children.makeObjectsPerformCallback([this, &index](Node* child){
children.forEach([this, &index](Node* child){
Sprite* sp = static_cast<Sprite*>(child);
if (sp && (sp->getZOrder() < 0))
{
@ -441,7 +441,7 @@ int SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, int index)
index++;
}
children.makeObjectsPerformCallback([this, &index](Node* child){
children.forEach([this, &index](Node* child){
Sprite* sp = static_cast<Sprite*>(child);
if (sp && (sp->getZOrder() >= 0))
{
@ -559,7 +559,7 @@ void SpriteBatchNode::appendChild(Sprite* sprite)
_textureAtlas->insertQuad(&quad, index);
// add children recursively
sprite->getChildren().makeObjectsPerformCallback([this](Node* child){
sprite->getChildren().forEach([this](Node* child){
appendChild(static_cast<Sprite*>(child));
});
}
@ -586,7 +586,7 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
// remove children recursively
auto children = sprite->getChildren();
children.makeObjectsPerformCallback([this](Node* obj){
children.forEach([this](Node* obj){
Sprite* child = static_cast<Sprite*>(obj);
if (child)
{

Просмотреть файл

@ -391,7 +391,7 @@ Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
// update possible children
_children.makeObjectsPerformCallback([&indexForZ](Node* child){
_children.forEach([&indexForZ](Node* child){
Sprite* sp = static_cast<Sprite*>(child);
if (child)
{
@ -593,7 +593,7 @@ void TMXLayer::removeTileAt(const Point& pos)
_textureAtlas->removeQuadAtIndex(atlasIndex);
// update possible children
_children.makeObjectsPerformCallback([&atlasIndex](Node* obj){
_children.forEach([&atlasIndex](Node* obj){
Sprite* child = static_cast<Sprite*>(obj);
if (child)
{

Просмотреть файл

@ -117,6 +117,11 @@ public:
return _data.size();
}
bool empty() const
{
return _data.empty();
}
/** Returns index of a certain object, return UINT_MAX if doesn't contain the object */
long getIndexOfObject(T object) const
{
@ -297,7 +302,7 @@ public:
_data.shrink_to_fit();
}
void makeObjectsPerformCallback(std::function<void(T)> callback)
void forEach(std::function<void(T)> callback)
{
if (count() <= 0)
return;

Просмотреть файл

@ -328,7 +328,7 @@ void CCBReader::cleanUpNodeGraph(Node *node)
{
node->setUserObject(nullptr);
node->getChildren().makeObjectsPerformCallback([this](Node* obj){
node->getChildren().forEach([this](Node* obj){
cleanUpNodeGraph(obj);
});
}

Просмотреть файл

@ -163,7 +163,7 @@ void BatchNode::visit()
void BatchNode::draw()
{
if (_children.count() == 0)
if (_children.empty())
{
return;
}

Просмотреть файл

@ -227,7 +227,7 @@ void Bone::update(float delta)
DisplayFactory::updateDisplay(this, delta, _boneTransformDirty || _armature->getArmatureTransformDirty());
_children.makeObjectsPerformCallback([&delta](Node* obj){
_children.forEach([&delta](Node* obj){
Bone *childBone = static_cast<Bone*>(obj);
childBone->update(delta);
});
@ -303,7 +303,7 @@ void Bone::addChildBone(Bone *child)
CCASSERT( nullptr != child, "Argument must be non-nil");
CCASSERT( nullptr == child->_parentBone, "child already added. It can't be added again");
if(_children.count() == 0)
if(_children.empty())
{
_children.setCapacity(4);
}
@ -317,7 +317,7 @@ void Bone::addChildBone(Bone *child)
void Bone::removeChildBone(Bone *bone, bool recursion)
{
if (_children.count() > 0 && _children.getIndexOfObject(bone) != CC_INVALID_INDEX )
if (!_children.empty() && _children.getIndexOfObject(bone) != CC_INVALID_INDEX )
{
if(recursion)
{

Просмотреть файл

@ -222,16 +222,14 @@ void Control::removeTargetWithActionForControlEvent(Object* target, Handler acti
void Control::setOpacityModifyRGB(bool bOpacityModifyRGB)
{
_isOpacityModifyRGB=bOpacityModifyRGB;
Object* child;
Array* children=getChildren();
CCARRAY_FOREACH(children, child)
{
RGBAProtocol* pNode = dynamic_cast<RGBAProtocol*>(child);
if (pNode)
_children.forEach([&](Node* obj){
RGBAProtocol* rgba = dynamic_cast<RGBAProtocol*>(obj);
if (rgba)
{
pNode->setOpacityModifyRGB(bOpacityModifyRGB);
rgba->setOpacityModifyRGB(bOpacityModifyRGB);
}
}
});
}
bool Control::isOpacityModifyRGB() const

Просмотреть файл

@ -699,17 +699,16 @@ void Scale9Sprite::setOpacityModifyRGB(bool var)
return;
}
_opacityModifyRGB = var;
Object* child;
Array* children = _scale9Image->getChildren();
CCARRAY_FOREACH(children, child)
{
RGBAProtocol* pNode = dynamic_cast<RGBAProtocol*>(child);
if (pNode)
_scale9Image->getChildren().forEach([this](Node* child){
RGBAProtocol* rgba = dynamic_cast<RGBAProtocol*>(child);
if (rgba)
{
pNode->setOpacityModifyRGB(_opacityModifyRGB);
rgba->setOpacityModifyRGB(_opacityModifyRGB);
}
}
});
}
bool Scale9Sprite::isOpacityModifyRGB() const
{
return _opacityModifyRGB;
@ -789,16 +788,14 @@ void Scale9Sprite::setColor(const Color3B& color)
}
NodeRGBA::setColor(color);
Object* child;
Array* children = _scale9Image->getChildren();
CCARRAY_FOREACH(children, child)
{
RGBAProtocol* pNode = dynamic_cast<RGBAProtocol*>(child);
if (pNode)
_scale9Image->getChildren().forEach([&color](Node* child){
RGBAProtocol* rgba = dynamic_cast<RGBAProtocol*>(child);
if (rgba)
{
pNode->setColor(color);
rgba->setColor(color);
}
}
});
}
const Color3B& Scale9Sprite::getColor() const
@ -813,16 +810,14 @@ void Scale9Sprite::setOpacity(GLubyte opacity)
return;
}
NodeRGBA::setOpacity(opacity);
Object* child;
Array* children = _scale9Image->getChildren();
CCARRAY_FOREACH(children, child)
{
RGBAProtocol* pNode = dynamic_cast<RGBAProtocol*>(child);
if (pNode)
_scale9Image->getChildren().forEach([&opacity](Node* child){
RGBAProtocol* rgba = dynamic_cast<RGBAProtocol*>(child);
if (rgba)
{
pNode->setOpacity(opacity);
rgba->setOpacity(opacity);
}
}
});
}
GLubyte Scale9Sprite::getOpacity() const
@ -837,16 +832,14 @@ void Scale9Sprite::updateDisplayedColor(const cocos2d::Color3B &parentColor)
return;
}
NodeRGBA::updateDisplayedColor(parentColor);
Object* child;
Array* children = _scale9Image->getChildren();
CCARRAY_FOREACH(children, child)
{
RGBAProtocol* pNode = dynamic_cast<RGBAProtocol*>(child);
if (pNode)
_scale9Image->getChildren().forEach([&parentColor](Node* child){
RGBAProtocol* rgba = dynamic_cast<RGBAProtocol*>(child);
if (rgba)
{
pNode->updateDisplayedColor(parentColor);
rgba->updateDisplayedColor(parentColor);
}
}
});
}
void Scale9Sprite::updateDisplayedOpacity(GLubyte parentOpacity)
@ -856,16 +849,14 @@ void Scale9Sprite::updateDisplayedOpacity(GLubyte parentOpacity)
return;
}
NodeRGBA::updateDisplayedOpacity(parentOpacity);
Object* child;
Array* children = _scale9Image->getChildren();
CCARRAY_FOREACH(children, child)
{
RGBAProtocol* pNode = dynamic_cast<RGBAProtocol*>(child);
if (pNode)
_scale9Image->getChildren().forEach([&parentOpacity](Node* child){
RGBAProtocol* rgba = dynamic_cast<RGBAProtocol*>(child);
if (rgba)
{
pNode->updateDisplayedOpacity(parentOpacity);
rgba->updateDisplayedOpacity(parentOpacity);
}
}
});
}
NS_CC_EXT_END

Просмотреть файл

@ -153,26 +153,16 @@ void ScrollView::pause(Object* sender)
{
_container->pause();
Object* pObj = NULL;
Array* pChildren = _container->getChildren();
CCARRAY_FOREACH(pChildren, pObj)
{
Node* pChild = static_cast<Node*>(pObj);
pChild->pause();
}
_container->getChildren().forEach([](Node* child){
child->pause();
});
}
void ScrollView::resume(Object* sender)
{
Object* pObj = NULL;
Array* pChildren = _container->getChildren();
CCARRAY_FOREACH(pChildren, pObj)
{
Node* pChild = static_cast<Node*>(pObj);
pChild->resume();
}
_container->getChildren().forEach([](Node* child){
child->resume();
});
_container->resume();
}
@ -567,14 +557,14 @@ void ScrollView::visit()
this->transform();
this->beforeDraw();
if(_children)
if (!_children.empty())
{
int i=0;
// draw children zOrder < 0
for( ; i < _children->count(); i++ )
for( ; i < _children.count(); i++ )
{
Node *child = static_cast<Node*>( _children->getObjectAtIndex(i) );
Node *child = _children[i];
if ( child->getZOrder() < 0 )
{
child->visit();
@ -589,9 +579,9 @@ void ScrollView::visit()
this->draw();
// draw children zOrder >= 0
for( ; i < _children->count(); i++ )
for( ; i < _children.count(); i++ )
{
Node *child = static_cast<Node*>( _children->getObjectAtIndex(i) );
Node *child = _children[i];
child->visit();
}

Просмотреть файл

@ -2,10 +2,10 @@
#include "AppMacros.h"
#include "CCEventListenerTouch.h"
#include "CCVector.h"
USING_NS_CC;
Scene* HelloWorld::scene()
{
// 'scene' is an autorelease object
@ -21,9 +21,61 @@ Scene* HelloWorld::scene()
return scene;
}
void showSprites(const Vector<Sprite*>& sprites)
{
log("container size = %ld", sprites.count());
for (auto& sp : sprites)
{
log("sp tag: %d, ref count = %d", sp->getTag(), sp->retainCount());
}
}
Vector<Sprite*> createAllSprites()
{
Vector<Sprite*> ret;
ret.addObject(Sprite::create());
ret.addObject(Sprite::create());
return ret;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
// Vector<Sprite*> container;
//
// for (int i = 0; i < 10; ++i)
// {
// auto sp = Sprite::create();
// sp->setTag(i);
// container.addObject(sp);
// }
//
// showSprites(container);
//
// Vector<Sprite*> containerCopy = container;
//
// showSprites(containerCopy);
//
// containerCopy = container;
//
// showSprites(containerCopy);
// Vector<Sprite*> moveVector(createAllSprites());
// showSprites(moveVector);
//
// CCLOG("------------- 2 ----------");
// moveVector = createAllSprites();
// showSprites(moveVector);
//
// CCLOG("------------- 3 ----------");
// Vector<Sprite*> aaa;
// aaa.addObject(Sprite::create());
// moveVector = aaa;
// showSprites(moveVector);
log("size of Vector = %ld", sizeof(Vector<Sprite*>));
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
@ -75,6 +127,10 @@ bool HelloWorld::init()
// add the sprite as a child to this layer
this->addChild(sprite);
this->getChildren().forEach([](Node* node){
log("node = %p, name = %s", node, typeid(*node).name());
});
return true;
}

Просмотреть файл

@ -47,15 +47,10 @@ void Bug422Layer::reset()
void Bug422Layer::check(Node* t)
{
auto array = t->getChildren();
Object* pChild = NULL;
CCARRAY_FOREACH(array, pChild)
{
CC_BREAK_IF(! pChild);
auto node = static_cast<Node*>(pChild);
log("%p, rc: %d", node, node->retainCount());
check(node);
}
t->getChildren().forEach([this](Node* child){
log("%p, rc: %d", child, child->retainCount());
check(child);
});
}
void Bug422Layer::menuCallback(Object* sender)

Просмотреть файл

@ -119,13 +119,9 @@ static void setEnableRecursiveCascading(Node* node, bool enable)
rgba->setCascadeOpacityEnabled(enable);
}
Object* obj;
auto children = node->getChildren();
CCARRAY_FOREACH(children, obj)
{
auto child = static_cast<Node*>(obj);
node->getChildren().forEach([enable](Node* child){
setEnableRecursiveCascading(child, enable);
}
});
}
// LayerTestCascadingOpacityA

Просмотреть файл

@ -1528,17 +1528,16 @@ void MultipleParticleSystems::update(float dt)
{
auto atlas = (LabelAtlas*) getChildByTag(kTagParticleCount);
unsigned int count = 0;
Object* pObj = NULL;
CCARRAY_FOREACH(getChildren(), pObj)
{
auto item = dynamic_cast<ParticleSystem*>(pObj);
unsigned int count = 0;
getChildren().forEach([&count](Node* child){
auto item = dynamic_cast<ParticleSystem*>(child);
if (item != NULL)
{
count += item->getParticleCount();
}
}
});
char str[100] = {0};
sprintf(str, "%4d", count);
atlas->setString(str);