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
+19
View File
@@ -2,6 +2,7 @@
#include <functional>
#include <memory>
#include <shared_mutex>
#include <string>
#include <unordered_map>
@@ -102,3 +103,21 @@ private:
std::unordered_map<std::string, std::shared_ptr<File>> name_to_file;
uint64_t ttl_usecs;
};
class ThreadSafeFileCache {
public:
explicit ThreadSafeFileCache() = default;
ThreadSafeFileCache(const ThreadSafeFileCache&) = delete;
ThreadSafeFileCache(ThreadSafeFileCache&&) = delete;
ThreadSafeFileCache& operator=(const ThreadSafeFileCache&) = delete;
ThreadSafeFileCache& operator=(ThreadSafeFileCache&&) = delete;
~ThreadSafeFileCache() = default;
// Warning: generate() is called while the lock is held for writing, so it
// will block other threads.
std::shared_ptr<const std::string> get(const std::string& name, std::function<std::shared_ptr<const std::string>(const std::string&)> generate);
private:
std::shared_mutex lock;
std::unordered_map<std::string, std::shared_ptr<const std::string>> name_to_file;
};