diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-03-02 19:31:34 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-03-02 19:31:34 +0300 |
commit | 63d82eada2fccdecf3c90452e93860a37656e7c4 (patch) | |
tree | 1b0fdd869d9066524057339212b7255e59c8485b | |
parent | edc8de3400acbbae60930a9c1d4f946df5b2e68f (diff) | |
download | manaverse-63d82eada2fccdecf3c90452e93860a37656e7c4.tar.gz manaverse-63d82eada2fccdecf3c90452e93860a37656e7c4.tar.bz2 manaverse-63d82eada2fccdecf3c90452e93860a37656e7c4.tar.xz manaverse-63d82eada2fccdecf3c90452e93860a37656e7c4.zip |
auto save config if it was changed in game each 10 seconds.
-rw-r--r-- | src/configuration.cpp | 11 | ||||
-rw-r--r-- | src/configuration.h | 3 | ||||
-rw-r--r-- | src/game.cpp | 10 | ||||
-rw-r--r-- | src/game.h | 1 |
4 files changed, 23 insertions, 2 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp index ed2adfc61..36a1a724f 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -223,6 +223,7 @@ void ConfigurationObject::deleteKey(const std::string &key) void Configuration::setValue(const std::string &key, const std::string &value) { ConfigurationObject::setValue(key, value); + mUpdated = true; // Notify listeners const ListenerMapIterator list = mListenerMap.find(key); @@ -347,7 +348,8 @@ Configuration::Configuration() : mDefaultsData(nullptr), mDirectory(), mFilename(), - mUseResManager(false) + mUseResManager(false), + mUpdated(false) { #ifdef DEBUG_CONFIG mLogKeys = false; @@ -803,11 +805,18 @@ void ConfigurationObject::writeToXML(const XmlTextWriterPtr writer) } } +void Configuration::writeUpdated() +{ + if (mUpdated) + write(); +} + void Configuration::write() { if (mConfigPath.empty()) return; + mUpdated = false; // Do not attempt to write to file that cannot be opened for writing FILE *const testFile = fopen(mConfigPath.c_str(), "w"); if (!testFile) diff --git a/src/configuration.h b/src/configuration.h index daa10f51b..d6bcda348 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -346,6 +346,8 @@ class Configuration final : public ConfigurationObject std::string getFileName() const A_WARN_UNUSED { return mFilename; } + void writeUpdated(); + private: /** * Clean up the default values member. @@ -365,6 +367,7 @@ class Configuration final : public ConfigurationObject std::string mDirectory; std::string mFilename; bool mUseResManager; + bool mUpdated; }; extern Configuration branding; diff --git a/src/game.cpp b/src/game.cpp index 253c4bff2..195492335 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -390,7 +390,8 @@ Game::Game(): mAdjustPerfomance(config.getBoolValue("adjustPerfomance")), mLowerCounter(0), mPing(0), - mTime(cur_time + 1) + mTime(cur_time + 1), + mTime2(cur_time + 10) { touchManager.setInGame(true); spellManager = new SpellManager; @@ -620,6 +621,13 @@ void Game::slowLogic() Being::reReadConfig(); if (killStats) killStats->recalcStats(); + + if (time > mTime2 || mTime2 - time > 10) + { + mTime2 = time + 10; + config.writeUpdated(); + serverConfig.writeUpdated(); + } } if (shopWindow) diff --git a/src/game.h b/src/game.h index 023796290..ad9285931 100644 --- a/src/game.h +++ b/src/game.h @@ -135,6 +135,7 @@ class Game final int mLowerCounter; int mPing; int mTime; + int mTime2; static Game *mInstance; }; |