add brute-force search command for game seeds that result in rare enemies

This commit is contained in:
Martin Michelsen
2024-01-12 23:54:23 -08:00
parent f188ea1554
commit d052163a9e
12 changed files with 455 additions and 118 deletions
+22
View File
@@ -74,3 +74,25 @@ FileContentsCache::GetResult FileContentsCache::get(const char* name,
std::function<std::string(const std::string&)> generate) {
return this->get(string(name), generate);
}
shared_ptr<const string> ThreadSafeFileCache::get(
const string& name, std::function<shared_ptr<const string>(const std::string&)> generate) {
try {
shared_lock g(this->lock);
auto ret = this->name_to_file.at(name);
if (!ret) {
throw cannot_open_file(name);
}
return ret;
} catch (const out_of_range&) {
unique_lock g(this->lock);
auto it = this->name_to_file.find(name);
if (it == this->name_to_file.end()) {
it = this->name_to_file.emplace(name, generate(name)).first;
}
if (!it->second) {
throw cannot_open_file(name);
}
return it->second;
}
}