summaryrefslogtreecommitdiff
path: root/src/compoundsprite.h
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-01-28 21:59:34 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-01-29 13:24:20 +0100
commit3cd5ac3ced565c86a5e5ca4fdb336e91ba55f524 (patch)
tree68c8b86fe57f5a56105714c8e1aa63dfd969456e /src/compoundsprite.h
parent4502951aed77f18175adb601f0e094fd921c360d (diff)
downloadmana-3cd5ac3ced565c86a5e5ca4fdb336e91ba55f524.tar.gz
mana-3cd5ac3ced565c86a5e5ca4fdb336e91ba55f524.tar.bz2
mana-3cd5ac3ced565c86a5e5ca4fdb336e91ba55f524.tar.xz
mana-3cd5ac3ced565c86a5e5ca4fdb336e91ba55f524.zip
Removed inheritance from std::vector by CompoundSprite
In my opinion, the code is clearer when using aggregation. For performance it makes no difference. This also fixes a memory leak in CompountSprite::clear, which forgot to delete any existing sprites. Reviewed-by: Erik Schilling
Diffstat (limited to 'src/compoundsprite.h')
-rw-r--r--src/compoundsprite.h20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/compoundsprite.h b/src/compoundsprite.h
index c65848b9..10ee01e1 100644
--- a/src/compoundsprite.h
+++ b/src/compoundsprite.h
@@ -27,7 +27,7 @@
class Image;
-class CompoundSprite : public Sprite, private std::vector<Sprite*>
+class CompoundSprite : public Sprite
{
public:
CompoundSprite();
@@ -40,7 +40,7 @@ public:
virtual bool update(int time);
- virtual bool draw(Graphics* graphics, int posX, int posY) const;
+ virtual bool draw(Graphics *graphics, int posX, int posY) const;
/**
* Gets the width in pixels of the first sprite in the list.
@@ -60,7 +60,7 @@ public:
int getOffsetY() const
{ return mOffsetY; }
- virtual const Image* getImage() const;
+ virtual const Image *getImage() const;
virtual bool setDirection(SpriteDirection direction);
@@ -75,14 +75,14 @@ public:
int getDuration() const;
size_t size() const
- { return std::vector<Sprite*>::size(); }
+ { return mSprites.size(); }
- void addSprite(Sprite* sprite);
+ void addSprite(Sprite *sprite);
- void setSprite(int layer, Sprite* sprite);
+ void setSprite(int layer, Sprite *sprite);
Sprite *getSprite(int layer) const
- { return at(layer); }
+ { return mSprites.at(layer); }
void removeSprite(int layer);
@@ -104,8 +104,8 @@ public:
{ mNeedsRedraw = true; }
private:
- typedef CompoundSprite::iterator SpriteIterator;
- typedef CompoundSprite::const_iterator SpriteConstIterator;
+ typedef std::vector<Sprite*>::iterator SpriteIterator;
+ typedef std::vector<Sprite*>::const_iterator SpriteConstIterator;
void redraw() const;
@@ -116,6 +116,8 @@ private:
mutable int mOffsetX, mOffsetY;
mutable bool mNeedsRedraw;
+
+ std::vector<Sprite*> mSprites;
};
#endif // COMPOUNDSPRITE_H