Merge pull request #11370 from unknownbrackets/tex-replace

Replacement: Cut down on parsing for large inis
This commit is contained in:
Henrik Rydgård 2018-09-09 10:50:05 +02:00 committed by GitHub
commit 47cccc0ff0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -112,29 +112,24 @@ bool TextureReplacer::LoadIni() {
ERROR_LOG(G3D, "Unsupported texture replacement version %d, trying anyway", version); ERROR_LOG(G3D, "Unsupported texture replacement version %d, trying anyway", version);
} }
std::vector<std::string> hashNames; if (ini.HasSection("hashes")) {
if (ini.GetKeys("hashes", hashNames)) { auto hashes = ini.GetOrCreateSection("hashes")->ToMap();
auto hashes = ini.GetOrCreateSection("hashes");
// Format: hashname = filename.png // Format: hashname = filename.png
for (std::string hashName : hashNames) { for (const auto &item : hashes) {
ReplacementAliasKey key(0, 0, 0); ReplacementAliasKey key(0, 0, 0);
if (sscanf(hashName.c_str(), "%16llx%8x_%d", &key.cachekey, &key.hash, &key.level) >= 1) { if (sscanf(item.first.c_str(), "%16llx%8x_%d", &key.cachekey, &key.hash, &key.level) >= 1) {
hashes->Get(hashName.c_str(), &aliases_[key], ""); aliases_[key] = item.second;
} else { } else {
ERROR_LOG(G3D, "Unsupported syntax under [hashes]: %s", hashName.c_str()); ERROR_LOG(G3D, "Unsupported syntax under [hashes]: %s", item.first.c_str());
} }
} }
} }
std::vector<std::string> hashrangeKeys; if (ini.HasSection("hashranges")) {
if (ini.GetKeys("hashranges", hashrangeKeys)) { auto hashranges = ini.GetOrCreateSection("hashranges")->ToMap();
auto hashranges = ini.GetOrCreateSection("hashranges");
// Format: addr,w,h = newW,newH // Format: addr,w,h = newW,newH
for (const std::string &key : hashrangeKeys) { for (const auto &item : hashranges) {
std::string value; ParseHashRange(item.first, item.second);
if (hashranges->Get(key.c_str(), &value, "")) {
ParseHashRange(key, value);
}
} }
} }
} }