From 4752e20ad42dff8afd2015a7a74fca42da680943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 9 Mar 2023 00:24:30 +0100 Subject: [PATCH] Don't reuse the ReplacedTexture struct in "saved cache". --- Core/TextureReplacer.cpp | 18 ++++++++---------- Core/TextureReplacer.h | 9 ++++++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Core/TextureReplacer.cpp b/Core/TextureReplacer.cpp index e15df31edd..22ce25ebb1 100644 --- a/Core/TextureReplacer.cpp +++ b/Core/TextureReplacer.cpp @@ -736,7 +736,6 @@ void TextureReplacer::NotifyTextureDecoded(const ReplacedTextureDecodeInfo &repl cachekey = cachekey & 0xFFFFFFFFULL; } - /* bool found = false; std::string hashfile = LookupHashFile(cachekey, replacedInfo.hash, &found); const Path filename = basePath_ / hashfile; @@ -753,9 +752,10 @@ void TextureReplacer::NotifyTextureDecoded(const ReplacedTextureDecodeInfo &repl double now = time_now_d(); if (it != savedCache_.end()) { // We've already saved this texture. Let's only save if it's bigger (e.g. scaled now.) - if (it->second.first.w >= w && it->second.first.h >= h) { + // TODO: Isn't this check backwards? + if (it->second.levelW[level] >= w && it->second.levelH[level] >= h) { // If it's been more than 5 seconds, we'll check again. Maybe they deleted. - double age = now - it->second.second; + double age = now - it->second.lastTimeSaved; if (age < 5.0) return; @@ -794,13 +794,11 @@ void TextureReplacer::NotifyTextureDecoded(const ReplacedTextureDecodeInfo &repl // Remember that we've saved this for next time. // Should be OK that the actual disk write may not be finished yet. - ReplacedTextureLevel saved; - saved.fmt = Draw::DataFormat::R8G8B8A8_UNORM; - saved.file = filename; - saved.w = w; - saved.h = h; - savedCache_[replacementKey] = std::make_pair(saved, now); - */ + SavedTextureCacheData &saveData = savedCache_[replacementKey]; + saveData.levelW[level] = w; + saveData.levelH[level] = h; + saveData.levelSaved[level] = true; + saveData.lastTimeSaved = now; } void TextureReplacer::Decimate(ReplacerDecimateMode mode) { diff --git a/Core/TextureReplacer.h b/Core/TextureReplacer.h index efcd4269ae..7d6eafefcb 100644 --- a/Core/TextureReplacer.h +++ b/Core/TextureReplacer.h @@ -64,6 +64,13 @@ struct ReplacedTextureLevel { VFSFileReference *fileRef = nullptr; }; +struct SavedTextureCacheData { + int levelW[8]{}; + int levelH[8]{}; + bool levelSaved[8]{}; + double lastTimeSaved; +}; + struct ReplacedLevelsCache { std::mutex lock; std::vector> data; @@ -252,7 +259,7 @@ protected: std::unordered_map filtering_; std::unordered_map cache_; - std::unordered_map> savedCache_; + std::unordered_map savedCache_; // the key is from aliases_. It's a |-separated sequence of texture filenames of the levels of a texture. std::unordered_map levelCache_;