From 89565bacd17453c1ce2a8cff7cf6ea5822a262f5 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 2 Apr 2012 14:34:21 +0200 Subject: [PATCH 01/20] since the default method is not available in older boost we should check by ourselfs if the options are given and dont use notify --- apps/mwiniimporter/main.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 9a6e61645..43b17b76a 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -9,7 +9,7 @@ namespace bpo = boost::program_options; int main(int argc, char *argv[]) { - bpo::options_description desc("Syntax: mwiniimporter \nAllowed options"); + bpo::options_description desc("Syntax: mwiniimporter -i inifile -c configfile \nAllowed options"); desc.add_options() ("help,h", "produce help message") ("verbose,v", "verbose output") @@ -20,25 +20,11 @@ int main(int argc, char *argv[]) { ; bpo::variables_map vm; - try { - bpo::store(boost::program_options::parse_command_line(argc, argv, desc), vm); + bpo::store(boost::program_options::parse_command_line(argc, argv, desc), vm); - // parse help before calling notify because we dont want it to throw an error if help is set - if(vm.count("help")) { - std::cout << desc; - return 0; - } - - bpo::notify(vm); - - } - catch(std::exception& e) { - std::cerr << "Error:" << e.what() << std::endl; - return -1; - } - catch(...) { - std::cerr << "Error" << std::endl; - return -2; + if(vm.count("help") || !vm.count("ini") || !vm.count("cfg")) { + std::cout << desc; + return 0; } std::string iniFile = vm["ini"].as(); From 16674ad141661ea77b5903b1cba0716bd19ea7d2 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 2 Apr 2012 14:42:01 +0200 Subject: [PATCH 02/20] open file for writing AFTER reading it :) --- apps/mwiniimporter/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 43b17b76a..836f84eb0 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -47,7 +47,6 @@ int main(int argc, char *argv[]) { MwIniImporter importer; importer.setVerbose(vm.count("verbose")); - boost::iostreams::stream file(outputFile); MwIniImporter::multistrmap ini = importer.loadIniFile(iniFile); MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile); @@ -59,6 +58,7 @@ int main(int argc, char *argv[]) { } std::cout << "write to: " << outputFile << std::endl; + boost::iostreams::stream file(outputFile); importer.writeToFile(file, cfg); return 0; From 6e19076dc55b20bdd71a9ba4e680dee5018721ed Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 2 Apr 2012 17:07:18 +0200 Subject: [PATCH 03/20] fallback for ini importer --- apps/mwiniimporter/importer.cpp | 39 ++++++++++++++++++++++++++++----- apps/mwiniimporter/importer.hpp | 4 +++- apps/mwiniimporter/main.cpp | 9 ++++++-- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 08b05f417..80ec4a5fd 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -14,10 +14,19 @@ MwIniImporter::MwIniImporter() { { "fps", "General:Show FPS" }, { 0, 0 } }; + const char *fallback[][2] = { + { "Weather_Sunrise_Time", "Weather:Sunrise Time" }, + { "Weather_Sunset_Time", "Weather:Sunset Time" }, + { 0, 0 } + }; for(int i=0; map[i][0]; i++) { mMergeMap.insert(std::make_pair(map[i][0], map[i][1])); } + + for(int i=0; fallback[i][0]; i++) { + mMergeFallback.insert(std::make_pair(fallback[i][0], fallback[i][1])); + } } void MwIniImporter::setVerbose(bool verbose) { @@ -116,16 +125,36 @@ void MwIniImporter::merge(multistrmap &cfg, multistrmap &ini) { multistrmap::iterator iniIt; for(strmap::iterator it=mMergeMap.begin(); it!=mMergeMap.end(); it++) { if((iniIt = ini.find(it->second)) != ini.end()) { - cfg.erase(it->first); - if(!this->specialMerge(it->first, it->second, cfg, ini)) { - cfg.insert(std::make_pair >(it->first, iniIt->second)); + for(std::vector::iterator vc = iniIt->second.begin(); vc != iniIt->second.end(); vc++) { + cfg.erase(it->first); + insertMultistrmap(cfg, it->first, *vc); } } } } -bool MwIniImporter::specialMerge(std::string cfgKey, std::string iniKey, multistrmap &cfg, multistrmap &ini) { - return false; +void MwIniImporter::mergeFallback(multistrmap &cfg, multistrmap &ini) { + cfg.erase("fallback"); + + multistrmap::iterator cfgIt; + multistrmap::iterator iniIt; + for(strmap::iterator it=mMergeFallback.begin(); it!=mMergeFallback.end(); it++) { + if((iniIt = ini.find(it->second)) != ini.end()) { + for(std::vector::iterator vc = iniIt->second.begin(); vc != iniIt->second.end(); vc++) { + std::string value("\""); + value.append(it->first).append("=").append(vc->substr(0,vc->length()-1)).append("\""); + insertMultistrmap(cfg, "fallback", value); + } + } + } +}; + +void MwIniImporter::insertMultistrmap(multistrmap &cfg, std::string key, std::string value) { + multistrmap::iterator it = cfg.find(key); + if(it == cfg.end()) { + cfg.insert(std::make_pair >(key, std::vector() )); + } + cfg[key].push_back(value); } void MwIniImporter::importGameFiles(multistrmap &cfg, multistrmap &ini) { diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index 988f10255..9ef7b6703 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -18,14 +18,16 @@ class MwIniImporter { multistrmap loadIniFile(std::string filename); multistrmap loadCfgFile(std::string filename); void merge(multistrmap &cfg, multistrmap &ini); + void mergeFallback(multistrmap &cfg, multistrmap &ini); void importGameFiles(multistrmap &cfg, multistrmap &ini); void writeToFile(boost::iostreams::stream &out, multistrmap &cfg); private: - bool specialMerge(std::string cfgKey, std::string iniKey, multistrmap &cfg, multistrmap &ini); + void insertMultistrmap(multistrmap &cfg, std::string key, std::string value); std::string numberToString(int n); bool mVerbose; strmap mMergeMap; + strmap mMergeFallback; }; diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 836f84eb0..c5409b812 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -16,6 +16,7 @@ int main(int argc, char *argv[]) { ("ini,i", bpo::value(), "morrowind.ini file") ("cfg,c", bpo::value(), "openmw.cfg file") ("output,o", bpo::value()->default_value(""), "openmw.cfg file") + ("fallback,f", "import fallback settings") ("game-files,g", "import esm and esp files") ; @@ -44,7 +45,7 @@ int main(int argc, char *argv[]) { std::cerr << "cfg file does not exist" << std::endl; return -4; } - + MwIniImporter importer; importer.setVerbose(vm.count("verbose")); @@ -52,7 +53,11 @@ int main(int argc, char *argv[]) { MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile); importer.merge(cfg, ini); - + + if(vm.count("fallback")) { + importer.mergeFallback(cfg, ini); + } + if(vm.count("game-files")) { importer.importGameFiles(cfg, ini); } From ab9c4306328446807bde837a0befbe45ed3c1381 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 2 Apr 2012 20:47:09 +0200 Subject: [PATCH 04/20] fallback in apps/openmw; fix for apps/mwiniimporter --- apps/mwiniimporter/importer.cpp | 4 ++-- apps/mwiniimporter/main.cpp | 2 ++ apps/openmw/engine.cpp | 7 ++++++- apps/openmw/engine.hpp | 3 +++ apps/openmw/main.cpp | 25 ++++++++++++++---------- apps/openmw/mwworld/world.cpp | 34 ++++++++++++++++++++++++++++++++- apps/openmw/mwworld/world.hpp | 7 ++++++- 7 files changed, 67 insertions(+), 15 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 80ec4a5fd..e8fafab44 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -141,8 +141,8 @@ void MwIniImporter::mergeFallback(multistrmap &cfg, multistrmap &ini) { for(strmap::iterator it=mMergeFallback.begin(); it!=mMergeFallback.end(); it++) { if((iniIt = ini.find(it->second)) != ini.end()) { for(std::vector::iterator vc = iniIt->second.begin(); vc != iniIt->second.end(); vc++) { - std::string value("\""); - value.append(it->first).append("=").append(vc->substr(0,vc->length()-1)).append("\""); + std::string value(it->first); + value.append("=").append(vc->substr(0,vc->length()-1)); insertMultistrmap(cfg, "fallback", value); } } diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index c5409b812..dc9bbcd0a 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -28,6 +28,8 @@ int main(int argc, char *argv[]) { return 0; } + bpo::notify(vm); + std::string iniFile = vm["ini"].as(); std::string cfgFile = vm["cfg"].as(); diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 2dab53ecc..c6684593e 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -341,7 +341,7 @@ void OMW::Engine::go() // Create the world mEnvironment.mWorld = new MWWorld::World (*mOgre, mFileCollections, mMaster, - mResDir, mNewGame, mEnvironment, mEncoding); + mResDir, mNewGame, mEnvironment, mEncoding, mFallbackPairs); // Create window manager - this manages all the MW-specific GUI windows MWScript::registerExtensions (mExtensions); @@ -508,3 +508,8 @@ void OMW::Engine::setEncoding(const std::string& encoding) { mEncoding = encoding; } + +void OMW::Engine::setFallbackValues(std::vector pairs) +{ + mFallbackPairs = pairs; +} diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 690430784..f1df98f4c 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -76,6 +76,7 @@ namespace OMW bool mReportFocus; float mFocusTDiff; std::string mFocusName; + std::vector mFallbackPairs; MWWorld::Environment mEnvironment; Compiler::Extensions mExtensions; @@ -163,6 +164,8 @@ namespace OMW void setAnimationVerbose(bool animverbose); + void setFallbackValues(std::vector pairs); + private: Files::ConfigurationManager& mCfgMgr; }; diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index cd1e0e26e..0dc534377 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -92,39 +92,43 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("plugin", bpo::value()->default_value(StringsVector(), "") ->multitoken(), "plugin file(s)") - ("fps", boost::program_options::value()->implicit_value(1) + ("fps", bpo::value()->implicit_value(1) ->default_value(0), "fps counter detail (0 = off, 1 = fps counter, 2 = full detail)") - ("anim-verbose", boost::program_options::value()->implicit_value(true) + ("anim-verbose", bpo::value()->implicit_value(true) ->default_value(false), "output animation indices files") - ("debug", boost::program_options::value()->implicit_value(true) + ("debug", bpo::value()->implicit_value(true) ->default_value(false), "debug mode") - ("nosound", boost::program_options::value()->implicit_value(true) + ("nosound", bpo::value()->implicit_value(true) ->default_value(false), "disable all sounds") - ("script-verbose", boost::program_options::value()->implicit_value(true) + ("script-verbose", bpo::value()->implicit_value(true) ->default_value(false), "verbose script output") - ("new-game", boost::program_options::value()->implicit_value(true) + ("new-game", bpo::value()->implicit_value(true) ->default_value(false), "activate char gen/new game mechanics") - ("script-all", boost::program_options::value()->implicit_value(true) + ("script-all", bpo::value()->implicit_value(true) ->default_value(false), "compile all scripts (excluding dialogue scripts) at startup") - ("fs-strict", boost::program_options::value()->implicit_value(true) + ("fs-strict", bpo::value()->implicit_value(true) ->default_value(false), "strict file system handling (no case folding)") - ( "encoding", boost::program_options::value()-> + ( "encoding", bpo::value()-> default_value("win1252"), "Character encoding used in OpenMW game messages:\n" "\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n" "\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n" "\n\twin1252 - Western European (Latin) alphabet, used by default") - ("report-focus", boost::program_options::value()->implicit_value(true) + ("report-focus", bpo::value()->implicit_value(true) ->default_value(false), "write name of focussed object to cout") + + ("fallback", bpo::value()->default_value(StringsVector(), "") + ->multitoken()->composing(), "fallback values") + ; bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv) @@ -232,6 +236,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setCompileAll(variables["script-all"].as()); engine.setReportFocus(variables["report-focus"].as()); engine.setAnimationVerbose(variables["anim-verbose"].as()); + engine.setFallbackValues(variables["fallback"].as >()); return true; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 3a15f42ba..093c3fef0 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -152,10 +152,40 @@ namespace MWWorld mRendering->skyDisable(); } + void World::setFallbackValues(std::vector pairs) + { + for(std::vector::iterator it = pairs.begin(); it != pairs.end(); it++) + { + std::string kv = *it; + int seperator = kv.find("="); + if(seperator < 1 || seperator == (kv.length()-1)) + { + continue; + } + + std::string key = it->substr(0,seperator); + std::string value = it->substr(seperator+1); + if(mFallback.find(key) == mFallback.end()) { + std::cout << "insert " << key << ":" << value << std::endl; + mFallback.insert(std::make_pair(key,value)); + } + } + } + + std::string World::getFallback(std::string key) + { + std::map::iterator it; + if((it = mFallback.find(key)) == mFallback.end()) + { + return std::string(""); + } + return it->second; + } + World::World (OEngine::Render::OgreRenderer& renderer, const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, - bool newGame, Environment& environment, const std::string& encoding) + bool newGame, Environment& environment, const std::string& encoding, std::vector fallbackPairs) : mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), mSky (true), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this), mNumFacing(0) @@ -190,6 +220,8 @@ namespace MWWorld } mWorldScene = new Scene(environment, this, *mRendering, mPhysics); + + setFallbackValues(fallbackPairs); } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 0d46fe4e8..d6b422141 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -100,6 +100,7 @@ namespace MWWorld std::string mFaced1Name; std::string mFaced2Name; int mNumFacing; + std::map mFallback; int getDaysPerMonth (int month) const; @@ -110,7 +111,7 @@ namespace MWWorld World (OEngine::Render::OgreRenderer& renderer, const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, - Environment& environment, const std::string& encoding); + Environment& environment, const std::string& encoding, std::vector fallbackPairs); ~World(); @@ -125,6 +126,10 @@ namespace MWWorld void adjustSky(); + void setFallbackValues(std::vector pairs); + + std::string getFallback(std::string key); + MWWorld::Player& getPlayer(); const ESMS::ESMStore& getStore() const; From 2d23d79fd5d7dc954c1228a5a8197ad46692a311 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 3 Apr 2012 00:44:26 +0200 Subject: [PATCH 05/20] allways merge fallback; better syntax --- apps/mwiniimporter/importer.cpp | 20 ++++++++++---------- apps/mwiniimporter/importer.hpp | 2 +- apps/mwiniimporter/main.cpp | 6 +----- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index e8fafab44..60f2c620d 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -14,18 +14,16 @@ MwIniImporter::MwIniImporter() { { "fps", "General:Show FPS" }, { 0, 0 } }; - const char *fallback[][2] = { - { "Weather_Sunrise_Time", "Weather:Sunrise Time" }, - { "Weather_Sunset_Time", "Weather:Sunset Time" }, - { 0, 0 } + const char *fallback[] = { + "Weather:Sunrise Time", "Weather_Sunset_Time", 0 }; for(int i=0; map[i][0]; i++) { mMergeMap.insert(std::make_pair(map[i][0], map[i][1])); } - for(int i=0; fallback[i][0]; i++) { - mMergeFallback.insert(std::make_pair(fallback[i][0], fallback[i][1])); + for(int i=0; fallback[i]; i++) { + mMergeFallback.push_back(fallback[i]); } } @@ -138,11 +136,13 @@ void MwIniImporter::mergeFallback(multistrmap &cfg, multistrmap &ini) { multistrmap::iterator cfgIt; multistrmap::iterator iniIt; - for(strmap::iterator it=mMergeFallback.begin(); it!=mMergeFallback.end(); it++) { - if((iniIt = ini.find(it->second)) != ini.end()) { + for(std::vector::iterator it=mMergeFallback.begin(); it!=mMergeFallback.end(); it++) { + if((iniIt = ini.find(*it)) != ini.end()) { for(std::vector::iterator vc = iniIt->second.begin(); vc != iniIt->second.end(); vc++) { - std::string value(it->first); - value.append("=").append(vc->substr(0,vc->length()-1)); + std::string value(*it); + std::replace( value.begin(), value.end(), ' ', '_' ); + std::replace( value.begin(), value.end(), ':', '_' ); + value.append(",").append(vc->substr(0,vc->length()-1)); insertMultistrmap(cfg, "fallback", value); } } diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index 9ef7b6703..ced332a72 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -27,7 +27,7 @@ class MwIniImporter { std::string numberToString(int n); bool mVerbose; strmap mMergeMap; - strmap mMergeFallback; + std::vector mMergeFallback; }; diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index dc9bbcd0a..051e7db2b 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -16,7 +16,6 @@ int main(int argc, char *argv[]) { ("ini,i", bpo::value(), "morrowind.ini file") ("cfg,c", bpo::value(), "openmw.cfg file") ("output,o", bpo::value()->default_value(""), "openmw.cfg file") - ("fallback,f", "import fallback settings") ("game-files,g", "import esm and esp files") ; @@ -55,10 +54,7 @@ int main(int argc, char *argv[]) { MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile); importer.merge(cfg, ini); - - if(vm.count("fallback")) { - importer.mergeFallback(cfg, ini); - } + importer.mergeFallback(cfg, ini); if(vm.count("game-files")) { importer.importGameFiles(cfg, ini); From d87dffa948af48002863efd1a92837ba88574068 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 3 Apr 2012 01:47:43 +0200 Subject: [PATCH 06/20] should work... but does not even compile --- apps/openmw/main.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 0dc534377..e1ddb03e7 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -54,6 +54,35 @@ inline boost::filesystem::path lexical_cast mMap; + + static void + validate(boost::any &v, std::vector const &tokens) + { + if(v.empty()) + { + v = boost::any(FallbackMap()); + } + + FallbackMap *map = boost::any_cast(&v); + + std::map::iterator mapIt; + for(std::vector::const_iterator it=tokens.begin(); it != tokens.end(); it++) + { + int sep = it->find(","); + std::string key(it->substr(0,sep-1)); + std::string value(it->substr(sep)); + + if((mapIt = map->mMap.find(key)) == map->mMap.end()) + { + map->mMap.insert(std::make_pair(key,value)); + } + } + } +}; + + /** * \brief Parses application command line and calls \ref Cfg::ConfigurationManager * to parse configuration files. @@ -126,7 +155,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("report-focus", bpo::value()->implicit_value(true) ->default_value(false), "write name of focussed object to cout") - ("fallback", bpo::value()->default_value(StringsVector(), "") + ("fallback", bpo::value() ->multitoken()->composing(), "fallback values") ; @@ -236,7 +265,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setCompileAll(variables["script-all"].as()); engine.setReportFocus(variables["report-focus"].as()); engine.setAnimationVerbose(variables["anim-verbose"].as()); - engine.setFallbackValues(variables["fallback"].as >()); + //engine.setFallbackValues(variables["fallback"].as >()); return true; } From 73705dadf6036323bbbe79e2da0dbe7c52f7991d Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 3 Apr 2012 02:14:39 +0200 Subject: [PATCH 07/20] parse fallback with boost program option custom validators --- apps/openmw/engine.cpp | 6 ++--- apps/openmw/engine.hpp | 4 +-- apps/openmw/main.cpp | 46 ++++++++++++++++++----------------- apps/openmw/mwworld/world.cpp | 24 ++++-------------- apps/openmw/mwworld/world.hpp | 4 +-- 5 files changed, 36 insertions(+), 48 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index c6684593e..dae5aaff1 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -341,7 +341,7 @@ void OMW::Engine::go() // Create the world mEnvironment.mWorld = new MWWorld::World (*mOgre, mFileCollections, mMaster, - mResDir, mNewGame, mEnvironment, mEncoding, mFallbackPairs); + mResDir, mNewGame, mEnvironment, mEncoding, mFallbackMap); // Create window manager - this manages all the MW-specific GUI windows MWScript::registerExtensions (mExtensions); @@ -509,7 +509,7 @@ void OMW::Engine::setEncoding(const std::string& encoding) mEncoding = encoding; } -void OMW::Engine::setFallbackValues(std::vector pairs) +void OMW::Engine::setFallbackValues(std::map fallbackMap) { - mFallbackPairs = pairs; + mFallbackMap = fallbackMap; } diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index f1df98f4c..6eae20cc0 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -76,7 +76,7 @@ namespace OMW bool mReportFocus; float mFocusTDiff; std::string mFocusName; - std::vector mFallbackPairs; + std::map mFallbackMap; MWWorld::Environment mEnvironment; Compiler::Extensions mExtensions; @@ -164,7 +164,7 @@ namespace OMW void setAnimationVerbose(bool animverbose); - void setFallbackValues(std::vector pairs); + void setFallbackValues(std::map map); private: Files::ConfigurationManager& mCfgMgr; diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index e1ddb03e7..b541ea0d3 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -56,31 +56,33 @@ using namespace std; struct FallbackMap { std::map mMap; +}; - static void - validate(boost::any &v, std::vector const &tokens) +void validate(boost::any &v, std::vector const &tokens, FallbackMap*, int) +{ + if(v.empty()) { - if(v.empty()) - { - v = boost::any(FallbackMap()); - } - - FallbackMap *map = boost::any_cast(&v); - - std::map::iterator mapIt; - for(std::vector::const_iterator it=tokens.begin(); it != tokens.end(); it++) + v = boost::any(FallbackMap()); + } + + FallbackMap *map = boost::any_cast(&v); + + std::map::iterator mapIt; + for(std::vector::const_iterator it=tokens.begin(); it != tokens.end(); it++) + { + int sep = it->find(","); + if(sep < 1) + continue; + + std::string key(it->substr(0,sep)); + std::string value(it->substr(sep+1)); + + if((mapIt = map->mMap.find(key)) == map->mMap.end()) { - int sep = it->find(","); - std::string key(it->substr(0,sep-1)); - std::string value(it->substr(sep)); - - if((mapIt = map->mMap.find(key)) == map->mMap.end()) - { - map->mMap.insert(std::make_pair(key,value)); - } + map->mMap.insert(std::make_pair(key,value)); } - } -}; + } +} /** @@ -265,7 +267,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setCompileAll(variables["script-all"].as()); engine.setReportFocus(variables["report-focus"].as()); engine.setAnimationVerbose(variables["anim-verbose"].as()); - //engine.setFallbackValues(variables["fallback"].as >()); + engine.setFallbackValues(variables["fallback"].as().mMap); return true; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 093c3fef0..596adcf6b 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -152,24 +152,9 @@ namespace MWWorld mRendering->skyDisable(); } - void World::setFallbackValues(std::vector pairs) + void World::setFallbackValues(std::map fallbackMap) { - for(std::vector::iterator it = pairs.begin(); it != pairs.end(); it++) - { - std::string kv = *it; - int seperator = kv.find("="); - if(seperator < 1 || seperator == (kv.length()-1)) - { - continue; - } - - std::string key = it->substr(0,seperator); - std::string value = it->substr(seperator+1); - if(mFallback.find(key) == mFallback.end()) { - std::cout << "insert " << key << ":" << value << std::endl; - mFallback.insert(std::make_pair(key,value)); - } - } + mFallback = fallbackMap; } std::string World::getFallback(std::string key) @@ -185,7 +170,7 @@ namespace MWWorld World::World (OEngine::Render::OgreRenderer& renderer, const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, - bool newGame, Environment& environment, const std::string& encoding, std::vector fallbackPairs) + bool newGame, Environment& environment, const std::string& encoding, std::map fallbackMap) : mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0), mSky (true), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this), mNumFacing(0) @@ -221,7 +206,8 @@ namespace MWWorld mWorldScene = new Scene(environment, this, *mRendering, mPhysics); - setFallbackValues(fallbackPairs); + setFallbackValues(fallbackMap); + std::cout << "Weather_Sunrise_Time=" << getFallback("Weather_Sunrise_Time") << std::endl; } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index d6b422141..7f18762f5 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -111,7 +111,7 @@ namespace MWWorld World (OEngine::Render::OgreRenderer& renderer, const Files::Collections& fileCollections, const std::string& master, const boost::filesystem::path& resDir, bool newGame, - Environment& environment, const std::string& encoding, std::vector fallbackPairs); + Environment& environment, const std::string& encoding, std::map fallbackMap); ~World(); @@ -126,7 +126,7 @@ namespace MWWorld void adjustSky(); - void setFallbackValues(std::vector pairs); + void setFallbackValues(std::map fallbackMap); std::string getFallback(std::string key); From 329d59e52bc7256bb30fa24bd8a0ab01e36d189c Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 3 Apr 2012 02:17:15 +0200 Subject: [PATCH 08/20] typo --- apps/mwiniimporter/importer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 60f2c620d..f1cec0479 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -15,7 +15,9 @@ MwIniImporter::MwIniImporter() { { 0, 0 } }; const char *fallback[] = { - "Weather:Sunrise Time", "Weather_Sunset_Time", 0 + "Weather:Sunrise Time", + "Weather:Sunset Time", + 0 }; for(int i=0; map[i][0]; i++) { From 329ba24eab7ee016bd103367c061f87f04f6d282 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 4 Apr 2012 15:11:30 +0200 Subject: [PATCH 09/20] streamlined command line options --- apps/mwiniimporter/main.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 051e7db2b..234d7d57d 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -9,7 +9,8 @@ namespace bpo = boost::program_options; int main(int argc, char *argv[]) { - bpo::options_description desc("Syntax: mwiniimporter -i inifile -c configfile \nAllowed options"); + bpo::options_description desc("Syntax: mwiniimporter inifile configfile\nAllowed options"); + bpo::positional_options_description p_desc; desc.add_options() ("help,h", "produce help message") ("verbose,v", "verbose output") @@ -18,9 +19,15 @@ int main(int argc, char *argv[]) { ("output,o", bpo::value()->default_value(""), "openmw.cfg file") ("game-files,g", "import esm and esp files") ; + p_desc.add("ini", 1).add("cfg", 1); bpo::variables_map vm; - bpo::store(boost::program_options::parse_command_line(argc, argv, desc), vm); + bpo::parsed_options parsed = bpo::command_line_parser(argc, argv) + .options(desc) + .positional(p_desc) + .run(); + + bpo::store(parsed, vm); if(vm.count("help") || !vm.count("ini") || !vm.count("cfg")) { std::cout << desc; From de510d445b328f5315a3aff4ac00d610bb23fa8e Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 4 Apr 2012 15:23:14 +0200 Subject: [PATCH 10/20] throw an error if the --fallback syntax is wrong --- apps/openmw/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index b541ea0d3..cdc4af4b0 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -71,8 +71,8 @@ void validate(boost::any &v, std::vector const &tokens, FallbackMap for(std::vector::const_iterator it=tokens.begin(); it != tokens.end(); it++) { int sep = it->find(","); - if(sep < 1) - continue; + if(sep < 1 || sep = it->length()-1) + throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); std::string key(it->substr(0,sep)); std::string value(it->substr(sep+1)); From 16e7bf353a50a0188cf1790417751d89ea24d83e Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 4 Apr 2012 16:08:46 +0200 Subject: [PATCH 11/20] remove debug message --- apps/openmw/mwworld/world.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 596adcf6b..7f4169b9d 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -205,9 +205,8 @@ namespace MWWorld } mWorldScene = new Scene(environment, this, *mRendering, mPhysics); - + setFallbackValues(fallbackMap); - std::cout << "Weather_Sunrise_Time=" << getFallback("Weather_Sunrise_Time") << std::endl; } From 48b7b03453197ff5069aee6b9714838bc95085be Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 4 Apr 2012 16:15:15 +0200 Subject: [PATCH 12/20] typo; World::getFallback(std::string key, std::string def) --- apps/openmw/main.cpp | 2 +- apps/openmw/mwworld/world.cpp | 7 ++++++- apps/openmw/mwworld/world.hpp | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index cdc4af4b0..06b068621 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -71,7 +71,7 @@ void validate(boost::any &v, std::vector const &tokens, FallbackMap for(std::vector::const_iterator it=tokens.begin(); it != tokens.end(); it++) { int sep = it->find(","); - if(sep < 1 || sep = it->length()-1) + if(sep < 1 || sep == (it->length()-1)) throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); std::string key(it->substr(0,sep)); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 7f4169b9d..431a7a18c 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -158,11 +158,16 @@ namespace MWWorld } std::string World::getFallback(std::string key) + { + return getFallback(key, ""); + } + + std::string World::getFallback(std::string key, std::string def) { std::map::iterator it; if((it = mFallback.find(key)) == mFallback.end()) { - return std::string(""); + return def; } return it->second; } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 7f18762f5..799b0d094 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -130,6 +130,8 @@ namespace MWWorld std::string getFallback(std::string key); + std::string getFallback(std::string key, std::string def); + MWWorld::Player& getPlayer(); const ESMS::ESMStore& getStore() const; From 94a220dcdd9d222b1799c6731898da768c496fac Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 4 Apr 2012 19:52:07 +0200 Subject: [PATCH 13/20] set a default value for --fallback --- apps/openmw/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 06b068621..2e56d528b 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -267,7 +267,11 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setCompileAll(variables["script-all"].as()); engine.setReportFocus(variables["report-focus"].as()); engine.setAnimationVerbose(variables["anim-verbose"].as()); - engine.setFallbackValues(variables["fallback"].as().mMap); + + if(variables.count("fallback")) + { + engine.setFallbackValues(variables["fallback"].as().mMap); + } return true; } From a974d88cf1fab6f5d5d18b7762f943ea6c101fb6 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 4 Apr 2012 19:58:04 +0200 Subject: [PATCH 14/20] Revert "set a default value for --fallback" This reverts commit 94a220dcdd9d222b1799c6731898da768c496fac. --- apps/openmw/main.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 2e56d528b..06b068621 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -267,11 +267,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setCompileAll(variables["script-all"].as()); engine.setReportFocus(variables["report-focus"].as()); engine.setAnimationVerbose(variables["anim-verbose"].as()); - - if(variables.count("fallback")) - { - engine.setFallbackValues(variables["fallback"].as().mMap); - } + engine.setFallbackValues(variables["fallback"].as().mMap); return true; } From d3a6484bbc052706949fd176a01ada7c549d9853 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 4 Apr 2012 19:59:46 +0200 Subject: [PATCH 15/20] set the default value for --fallback the right way --- apps/openmw/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 06b068621..545014206 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -157,7 +157,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("report-focus", bpo::value()->implicit_value(true) ->default_value(false), "write name of focussed object to cout") - ("fallback", bpo::value() + ("fallback", bpo::value()->default_value(FallbackMap(), "") ->multitoken()->composing(), "fallback values") ; From 6ccb32d26c55808b55f2c637b250e977144a3d07 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 4 Apr 2012 20:06:31 +0200 Subject: [PATCH 16/20] import nosound option --- apps/mwiniimporter/importer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index f1cec0479..5503a7c1a 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -12,6 +12,7 @@ MwIniImporter::MwIniImporter() { const char *map[][2] = { { "fps", "General:Show FPS" }, + { "nosound", "General:Disable Audio" }, { 0, 0 } }; const char *fallback[] = { From 5dd65c11ee85f43cca92caea85fa22fb8b82c07b Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 4 Apr 2012 21:04:52 +0200 Subject: [PATCH 17/20] forgot to save the file --- apps/openmw/main.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 0a2d35699..bc6159e2a 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -123,14 +123,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("plugin", bpo::value()->default_value(StringsVector(), "") ->multitoken(), "plugin file(s)") -<<<<<<< HEAD - ("fps", bpo::value()->implicit_value(1) - ->default_value(0), "fps counter detail (0 = off, 1 = fps counter, 2 = full detail)") - ("anim-verbose", bpo::value()->implicit_value(true) -======= - ("anim-verbose", boost::program_options::value()->implicit_value(true) ->>>>>>> e403c7158acfb118bed01a08a46431b24cff8747 ->default_value(false), "output animation indices files") ("debug", bpo::value()->implicit_value(true) From 8c84f68dab58b36a4a8a7d51a634cc2192788798 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 4 Apr 2012 23:51:22 +0200 Subject: [PATCH 18/20] fix for older boost versions; unsigned warning --- apps/openmw/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index bc6159e2a..11efc2867 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -71,8 +71,12 @@ void validate(boost::any &v, std::vector const &tokens, FallbackMap for(std::vector::const_iterator it=tokens.begin(); it != tokens.end(); it++) { int sep = it->find(","); - if(sep < 1 || sep == (it->length()-1)) + if(sep < 1 || sep == (int)it->length()-1) +#if (BOOST_VERSION <= 104200) + throw boost::program_options::validation_error("invalid value"); +#else throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); +#endif /* #if (BOOST_VERSION <= 104200) */ std::string key(it->substr(0,sep)); std::string value(it->substr(sep+1)); From 56c9992b29f63a01c887a42a38d2174d4922d6bf Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 4 Apr 2012 23:52:42 +0200 Subject: [PATCH 19/20] typo --- apps/openmw/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 11efc2867..11516d43c 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -72,11 +72,11 @@ void validate(boost::any &v, std::vector const &tokens, FallbackMap { int sep = it->find(","); if(sep < 1 || sep == (int)it->length()-1) -#if (BOOST_VERSION <= 104200) +#if (BOOST_VERSION < 104200) throw boost::program_options::validation_error("invalid value"); #else throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); -#endif /* #if (BOOST_VERSION <= 104200) */ +#endif/ std::string key(it->substr(0,sep)); std::string value(it->substr(sep+1)); From f7bfea586198dc97df92bd2b96e4c1c50ed7710d Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Thu, 5 Apr 2012 00:16:44 +0200 Subject: [PATCH 20/20] typo 2 -.- --- apps/openmw/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 11516d43c..df52faab1 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -76,7 +76,7 @@ void validate(boost::any &v, std::vector const &tokens, FallbackMap throw boost::program_options::validation_error("invalid value"); #else throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); -#endif/ +#endif std::string key(it->substr(0,sep)); std::string value(it->substr(sep+1));