diff options
author | flow <flowlnlnln@gmail.com> | 2022-08-30 18:06:13 -0300 |
---|---|---|
committer | flow <flowlnlnln@gmail.com> | 2022-09-03 13:37:22 -0300 |
commit | 3b13e692d29c96f99b2c153dd2c7933070eb8479 (patch) | |
tree | a0296e12519a146ef8545622453dff23b19b552c /launcher/minecraft/mod/ResourcePack.h | |
parent | 0331f5a1eb3e9fa21e89fc7fd56fdd4e87f29e44 (diff) | |
download | PrismLauncher-3b13e692d29c96f99b2c153dd2c7933070eb8479.tar.gz PrismLauncher-3b13e692d29c96f99b2c153dd2c7933070eb8479.tar.bz2 PrismLauncher-3b13e692d29c96f99b2c153dd2c7933070eb8479.zip |
feat: move resource pack images to QPixmapCache
This takes care of evicting entries when the cache gets too big for us,
so we can add new entries without much worries.
Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/minecraft/mod/ResourcePack.h')
-rw-r--r-- | launcher/minecraft/mod/ResourcePack.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/launcher/minecraft/mod/ResourcePack.h b/launcher/minecraft/mod/ResourcePack.h index 720fa3a0..03121908 100644 --- a/launcher/minecraft/mod/ResourcePack.h +++ b/launcher/minecraft/mod/ResourcePack.h @@ -5,6 +5,7 @@ #include <QImage> #include <QMutex> #include <QPixmap> +#include <QPixmapCache> class Version; @@ -30,8 +31,7 @@ class ResourcePack : public Resource { [[nodiscard]] QString description() const { return m_description; } /** Gets the image of the resource pack, converted to a QPixmap for drawing, and scaled to size. */ - [[nodiscard]] QPixmap image(QSize size) const { return QPixmap::fromImage(m_pack_image).scaled(size); } - [[nodiscard]] QSize image_size() const { return m_pack_image.size(); } + [[nodiscard]] QPixmap image(QSize size); /** Thread-safe. */ void setPackFormat(int new_format_id); @@ -57,8 +57,13 @@ class ResourcePack : public Resource { */ QString m_description; - /** The resource pack's image, as per the pack.png file. - * TODO: This could probably be just a key into a static image cache. + /** The resource pack's image file cache key, for access in the QPixmapCache global instance. + * + * The 'was_ever_used' state simply identifies whether the key was never inserted on the cache (true), + * so as to tell whether a cache entry is inexistent or if it was just evicted from the cache. */ - QImage m_pack_image; + struct { + QPixmapCache::Key key; + bool was_ever_used = false; + } m_pack_image_cache_key; }; |