From 7102a825c265ac8d6d43152ccb963731859a7709 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 23 Apr 2012 11:15:47 +0200 Subject: [PATCH] Issue 255: moved global scripts into script manager (simplifying the environment class) --- apps/openmw/engine.cpp | 8 ++------ apps/openmw/mwbase/environment.cpp | 13 +------------ apps/openmw/mwbase/environment.hpp | 6 ------ apps/openmw/mwscript/interpretercontext.cpp | 7 ++++--- apps/openmw/mwscript/scriptmanager.cpp | 7 ++++++- apps/openmw/mwscript/scriptmanager.hpp | 6 +++++- apps/openmw/mwworld/environment.hpp | 4 +--- 7 files changed, 19 insertions(+), 32 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 2d3c872dd7..ef1497905e 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -142,7 +142,7 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration); // global scripts - mEnvironment.mGlobalScripts->run (mEnvironment); + mEnvironment.mScriptManager->getGlobalScripts().run (mEnvironment); bool changed = mEnvironment.mWorld->hasCellChanged(); @@ -205,7 +205,6 @@ OMW::Engine::~Engine() { delete mEnvironment.mWorld; delete mEnvironment.mSoundManager; - delete mEnvironment.mGlobalScripts; delete mEnvironment.mMechanicsManager; delete mEnvironment.mDialogueManager; delete mEnvironment.mJournal; @@ -219,7 +218,7 @@ OMW::Engine::~Engine() void OMW::Engine::loadBSA() { const Files::MultiDirCollection& bsa = mFileCollections.getCollection (".bsa"); - + for (Files::MultiDirCollection::TIter iter(bsa.begin()); iter!=bsa.end(); ++iter) { std::cout << "Adding " << iter->second.string() << std::endl; @@ -402,9 +401,6 @@ void OMW::Engine::go() mEnvironment.mScriptManager = new MWScript::ScriptManager (mEnvironment.mWorld->getStore(), mVerboseScripts, *mScriptContext); - mEnvironment.mGlobalScripts = new MWScript::GlobalScripts (mEnvironment.mWorld->getStore(), - *mEnvironment.mScriptManager); - // Create game mechanics system mEnvironment.mMechanicsManager = new MWMechanics::MechanicsManager (mEnvironment); diff --git a/apps/openmw/mwbase/environment.cpp b/apps/openmw/mwbase/environment.cpp index 43e726e7c8..0845051711 100644 --- a/apps/openmw/mwbase/environment.cpp +++ b/apps/openmw/mwbase/environment.cpp @@ -6,7 +6,7 @@ MWBase::Environment *MWBase::Environment::sThis = 0; MWBase::Environment::Environment() -: mWorld (0), mSoundManager (0), mGlobalScripts (0), mScriptManager (0), mWindowManager (0), +: mWorld (0), mSoundManager (0), mScriptManager (0), mWindowManager (0), mMechanicsManager (0), mDialogueManager (0), mJournal (0), mFrameDuration (0) { assert (!sThis); @@ -28,11 +28,6 @@ void MWBase::Environment::setSoundManager (MWSound::SoundManager *soundManager) mSoundManager = soundManager; } -void MWBase::Environment::setGlobalScripts (MWScript::GlobalScripts *globalScripts) -{ - mGlobalScripts = globalScripts; -} - void MWBase::Environment::setScriptManager (MWScript::ScriptManager *scriptManager) { mScriptManager = scriptManager; @@ -75,12 +70,6 @@ MWSound::SoundManager *MWBase::Environment::getSoundManager() const return mSoundManager; } -MWScript::GlobalScripts *MWBase::Environment::getGlobalScripts() const -{ - assert (mGlobalScripts); - return mGlobalScripts; -} - MWScript::ScriptManager *MWBase::Environment::getScriptManager() const { assert (mScriptManager); diff --git a/apps/openmw/mwbase/environment.hpp b/apps/openmw/mwbase/environment.hpp index 9fca704350..1b1ace0c73 100644 --- a/apps/openmw/mwbase/environment.hpp +++ b/apps/openmw/mwbase/environment.hpp @@ -8,7 +8,6 @@ namespace MWSound namespace MWScript { - class GlobalScripts; class ScriptManager; } @@ -52,7 +51,6 @@ namespace MWBase MWWorld::World *mWorld; MWSound::SoundManager *mSoundManager; - MWScript::GlobalScripts *mGlobalScripts; MWScript::ScriptManager *mScriptManager; MWGui::WindowManager *mWindowManager; MWMechanics::MechanicsManager *mMechanicsManager; @@ -76,8 +74,6 @@ namespace MWBase void setSoundManager (MWSound::SoundManager *soundManager); - void setGlobalScripts (MWScript::GlobalScripts *globalScripts); - void setScriptManager (MWScript::ScriptManager *scriptManager); void setWindowManager (MWGui::WindowManager *windowManager); @@ -95,8 +91,6 @@ namespace MWBase MWSound::SoundManager *getSoundManager() const; - MWScript::GlobalScripts *getGlobalScripts() const; - MWScript::ScriptManager *getScriptManager() const; MWGui::WindowManager *getWindowManager() const; diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 258493782c..acd1d957d6 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -15,6 +15,7 @@ #include "locals.hpp" #include "globalscripts.hpp" +#include "scriptmanager.hpp" namespace MWScript { @@ -174,17 +175,17 @@ namespace MWScript bool InterpreterContext::isScriptRunning (const std::string& name) const { - return mEnvironment.mGlobalScripts->isRunning (name); + return mEnvironment.mScriptManager->getGlobalScripts().isRunning (name); } void InterpreterContext::startScript (const std::string& name) { - mEnvironment.mGlobalScripts->addScript (name); + mEnvironment.mScriptManager->getGlobalScripts().addScript (name); } void InterpreterContext::stopScript (const std::string& name) { - mEnvironment.mGlobalScripts->removeScript (name); + mEnvironment.mScriptManager->getGlobalScripts().removeScript (name); } float InterpreterContext::getDistance (const std::string& name, const std::string& id) const diff --git a/apps/openmw/mwscript/scriptmanager.cpp b/apps/openmw/mwscript/scriptmanager.cpp index e93f2deeca..506cf049c4 100644 --- a/apps/openmw/mwscript/scriptmanager.cpp +++ b/apps/openmw/mwscript/scriptmanager.cpp @@ -20,7 +20,7 @@ namespace MWScript Compiler::Context& compilerContext) : mErrorHandler (std::cerr), mStore (store), mVerbose (verbose), mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext), - mOpcodesInstalled (false) + mOpcodesInstalled (false), mGlobalScripts (store, *this) {} bool ScriptManager::compile (const std::string& name) @@ -151,4 +151,9 @@ namespace MWScript return iter->second.second; } + + GlobalScripts& ScriptManager::getGlobalScripts() + { + return mGlobalScripts; + } } diff --git a/apps/openmw/mwscript/scriptmanager.hpp b/apps/openmw/mwscript/scriptmanager.hpp index 35cbc0d1e8..35c1fadd9e 100644 --- a/apps/openmw/mwscript/scriptmanager.hpp +++ b/apps/openmw/mwscript/scriptmanager.hpp @@ -11,6 +11,8 @@ #include #include +#include "globalscripts.hpp" + namespace ESMS { struct ESMStore; @@ -42,8 +44,8 @@ namespace MWScript typedef std::pair, Compiler::Locals> CompiledScript; typedef std::map ScriptCollection; - ScriptCollection mScripts; + GlobalScripts mGlobalScripts; public: @@ -63,6 +65,8 @@ namespace MWScript Compiler::Locals& getLocals (const std::string& name); ///< Return locals for script \a name. + + GlobalScripts& getGlobalScripts(); }; }; diff --git a/apps/openmw/mwworld/environment.hpp b/apps/openmw/mwworld/environment.hpp index 3a83f886fd..8c4a001e0c 100644 --- a/apps/openmw/mwworld/environment.hpp +++ b/apps/openmw/mwworld/environment.hpp @@ -8,7 +8,6 @@ namespace MWSound namespace MWScript { - class GlobalScripts; class ScriptManager; } @@ -42,14 +41,13 @@ namespace MWWorld { public: Environment() - : mWorld (0), mSoundManager (0), mGlobalScripts (0), mScriptManager (0), mWindowManager (0), + : mWorld (0), mSoundManager (0), mScriptManager (0), mWindowManager (0), mMechanicsManager (0), mDialogueManager (0), mJournal (0), mFrameDuration (0), mInputManager (0) {} World *mWorld; MWSound::SoundManager *mSoundManager; - MWScript::GlobalScripts *mGlobalScripts; MWScript::ScriptManager *mScriptManager; MWGui::WindowManager *mWindowManager; MWMechanics::MechanicsManager *mMechanicsManager;