1
0
forked from 0ad/0ad
0ad/source/gui/CGUISprite.cpp
janwas c817566222 # housekeeping
replaced all (*) CStr / CStrW by-value params with const reference. hoo
boy.

please always perform this optimization (actually standard idiom) when
writing the code - it takes little work, tells the next guy that the
string won't be modified, and makes a large performance difference.

(* where possible.. a few require other changes and will follow later)

This was SVN commit r4151.
2006-07-20 14:37:58 +00:00

53 lines
1.1 KiB
C++

#include "precompiled.h"
#include "CGUISprite.h"
void CGUISpriteInstance::Draw(CRect Size, int CellID, std::map<CStr, CGUISprite> &Sprites)
{
if (m_CachedSize != Size || m_CachedCellID != CellID)
{
GUIRenderer::UpdateDrawCallCache(m_DrawCallCache, m_SpriteName, Size, CellID, Sprites);
m_CachedSize = Size;
m_CachedCellID = CellID;
}
GUIRenderer::Draw(m_DrawCallCache);
}
void CGUISpriteInstance::Invalidate()
{
m_CachedSize = CRect();
m_CachedCellID = -1;
}
bool CGUISpriteInstance::IsEmpty() const
{
return m_SpriteName=="";
}
// Plus a load of constructors / assignment operators, which don't copy the
// DrawCall cache (to avoid losing track of who has allocated various bits
// of data):
CGUISpriteInstance::CGUISpriteInstance()
: m_CachedCellID(-1)
{
}
CGUISpriteInstance::CGUISpriteInstance(const CStr& SpriteName)
: m_SpriteName(SpriteName)
{
}
CGUISpriteInstance::CGUISpriteInstance(const CGUISpriteInstance &Sprite)
: m_SpriteName(Sprite.m_SpriteName)
{
}
CGUISpriteInstance &CGUISpriteInstance::operator=(const CStr& SpriteName)
{
m_SpriteName = SpriteName;
m_DrawCallCache.clear();
Invalidate();
return *this;
}