summaryrefslogtreecommitdiff
path: root/src/compoundsprite.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/compoundsprite.cpp')
-rw-r--r--src/compoundsprite.cpp78
1 files changed, 40 insertions, 38 deletions
diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp
index e76a55dcf..61fb3d4e0 100644
--- a/src/compoundsprite.cpp
+++ b/src/compoundsprite.cpp
@@ -61,10 +61,6 @@ CompoundSprite::CompoundSprite() :
CompoundSprite::~CompoundSprite()
{
- SpriteIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++it)
- delete (*it);
-
clear();
// delete mImage;
@@ -78,7 +74,7 @@ bool CompoundSprite::reset()
bool ret = false;
SpriteIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++it)
+ for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it)
{
if (*it)
ret |= (*it)->reset();
@@ -93,7 +89,7 @@ bool CompoundSprite::play(std::string action)
bool ret = false;
SpriteIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++it)
+ for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it)
{
if (*it)
ret |= (*it)->play(action);
@@ -108,7 +104,7 @@ bool CompoundSprite::update(int time)
bool ret = false;
SpriteIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++it)
+ for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it)
{
if (*it)
ret |= (*it)->update(time);
@@ -118,11 +114,14 @@ bool CompoundSprite::update(int time)
return ret;
}
-bool CompoundSprite::draw(Graphics* graphics, int posX, int posY) const
+bool CompoundSprite::draw(Graphics *graphics, int posX, int posY) const
{
if (mNeedsRedraw)
updateImages();
+ if (mSprites.empty()) // Nothing to draw
+ return false;
+
if (mAlpha == 1.0f && mImage)
{
return graphics->drawImage(mImage, posX + mOffsetX, posY + mOffsetY);
@@ -144,7 +143,7 @@ bool CompoundSprite::draw(Graphics* graphics, int posX, int posY) const
void CompoundSprite::drawSprites(Graphics* graphics, int posX, int posY) const
{
SpriteConstIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++it)
+ for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it)
{
if (*it)
{
@@ -158,7 +157,7 @@ void CompoundSprite::drawSpritesSDL(Graphics* graphics,
int posX, int posY) const
{
SpriteConstIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++it)
+ for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it)
{
if (*it)
(*it)->draw(graphics, posX, posY);
@@ -170,7 +169,7 @@ int CompoundSprite::getWidth() const
Sprite *base = nullptr;
SpriteConstIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++it)
+ for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it)
{
if ((base = (*it)))
break;
@@ -187,7 +186,7 @@ int CompoundSprite::getHeight() const
Sprite *base = nullptr;
SpriteConstIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++it)
+ for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it)
{
if ((base = (*it)))
break;
@@ -199,7 +198,7 @@ int CompoundSprite::getHeight() const
return 0;
}
-const Image* CompoundSprite::getImage() const
+const Image *CompoundSprite::getImage() const
{
return mImage;
}
@@ -209,7 +208,7 @@ bool CompoundSprite::setSpriteDirection(SpriteDirection direction)
bool ret = false;
SpriteIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++it)
+ for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it)
{
if (*it)
ret |= (*it)->setSpriteDirection(direction);
@@ -230,7 +229,7 @@ int CompoundSprite::getNumberOfLayers() const
unsigned int CompoundSprite::getCurrentFrame() const
{
SpriteConstIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++it)
+ for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it)
{
if (*it)
return (*it)->getCurrentFrame();
@@ -242,7 +241,7 @@ unsigned int CompoundSprite::getCurrentFrame() const
unsigned int CompoundSprite::getFrameCount() const
{
SpriteConstIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++it)
+ for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it)
{
if (*it)
return (*it)->getFrameCount();
@@ -251,42 +250,43 @@ unsigned int CompoundSprite::getFrameCount() const
return 0;
}
-void CompoundSprite::addSprite(Sprite* sprite)
+void CompoundSprite::addSprite(Sprite *sprite)
{
- push_back(sprite);
+ mSprites.push_back(sprite);
mNeedsRedraw = true;
}
void CompoundSprite::setSprite(int layer, Sprite* sprite)
{
// Skip if it won't change anything
- if (at(layer) == sprite)
+ if (mSprites.at(layer) == sprite)
return;
- if (at(layer))
- delete at(layer);
- at(layer) = sprite;
+ if (mSprites.at(layer))
+ delete mSprites.at(layer);
+ mSprites[layer] = sprite;
mNeedsRedraw = true;
}
void CompoundSprite::removeSprite(int layer)
{
// Skip if it won't change anything
- if (at(layer) == nullptr)
+ if (!mSprites.at(layer))
return;
- delete at(layer);
- at(layer) = nullptr;
+ delete mSprites.at(layer);
+ mSprites.at(layer) = nullptr;
mNeedsRedraw = true;
}
void CompoundSprite::clear()
{
// Skip if it won't change anything
- if (empty())
- return;
-
- std::vector<Sprite*>::clear();
+ if (!mSprites.empty())
+ {
+ delete_all(mSprites);
+ mSprites.clear();
+ }
mNeedsRedraw = true;
delete_all(imagesCache);
imagesCache.clear();
@@ -297,10 +297,11 @@ void CompoundSprite::clear()
void CompoundSprite::ensureSize(size_t layerCount)
{
// Skip if it won't change anything
- if (size() >= layerCount)
+ if (mSprites.size() >= layerCount)
return;
- resize(layerCount, nullptr);
+// resize(layerCount, nullptr);
+ mSprites.resize(layerCount);
}
/**
@@ -308,7 +309,7 @@ void CompoundSprite::ensureSize(size_t layerCount)
*/
unsigned int CompoundSprite::getCurrentFrame(unsigned int layer)
{
- if (layer >= size())
+ if (layer >= mSprites.size())
return 0;
Sprite *s = getSprite(layer);
@@ -323,7 +324,7 @@ unsigned int CompoundSprite::getCurrentFrame(unsigned int layer)
*/
unsigned int CompoundSprite::getFrameCount(unsigned int layer)
{
- if (layer >= size())
+ if (layer >= mSprites.size())
return 0;
Sprite *s = getSprite(layer);
@@ -418,7 +419,8 @@ void CompoundSprite::setAlpha(float alpha)
#endif
{
SpriteConstIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++ it)
+ for (it = mSprites.begin(), it_end = mSprites.end();
+ it != it_end; ++ it)
{
if (*it)
(*it)->setAlpha(alpha);
@@ -490,8 +492,8 @@ bool CompoundSprite::updateFromCache() const
if (ic && ic->data.size() == size())
{
bool fail(false);
- SpriteConstIterator it1 = begin();
- SpriteConstIterator it1_end = end();
+ SpriteConstIterator it1 = mSprites.begin();
+ SpriteConstIterator it1_end = mSprites.end();
VectorPointers::const_iterator it2 = ic->data.begin();
VectorPointers::const_iterator it2_end = ic->data.end();
@@ -535,7 +537,7 @@ void CompoundSprite::initCurrentCacheItem() const
// mCacheItem->alpha = mAlpha;
SpriteConstIterator it, it_end;
- for (it = begin(), it_end = end(); it != it_end; ++ it)
+ for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it)
{
if (*it)
mCacheItem->data.push_back((*it)->getHash());
@@ -548,7 +550,7 @@ bool CompoundSprite::updateNumber(unsigned num)
{
SpriteConstIterator it, it_end;
bool res(false);
- for (it = begin(), it_end = end(); it != it_end; ++ it)
+ for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it)
{
if (*it)
{