Mini refactor: Separate input and output arguments for LookupHashRange

This commit is contained in:
Henrik Rydgård 2023-03-16 09:55:49 +01:00
parent 34926472aa
commit c58ceb5160
2 changed files with 16 additions and 12 deletions

View file

@ -395,7 +395,7 @@ void TextureReplacer::ParseReduceHashRange(const std::string& key, const std::st
u32 TextureReplacer::ComputeHash(u32 addr, int bufw, int w, int h, GETextureFormat fmt, u16 maxSeenV) {
_dbg_assert_msg_(enabled_, "Replacement not enabled");
if (!LookupHashRange(addr, w, h)) {
if (!LookupHashRange(addr, w, h, &w, &h)) {
// There wasn't any hash range, let's fall back to maxSeenV logic.
if (h == 512 && maxSeenV < 512 && maxSeenV != 0) {
h = (int)maxSeenV;
@ -502,7 +502,7 @@ void TextureReplacer::PopulateReplacement(ReplacedTexture *texture, u64 cachekey
desc->hash = hash;
desc->basePath = basePath_;
desc->formatSupport = formatSupport_;
LookupHashRange(cachekey >> 32, desc->newW, desc->newH);
LookupHashRange(cachekey >> 32, w, h, &desc->newW, &desc->newH);
if (ignoreAddress_) {
cachekey = cachekey & 0xFFFFFFFFULL;
@ -675,9 +675,9 @@ void TextureReplacer::NotifyTextureDecoded(const ReplacedTextureDecodeInfo &repl
}
// Only save the hashed portion of the PNG.
int lookupW = w / replacedInfo.scaleFactor;
int lookupH = h / replacedInfo.scaleFactor;
if (LookupHashRange(replacedInfo.addr, lookupW, lookupH)) {
int lookupW;
int lookupH;
if (LookupHashRange(replacedInfo.addr, w / replacedInfo.scaleFactor, h / replacedInfo.scaleFactor, &lookupW, &lookupH)) {
w = lookupW * replacedInfo.scaleFactor;
h = lookupH * replacedInfo.scaleFactor;
}
@ -852,17 +852,19 @@ std::string TextureReplacer::HashName(u64 cachekey, u32 hash, int level) {
return hashname;
}
bool TextureReplacer::LookupHashRange(u32 addr, int &w, int &h) {
bool TextureReplacer::LookupHashRange(u32 addr, int w, int h, int *newW, int *newH) {
const u64 rangeKey = ((u64)addr << 32) | ((u64)w << 16) | h;
auto range = hashranges_.find(rangeKey);
if (range != hashranges_.end()) {
const WidthHeightPair &wh = range->second;
w = wh.first;
h = wh.second;
*newW = wh.first;
*newH = wh.second;
return true;
} else {
*newW = w;
*newH = h;
return false;
}
return false;
}
float TextureReplacer::LookupReduceHashRange(int& w, int& h) {

View file

@ -131,7 +131,7 @@ protected:
void ParseHashRange(const std::string &key, const std::string &value);
void ParseFiltering(const std::string &key, const std::string &value);
void ParseReduceHashRange(const std::string& key, const std::string& value);
bool LookupHashRange(u32 addr, int &w, int &h);
bool LookupHashRange(u32 addr, int w, int h, int *newW, int *newH);
float LookupReduceHashRange(int& w, int& h);
std::string LookupHashFile(u64 cachekey, u32 hash, bool *foundAlias, bool *ignored);
void PopulateReplacement(ReplacedTexture *result, u64 cachekey, u32 hash, int w, int h);
@ -157,12 +157,14 @@ protected:
typedef std::pair<int, int> WidthHeightPair;
std::unordered_map<u64, WidthHeightPair> hashranges_;
std::unordered_map<u64, float> reducehashranges_;
std::unordered_map<ReplacementCacheKey, std::string> aliases_;
std::unordered_map<ReplacementCacheKey, TextureFiltering> filtering_;
std::unordered_map<ReplacementCacheKey, ReplacedTexture *> cache_;
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.
// the key is either from aliases_, in which case it's a |-separated sequence of texture filenames of the levels of a texture.
// alternatively the key is from the generated texture filename.
std::unordered_map<std::string, ReplacedLevelsCache> levelCache_;
};