From 823aa330987205b251d9f662cfdd4c39149c6ec7 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 21 Mar 2007 21:56:12 +0000 Subject: Renamed Spriteset to ImageSet. --- src/resources/animation.h | 1 - src/resources/imageset.cpp | 65 ++++++++++++++++++++++++++++++++++++ src/resources/imageset.h | 66 +++++++++++++++++++++++++++++++++++++ src/resources/resourcemanager.cpp | 22 ++++++------- src/resources/resourcemanager.h | 8 ++--- src/resources/spritedef.cpp | 34 +++++++++---------- src/resources/spritedef.h | 10 +++--- src/resources/spriteset.cpp | 65 ------------------------------------ src/resources/spriteset.h | 69 --------------------------------------- 9 files changed, 168 insertions(+), 172 deletions(-) create mode 100644 src/resources/imageset.cpp create mode 100644 src/resources/imageset.h delete mode 100644 src/resources/spriteset.cpp delete mode 100644 src/resources/spriteset.h (limited to 'src/resources') 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 class Image; -class Spriteset; /** * A single frame in an animation, with a delay and an offset. diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp new file mode 100644 index 00000000..677c024b --- /dev/null +++ b/src/resources/imageset.cpp @@ -0,0 +1,65 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "imageset.h" + +#include "../log.h" + +#include "image.h" + +#include "../utils/dtor.h" + +ImageSet::ImageSet(const std::string& idPath, + Image *img, + int width, int height): + Resource(idPath) +{ + for (int y = 0; y + height <= img->getHeight(); y += height) + { + for (int x = 0; x + width <= img->getWidth(); x += width) + { + mImages.push_back(img->getSubImage(x, y, width, height)); + } + } + mWidth = width; + mHeight = height; +} + +ImageSet::~ImageSet() +{ + for_each(mImages.begin(), mImages.end(), make_dtor(mImages)); +} + +Image* +ImageSet::get(size_type i) +{ + if (i >= mImages.size()) + { + logger->log("Warning: Sprite #%i does not exist in this image set", i); + return NULL; + } + else + { + return mImages[i]; + } +} diff --git a/src/resources/imageset.h b/src/resources/imageset.h new file mode 100644 index 00000000..3469a3bb --- /dev/null +++ b/src/resources/imageset.h @@ -0,0 +1,66 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_IMAGESET_H +#define _TMW_IMAGESET_H + +#include + +#include "resource.h" + +class Image; + + +/** + * Stores a set of subimages originating from a single image. + */ +class ImageSet : public Resource +{ + public: + /* + * Cuts the passed image in a grid of sub images. + */ + ImageSet(const std::string &idPath, Image *img, int w, int h); + + /** + * Destructor. + */ + ~ImageSet(); + + int getWidth() { return mWidth; }; + + int getHeight() { return mHeight; }; + + typedef std::vector::size_type size_type; + Image* get(size_type i); + + size_type size() { return mImages.size(); } + + private: + std::vector 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(iter->second) != 0) + if (dynamic_cast(iter->second) != 0) { cleanUp(iter->second); ResourceIterator toErase = iter; @@ -229,8 +229,8 @@ ResourceManager::getSoundEffect(const std::string &idPath) return dynamic_cast(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(resIter->second); + return dynamic_cast(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 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 Spritesets; - typedef Spritesets::iterator SpritesetIterator; + typedef std::map ImageSets; + typedef ImageSets::iterator ImageSetIterator; typedef std::map Actions; - Spritesets mSpritesets; + ImageSets mImageSets; Actions mActions; Action *mAction; SpriteDirection mDirection; diff --git a/src/resources/spriteset.cpp b/src/resources/spriteset.cpp deleted file mode 100644 index 96bcef0c..00000000 --- a/src/resources/spriteset.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#include "spriteset.h" - -#include "../log.h" - -#include "image.h" - -#include "../utils/dtor.h" - -Spriteset::Spriteset(const std::string& idPath, - Image *img, - int width, int height): - Resource(idPath) -{ - for (int y = 0; y + height <= img->getHeight(); y += height) - { - for (int x = 0; x + width <= img->getWidth(); x += width) - { - mSpriteset.push_back(img->getSubImage(x, y, width, height)); - } - } - mWidth = width; - mHeight = height; -} - -Spriteset::~Spriteset() -{ - for_each(mSpriteset.begin(), mSpriteset.end(), make_dtor(mSpriteset)); -} - -Image* -Spriteset::get(size_type i) -{ - if (i >= mSpriteset.size()) - { - logger->log("Warning: Sprite #%i does not exist in this spriteset", i); - return NULL; - } - else - { - return mSpriteset[i]; - } -} diff --git a/src/resources/spriteset.h b/src/resources/spriteset.h deleted file mode 100644 index 7f6b42df..00000000 --- a/src/resources/spriteset.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef _TMW_SPRITESET_H -#define _TMW_SPRITESET_H - -#include - -#include "resource.h" - -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 -{ - public: - /* - * Cuts the passed image in a grid of sub images. - */ - Spriteset(const std::string &idPath, Image *img, int w, int h); - - /** - * Destructor. - */ - ~Spriteset(); - - int getWidth() { return mWidth; }; - - int getHeight() { return mHeight; }; - - typedef std::vector::size_type size_type; - Image* get(size_type i); - - size_type size() { return mSpriteset.size(); } - - private: - // Vector storing the whole spriteset. - std::vector mSpriteset; - // Height and width of the images in the spriteset - int mHeight; - int mWidth; -}; - -#endif -- cgit v1.2.3-70-g09d2