void TextureAtlas::moveQuadsFromIndex(ssize_t oldIndex, ssize_t amount, ssize_t newIndex)
{
CCASSERT(oldIndex>=0 && amount>=0 && newIndex>=0, "values must be >= 0");
CCASSERT(newIndex + amount <= _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
CCASSERT(oldIndex < _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
if( oldIndex == newIndex )
{
return;
}
//create buffer
size_t quadSize = sizeof(V3F_C4B_T2F_Quad);
V3F_C4B_T2F_Quad* tempQuads = (V3F_C4B_T2F_Quad*)malloc( quadSize * amount);
memcpy( tempQuads, &_quads, quadSize * amount );
if (newIndex < oldIndex)
{
// move quads from newIndex to newIndex + amount to make room for buffer
/* 这里的编码是不是写反了?应为:
* memmove(&_quads, &_quads, (oldIndex - newIndex)*quadSize);
*/
memmove( &_quads, &_quads, (oldIndex-newIndex)*quadSize);
}
else
{
// move quads above back
memmove( &_quads, &_quads, (newIndex-oldIndex)*quadSize);
}
memcpy( &_quads, tempQuads, amount*quadSize);
free(tempQuads);
_dirty = true;
}
v3.3中就是如此编码的,我看了一下v3.6中依旧如此。
具体的分析可参见我的这篇帖子:
cocos2d-x v3.3 TextureAtlas
http://www.cocoachina.com/bbs/read.php?tid=311439