diff --git a/core/2d/Label.cpp b/core/2d/Label.cpp index 08209143d3..4623ff617a 100644 --- a/core/2d/Label.cpp +++ b/core/2d/Label.cpp @@ -141,7 +141,7 @@ public: if (_textureAtlas) { - _textureAtlas->updateQuad(&_quad, _atlasIndex); + _textureAtlas->updateQuad(_quad, _atlasIndex); } _recursiveDirty = false; @@ -176,7 +176,7 @@ public: _quad.tl.colors = color4; _quad.tr.colors = color4; - _textureAtlas->updateQuad(&_quad, _atlasIndex); + _textureAtlas->updateQuad(_quad, _atlasIndex); } void setVisible(bool visible) override @@ -2388,7 +2388,7 @@ void Label::updateColor() quads[index].br.colors = color4; quads[index].tl.colors = color4; quads[index].tr.colors = color4; - textureAtlas->updateQuad(&quads[index], index); + textureAtlas->updateQuad(quads[index], index); } } } diff --git a/core/2d/LabelAtlas.cpp b/core/2d/LabelAtlas.cpp index 6a9f37c316..47bde5f2df 100644 --- a/core/2d/LabelAtlas.cpp +++ b/core/2d/LabelAtlas.cpp @@ -263,7 +263,7 @@ void LabelAtlas::updateColor() quads[index].br.colors = color4; quads[index].tl.colors = color4; quads[index].tr.colors = color4; - _textureAtlas->updateQuad(&quads[index], index); + _textureAtlas->updateQuad(quads[index], index); } } } diff --git a/core/2d/Layer.cpp b/core/2d/Layer.cpp index f331a8da14..2095b3c5bf 100644 --- a/core/2d/Layer.cpp +++ b/core/2d/Layer.cpp @@ -265,7 +265,7 @@ void LayerGradient::updateColor() if (_renderMode == RenderMode::QUAD_BATCHNODE) { if (_atlasIndex != INDEX_NOT_INITIALIZED) - _textureAtlas->updateQuad(&_quad, _atlasIndex); + _textureAtlas->updateQuad(_quad, _atlasIndex); else // no need to set it recursively // update dirty_, don't update recursiveDirty_ diff --git a/core/2d/ProgressTimer.cpp b/core/2d/ProgressTimer.cpp index e854528602..e7e1fd2bb8 100644 --- a/core/2d/ProgressTimer.cpp +++ b/core/2d/ProgressTimer.cpp @@ -241,10 +241,10 @@ void ProgressTimer::updateColor() if (!_vertexData.empty()) { - const Color4B& sc = _sprite->getQuad().tl.colors; - for (int i = 0; i < _vertexData.size(); ++i) + const auto& sc = _sprite->getQuad().tl.colors; + for (auto& d : _vertexData) { - _vertexData[i].colors = sc; + d.colors = sc; } } } diff --git a/core/2d/Sprite.cpp b/core/2d/Sprite.cpp index 8b68fb791d..3bcff3b2b7 100644 --- a/core/2d/Sprite.cpp +++ b/core/2d/Sprite.cpp @@ -1041,7 +1041,7 @@ void Sprite::updateTransform() // MARMALADE CHANGE: ADDED CHECK FOR nullptr, TO PERMIT SPRITES WITH NO BATCH NODE / TEXTURE ATLAS if (_textureAtlas) - _textureAtlas->updateQuad(&_quad, _atlasIndex); + _textureAtlas->updateQuad(_quad, _atlasIndex); _recursiveDirty = false; setDirty(false); @@ -1509,7 +1509,7 @@ void Sprite::updateColor() if (_renderMode == RenderMode::QUAD_BATCHNODE) { if (_atlasIndex != INDEX_NOT_INITIALIZED) - _textureAtlas->updateQuad(&_quad, _atlasIndex); + _textureAtlas->updateQuad(_quad, _atlasIndex); else // no need to set it recursively // update dirty_, don't update recursiveDirty_ diff --git a/core/2d/Sprite.h b/core/2d/Sprite.h index 26aa42e63d..6cc54e789e 100644 --- a/core/2d/Sprite.h +++ b/core/2d/Sprite.h @@ -393,7 +393,7 @@ public: * @js NA * @lua NA */ - V3F_C4B_T2F_Quad getQuad() const { return _quad; } + const V3F_C4B_T2F_Quad& getQuad() const { return _quad; } /** * Returns whether or not the texture rectangle is rotated. diff --git a/core/2d/SpriteBatchNode.cpp b/core/2d/SpriteBatchNode.cpp index c3f9ed4646..2447219a9c 100644 --- a/core/2d/SpriteBatchNode.cpp +++ b/core/2d/SpriteBatchNode.cpp @@ -604,8 +604,8 @@ void SpriteBatchNode::appendChild(Sprite* sprite) sprite->setAtlasIndex(index); - V3F_C4B_T2F_Quad quad = sprite->getQuad(); - _textureAtlas->insertQuad(&quad, index); + auto&& quad = sprite->getQuad(); + _textureAtlas->insertQuad(quad, index); // add children recursively auto& children = sprite->getChildren(); @@ -723,8 +723,8 @@ void SpriteBatchNode::insertQuadFromSprite(Sprite* sprite, ssize_t index) sprite->setBatchNode(this); sprite->setAtlasIndex(static_cast(index)); - V3F_C4B_T2F_Quad quad = sprite->getQuad(); - _textureAtlas->insertQuad(&quad, index); + auto&& quad = sprite->getQuad(); + _textureAtlas->insertQuad(quad, index); // FIXME:: updateTransform will update the textureAtlas too, using updateQuad. // FIXME:: so, it should be AFTER the insertQuad diff --git a/core/renderer/TextureAtlas.cpp b/core/renderer/TextureAtlas.cpp index 26d83fdd3e..eba146a062 100644 --- a/core/renderer/TextureAtlas.cpp +++ b/core/renderer/TextureAtlas.cpp @@ -204,18 +204,18 @@ void TextureAtlas::setupIndices() // TextureAtlas - Update, Insert, Move & Remove -void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad* quad, ssize_t index) +void TextureAtlas::updateQuad(const V3F_C4B_T2F_Quad& quad, ssize_t index) { AXASSERT(index >= 0 && index < _capacity, "updateQuadWithTexture: Invalid index"); _totalQuads = MAX(index + 1, _totalQuads); - _quads[index] = *quad; + _quads[index] = quad; _dirty = true; } -void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad* quad, ssize_t index) +void TextureAtlas::insertQuad(const V3F_C4B_T2F_Quad& quad, ssize_t index) { AXASSERT(index >= 0 && index < _capacity, "insertQuadWithTexture: Invalid index"); @@ -232,7 +232,7 @@ void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad* quad, ssize_t index) memmove(&_quads[index + 1], &_quads[index], sizeof(_quads[0]) * remaining); } - _quads[index] = *quad; + _quads[index] = quad; _dirty = true; } diff --git a/core/renderer/TextureAtlas.h b/core/renderer/TextureAtlas.h index 11e9a3b380..36b8bf0b2d 100644 --- a/core/renderer/TextureAtlas.h +++ b/core/renderer/TextureAtlas.h @@ -111,14 +111,14 @@ public: @param index Index must be between 0 and the atlas capacity - 1. @since v0.8 */ - void updateQuad(V3F_C4B_T2F_Quad* quad, ssize_t index); + void updateQuad(const V3F_C4B_T2F_Quad& quad, ssize_t index); /** Inserts a Quad (texture, vertex and color) at a certain index. @param quad Quad that are going to be rendered. @param index Index must be between 0 and the atlas capacity - 1. @since v0.8 */ - void insertQuad(V3F_C4B_T2F_Quad* quad, ssize_t index); + void insertQuad(const V3F_C4B_T2F_Quad& quad, ssize_t index); /** Inserts a c array of quads at a given index. @param quads Quad that are going to be rendered. diff --git a/extensions/cocostudio/Skin.cpp b/extensions/cocostudio/Skin.cpp index 6ae7e1c4da..e2fe4b99b1 100644 --- a/extensions/cocostudio/Skin.cpp +++ b/extensions/cocostudio/Skin.cpp @@ -202,7 +202,7 @@ void Skin::updateTransform() // MARMALADE CHANGE: ADDED CHECK FOR nullptr, TO PERMIT SPRITES WITH NO BATCH NODE / TEXTURE ATLAS if (_textureAtlas) { - _textureAtlas->updateQuad(&_quad, _textureAtlas->getTotalQuads()); + _textureAtlas->updateQuad(_quad, _textureAtlas->getTotalQuads()); } }