Store a GameCache in Game, don't inherit from it

This commit is contained in:
Oliver Hamlet
2017-03-25 11:29:07 +00:00
parent dd5ae4dd51
commit be80f5a244
6 changed files with 22 additions and 14 deletions
+2 -2
View File
@@ -69,7 +69,7 @@ void ApiDatabase::LoadLists(const std::string& masterlistPath,
void ApiDatabase::EvalLists() {
// Clear caches before evaluating conditions.
game_.ClearCachedConditions();
game_.GetCache()->ClearCachedConditions();
Masterlist temp = masterlist_;
MetadataList userTemp = userlist_;
@@ -146,7 +146,7 @@ std::vector<Message> ApiDatabase::GetGeneralMessages(bool evaluateConditions) co
if (evaluateConditions) {
// Evaluate conditions from scratch.
game_.ClearCachedConditions();
game_.GetCache()->ClearCachedConditions();
ConditionEvaluator evaluator(&game_);
for (auto it = std::begin(masterlistMessages); it != std::end(masterlistMessages);) {
if (!evaluator.evaluate(it->GetCondition()))
+11 -6
View File
@@ -63,7 +63,8 @@ Game::Game(const GameType gameType,
const boost::filesystem::path& localDataPath) :
type_(gameType),
gamePath_(gamePath),
localDataPath_(localDataPath) {
localDataPath_(localDataPath),
cache_(std::make_shared<GameCache>()) {
BOOST_LOG_TRIVIAL(info) << "Initialising load order data for game of type " << (int)type_ << " at: " << gamePath_;
loadOrderHandler_.Init(type_, gamePath_, localDataPath_);
@@ -86,6 +87,10 @@ std::string Game::GetArchiveFileExtension() const {
return ".bsa";
}
std::shared_ptr<GameCache> Game::GetCache() {
return cache_;
}
std::shared_ptr<DatabaseInterface> Game::GetDatabase() {
return database_;
}
@@ -136,7 +141,7 @@ void Game::LoadPlugins(const std::vector<std::string>& plugins, bool loadHeaders
}
// Clear the existing plugin cache.
ClearCachedPlugins();
cache_->ClearCachedPlugins();
// Load the plugins.
BOOST_LOG_TRIVIAL(trace) << "Starting plugin loading.";
@@ -147,9 +152,9 @@ void Game::LoadPlugins(const std::vector<std::string>& plugins, bool loadHeaders
for (auto pluginName : pluginGroup) {
BOOST_LOG_TRIVIAL(trace) << "Loading " << pluginName;
if (boost::iequals(pluginName, masterFile_))
AddPlugin(Plugin(*this, pluginName, true));
cache_->AddPlugin(Plugin(*this, pluginName, true));
else
AddPlugin(Plugin(*this, pluginName, loadHeadersOnly));
cache_->AddPlugin(Plugin(*this, pluginName, loadHeadersOnly));
}
}));
}
@@ -162,12 +167,12 @@ void Game::LoadPlugins(const std::vector<std::string>& plugins, bool loadHeaders
}
std::shared_ptr<const PluginInterface> Game::GetPlugin(const std::string& pluginName) const {
return std::static_pointer_cast<const PluginInterface>(GameCache::GetPlugin(pluginName));
return std::static_pointer_cast<const PluginInterface>(cache_->GetPlugin(pluginName));
}
std::set<std::shared_ptr<const PluginInterface>> Game::GetLoadedPlugins() const {
std::set<std::shared_ptr<const PluginInterface>> interfacePointers;
for (auto& plugin : GameCache::GetPlugins()) {
for (auto& plugin : cache_->GetPlugins()) {
interfacePointers.insert(std::static_pointer_cast<const PluginInterface>(plugin));
}
+4 -1
View File
@@ -34,7 +34,7 @@
#include "loot/game_interface.h"
namespace loot {
class Game : public GameInterface, public GameCache {
class Game : public GameInterface {
public:
Game(const GameType gameType,
const boost::filesystem::path& gamePath = "",
@@ -47,6 +47,8 @@ public:
boost::filesystem::path DataPath() const;
std::string GetArchiveFileExtension() const;
std::shared_ptr<GameCache> GetCache();
// Game Interface Methods //
////////////////////////////
@@ -70,6 +72,7 @@ public:
void SetLoadOrder(const std::vector<std::string>& loadOrder);
private:
std::shared_ptr<GameCache> cache_;
std::shared_ptr<DatabaseInterface> database_;
const GameType type_;
+2 -2
View File
@@ -49,13 +49,13 @@ bool ConditionEvaluator::evaluate(const std::string& condition) {
BOOST_LOG_TRIVIAL(trace) << "Evaluating condition: " << condition;
auto cachedValue = game_->GetCachedCondition(condition);
auto cachedValue = game_->GetCache()->GetCachedCondition(condition);
if (cachedValue.second)
return cachedValue.first;
bool result = parseCondition(condition);
game_->CacheCondition(condition, result);
game_->GetCache()->CacheCondition(condition, result);
return result;
}
+1 -1
View File
@@ -212,7 +212,7 @@ void PluginSorter::AddPluginVertices(Game& game) {
// Using a set of plugin names followed by finding the matching key
// in the unordered map, as it's probably faster than copying the
// full plugin objects then sorting them.
for (const auto &plugin : game.GetPlugins()) {
for (const auto &plugin : game.GetCache()->GetPlugins()) {
BOOST_LOG_TRIVIAL(trace) << "Getting and evaluating metadata for plugin " << plugin->GetName();
auto metadata = game.GetDatabase()->GetPluginMetadata(plugin->GetName(), true, true);
+2 -2
View File
@@ -103,7 +103,7 @@ TEST_P(GameTest, loadPluginsWithHeadersOnlyTrueShouldLoadTheHeadersOfAllInstalle
Game game = Game(GetParam(), dataPath.parent_path(), localPath);
EXPECT_NO_THROW(loadInstalledPlugins(game, true));
EXPECT_EQ(11, game.GetPlugins().size());
EXPECT_EQ(11, game.GetCache()->GetPlugins().size());
// Check that one plugin's header has been read.
ASSERT_NO_THROW(game.GetPlugin(masterFile));
@@ -118,7 +118,7 @@ TEST_P(GameTest, loadPluginsWithHeadersOnlyFalseShouldFullyLoadAllInstalledPlugi
Game game = Game(GetParam(), dataPath.parent_path(), localPath);
EXPECT_NO_THROW(loadInstalledPlugins(game, false));
EXPECT_EQ(11, game.GetPlugins().size());
EXPECT_EQ(11, game.GetCache()->GetPlugins().size());
// Check that one plugin's header has been read.
ASSERT_NO_THROW(game.GetPlugin(blankEsm));