diff options
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/animation.h | 1 | ||||
-rw-r--r-- | src/resources/imageset.cpp (renamed from src/resources/spriteset.cpp) | 18 | ||||
-rw-r--r-- | src/resources/imageset.h (renamed from src/resources/spriteset.h) | 23 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 22 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 8 | ||||
-rw-r--r-- | src/resources/spritedef.cpp | 34 | ||||
-rw-r--r-- | src/resources/spritedef.h | 10 |
7 files changed, 56 insertions, 60 deletions
diff --git a/src/resources/animation.h b/src/resources/animation.h index 54142bcb..d0d11c69 100644 --- a/src/resources/animation.h +++ b/src/resources/animation.h @@ -29,7 +29,6 @@ #include <libxml/tree.h> class Image; -class Spriteset; /** * A single frame in an animation, with a delay and an offset. diff --git a/src/resources/spriteset.cpp b/src/resources/imageset.cpp index 96bcef0c..677c024b 100644 --- a/src/resources/spriteset.cpp +++ b/src/resources/imageset.cpp @@ -21,7 +21,7 @@ * $Id$ */ -#include "spriteset.h" +#include "imageset.h" #include "../log.h" @@ -29,7 +29,7 @@ #include "../utils/dtor.h" -Spriteset::Spriteset(const std::string& idPath, +ImageSet::ImageSet(const std::string& idPath, Image *img, int width, int height): Resource(idPath) @@ -38,28 +38,28 @@ Spriteset::Spriteset(const std::string& idPath, { for (int x = 0; x + width <= img->getWidth(); x += width) { - mSpriteset.push_back(img->getSubImage(x, y, width, height)); + mImages.push_back(img->getSubImage(x, y, width, height)); } } mWidth = width; mHeight = height; } -Spriteset::~Spriteset() +ImageSet::~ImageSet() { - for_each(mSpriteset.begin(), mSpriteset.end(), make_dtor(mSpriteset)); + for_each(mImages.begin(), mImages.end(), make_dtor(mImages)); } Image* -Spriteset::get(size_type i) +ImageSet::get(size_type i) { - if (i >= mSpriteset.size()) + if (i >= mImages.size()) { - logger->log("Warning: Sprite #%i does not exist in this spriteset", i); + logger->log("Warning: Sprite #%i does not exist in this image set", i); return NULL; } else { - return mSpriteset[i]; + return mImages[i]; } } diff --git a/src/resources/spriteset.h b/src/resources/imageset.h index 7f6b42df..3469a3bb 100644 --- a/src/resources/spriteset.h +++ b/src/resources/imageset.h @@ -21,8 +21,8 @@ * $Id$ */ -#ifndef _TMW_SPRITESET_H -#define _TMW_SPRITESET_H +#ifndef _TMW_IMAGESET_H +#define _TMW_IMAGESET_H #include <vector> @@ -33,21 +33,19 @@ class Image; /** * Stores a set of subimages originating from a single image. - * - * TODO: Should probably be renamed to ImageSet or TileSet. */ -class Spriteset : public Resource +class ImageSet : public Resource { public: /* * Cuts the passed image in a grid of sub images. */ - Spriteset(const std::string &idPath, Image *img, int w, int h); + ImageSet(const std::string &idPath, Image *img, int w, int h); /** * Destructor. */ - ~Spriteset(); + ~ImageSet(); int getWidth() { return mWidth; }; @@ -56,14 +54,13 @@ class Spriteset : public Resource typedef std::vector<Image*>::size_type size_type; Image* get(size_type i); - size_type size() { return mSpriteset.size(); } + size_type size() { return mImages.size(); } private: - // Vector storing the whole spriteset. - std::vector<Image*> mSpriteset; - // Height and width of the images in the spriteset - int mHeight; - int mWidth; + std::vector<Image*> mImages; + + int mHeight; /**< Height of the images in the image set. */ + int mWidth; /**< Width of the images in the image set. */ }; #endif diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 37a82b0c..985c11dd 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -31,7 +31,7 @@ #include "image.h" #include "music.h" #include "soundeffect.h" -#include "spriteset.h" +#include "imageset.h" #include "spritedef.h" #include "../log.h" @@ -46,7 +46,7 @@ ResourceManager::ResourceManager() ResourceManager::~ResourceManager() { - // Release any remaining spritedefs first because they depend on spritesets + // Release any remaining spritedefs first because they depend on image sets ResourceIterator iter = mResources.begin(); while (iter != mResources.end()) { @@ -63,11 +63,11 @@ ResourceManager::~ResourceManager() } } - // Release any remaining spritesets first because they depend on images + // Release any remaining image sets first because they depend on images iter = mResources.begin(); while (iter != mResources.end()) { - if (dynamic_cast<Spriteset*>(iter->second) != 0) + if (dynamic_cast<ImageSet*>(iter->second) != 0) { cleanUp(iter->second); ResourceIterator toErase = iter; @@ -229,8 +229,8 @@ ResourceManager::getSoundEffect(const std::string &idPath) return dynamic_cast<SoundEffect*>(get(SOUND_EFFECT, idPath)); } -Spriteset* -ResourceManager::getSpriteset(const std::string &imagePath, int w, int h) +ImageSet* +ResourceManager::getImageSet(const std::string &imagePath, int w, int h) { std::stringstream ss; ss << imagePath << "[" << w << "x" << h << "]"; @@ -240,7 +240,7 @@ ResourceManager::getSpriteset(const std::string &imagePath, int w, int h) if (resIter != mResources.end()) { resIter->second->incRef(); - return dynamic_cast<Spriteset*>(resIter->second); + return dynamic_cast<ImageSet*>(resIter->second); } Image *img = getImage(imagePath); @@ -249,13 +249,13 @@ ResourceManager::getSpriteset(const std::string &imagePath, int w, int h) return NULL; } - Spriteset *spriteset = new Spriteset(idPath, img, w, h); - spriteset->incRef(); - mResources[idPath] = spriteset; + ImageSet *imageSet = new ImageSet(idPath, img, w, h); + imageSet->incRef(); + mResources[idPath] = imageSet; img->decRef(); - return spriteset; + return imageSet; } SpriteDef* diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index e176e337..db29e6d3 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -33,7 +33,7 @@ class Resource; class Image; class Music; class SoundEffect; -class Spriteset; +class ImageSet; class SpriteDef; /** @@ -143,11 +143,11 @@ class ResourceManager getSoundEffect(const std::string &idPath); /** - * Creates a spriteset based on the image referenced by the given + * Creates a image set based on the image referenced by the given * path and the supplied sprite sizes */ - Spriteset* - getSpriteset(const std::string &imagePath, int w, int h); + ImageSet* + getImageSet(const std::string &imagePath, int w, int h); /** * Creates a sprite definition based on a given path and the supplied diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index feb6f8f8..d29bd847 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -28,7 +28,7 @@ #include "animation.h" #include "action.h" #include "resourcemanager.h" -#include "spriteset.h" +#include "imageset.h" #include "image.h" #include "../utils/xml.h" @@ -135,30 +135,30 @@ SpriteDef::loadImageSet(xmlNodePtr node) std::string imageSrc = XML::getProperty(node, "src", ""); ResourceManager *resman = ResourceManager::getInstance(); - Spriteset *spriteset = resman->getSpriteset(imageSrc, width, height); + ImageSet *imageSet = resman->getImageSet(imageSrc, width, height); - if (!spriteset) + if (!imageSet) { logger->error("Couldn't load imageset!"); } - mSpritesets[name] = spriteset; + mImageSets[name] = imageSet; } void SpriteDef::loadAction(xmlNodePtr node, int variant_offset) { const std::string actionName = XML::getProperty(node, "name", ""); - const std::string imagesetName = XML::getProperty(node, "imageset", ""); + const std::string imageSetName = XML::getProperty(node, "imageset", ""); - SpritesetIterator si = mSpritesets.find(imagesetName); - if (si == mSpritesets.end()) + ImageSetIterator si = mImageSets.find(imageSetName); + if (si == mImageSets.end()) { logger->log("Warning: imageset \"%s\" not defined in %s", - imagesetName.c_str(), getIdPath().c_str()); + imageSetName.c_str(), getIdPath().c_str()); return; } - Spriteset *imageset = si->second; + ImageSet *imageSet = si->second; SpriteAction actionType = makeSpriteAction(actionName); if (actionType == ACTION_INVALID) @@ -183,14 +183,14 @@ SpriteDef::loadAction(xmlNodePtr node, int variant_offset) { if (xmlStrEqual(animationNode->name, BAD_CAST "animation")) { - loadAnimation(animationNode, action, imageset, variant_offset); + loadAnimation(animationNode, action, imageSet, variant_offset); } } } void SpriteDef::loadAnimation(xmlNodePtr animationNode, - Action *action, Spriteset *imageset, + Action *action, ImageSet *imageSet, int variant_offset) { std::string directionName = @@ -215,8 +215,8 @@ SpriteDef::loadAnimation(xmlNodePtr animationNode, int delay = XML::getProperty(frameNode, "delay", 0); int offsetX = XML::getProperty(frameNode, "offsetX", 0); int offsetY = XML::getProperty(frameNode, "offsetY", 0); - offsetY -= imageset->getHeight() - 32; - offsetX -= imageset->getWidth() / 2 - 16; + offsetY -= imageSet->getHeight() - 32; + offsetX -= imageSet->getWidth() / 2 - 16; if (xmlStrEqual(frameNode->name, BAD_CAST "frame")) { @@ -228,7 +228,7 @@ SpriteDef::loadAnimation(xmlNodePtr animationNode, continue; } - Image *img = imageset->get(index + variant_offset); + Image *img = imageSet->get(index + variant_offset); if (!img) { @@ -251,7 +251,7 @@ SpriteDef::loadAnimation(xmlNodePtr animationNode, while (end >= start) { - Image *img = imageset->get(start + variant_offset); + Image *img = imageSet->get(start + variant_offset); if (!img) { @@ -296,8 +296,8 @@ SpriteDef::substituteAction(SpriteAction complete, SpriteAction with) SpriteDef::~SpriteDef() { - for (SpritesetIterator i = mSpritesets.begin(); - i != mSpritesets.end(); ++i) + for (ImageSetIterator i = mImageSets.begin(); + i != mImageSets.end(); ++i) { i->second->decRef(); } diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index 057129ad..6d335b02 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -32,7 +32,7 @@ #include <libxml/tree.h> class Action; -class Spriteset; +class ImageSet; enum SpriteAction { @@ -111,7 +111,7 @@ class SpriteDef : public Resource */ void loadAnimation(xmlNodePtr animationNode, - Action *action, Spriteset *imageset, + Action *action, ImageSet *imageSet, int variant_offset); /** @@ -140,12 +140,12 @@ class SpriteDef : public Resource makeSpriteDirection(const std::string &direction); - typedef std::map<std::string, Spriteset*> Spritesets; - typedef Spritesets::iterator SpritesetIterator; + typedef std::map<std::string, ImageSet*> ImageSets; + typedef ImageSets::iterator ImageSetIterator; typedef std::map<SpriteAction, Action*> Actions; - Spritesets mSpritesets; + ImageSets mImageSets; Actions mActions; Action *mAction; SpriteDirection mDirection; |