1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 09:53:54 +00:00

Issue 255: moved global scripts into script manager (simplifying the environment class)

This commit is contained in:
Marc Zinnschlag 2012-04-23 11:15:47 +02:00
parent 2bfd90f3f9
commit 7102a825c2
7 changed files with 19 additions and 32 deletions

View file

@ -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;
@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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

View file

@ -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;
}
}

View file

@ -11,6 +11,8 @@
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/types.hpp>
#include "globalscripts.hpp"
namespace ESMS
{
struct ESMStore;
@ -42,8 +44,8 @@ namespace MWScript
typedef std::pair<std::vector<Interpreter::Type_Code>, Compiler::Locals> CompiledScript;
typedef std::map<std::string, CompiledScript> 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();
};
};

View file

@ -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;