在这诚恳地请教一个问题:3.0beta版本中TextureAtlas类有个函数void TextureAtlas::moveQuadsFromIndex(ssize_t oldIndex, ssize_t amount, ssize_t newIndex),定义如下所示
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);
}
else
{
// move quads above back
memmove( &_quads, &_quads, (newIndex-oldIndex)*quadSize);
}
memcpy( &_quads, tempQuads, amount*quadSize);
free(tempQuads);
_dirty = true;
}
当中的这一段
if (newIndex < oldIndex)
{
// move quads from newIndex to newIndex + amount to make room for buffer
memmove( &_quads, &_quads, (oldIndex-newIndex)*quadSize);
}
这个作者原意是不是要移动newIndex位置(开始算)起的(oldIndex-newIndex)*quadSize个字节到newIndex+amount位置?是的话这句是不是要这样写:
memmove( &_quads, &_quads, (oldIndex-newIndex)*quadSize);
或者是我理解错了!本人没有其它意思,单纯地看不懂这一点,特地请教!!如有冒犯,请见谅!!