mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-30 02:56:44 +00:00 
			
		
		
		
	added script manager (doesn't do anything yet); local scriptes for active cells are passed on to the script manager
This commit is contained in:
		
							parent
							
								
									a06b84ac86
								
							
						
					
					
						commit
						2064c43d89
					
				
					 8 changed files with 179 additions and 7 deletions
				
			
		|  | @ -37,9 +37,11 @@ set(GAMEINPUT_HEADER | ||||||
|     apps/openmw/mwinput/inputmanager.hpp) |     apps/openmw/mwinput/inputmanager.hpp) | ||||||
| source_group(apps\\openmw\\mwinput FILES ${GAMEINPUT} ${GAMEINPUT_HEADER})     | source_group(apps\\openmw\\mwinput FILES ${GAMEINPUT} ${GAMEINPUT_HEADER})     | ||||||
| 
 | 
 | ||||||
| # set(GAMESCRIPT) | set(GAMESCRIPT | ||||||
|  |     apps/openmw/mwscript/scriptmanager.cpp) | ||||||
| set(GAMESCRIPT_HEADER  | 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})     | source_group(apps\\openmw\\mwscript FILES ${GAMESCRIPT} ${GAMESCRIPT_HEADER})     | ||||||
| 
 | 
 | ||||||
| set(APPS ${GAME} ${GAMEREND} ${GAMEINPUT} ${GAMESCRIPT}) | set(APPS ${GAME} ${GAMEREND} ${GAMEINPUT} ${GAMESCRIPT}) | ||||||
|  |  | ||||||
|  | @ -8,6 +8,7 @@ | ||||||
| #include "components/bsa/bsa_archive.hpp" | #include "components/bsa/bsa_archive.hpp" | ||||||
| 
 | 
 | ||||||
| #include "mwinput/inputmanager.hpp" | #include "mwinput/inputmanager.hpp" | ||||||
|  | #include "mwscript/scriptmanager.hpp" | ||||||
| 
 | 
 | ||||||
| #include "world.hpp" | #include "world.hpp" | ||||||
| 
 | 
 | ||||||
|  | @ -24,8 +25,17 @@ protected: | ||||||
|   OMW::Engine* mpEngine; |   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( |     mspCommandServer.reset( | ||||||
|         new OMW::CommandServer::Server(&mCommandQueue, kCommandServerPort)); |         new OMW::CommandServer::Server(&mCommandQueue, kCommandServerPort)); | ||||||
|  | @ -35,6 +45,7 @@ OMW::Engine::~Engine() | ||||||
| { | { | ||||||
| //    mspCommandServer->stop();
 | //    mspCommandServer->stop();
 | ||||||
|     delete mWorld; |     delete mWorld; | ||||||
|  |     delete mScriptManager; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Load all BSA files in data directory.
 | // Load all BSA files in data directory.
 | ||||||
|  | @ -98,6 +109,11 @@ void OMW::Engine::enableDebugMode() | ||||||
|     mDebug = true; |     mDebug = true; | ||||||
| } | } | ||||||
|             |             | ||||||
|  | void OMW::Engine::enableVerboseScripts() | ||||||
|  | { | ||||||
|  |     mVerboseScripts = true; | ||||||
|  | } | ||||||
|  |              | ||||||
| void OMW::Engine::processCommands() | void OMW::Engine::processCommands() | ||||||
| { | { | ||||||
|     Command cmd; |     Command cmd; | ||||||
|  | @ -143,6 +159,10 @@ void OMW::Engine::go() | ||||||
|     // Create the world
 |     // Create the world
 | ||||||
|     mWorld = new World (mOgre, mDataDir, mMaster, mCellName); |     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"; |     std::cout << "Setting up input system\n"; | ||||||
| 
 | 
 | ||||||
|     // Sets up the input system
 |     // Sets up the input system
 | ||||||
|  |  | ||||||
|  | @ -6,11 +6,17 @@ | ||||||
| #include <boost/filesystem.hpp> | #include <boost/filesystem.hpp> | ||||||
| 
 | 
 | ||||||
| #include "components/engine/ogre/renderer.hpp" | #include "components/engine/ogre/renderer.hpp" | ||||||
| #include "apps/openmw/mwrender/mwscene.hpp" |  | ||||||
| #include "components/misc/tsdeque.hpp" | #include "components/misc/tsdeque.hpp" | ||||||
| #include "components/commandserver/server.hpp" | #include "components/commandserver/server.hpp" | ||||||
| #include "components/commandserver/command.hpp" | #include "components/commandserver/command.hpp" | ||||||
| 
 | 
 | ||||||
|  | #include "mwrender/mwscene.hpp" | ||||||
|  | 
 | ||||||
|  | namespace MWScript | ||||||
|  | { | ||||||
|  |     class ScriptManager; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| namespace OMW | namespace OMW | ||||||
| { | { | ||||||
|     class World; |     class World; | ||||||
|  | @ -27,10 +33,13 @@ namespace OMW | ||||||
|             std::string mMaster; |             std::string mMaster; | ||||||
|             World *mWorld; |             World *mWorld; | ||||||
|             bool mDebug; |             bool mDebug; | ||||||
|  |             bool mVerboseScripts; | ||||||
| 
 | 
 | ||||||
|             TsDeque<OMW::Command>                     mCommandQueue; |             TsDeque<OMW::Command>                     mCommandQueue; | ||||||
|             std::auto_ptr<OMW::CommandServer::Server> mspCommandServer; |             std::auto_ptr<OMW::CommandServer::Server> mspCommandServer; | ||||||
| 
 | 
 | ||||||
|  |             MWScript::ScriptManager *mScriptManager; | ||||||
|  | 
 | ||||||
|             // not implemented
 |             // not implemented
 | ||||||
|             Engine (const Engine&); |             Engine (const Engine&); | ||||||
|             Engine& operator= (const Engine&); |             Engine& operator= (const Engine&); | ||||||
|  | @ -42,6 +51,8 @@ namespace OMW | ||||||
|             /// Load all BSA files in data directory.
 |             /// Load all BSA files in data directory.
 | ||||||
|             void loadBSA(); |             void loadBSA(); | ||||||
| 
 | 
 | ||||||
|  |             void executeLocalScripts(); | ||||||
|  | 
 | ||||||
|         public: |         public: | ||||||
| 
 | 
 | ||||||
|             Engine(); |             Engine(); | ||||||
|  | @ -63,6 +74,9 @@ namespace OMW | ||||||
|             /// - non-exclusive input
 |             /// - non-exclusive input
 | ||||||
|             void enableDebugMode(); |             void enableDebugMode(); | ||||||
| 
 | 
 | ||||||
|  |             /// Enable verbose script output
 | ||||||
|  |             void enableVerboseScripts(); | ||||||
|  | 
 | ||||||
|             /// Process pending commands
 |             /// Process pending commands
 | ||||||
|             void processCommands(); |             void processCommands(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -30,6 +30,7 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) | ||||||
|         ("master", bpo::value<std::string>()->default_value ("Morrowind"), |         ("master", bpo::value<std::string>()->default_value ("Morrowind"), | ||||||
|             "master file") |             "master file") | ||||||
|         ( "debug", "debug mode" ) |         ( "debug", "debug mode" ) | ||||||
|  |         ( "script-verbose", "verbose script output" ) | ||||||
|         ; |         ; | ||||||
|    |    | ||||||
|     bpo::variables_map variables; |     bpo::variables_map variables; | ||||||
|  | @ -55,6 +56,9 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) | ||||||
|     if (variables.count ("debug")) |     if (variables.count ("debug")) | ||||||
|         engine.enableDebugMode(); |         engine.enableDebugMode(); | ||||||
|          |          | ||||||
|  |     if (variables.count ("script-verbose")) | ||||||
|  |         engine.enableVerboseScripts(); | ||||||
|  | 
 | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										19
									
								
								apps/openmw/mwscript/scriptmanager.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								apps/openmw/mwscript/scriptmanager.cpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | ||||||
|  | 
 | ||||||
|  | #include "scriptmanager.hpp" | ||||||
|  | 
 | ||||||
|  | #include <iostream> | ||||||
|  | 
 | ||||||
|  | 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; | ||||||
|  |      | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
							
								
								
									
										47
									
								
								apps/openmw/mwscript/scriptmanager.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								apps/openmw/mwscript/scriptmanager.hpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,47 @@ | ||||||
|  | #ifndef GAME_SCRIPT_SCRIPTMANAGER_H | ||||||
|  | #define GAME_SCRIPT_SCRIPTMANAGER_H | ||||||
|  | 
 | ||||||
|  | #include <map> | ||||||
|  | #include <vector> | ||||||
|  | #include <string> | ||||||
|  | 
 | ||||||
|  | #include <components/interpreter/types.hpp> | ||||||
|  | 
 | ||||||
|  | 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<std::string, std::vector<Interpreter::Type_Code> > mScripts; | ||||||
|  |              | ||||||
|  |         public: | ||||||
|  |          | ||||||
|  |             ScriptManager (const ESMS::ESMStore& store, bool verbose); | ||||||
|  |              | ||||||
|  |             void run (const std::string& name/*, Compiler::Context& compilerContext,
 | ||||||
|  |                 Interpreter::Context& interpreterContext, Locals& locals*/); | ||||||
|  |     }; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @ -7,8 +7,50 @@ | ||||||
| #include "apps/openmw/mwrender/sky.hpp" | #include "apps/openmw/mwrender/sky.hpp" | ||||||
| #include "apps/openmw/mwrender/interior.hpp" | #include "apps/openmw/mwrender/interior.hpp" | ||||||
| 
 | 
 | ||||||
|  | namespace | ||||||
|  | { | ||||||
|  |     template<typename T> | ||||||
|  |     void listCellScripts (ESMS::CellRefList<T, OMW::RefData>& cellRefList, | ||||||
|  |         OMW::World::ScriptList& scriptList) | ||||||
|  |     { | ||||||
|  |         for (typename ESMS::CellRefList<T, OMW::RefData>::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<MWScript::Locals *> (0))); | ||||||
|  |              | ||||||
|  |             // TODO local variables
 | ||||||
|  |          | ||||||
|  |          | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| namespace OMW | namespace OMW | ||||||
| { | { | ||||||
|  |     void World::insertInteriorScripts (ESMS::CellStore<OMW::RefData>& 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, |     World::World (Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir, | ||||||
|         const std::string& master, const std::string& startCell) |         const std::string& master, const std::string& startCell) | ||||||
|     : mSkyManager (0), mScene (renderer), mPlayerPos (mScene.getCamera()) |     : mSkyManager (0), mScene (renderer), mPlayerPos (mScene.getCamera()) | ||||||
|  | @ -24,6 +66,8 @@ namespace OMW | ||||||
|          |          | ||||||
|         mInteriors[startCell].loadInt (startCell, mStore, mEsm); |         mInteriors[startCell].loadInt (startCell, mStore, mEsm); | ||||||
|          |          | ||||||
|  |         insertInteriorScripts (mInteriors[startCell]); | ||||||
|  |          | ||||||
|         std::cout << "\nSetting up cell rendering\n"; |         std::cout << "\nSetting up cell rendering\n"; | ||||||
| 
 | 
 | ||||||
|         // This connects the cell data with the rendering scene.
 |         // This connects the cell data with the rendering scene.
 | ||||||
|  | @ -58,4 +102,14 @@ namespace OMW | ||||||
|     { |     { | ||||||
|         return mPlayerPos; |         return mPlayerPos; | ||||||
|     } |     } | ||||||
|  |      | ||||||
|  |     ESMS::ESMStore& World::getStore() | ||||||
|  |     { | ||||||
|  |         return mStore; | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     const World::ScriptList& World::getLocalScripts() const | ||||||
|  |     { | ||||||
|  |         return mLocalScripts; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -11,7 +11,7 @@ | ||||||
| #include "apps/openmw/mwrender/playerpos.hpp" | #include "apps/openmw/mwrender/playerpos.hpp" | ||||||
| #include "apps/openmw/mwrender/mwscene.hpp" | #include "apps/openmw/mwrender/mwscene.hpp" | ||||||
| 
 | 
 | ||||||
| #include "apps/openmw/refdata.hpp" | #include "refdata.hpp" | ||||||
| 
 | 
 | ||||||
| namespace Render | namespace Render | ||||||
| { | { | ||||||
|  | @ -30,6 +30,12 @@ namespace OMW | ||||||
|      |      | ||||||
|     class World |     class World | ||||||
|     { |     { | ||||||
|  |         public: | ||||||
|  |          | ||||||
|  |             typedef std::vector<std::pair<std::string, MWScript::Locals *> > ScriptList; | ||||||
|  |          | ||||||
|  |         private: | ||||||
|  |          | ||||||
|             typedef ESMS::CellStore<RefData> CellStore; |             typedef ESMS::CellStore<RefData> CellStore; | ||||||
|             typedef std::map<CellStore *, MWRender::CellRender *> CellRenderCollection; |             typedef std::map<CellStore *, MWRender::CellRender *> CellRenderCollection; | ||||||
|      |      | ||||||
|  | @ -41,11 +47,14 @@ namespace OMW | ||||||
|             ESM::ESMReader mEsm; |             ESM::ESMReader mEsm; | ||||||
|             ESMS::ESMStore mStore; |             ESMS::ESMStore mStore; | ||||||
|             std::map<std::string, CellStore> mInteriors; |             std::map<std::string, CellStore> mInteriors; | ||||||
|  |             ScriptList mLocalScripts; | ||||||
|      |      | ||||||
|             // not implemented
 |             // not implemented
 | ||||||
|             World (const World&); |             World (const World&); | ||||||
|             World& operator= (const World&); |             World& operator= (const World&); | ||||||
|      |      | ||||||
|  |             void insertInteriorScripts (ESMS::CellStore<OMW::RefData>& cell); | ||||||
|  |      | ||||||
|         public: |         public: | ||||||
|          |          | ||||||
|             World (Render::OgreRenderer& renderer, const boost::filesystem::path& master, |             World (Render::OgreRenderer& renderer, const boost::filesystem::path& master, | ||||||
|  | @ -55,7 +64,10 @@ namespace OMW | ||||||
|              |              | ||||||
|             MWRender::PlayerPos& getPlayerPos(); |             MWRender::PlayerPos& getPlayerPos(); | ||||||
|              |              | ||||||
|  |             ESMS::ESMStore& getStore(); | ||||||
|              |              | ||||||
|  |             const ScriptList& getLocalScripts() const; | ||||||
|  |             ///< Names and local variable state of all local scripts in active cells.
 | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue