Issue #107: ScriptManager is accessed only through the interface class from now on

actorid
Marc Zinnschlag 13 years ago
parent 9b567e4ba6
commit 28ecfb4290

@ -36,7 +36,7 @@ add_openmw_dir (mwdialogue
)
add_openmw_dir (mwscript
locals scriptmanager compilercontext interpretercontext cellextensions miscextensions
locals scriptmanagerimp compilercontext interpretercontext cellextensions miscextensions
guiextensions soundextensions skyextensions statsextensions containerextensions
aiextensions controlextensions extensions globalscripts ref dialogueextensions
animationextensions transformationextensions consoleextensions userextensions
@ -64,7 +64,7 @@ add_openmw_dir (mwmechanics
)
add_openmw_dir (mwbase
environment world
environment world scriptmanager
)
# Main executable

@ -18,7 +18,7 @@
#include "mwgui/window_manager.hpp"
#include "mwgui/cursorreplace.hpp"
#include "mwscript/scriptmanager.hpp"
#include "mwscript/scriptmanagerimp.hpp"
#include "mwscript/extensions.hpp"
#include "mwsound/soundmanager.hpp"

@ -5,8 +5,6 @@
#include "../mwinput/inputmanager.hpp"
#include "../mwscript/scriptmanager.hpp"
#include "../mwsound/soundmanager.hpp"
#include "../mwdialogue/dialoguemanager.hpp"
@ -15,6 +13,7 @@
#include "../mwmechanics/mechanicsmanager.hpp"
#include "world.hpp"
#include "scriptmanager.hpp"
MWBase::Environment *MWBase::Environment::sThis = 0;
@ -42,7 +41,7 @@ void MWBase::Environment::setSoundManager (MWSound::SoundManager *soundManager)
mSoundManager = soundManager;
}
void MWBase::Environment::setScriptManager (MWScript::ScriptManager *scriptManager)
void MWBase::Environment::setScriptManager (ScriptManager *scriptManager)
{
mScriptManager = scriptManager;
}
@ -89,7 +88,7 @@ MWSound::SoundManager *MWBase::Environment::getSoundManager() const
return mSoundManager;
}
MWScript::ScriptManager *MWBase::Environment::getScriptManager() const
MWBase::ScriptManager *MWBase::Environment::getScriptManager() const
{
assert (mScriptManager);
return mScriptManager;

@ -6,11 +6,6 @@ namespace MWSound
class SoundManager;
}
namespace MWScript
{
class ScriptManager;
}
namespace MWGui
{
class WindowManager;
@ -35,6 +30,7 @@ namespace MWInput
namespace MWBase
{
class World;
class ScriptManager;
/// \brief Central hub for mw-subsystems
///
@ -48,7 +44,7 @@ namespace MWBase
World *mWorld;
MWSound::SoundManager *mSoundManager;
MWScript::ScriptManager *mScriptManager;
ScriptManager *mScriptManager;
MWGui::WindowManager *mWindowManager;
MWMechanics::MechanicsManager *mMechanicsManager;
MWDialogue::DialogueManager *mDialogueManager;
@ -72,7 +68,7 @@ namespace MWBase
void setSoundManager (MWSound::SoundManager *soundManager);
void setScriptManager (MWScript::ScriptManager *scriptManager);
void setScriptManager (MWBase::ScriptManager *scriptManager);
void setWindowManager (MWGui::WindowManager *windowManager);
@ -91,7 +87,7 @@ namespace MWBase
MWSound::SoundManager *getSoundManager() const;
MWScript::ScriptManager *getScriptManager() const;
MWBase::ScriptManager *getScriptManager() const;
MWGui::WindowManager *getWindowManager() const;

@ -0,0 +1,62 @@
#ifndef GAME_MWBASE_SCRIPTMANAGERIMP_H
#define GAME_MWBASE_SCRIPTMANAGERIMP_H
#include <string>
namespace Interpreter
{
class Context;
}
namespace Compiler
{
class Locals;
}
namespace MWScript
{
class GlobalScripts;
}
namespace MWBase
{
/// \brief Interface for script manager (implemented in MWScript)
class ScriptManager
{
ScriptManager (const ScriptManager&);
///< not implemented
ScriptManager& operator= (const ScriptManager&);
///< not implemented
public:
ScriptManager() {}
virtual ~ScriptManager() {}
virtual void run (const std::string& name, Interpreter::Context& interpreterContext) = 0;
///< Run the script with the given name (compile first, if not compiled yet)
virtual bool compile (const std::string& name) = 0;
///< Compile script with the given namen
/// \return Success?
virtual std::pair<int, int> compileAll() = 0;
///< Compile all scripts
/// \return count, success
virtual Compiler::Locals& getLocals (const std::string& name) = 0;
///< Return locals for script \a name.
virtual MWScript::GlobalScripts& getGlobalScripts() = 0;
virtual int getLocalIndex (const std::string& scriptId, const std::string& variable,
char type) = 0;
///< Return index of the variable of the given name and type in the given script. Will
/// throw an exception, if there is no such script or variable or the type does not match.
};
}
#endif

@ -11,6 +11,7 @@
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/scriptmanager.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/refdata.hpp"
@ -26,7 +27,6 @@
#include <iostream>
#include "../mwscript/extensions.hpp"
#include "../mwscript/scriptmanager.hpp"
#include <components/compiler/exception.hpp>
#include <components/compiler/errorhandler.hpp>

@ -3,14 +3,15 @@
#include <components/esm_store/store.hpp>
#include <components/compiler/locals.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/scriptmanager.hpp"
#include "../mwworld/ptr.hpp"
#include "../mwworld/class.hpp"
#include "scriptmanager.hpp"
namespace MWScript
{
CompilerContext::CompilerContext (Type type)

@ -6,13 +6,15 @@
#include <components/esm_store/reclists.hpp>
#include <components/esm_store/store.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/scriptmanager.hpp"
#include "interpretercontext.hpp"
#include "scriptmanager.hpp"
namespace MWScript
{
GlobalScripts::GlobalScripts (const ESMS::ESMStore& store, ScriptManager& scriptManager)
: mStore (store), mScriptManager (scriptManager)
GlobalScripts::GlobalScripts (const ESMS::ESMStore& store)
: mStore (store)
{
addScript ("Main");
@ -63,9 +65,8 @@ namespace MWScript
{
MWScript::InterpreterContext interpreterContext (
&iter->second.second, MWWorld::Ptr());
mScriptManager.run (iter->first, interpreterContext);
MWBase::Environment::get().getScriptManager()->run (iter->first, interpreterContext);
}
}
}
}

@ -13,17 +13,14 @@ namespace ESMS
namespace MWScript
{
class ScriptManager;
class GlobalScripts
{
const ESMS::ESMStore& mStore;
ScriptManager& mScriptManager;
std::map<std::string, std::pair<bool, Locals> > mScripts; // running, local variables
public:
GlobalScripts (const ESMS::ESMStore& store, ScriptManager& scriptManager);
GlobalScripts (const ESMS::ESMStore& store);
void addScript (const std::string& name);

@ -8,6 +8,7 @@
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/scriptmanager.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/player.hpp"
@ -18,7 +19,6 @@
#include "locals.hpp"
#include "globalscripts.hpp"
#include "scriptmanager.hpp"
namespace MWScript
{

@ -1,5 +1,5 @@
#include "scriptmanager.hpp"
#include "scriptmanagerimp.hpp"
#include <cassert>
#include <iostream>
@ -21,7 +21,7 @@ namespace MWScript
Compiler::Context& compilerContext)
: mErrorHandler (std::cerr), mStore (store), mVerbose (verbose),
mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext),
mOpcodesInstalled (false), mGlobalScripts (store, *this)
mOpcodesInstalled (false), mGlobalScripts (store)
{}
bool ScriptManager::compile (const std::string& name)

@ -10,6 +10,8 @@
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/types.hpp>
#include "../mwbase/scriptmanager.hpp"
#include "globalscripts.hpp"
namespace ESMS
@ -30,7 +32,7 @@ namespace Interpreter
namespace MWScript
{
class ScriptManager
class ScriptManager : public MWBase::ScriptManager
{
Compiler::StreamErrorHandler mErrorHandler;
const ESMS::ESMStore& mStore;
@ -51,23 +53,24 @@ namespace MWScript
ScriptManager (const ESMS::ESMStore& store, bool verbose,
Compiler::Context& compilerContext);
void run (const std::string& name, Interpreter::Context& interpreterContext);
virtual 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);
virtual bool compile (const std::string& name);
///< Compile script with the given namen
/// \return Success?
std::pair<int, int> compileAll();
virtual std::pair<int, int> compileAll();
///< Compile all scripts
/// \return count, success
Compiler::Locals& getLocals (const std::string& name);
virtual Compiler::Locals& getLocals (const std::string& name);
///< Return locals for script \a name.
GlobalScripts& getGlobalScripts();
virtual GlobalScripts& getGlobalScripts();
int getLocalIndex (const std::string& scriptId, const std::string& variable, char type);
virtual int getLocalIndex (const std::string& scriptId, const std::string& variable,
char type);
///< Return index of the variable of the given name and type in the given script. Will
/// throw an exception, if there is no such script or variable or the type does not match.
};
Loading…
Cancel
Save