diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-10-15 02:28:57 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-10-15 02:28:57 +0300 |
commit | 43a28f04fa3ddf4b612f58c25a896293a01567e3 (patch) | |
tree | 58ca2cac232c28ffd59609ad3998b97628f13e33 /src/settings.h | |
parent | 080002f8ed1af6d34cdc6f5abff0f51586ca831c (diff) | |
download | minetest-43a28f04fa3ddf4b612f58c25a896293a01567e3.tar.gz minetest-43a28f04fa3ddf4b612f58c25a896293a01567e3.tar.bz2 minetest-43a28f04fa3ddf4b612f58c25a896293a01567e3.zip |
mobv2
Diffstat (limited to 'src/settings.h')
-rw-r--r-- | src/settings.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/settings.h b/src/settings.h index f972ce3ec..e8f376938 100644 --- a/src/settings.h +++ b/src/settings.h @@ -102,6 +102,22 @@ public: return true; } + void parseConfigLines(std::istream &is, const std::string &endstring) + { + for(;;){ + if(is.eof()) + break; + std::string line; + std::getline(is, line); + std::string trimmedline = trim(line); + if(endstring != ""){ + if(trimmedline == endstring) + break; + } + parseConfigLine(line); + } + } + // Returns false on EOF bool parseConfigObject(std::istream &is) { @@ -481,6 +497,16 @@ public: return value; } + v2f getV2F(std::string name) + { + v2f value; + Strfnd f(get(name)); + f.next("("); + value.X = stof(f.next(",")); + value.Y = stof(f.next(")")); + return value; + } + u64 getU64(std::string name) { u64 value = 0; @@ -515,6 +541,13 @@ public: set(name, os.str()); } + void setV2F(std::string name, v2f value) + { + std::ostringstream os; + os<<"("<<value.X<<","<<value.Y<<")"; + set(name, os.str()); + } + void setU64(std::string name, u64 value) { std::ostringstream os; @@ -530,6 +563,47 @@ public: m_defaults.clear(); } + void updateValue(Settings &other, const std::string &name) + { + JMutexAutoLock lock(m_mutex); + + if(&other == this) + return; + + try{ + std::string val = other.get(name); + m_settings[name] = val; + } catch(SettingNotFoundException &e){ + } + + return; + } + + void update(Settings &other) + { + JMutexAutoLock lock(m_mutex); + JMutexAutoLock lock2(other.m_mutex); + + if(&other == this) + return; + + for(core::map<std::string, std::string>::Iterator + i = other.m_settings.getIterator(); + i.atEnd() == false; i++) + { + m_settings[i.getNode()->getKey()] = i.getNode()->getValue(); + } + + for(core::map<std::string, std::string>::Iterator + i = other.m_defaults.getIterator(); + i.atEnd() == false; i++) + { + m_defaults[i.getNode()->getKey()] = i.getNode()->getValue(); + } + + return; + } + Settings & operator+=(Settings &other) { JMutexAutoLock lock(m_mutex); |