From ab9c4306328446807bde837a0befbe45ed3c1381 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 2 Apr 2012 20:47:09 +0200 Subject: [PATCH] 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;