aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft/mod/ResourcePack.cpp
diff options
context:
space:
mode:
authorTrial97 <alexandru.tripon97@gmail.com>2023-06-25 10:12:29 +0300
committerTrial97 <alexandru.tripon97@gmail.com>2023-06-25 10:12:29 +0300
commit54d7477679d4be05ce69dfe7d3ff21b0de46e8af (patch)
tree8a3eb84a1d352ed4c57e7f06cd9772f1de08e384 /launcher/minecraft/mod/ResourcePack.cpp
parentba609f3600e17704f358b28dd3d5ee14319cc98c (diff)
parentbcf45c74a1b0b3389c05927637bf8aa95b8e43cf (diff)
downloadPrismLauncher-54d7477679d4be05ce69dfe7d3ff21b0de46e8af.tar.gz
PrismLauncher-54d7477679d4be05ce69dfe7d3ff21b0de46e8af.tar.bz2
PrismLauncher-54d7477679d4be05ce69dfe7d3ff21b0de46e8af.zip
Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into visit_mod_page
Diffstat (limited to 'launcher/minecraft/mod/ResourcePack.cpp')
-rw-r--r--launcher/minecraft/mod/ResourcePack.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/launcher/minecraft/mod/ResourcePack.cpp b/launcher/minecraft/mod/ResourcePack.cpp
index 759d2b56..e06c1ac1 100644
--- a/launcher/minecraft/mod/ResourcePack.cpp
+++ b/launcher/minecraft/mod/ResourcePack.cpp
@@ -40,7 +40,7 @@ void ResourcePack::setDescription(QString new_description)
m_description = new_description;
}
-void ResourcePack::setImage(QImage new_image)
+void ResourcePack::setImage(QImage new_image) const
{
QMutexLocker locker(&m_data_lock);
@@ -49,7 +49,10 @@ void ResourcePack::setImage(QImage new_image)
if (m_pack_image_cache_key.key.isValid())
PixmapCache::instance().remove(m_pack_image_cache_key.key);
- m_pack_image_cache_key.key = PixmapCache::instance().insert(QPixmap::fromImage(new_image));
+ // scale the image to avoid flooding the pixmapcache
+ auto pixmap = QPixmap::fromImage(new_image.scaled({64, 64}, Qt::AspectRatioMode::KeepAspectRatioByExpanding));
+
+ m_pack_image_cache_key.key = PixmapCache::instance().insert(pixmap);
m_pack_image_cache_key.was_ever_used = true;
// This can happen if the pixmap is too big to fit in the cache :c
@@ -59,21 +62,25 @@ void ResourcePack::setImage(QImage new_image)
}
}
-QPixmap ResourcePack::image(QSize size)
+QPixmap ResourcePack::image(QSize size, Qt::AspectRatioMode mode) const
{
QPixmap cached_image;
if (PixmapCache::instance().find(m_pack_image_cache_key.key, &cached_image)) {
if (size.isNull())
return cached_image;
- return cached_image.scaled(size);
+ return cached_image.scaled(size, mode);
}
// No valid image we can get
- if (!m_pack_image_cache_key.was_ever_used)
+ if (!m_pack_image_cache_key.was_ever_used) {
return {};
+ } else {
+ qDebug() << "Resource Pack" << name() << "Had it's image evicted from the cache. reloading...";
+ PixmapCache::markCacheMissByEviciton();
+ }
// Imaged got evicted from the cache. Re-process it and retry.
- ResourcePackUtils::process(*this);
+ ResourcePackUtils::processPackPNG(*this);
return image(size);
}