summaryrefslogtreecommitdiff
path: root/src/compoundsprite.h
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-01-28 21:59:34 +0100
committerAndrei Karas <akaras@inbox.ru>2012-01-29 16:19:51 +0300
commitdb068ff16aa689c180037af831d9ba6fca7594d7 (patch)
treebf2106e046970b9b062c7fe429f35f5298f6a9eb /src/compoundsprite.h
parente18e3bdf005824b5875bda74053c116b6c4c059f (diff)
downloadmanaverse-db068ff16aa689c180037af831d9ba6fca7594d7.tar.gz
manaverse-db068ff16aa689c180037af831d9ba6fca7594d7.tar.bz2
manaverse-db068ff16aa689c180037af831d9ba6fca7594d7.tar.xz
manaverse-db068ff16aa689c180037af831d9ba6fca7594d7.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 Conflicts: src/compoundsprite.cpp src/compoundsprite.h
Diffstat (limited to 'src/compoundsprite.h')
-rw-r--r--src/compoundsprite.h21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/compoundsprite.h b/src/compoundsprite.h
index 1c04e44d2..1b9eeca34 100644
--- a/src/compoundsprite.h
+++ b/src/compoundsprite.h
@@ -44,11 +44,11 @@ class CompoundItem
Image *alphaImage;
};
-class CompoundSprite : public Sprite, private std::vector<Sprite*>
+class CompoundSprite : public Sprite
{
public:
- typedef CompoundSprite::iterator SpriteIterator;
- typedef CompoundSprite::const_iterator SpriteConstIterator;
+ typedef std::vector<Sprite*>::iterator SpriteIterator;
+ typedef std::vector<Sprite*>::const_iterator SpriteConstIterator;
CompoundSprite();
@@ -60,7 +60,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.
@@ -72,7 +72,7 @@ public:
*/
virtual int getHeight() const;
- virtual const Image* getImage() const;
+ virtual const Image *getImage() const;
virtual bool setSpriteDirection(SpriteDirection direction);
@@ -83,17 +83,17 @@ public:
unsigned int getFrameCount() const;
size_t size() const
- { return std::vector<Sprite*>::size(); }
+ { return mSprites.size(); }
bool empty() const
- { return std::vector<Sprite*>::empty(); }
+ { return mSprites.empty(); }
- 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);
@@ -144,6 +144,7 @@ private:
bool mEnableAlphaFix;
bool mDisableAdvBeingCaching;
bool mDisableBeingCaching;
+ std::vector<Sprite*> mSprites;
};
#endif // COMPOUNDSPRITE_H