diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-11-15 23:44:01 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-11-15 23:44:01 +0000 |
commit | 0e925e97554aae573e895afa4e3d8450f01df342 (patch) | |
tree | bbc30319410aecb9fec7c005e667cd7fb628bb17 /src/item.cpp | |
parent | ffa0fae492d954c0aed35a0acbd7b856778d7328 (diff) | |
download | mana-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/item.cpp')
-rw-r--r-- | src/item.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/item.cpp b/src/item.cpp index 66f638a5..210589e9 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -23,16 +23,38 @@ #include "item.h" +#include "resources/image.h" +#include "resources/resourcemanager.h" + Item::Item(int id, int quantity) : + mImage(0), mQuantity(quantity) { setId(id); } +Item::~Item() +{ + if (mImage) + mImage->decRef(); +} + void Item::setId(int id) { mId = id; + // Types 0 and 1 are not equippable items. mEquipment = id && getInfo().getType() >= 2; + + // Load the associated image + if (mImage) + mImage->decRef(); + + ResourceManager *resman = ResourceManager::getInstance(); + std::string imagePath = "graphics/items/" + getInfo().getImageName(); + mImage = resman->getImage(imagePath); + + if (!mImage) + mImage = resman->getImage("graphics/gui/unknown-item.png"); } |