summaryrefslogtreecommitdiff
path: root/src/item.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-28 08:02:46 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-04-08 20:43:23 +0200
commit14dc8218eeebd1583e6bd3c49013b3e501f47228 (patch)
tree387778ceddd2165ab033c742e5c0eff583a6327a /src/item.cpp
parentde442e7b15a52729ba37946e74f2799804a77dab (diff)
downloadmana-14dc8218eeebd1583e6bd3c49013b3e501f47228.tar.gz
mana-14dc8218eeebd1583e6bd3c49013b3e501f47228.tar.bz2
mana-14dc8218eeebd1583e6bd3c49013b3e501f47228.tar.xz
mana-14dc8218eeebd1583e6bd3c49013b3e501f47228.zip
Use ResourceRef<Image> in more places
Automatic reference counting of images is now used by Item, Icon, AnimatedSprite, ImageSprite, ParticleEmitter, Minimap, Desktop and Emote. Since ResourceManager::get automatically adds a reference, it needs to be explicitly subtracted when the resource is managed by ResourceRef. This is taken care of by the new ResourceManager::getImageRef. Also removed the apprently unused and duplicate "mDrawImage" from Item (which also didn't get decRef called on it). Fixes cleanup of emote ImageSet and ImageSprite instances, as well as particle images.
Diffstat (limited to 'src/item.cpp')
-rw-r--r--src/item.cpp26
1 files changed, 6 insertions, 20 deletions
diff --git a/src/item.cpp b/src/item.cpp
index 30536df0..5ce1fea5 100644
--- a/src/item.cpp
+++ b/src/item.cpp
@@ -36,38 +36,24 @@ Item::Item(int id, int quantity, bool equipped):
setId(id);
}
-Item::~Item()
-{
- if (mImage)
- mImage->decRef();
-}
+Item::~Item() = default;
void Item::setId(int id)
{
mId = id;
// Load the associated image
- if (mImage)
- mImage->decRef();
-
- if (mDrawImage)
- mDrawImage->decRef();
-
ResourceManager *resman = ResourceManager::getInstance();
- SpriteDisplay display = getInfo().getDisplay();
- std::string imagePath = paths.getStringValue("itemIcons")
- + display.image;
- mImage = resman->getImage(imagePath);
- mDrawImage = resman->getImage(imagePath);
+ const SpriteDisplay &display = getInfo().getDisplay();
+ mImage = resman->getImage(paths.getStringValue("itemIcons") + display.image);
if (!mImage)
mImage = Theme::getImageFromTheme(paths.getValue("unknownItemFile",
"unknown-item.png"));
- if (!mDrawImage)
- mDrawImage = Theme::getImageFromTheme(
- paths.getValue("unknownItemFile",
- "unknown-item.png"));
+ // Remove the automatic reference added by the ResourceManager
+ if (mImage)
+ mImage->decRef();
}
void Item::doEvent(Event::Type eventName)