Don't reuse the ReplacedTexture struct in "saved cache".

This commit is contained in:
Henrik Rydgård 2023-03-09 00:24:30 +01:00
parent bda09be109
commit 4752e20ad4
2 changed files with 16 additions and 11 deletions

View File

@ -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) {

View File

@ -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<std::vector<uint8_t>> data;
@ -252,7 +259,7 @@ protected:
std::unordered_map<ReplacementCacheKey, TextureFiltering> filtering_;
std::unordered_map<ReplacementCacheKey, ReplacedTexture *> cache_;
std::unordered_map<ReplacementCacheKey, std::pair<ReplacedTextureLevel, double>> savedCache_;
std::unordered_map<ReplacementCacheKey, SavedTextureCacheData> savedCache_;
// the key is from aliases_. It's a |-separated sequence of texture filenames of the levels of a texture.
std::unordered_map<std::string, ReplacedLevelsCache> levelCache_;