iterator in Sprite fixes

And replaces some std::for_each() with for() to prevent another object in the stack.
This commit is contained in:
Ricardo Quesada 2013-12-18 18:33:04 -08:00
parent 5d1fa0da12
commit b9a64725ab
5 changed files with 43 additions and 55 deletions

View File

@ -305,15 +305,12 @@ void Label::alignText()
LabelTextFormatter::alignText(this);
int strLen = cc_wcslen(_currentUTF16String);
std::for_each(_children.begin(), _children.end(), [this,&strLen](Node* child){
if (child)
{
int tag = child->getTag();
if(tag < 0 || tag >= strLen)
SpriteBatchNode::removeChild(child, true);
}
});
for(const auto &child : _children) {
int tag = child->getTag();
if(tag < 0 || tag >= strLen)
SpriteBatchNode::removeChild(child, true);
}
_reusedLetter->setBatchNode(nullptr);
int vaildIndex = 0;
@ -522,9 +519,8 @@ void Label::draw()
_shaderProgram->setUniformLocationWith3f(_uniformEffectColor, _effectColor.r/255.0f,_effectColor.g/255.0f,_effectColor.b/255.0f);
}
std::for_each(_children.begin(), _children.end(), [](Node* child){
for(const auto &child: _children)
child->updateTransform();
});
GL::blendFunc( _blendFunc.src, _blendFunc.dst );
@ -710,17 +706,14 @@ void Label::setOpacityModifyRGB(bool isOpacityModifyRGB)
{
_isOpacityModifyRGB = isOpacityModifyRGB;
std::for_each(_children.begin(), _children.end(), [this](Node* child){
if (child)
for(const auto& child: _children) {
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(child);
if (pRGBAProtocol)
{
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(child);
if (pRGBAProtocol)
{
pRGBAProtocol->setOpacityModifyRGB(_isOpacityModifyRGB);
}
pRGBAProtocol->setOpacityModifyRGB(_isOpacityModifyRGB);
}
});
}
_reusedLetter->setOpacityModifyRGB(true);
}
@ -752,10 +745,10 @@ void Label::updateDisplayedOpacity(GLubyte parentOpacity)
{
_displayedOpacity = _realOpacity * parentOpacity/255.0;
std::for_each(_children.begin(), _children.end(), [this](Node* child){
for(const auto &child: _children) {
Sprite *item = static_cast<Sprite*>( child );
item->updateDisplayedOpacity(_displayedOpacity);
});
}
V3F_C4B_T2F_Quad *quads = _textureAtlas->getQuads();
auto count = _textureAtlas->getTotalQuads();
@ -818,10 +811,10 @@ void Label::updateDisplayedColor(const Color3B& parentColor)
_displayedColor.g = _realColor.g * parentColor.g/255.0;
_displayedColor.b = _realColor.b * parentColor.b/255.0;
std::for_each(_children.begin(), _children.end(), [this](Node* child){
for(const auto &child : _children) {
Sprite *item = static_cast<Sprite*>( child );
item->updateDisplayedColor(_displayedColor);
});
}
V3F_C4B_T2F_Quad *quads = _textureAtlas->getQuads();
auto count = _textureAtlas->getTotalQuads();

View File

@ -747,9 +747,8 @@ void LabelBMFont::setString(unsigned short *newString, bool needUpdateLabel)
CC_SAFE_DELETE_ARRAY(tmp);
}
std::for_each(_children.begin(), _children.end(), [](Node* child){
for(const auto &child : _children)
child->setVisible(false);
});
this->createFontChars();
@ -823,16 +822,13 @@ void LabelBMFont::setOpacity(GLubyte opacity)
void LabelBMFont::setOpacityModifyRGB(bool var)
{
_isOpacityModifyRGB = var;
std::for_each(_children.begin(), _children.end(), [this](Node* child){
if (child)
for(const auto &child : _children) {
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(child);
if (pRGBAProtocol)
{
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(child);
if (pRGBAProtocol)
{
pRGBAProtocol->setOpacityModifyRGB(_isOpacityModifyRGB);
}
pRGBAProtocol->setOpacityModifyRGB(_isOpacityModifyRGB);
}
});
}
}
bool LabelBMFont::isOpacityModifyRGB() const
{
@ -843,10 +839,10 @@ void LabelBMFont::updateDisplayedOpacity(GLubyte parentOpacity)
{
_displayedOpacity = _realOpacity * parentOpacity/255.0f;
std::for_each(_children.begin(), _children.end(),[this](Node* child){
for(const auto &child : _children) {
Sprite *item = static_cast<Sprite*>( child );
item->updateDisplayedOpacity(_displayedOpacity);
});
}
}
void LabelBMFont::updateDisplayedColor(const Color3B& parentColor)
@ -855,10 +851,10 @@ void LabelBMFont::updateDisplayedColor(const Color3B& parentColor)
_displayedColor.g = _realColor.g * parentColor.g/255.0f;
_displayedColor.b = _realColor.b * parentColor.b/255.0f;
std::for_each(_children.begin(), _children.end(),[this](Node* child){
for(const auto &child : _children) {
Sprite *item = static_cast<Sprite*>( child );
item->updateDisplayedColor(_displayedColor);
});
}
}
bool LabelBMFont::isCascadeColorEnabled() const

View File

@ -507,13 +507,13 @@ void LayerRGBA::updateDisplayedOpacity(GLubyte parentOpacity)
if (_cascadeOpacityEnabled)
{
std::for_each(_children.begin(), _children.end(),[this](Node* obj){
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
for(const auto &child : _children) {
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(child);
if (item)
{
item->updateDisplayedOpacity(_displayedOpacity);
}
});
}
}
}
@ -525,13 +525,13 @@ void LayerRGBA::updateDisplayedColor(const Color3B& parentColor)
if (_cascadeColorEnabled)
{
std::for_each(_children.begin(), _children.end(),[this](Node* obj){
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
for(const auto &child : _children) {
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(child);
if (item)
{
item->updateDisplayedColor(_displayedColor);
}
});
}
}
}

View File

@ -831,7 +831,7 @@ void Node::visit()
// self draw
this->draw();
for(auto it=_children.cbegin()+i; it<_children.cend(); ++it)
for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
(*it)->visit();
}
else
@ -1474,13 +1474,13 @@ void NodeRGBA::updateDisplayedOpacity(GLubyte parentOpacity)
if (_cascadeOpacityEnabled)
{
std::for_each(_children.begin(), _children.end(), [this](Node* child){
for(const auto &child : _children) {
RGBAProtocol* item = dynamic_cast<RGBAProtocol*>(child);
if (item)
{
item->updateDisplayedOpacity(_displayedOpacity);
}
});
}
}
}
@ -1529,13 +1529,13 @@ void NodeRGBA::updateDisplayedColor(const Color3B& parentColor)
if (_cascadeColorEnabled)
{
std::for_each(_children.begin(), _children.end(), [this](Node* child){
for(const auto &child : _children) {
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(child);
if (item)
{
item->updateDisplayedColor(_displayedColor);
}
});
}
}
}

View File

@ -814,13 +814,13 @@ void Sprite::removeAllChildrenWithCleanup(bool cleanup)
{
if (_batchNode)
{
std::for_each(_children.begin(), _children.end(), [this](Node* child){
for(const auto &child : _children) {
Sprite* sprite = dynamic_cast<Sprite*>(child);
if (sprite)
{
_batchNode->removeSpriteFromAtlas(sprite);
}
});
}
}
Node::removeAllChildrenWithCleanup(cleanup);
@ -860,9 +860,8 @@ void Sprite::sortAllChildren()
if ( _batchNode)
{
std::for_each(_children.begin(), _children.end(), [](Node* child){
for(const auto &child : _children)
child->sortAllChildren();
});
}
_reorderChildDirty = false;
@ -897,13 +896,13 @@ void Sprite::setDirtyRecursively(bool bValue)
// recursively set dirty
if (_hasChildren)
{
std::for_each(_children.begin(), _children.end(), [](Node* child){
for(const auto &child: _children) {
Sprite* sp = dynamic_cast<Sprite*>(child);
if (sp)
{
sp->setDirtyRecursively(true);
}
});
}
}
}