SpriteBatch now always grows by a set amount to reduce the number of times it needs to resize it's arrays
This commit is contained in:
parent
7b6f144f61
commit
96c6958674
|
@ -397,7 +397,9 @@ void SpriteBatch::AddSprite(const Texture *texture, int destLeft, int destTop, i
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckForNewSpriteSpace();
|
if (GetRemainingSpriteSpaces() < 1)
|
||||||
|
AddMoreSpriteSpace(16);
|
||||||
|
|
||||||
SetSpriteInfo(m_currentSpritePointer, texture, destLeftF, destTopF, destRightF, destBottomF, texLeft, texTop, texRight, texBottom, color);
|
SetSpriteInfo(m_currentSpritePointer, texture, destLeftF, destTopF, destRightF, destBottomF, texLeft, texTop, texRight, texBottom, color);
|
||||||
++m_currentSpritePointer;
|
++m_currentSpritePointer;
|
||||||
}
|
}
|
||||||
|
@ -417,7 +419,9 @@ void SpriteBatch::AddSprite(const Texture *texture, int destLeft, int destTop, i
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckForNewSpriteSpace();
|
if (GetRemainingSpriteSpaces() < 1)
|
||||||
|
AddMoreSpriteSpace(16);
|
||||||
|
|
||||||
SetSpriteInfo(m_currentSpritePointer, texture, destLeftF, destTopF, destRightF, destBottomF, texCoordLeft, texCoordTop, texCoordRight, texCoordBottom, color);
|
SetSpriteInfo(m_currentSpritePointer, texture, destLeftF, destTopF, destRightF, destBottomF, texCoordLeft, texCoordTop, texCoordRight, texCoordBottom, color);
|
||||||
++m_currentSpritePointer;
|
++m_currentSpritePointer;
|
||||||
}
|
}
|
||||||
|
@ -431,8 +435,10 @@ void SpriteBatch::AddSprite(const Texture *texture, float destLeft, float destTo
|
||||||
if (!ClipSpriteCoords(destLeft, destTop, destRight, destBottom, texCoordLeft, texCoordTop, texCoordRight, texCoordBottom))
|
if (!ClipSpriteCoords(destLeft, destTop, destRight, destBottom, texCoordLeft, texCoordTop, texCoordRight, texCoordBottom))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GetRemainingSpriteSpaces() < 1)
|
||||||
|
AddMoreSpriteSpace(16);
|
||||||
|
|
||||||
CheckForNewSpriteSpace();
|
|
||||||
SetSpriteInfo(m_currentSpritePointer, texture, destLeft, destTop, destRight, destBottom, texCoordLeft, texCoordTop, texCoordRight, texCoordBottom, color);
|
SetSpriteInfo(m_currentSpritePointer, texture, destLeft, destTop, destRight, destBottom, texCoordLeft, texCoordTop, texCoordRight, texCoordBottom, color);
|
||||||
++m_currentSpritePointer;
|
++m_currentSpritePointer;
|
||||||
}
|
}
|
||||||
|
@ -603,23 +609,19 @@ void SpriteBatch::RenderQueueRange(uint firstSpriteIndex, uint lastSpriteIndex)
|
||||||
m_graphicsDevice->RenderTriangles(startVertex, (lastVertex - startVertex) / 3);
|
m_graphicsDevice->RenderTriangles(startVertex, (lastVertex - startVertex) / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteBatch::CheckForNewSpriteSpace()
|
uint SpriteBatch::GetRemainingSpriteSpaces() const
|
||||||
{
|
{
|
||||||
// HACK: the assumption is made here that this will never expand the buffers
|
uint currentMaxSprites = m_vertices->GetNumElements() / 6;
|
||||||
// by an amount that could be used to store more then one entity at a
|
return currentMaxSprites - m_currentSpritePointer;
|
||||||
// time. This is because we use std::vector::push_back to expand the
|
}
|
||||||
// entity object storage by only one.
|
|
||||||
|
|
||||||
uint verticesRequired = 6;
|
void SpriteBatch::AddMoreSpriteSpace(uint numSprites)
|
||||||
if (m_vertices->GetRemainingSpace() < verticesRequired)
|
{
|
||||||
{
|
uint numVerticesToAdd = numSprites * 6;
|
||||||
// need to add more space for a new entity of the specified type to fit
|
uint newTextureArraySize = m_textures.size() + numSprites;
|
||||||
m_vertices->Extend(verticesRequired - m_vertices->GetRemainingSpace());
|
|
||||||
ASSERT(m_vertices->GetRemainingSpace() >= verticesRequired);
|
m_vertices->Extend(numVerticesToAdd);
|
||||||
|
m_textures.resize(newTextureArraySize);
|
||||||
m_textures.push_back(NULL);
|
|
||||||
ASSERT(m_currentSpritePointer < m_textures.size());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int SpriteBatch::FixYCoord(int y, uint sourceHeight) const
|
inline int SpriteBatch::FixYCoord(int y, uint sourceHeight) const
|
||||||
|
|
|
@ -327,7 +327,8 @@ private:
|
||||||
void RenderQueue();
|
void RenderQueue();
|
||||||
void RenderQueueRange(uint firstSpriteIndex, uint lastSpriteIndex);
|
void RenderQueueRange(uint firstSpriteIndex, uint lastSpriteIndex);
|
||||||
|
|
||||||
void CheckForNewSpriteSpace();
|
uint GetRemainingSpriteSpaces() const;
|
||||||
|
void AddMoreSpriteSpace(uint numSprites);
|
||||||
|
|
||||||
int FixYCoord(int y, uint sourceHeight) const;
|
int FixYCoord(int y, uint sourceHeight) const;
|
||||||
float FixYCoord(int y, float sourceHeight) const;
|
float FixYCoord(int y, float sourceHeight) const;
|
||||||
|
|
Reference in a new issue