From 2064c43d89a8be366ee823a752699a6cce931aa1 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 2 Jul 2010 16:18:25 +0200 Subject: [PATCH] added script manager (doesn't do anything yet); local scriptes for active cells are passed on to the script manager --- CMakeLists.txt | 6 ++- apps/openmw/engine.cpp | 22 ++++++++++- apps/openmw/engine.hpp | 16 +++++++- apps/openmw/main.cpp | 4 ++ apps/openmw/mwscript/scriptmanager.cpp | 19 +++++++++ apps/openmw/mwscript/scriptmanager.hpp | 47 ++++++++++++++++++++++ apps/openmw/world.cpp | 54 ++++++++++++++++++++++++++ apps/openmw/world.hpp | 18 +++++++-- 8 files changed, 179 insertions(+), 7 deletions(-) create mode 100644 apps/openmw/mwscript/scriptmanager.cpp create mode 100644 apps/openmw/mwscript/scriptmanager.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0236d8f894..136858132f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,9 +37,11 @@ set(GAMEINPUT_HEADER apps/openmw/mwinput/inputmanager.hpp) source_group(apps\\openmw\\mwinput FILES ${GAMEINPUT} ${GAMEINPUT_HEADER}) -# set(GAMESCRIPT) +set(GAMESCRIPT + apps/openmw/mwscript/scriptmanager.cpp) set(GAMESCRIPT_HEADER - apps/openmw/mwscript/locals.hpp) + apps/openmw/mwscript/locals.hpp + apps/openmw/mwscript/scriptmanager.hpp) source_group(apps\\openmw\\mwscript FILES ${GAMESCRIPT} ${GAMESCRIPT_HEADER}) set(APPS ${GAME} ${GAMEREND} ${GAMEINPUT} ${GAMESCRIPT}) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 4acb433632..e308c9a38b 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -8,6 +8,7 @@ #include "components/bsa/bsa_archive.hpp" #include "mwinput/inputmanager.hpp" +#include "mwscript/scriptmanager.hpp" #include "world.hpp" @@ -24,8 +25,17 @@ protected: OMW::Engine* mpEngine; }; +void OMW::Engine::executeLocalScripts() +{ + for (World::ScriptList::const_iterator iter (mWorld->getLocalScripts().begin()); + iter!=mWorld->getLocalScripts().end(); ++iter) + { + mScriptManager->run (iter->first); + + } +} -OMW::Engine::Engine() : mWorld(NULL), mDebug (false) +OMW::Engine::Engine() : mWorld(NULL), mDebug (false), mScriptManager (0) { mspCommandServer.reset( new OMW::CommandServer::Server(&mCommandQueue, kCommandServerPort)); @@ -35,6 +45,7 @@ OMW::Engine::~Engine() { // mspCommandServer->stop(); delete mWorld; + delete mScriptManager; } // Load all BSA files in data directory. @@ -97,6 +108,11 @@ void OMW::Engine::enableDebugMode() { mDebug = true; } + +void OMW::Engine::enableVerboseScripts() +{ + mVerboseScripts = true; +} void OMW::Engine::processCommands() { @@ -143,6 +159,10 @@ void OMW::Engine::go() // Create the world mWorld = new World (mOgre, mDataDir, mMaster, mCellName); + mScriptManager = new MWScript::ScriptManager (mWorld->getStore(), mVerboseScripts); + + executeLocalScripts(); // TODO move into a framelistener + std::cout << "Setting up input system\n"; // Sets up the input system diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index af4907d01c..47f4e88c89 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -6,11 +6,17 @@ #include #include "components/engine/ogre/renderer.hpp" -#include "apps/openmw/mwrender/mwscene.hpp" #include "components/misc/tsdeque.hpp" #include "components/commandserver/server.hpp" #include "components/commandserver/command.hpp" +#include "mwrender/mwscene.hpp" + +namespace MWScript +{ + class ScriptManager; +} + namespace OMW { class World; @@ -27,10 +33,13 @@ namespace OMW std::string mMaster; World *mWorld; bool mDebug; + bool mVerboseScripts; TsDeque mCommandQueue; std::auto_ptr mspCommandServer; + MWScript::ScriptManager *mScriptManager; + // not implemented Engine (const Engine&); Engine& operator= (const Engine&); @@ -42,6 +51,8 @@ namespace OMW /// Load all BSA files in data directory. void loadBSA(); + void executeLocalScripts(); + public: Engine(); @@ -63,6 +74,9 @@ namespace OMW /// - non-exclusive input void enableDebugMode(); + /// Enable verbose script output + void enableVerboseScripts(); + /// Process pending commands void processCommands(); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 948b718bf4..0908c972cb 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -30,6 +30,7 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) ("master", bpo::value()->default_value ("Morrowind"), "master file") ( "debug", "debug mode" ) + ( "script-verbose", "verbose script output" ) ; bpo::variables_map variables; @@ -54,6 +55,9 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) if (variables.count ("debug")) engine.enableDebugMode(); + + if (variables.count ("script-verbose")) + engine.enableVerboseScripts(); return true; } diff --git a/apps/openmw/mwscript/scriptmanager.cpp b/apps/openmw/mwscript/scriptmanager.cpp new file mode 100644 index 0000000000..1c9f61abd4 --- /dev/null +++ b/apps/openmw/mwscript/scriptmanager.cpp @@ -0,0 +1,19 @@ + +#include "scriptmanager.hpp" + +#include + +namespace MWScript +{ + ScriptManager::ScriptManager (const ESMS::ESMStore& store, bool verbose) + : mStore (store), mVerbose (verbose) + {} + + void ScriptManager::run (const std::string& name/*, Compiler::Context& compilerContext, + Interpreter::Context& interpreterContext, Locals& locals*/) + { + std::cout << "script request: " << name << std::endl; + + } +} + diff --git a/apps/openmw/mwscript/scriptmanager.hpp b/apps/openmw/mwscript/scriptmanager.hpp new file mode 100644 index 0000000000..a399bb8da0 --- /dev/null +++ b/apps/openmw/mwscript/scriptmanager.hpp @@ -0,0 +1,47 @@ +#ifndef GAME_SCRIPT_SCRIPTMANAGER_H +#define GAME_SCRIPT_SCRIPTMANAGER_H + +#include +#include +#include + +#include + +namespace ESMS +{ + struct ESMStore; +} + +namespace Compiler +{ + class Context; +} + +namespace Interpreter +{ + class Context; +} + +namespace MWScript +{ + struct Locals; + + class ScriptManager + { + const ESMS::ESMStore& mStore; + bool mVerbose; + + std::map > mScripts; + + public: + + ScriptManager (const ESMS::ESMStore& store, bool verbose); + + void run (const std::string& name/*, Compiler::Context& compilerContext, + Interpreter::Context& interpreterContext, Locals& locals*/); + }; +}; + +#endif + + diff --git a/apps/openmw/world.cpp b/apps/openmw/world.cpp index 3aacfdb29a..a4460a5127 100644 --- a/apps/openmw/world.cpp +++ b/apps/openmw/world.cpp @@ -7,8 +7,50 @@ #include "apps/openmw/mwrender/sky.hpp" #include "apps/openmw/mwrender/interior.hpp" +namespace +{ + template + void listCellScripts (ESMS::CellRefList& cellRefList, + OMW::World::ScriptList& scriptList) + { + for (typename ESMS::CellRefList::List::iterator iter ( + cellRefList.list.begin()); + iter!=cellRefList.list.end(); ++iter) + { + if (!iter->base->script.empty()) + scriptList.push_back ( + std::make_pair (iter->base->script, static_cast (0))); + + // TODO local variables + + + } + } +} + namespace OMW { + void World::insertInteriorScripts (ESMS::CellStore& cell) + { + listCellScripts (cell.activators, mLocalScripts); + listCellScripts (cell.potions, mLocalScripts); + listCellScripts (cell.appas, mLocalScripts); + listCellScripts (cell.armors, mLocalScripts); + listCellScripts (cell.books, mLocalScripts); + listCellScripts (cell.clothes, mLocalScripts); + listCellScripts (cell.containers, mLocalScripts); + listCellScripts (cell.creatures, mLocalScripts); + listCellScripts (cell.doors, mLocalScripts); + listCellScripts (cell.ingreds, mLocalScripts); + listCellScripts (cell.lights, mLocalScripts); + listCellScripts (cell.lockpicks, mLocalScripts); + listCellScripts (cell.miscItems, mLocalScripts); + listCellScripts (cell.npcs, mLocalScripts); + listCellScripts (cell.probes, mLocalScripts); + listCellScripts (cell.repairs, mLocalScripts); + listCellScripts (cell.weapons, mLocalScripts); + } + World::World (Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir, const std::string& master, const std::string& startCell) : mSkyManager (0), mScene (renderer), mPlayerPos (mScene.getCamera()) @@ -24,6 +66,8 @@ namespace OMW mInteriors[startCell].loadInt (startCell, mStore, mEsm); + insertInteriorScripts (mInteriors[startCell]); + std::cout << "\nSetting up cell rendering\n"; // This connects the cell data with the rendering scene. @@ -58,4 +102,14 @@ namespace OMW { return mPlayerPos; } + + ESMS::ESMStore& World::getStore() + { + return mStore; + } + + const World::ScriptList& World::getLocalScripts() const + { + return mLocalScripts; + } } diff --git a/apps/openmw/world.hpp b/apps/openmw/world.hpp index f50743f556..7eed09dda8 100644 --- a/apps/openmw/world.hpp +++ b/apps/openmw/world.hpp @@ -11,7 +11,7 @@ #include "apps/openmw/mwrender/playerpos.hpp" #include "apps/openmw/mwrender/mwscene.hpp" -#include "apps/openmw/refdata.hpp" +#include "refdata.hpp" namespace Render { @@ -30,6 +30,12 @@ namespace OMW class World { + public: + + typedef std::vector > ScriptList; + + private: + typedef ESMS::CellStore CellStore; typedef std::map CellRenderCollection; @@ -41,11 +47,14 @@ namespace OMW ESM::ESMReader mEsm; ESMS::ESMStore mStore; std::map mInteriors; + ScriptList mLocalScripts; // not implemented World (const World&); World& operator= (const World&); + void insertInteriorScripts (ESMS::CellStore& cell); + public: World (Render::OgreRenderer& renderer, const boost::filesystem::path& master, @@ -54,8 +63,11 @@ namespace OMW ~World(); MWRender::PlayerPos& getPlayerPos(); - - + + ESMS::ESMStore& getStore(); + + const ScriptList& getLocalScripts() const; + ///< Names and local variable state of all local scripts in active cells. }; }