From 2eec0caca0abae3a94cc3a83a9ac9943a5c4e306 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 3 Jun 2015 19:59:54 +0200 Subject: [PATCH] Remove dependency on Ogre::StringConverter --- apps/openmw/mwmechanics/character.cpp | 25 +++++++++--- components/settings/settings.cpp | 57 +++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index f17f2331f..c5282bdf8 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -56,6 +56,13 @@ void wrap(float& rad) rad = std::fmod(rad-osg::PI, 2.0f*osg::PI)+osg::PI; } +std::string toString(int num) +{ + std::ostringstream stream; + stream << num; + return stream.str(); +} + std::string getBestAttack (const ESM::Weapon* weapon) { int slash = (weapon->mData.mSlash[0] + weapon->mData.mSlash[1])/2; @@ -220,13 +227,13 @@ public: std::string CharacterController::chooseRandomGroup (const std::string& prefix, int* num) { int numAnims=0; - while (mAnimation->hasAnimation(prefix + Ogre::StringConverter::toString(numAnims+1))) + while (mAnimation->hasAnimation(prefix + toString(numAnims+1))) ++numAnims; int roll = Misc::Rng::rollDice(numAnims) + 1; // [1, numAnims] if (num) *num = roll; - return prefix + Ogre::StringConverter::toString(roll); + return prefix + toString(roll); } void CharacterController::refreshCurrentAnims(CharacterState idle, CharacterState movement, bool force) @@ -569,7 +576,7 @@ void CharacterController::playDeath(float startpoint, CharacterState death) mCurrentDeath = "deathknockout"; break; default: - mCurrentDeath = "death" + Ogre::StringConverter::toString(death - CharState_Death1 + 1); + mCurrentDeath = "death" + toString(death - CharState_Death1 + 1); } mDeathState = death; @@ -736,9 +743,17 @@ void CharacterController::handleTextKey(const std::string &groupname, const std: split(soundgen, ' ', tokens); soundgen = tokens[0]; if (tokens.size() >= 2) - volume = Ogre::StringConverter::parseReal(tokens[1]); + { + std::stringstream stream; + stream << tokens[1]; + stream >> volume; + } if (tokens.size() >= 3) - pitch = Ogre::StringConverter::parseReal(tokens[2]); + { + std::stringstream stream; + stream << tokens[2]; + stream >> pitch; + } } std::string sound = mPtr.getClass().getSoundIdFromSndGen(mPtr, soundgen); diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index a9a78d035..90fd300ec 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -1,13 +1,56 @@ #include "settings.hpp" #include +#include -#include +#include #include #include #include +namespace +{ + + bool parseBool(const std::string& string) + { + return (Misc::StringUtils::ciEqual(string, "true")); + } + + float parseFloat(const std::string& string) + { + std::stringstream stream; + stream << string; + float ret = 0.f; + stream >> ret; + return ret; + } + + int parseInt(const std::string& string) + { + std::stringstream stream; + stream << string; + int ret = 0; + stream >> ret; + return ret; + } + + template + std::string toString(T val) + { + std::ostringstream stream; + stream << val; + return stream.str(); + } + + template <> + std::string toString(bool val) + { + return val ? "true" : "false"; + } + +} + namespace Settings { @@ -143,17 +186,17 @@ std::string Manager::getString(const std::string &setting, const std::string &ca float Manager::getFloat (const std::string& setting, const std::string& category) { - return Ogre::StringConverter::parseReal( getString(setting, category) ); + return parseFloat( getString(setting, category) ); } int Manager::getInt (const std::string& setting, const std::string& category) { - return Ogre::StringConverter::parseInt( getString(setting, category) ); + return parseInt( getString(setting, category) ); } bool Manager::getBool (const std::string& setting, const std::string& category) { - return Ogre::StringConverter::parseBool( getString(setting, category) ); + return parseBool( getString(setting, category) ); } void Manager::setString(const std::string &setting, const std::string &category, const std::string &value) @@ -174,17 +217,17 @@ void Manager::setString(const std::string &setting, const std::string &category, void Manager::setInt (const std::string& setting, const std::string& category, const int value) { - setString(setting, category, Ogre::StringConverter::toString(value)); + setString(setting, category, toString(value)); } void Manager::setFloat (const std::string &setting, const std::string &category, const float value) { - setString(setting, category, Ogre::StringConverter::toString(value)); + setString(setting, category, toString(value)); } void Manager::setBool(const std::string &setting, const std::string &category, const bool value) { - setString(setting, category, Ogre::StringConverter::toString(value)); + setString(setting, category, toString(value)); } const CategorySettingVector Manager::apply()