summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-11-15 23:44:01 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-11-15 23:44:01 +0000
commit0e925e97554aae573e895afa4e3d8450f01df342 (patch)
treebbc30319410aecb9fec7c005e667cd7fb628bb17 /src/resources
parentffa0fae492d954c0aed35a0acbd7b856778d7328 (diff)
downloadmana-0e925e97554aae573e895afa4e3d8450f01df342.tar.gz
mana-0e925e97554aae573e895afa4e3d8450f01df342.tar.bz2
mana-0e925e97554aae573e895afa4e3d8450f01df342.tar.xz
mana-0e925e97554aae573e895afa4e3d8450f01df342.zip
Moved item icon from ItemInfo class to the Item class, so that it can be loaded
on demand. Results in faster startup time and reduced memory usage.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/itemdb.cpp4
-rw-r--r--src/resources/iteminfo.cpp28
-rw-r--r--src/resources/iteminfo.h22
3 files changed, 6 insertions, 48 deletions
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index a83da342..ff537bc3 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -65,7 +65,7 @@ void ItemDB::load()
mUnknown = new ItemInfo();
mUnknown->setName("Unknown item");
- mUnknown->setImage("");
+ mUnknown->setImageName("");
mUnknown->setSprite("error.xml", 0);
mUnknown->setSprite("error.xml", 1);
@@ -118,7 +118,7 @@ void ItemDB::load()
int weaponType = XML::getProperty(node, "weapon_type", 0);
ItemInfo *itemInfo = new ItemInfo;
- itemInfo->setImage(image);
+ itemInfo->setImageName(image);
itemInfo->setName(name.empty() ? "Unnamed" : name);
itemInfo->setDescription(description);
itemInfo->setType(type);
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
index 82c46e3c..f1ebd0a9 100644
--- a/src/resources/iteminfo.cpp
+++ b/src/resources/iteminfo.cpp
@@ -23,36 +23,8 @@
#include "iteminfo.h"
-#include "resourcemanager.h"
-#include "image.h"
#include "itemdb.h"
-ItemInfo::~ItemInfo()
-{
- if (mImage)
- {
- mImage->decRef();
- }
-}
-
-void
-ItemInfo::setImage(const std::string &image)
-{
- if (mImage)
- {
- mImage->decRef();
- }
-
- ResourceManager *resman = ResourceManager::getInstance();
- mImageName = "graphics/items/" + image;
- mImage = ResourceManager::getInstance()->getImage(mImageName);
-
- if (!mImage)
- {
- mImage = resman->getImage("graphics/gui/unknown-item.png");
- }
-}
-
const std::string&
ItemInfo::getSprite(int gender) const
{
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index 2726a012..680c8d61 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -30,8 +30,6 @@
#include "spritedef.h"
-class Image;
-
enum EquipmentSoundEvent
{
EQUIP_EVENT_STRIKE,
@@ -49,7 +47,6 @@ class ItemInfo
* Constructor.
*/
ItemInfo():
- mImage(NULL),
mType(0),
mWeight(0),
mView(0),
@@ -57,21 +54,17 @@ class ItemInfo
{
}
- /**
- * Destructor.
- */
- ~ItemInfo();
-
void setName(const std::string &name)
{ mName = name; }
const std::string& getName() const
{ return mName; }
- void setImage(const std::string &image);
+ void setImageName(const std::string &imageName)
+ { mImageName = imageName; }
- Image* getImage() const
- { return mImage; }
+ const std::string& getImageName() const
+ { return mImageName; }
void setDescription(const std::string &description)
{ mDescription = description; }
@@ -116,13 +109,6 @@ class ItemInfo
protected:
std::string mImageName; /**< The filename of the icon image. */
-
- /* TODO (BL): I do not think the item info should keep a reference to
- * the item icon. It would probably be better if this was kept in the
- * Item class, so that the images can be lazily instantiated and also
- * unloaded when no longer used.
- */
- Image *mImage; /**< The loaded icon image. */
std::string mName;
std::string mDescription; /**< Short description. */
std::string mEffect; /**< Description of effects. */