diff --git a/src/backend/game/game_cache.cpp b/src/backend/game/game_cache.cpp index 533e6a5a..fa4bdfff 100644 --- a/src/backend/game/game_cache.cpp +++ b/src/backend/game/game_cache.cpp @@ -42,22 +42,15 @@ namespace loot { GameCache::GameCache() {} GameCache::GameCache(const GameCache& cache) : conditionCache(cache.conditionCache), - crcCache(cache.crcCache), activePlugins(cache.activePlugins) {} GameCache& GameCache::operator=(const GameCache& cache) { conditionCache = cache.conditionCache; - crcCache = cache.crcCache; activePlugins = cache.activePlugins; return *this; } - void GameCache::CacheCrc(const std::string& plugin, uint32_t crc) { - std::lock_guard guard(mutex); - crcCache.insert(pair(boost::locale::to_lower(plugin), crc)); - } - void GameCache::CacheCondition(const std::string& condition, bool result) { std::lock_guard guard(mutex); conditionCache.insert(pair(boost::locale::to_lower(condition), result)); @@ -68,17 +61,6 @@ namespace loot { activePlugins = plugins; } - uint32_t GameCache::GetCachedCrc(const std::string& plugin) const { - std::lock_guard guard(mutex); - - auto it = crcCache.find(boost::locale::to_lower(plugin)); - - if (it != crcCache.end()) - return it->second; - else - return 0; - } - std::pair GameCache::GetCachedCondition(const std::string& condition) const { std::lock_guard guard(mutex); @@ -100,7 +82,6 @@ namespace loot { std::lock_guard guard(mutex); conditionCache.clear(); - crcCache.clear(); activePlugins.clear(); } } diff --git a/src/backend/game/game_cache.h b/src/backend/game/game_cache.h index ebc06881..b20fdde3 100644 --- a/src/backend/game/game_cache.h +++ b/src/backend/game/game_cache.h @@ -39,12 +39,9 @@ namespace loot { GameCache& operator=(const GameCache& cache); - void CacheCrc(const std::string& plugin, uint32_t crc); void CacheCondition(const std::string& condition, bool result); void CacheActivePlugins(const std::unordered_set& plugins); - // Returns 0 if no cached CRC. - uint32_t GetCachedCrc(const std::string& plugin) const; // Returns false for second bool if no cached condition. std::pair GetCachedCondition(const std::string& condition) const; bool IsPluginActive(const std::string& plugin) const; @@ -53,7 +50,6 @@ namespace loot { private: //Caches for condition results, CRCs and active plugins. std::unordered_map conditionCache; - std::unordered_map crcCache; std::unordered_set activePlugins; mutable std::mutex mutex; diff --git a/src/backend/metadata/condition_grammar.h b/src/backend/metadata/condition_grammar.h index fc6c74c4..4b280c1c 100644 --- a/src/backend/metadata/condition_grammar.h +++ b/src/backend/metadata/condition_grammar.h @@ -287,21 +287,26 @@ namespace loot { if (_game == nullptr) return; - uint32_t crc = _game->GetCachedCrc(file); + uint32_t crc = 0; + if (file == "LOOT") + crc = GetCrc32(boost::filesystem::absolute("LOOT.exe")); + else { + // CRC could be for a plugin or a file. + // Get the CRC from the game plugin cache if possible. + auto pluginPairIt = _game->plugins.find(boost::locale::to_lower(file)); + if (pluginPairIt != _game->plugins.end()) + crc = pluginPairIt->second.Crc(); - if (crc == 0) { - if (file == "LOOT") - crc = GetCrc32(boost::filesystem::absolute("LOOT.exe")); - if (boost::filesystem::exists(_game->DataPath() / file)) - crc = GetCrc32(_game->DataPath() / file); - else if ((boost::iends_with(file, ".esp") || boost::iends_with(file, ".esm")) && boost::filesystem::exists(_game->DataPath() / (file + ".ghost"))) - crc = GetCrc32(_game->DataPath() / (file + ".ghost")); + if (crc == 0) { + if (boost::filesystem::exists(_game->DataPath() / file)) + crc = GetCrc32(_game->DataPath() / file); + else if ((boost::iends_with(file, ".esp") || boost::iends_with(file, ".esm")) && boost::filesystem::exists(_game->DataPath() / (file + ".ghost"))) + crc = GetCrc32(_game->DataPath() / (file + ".ghost")); + } else { result = false; return; } - - _game->CacheCrc(file, crc); } result = checksum == crc; diff --git a/src/backend/plugin/plugin.cpp b/src/backend/plugin/plugin.cpp index c6915020..5c760dc1 100644 --- a/src/backend/plugin/plugin.cpp +++ b/src/backend/plugin/plugin.cpp @@ -46,7 +46,7 @@ namespace loot { crc(0), numOverrideRecords(0) {} - Plugin::Plugin(Game& game, const std::string& name, const bool headerOnly) : + Plugin::Plugin(const Game& game, const std::string& name, const bool headerOnly) : PluginMetadata(name), libespm::Plugin(game.LibespmId()), _isEmpty(true), @@ -67,7 +67,6 @@ namespace loot { if (!headerOnly) { BOOST_LOG_TRIVIAL(trace) << Name() << ": Caching CRC value."; crc = GetCrc32(filepath); - game.CacheCrc(Name(), crc); } BOOST_LOG_TRIVIAL(trace) << Name() << ": Counting override FormIDs."; diff --git a/src/backend/plugin/plugin.h b/src/backend/plugin/plugin.h index e673b793..feed73ce 100644 --- a/src/backend/plugin/plugin.h +++ b/src/backend/plugin/plugin.h @@ -42,7 +42,7 @@ namespace loot { class Plugin : public PluginMetadata, private libespm::Plugin { public: Plugin(const std::string& name); - Plugin(Game& game, const std::string& name, const bool headerOnly); + Plugin(const Game& game, const std::string& name, const bool headerOnly); using libespm::Plugin::getDescription; using libespm::Plugin::getFormIds; diff --git a/src/tests/backend/game/test_game_cache.h b/src/tests/backend/game/test_game_cache.h index 311091ad..56fd00a7 100644 --- a/src/tests/backend/game/test_game_cache.h +++ b/src/tests/backend/game/test_game_cache.h @@ -35,12 +35,10 @@ TEST_F(GameCache, Constructors) { loot::GameCache cache; std::unordered_set plugins({"skyrim.esm"}); - EXPECT_NO_THROW(cache.CacheCrc("Blank.esp", 5)); EXPECT_NO_THROW(cache.CacheCondition("True Condition", true)); EXPECT_NO_THROW(cache.CacheActivePlugins(plugins)); loot::GameCache cache2(cache); - EXPECT_EQ(5, cache2.GetCachedCrc("blank.Esp")); EXPECT_EQ(std::make_pair(true, true), cache2.GetCachedCondition("true Condition")); EXPECT_TRUE(cache2.IsPluginActive("Skyrim.esm")); } @@ -49,23 +47,14 @@ TEST_F(GameCache, AssignmentOperator) { loot::GameCache cache; std::unordered_set plugins({"skyrim.esm"}); - EXPECT_NO_THROW(cache.CacheCrc("Blank.esp", 5)); EXPECT_NO_THROW(cache.CacheCondition("True Condition", true)); EXPECT_NO_THROW(cache.CacheActivePlugins(plugins)); loot::GameCache cache2 = cache; - EXPECT_EQ(5, cache2.GetCachedCrc("blank.Esp")); EXPECT_EQ(std::make_pair(true, true), cache2.GetCachedCondition("true Condition")); EXPECT_TRUE(cache2.IsPluginActive("Skyrim.esm")); } -TEST_F(GameCache, CacheCrc) { - loot::GameCache cache; - EXPECT_NO_THROW(cache.CacheCrc("Blank.esp", 5)); - EXPECT_EQ(5, cache.GetCachedCrc("blank.Esp")); - EXPECT_EQ(0, cache.GetCachedCrc("Blank.missing.esp")); -} - TEST_F(GameCache, CacheCondition) { loot::GameCache cache; EXPECT_NO_THROW(cache.CacheCondition("True Condition", true));