From 1c4db82a0e6119c342d9a6d89679fde9babdaba7 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 6 Oct 2010 14:52:53 +0200 Subject: [PATCH] added --script-all switch --- apps/openmw/engine.cpp | 29 ++++++++++++++++++++++++++ apps/openmw/engine.hpp | 4 ++++ apps/openmw/main.cpp | 4 ++++ apps/openmw/mwscript/scriptmanager.hpp | 18 +++++++++------- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 1d10603c5..466cc44f6 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -107,6 +107,7 @@ OMW::Engine::Engine() , mVerboseScripts (false) , mNewGame (false) , mUseSound (true) + , mCompileAll (false) , mScriptManager (0) , mScriptContext (0) , mGuiManager (0) @@ -301,6 +302,29 @@ void OMW::Engine::go() std::cout << " Music Error: " << e.what() << "\n"; } + // scripts + if (mCompileAll) + { + typedef ESMS::ScriptListT::MapType Container; + + Container scripts = mEnvironment.mWorld->getStore().scripts.list; + + int count = 0; + int success = 0; + + for (Container::const_iterator iter (scripts.begin()); iter!=scripts.end(); ++iter, ++count) + if (mScriptManager->compile (iter->first)) + ++success; + + if (count) + std::cout + << "compiled " << success << " of " << count << " scripts (" + << 100*static_cast (success)/count + << "%)" + << std::endl; + + } + // Start the main rendering loop mOgre.start(); @@ -341,3 +365,8 @@ void OMW::Engine::activate() interpreterContext.executeActivation(); } } + +void OMW::Engine::setCompileAll (bool all) +{ + mCompileAll = all; +} diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index d7420889f..01f339874 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -60,6 +60,7 @@ namespace OMW bool mVerboseScripts; bool mNewGame; bool mUseSound; + bool mCompileAll; MWWorld::Environment mEnvironment; MWScript::ScriptManager *mScriptManager; @@ -127,6 +128,9 @@ namespace OMW /// Activate the focussed object. void activate(); + + /// Compile all scripts (excludign dialogue scripts) at startup? + void setCompileAll (bool all); }; } diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 017c58873..5d312226d 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -34,6 +34,7 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) ( "nosound", "disable all sound" ) ( "script-verbose", "verbose script output" ) ( "new-game", "activate char gen/new game mechanics" ) + ( "script-all", "compile all scripts (excluding dialogue scripts) at startup") ; bpo::variables_map variables; @@ -75,6 +76,9 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) if (variables.count ("new-game")) engine.setNewGame(); + if (variables.count ("script-all")) + engine.setCompileAll (true); + return true; } diff --git a/apps/openmw/mwscript/scriptmanager.hpp b/apps/openmw/mwscript/scriptmanager.hpp index 5828fbcca..639fc59bf 100644 --- a/apps/openmw/mwscript/scriptmanager.hpp +++ b/apps/openmw/mwscript/scriptmanager.hpp @@ -27,7 +27,7 @@ namespace Interpreter } namespace MWScript -{ +{ class ScriptManager { Compiler::StreamErrorHandler mErrorHandler; @@ -35,19 +35,21 @@ namespace MWScript bool mVerbose; Compiler::Context& mCompilerContext; Compiler::FileParser mParser; - + std::map > mScripts; - - bool compile (const std::string& name); - + public: - + ScriptManager (const ESMS::ESMStore& store, bool verbose, Compiler::Context& compilerContext); - + void run (const std::string& name, Interpreter::Context& interpreterContext); + ///< Run the script with the given name (compile first, if not compiled yet) + + bool compile (const std::string& name); + ///< Compile script with the given namen + /// \return Success? }; }; #endif -