mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-09 22:13:31 +00:00
Issue #107: ScriptManager is accessed only through the interface class from now on
This commit is contained in:
parent
9b567e4ba6
commit
28ecfb4290
@ -36,7 +36,7 @@ add_openmw_dir (mwdialogue
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwscript
|
add_openmw_dir (mwscript
|
||||||
locals scriptmanager compilercontext interpretercontext cellextensions miscextensions
|
locals scriptmanagerimp compilercontext interpretercontext cellextensions miscextensions
|
||||||
guiextensions soundextensions skyextensions statsextensions containerextensions
|
guiextensions soundextensions skyextensions statsextensions containerextensions
|
||||||
aiextensions controlextensions extensions globalscripts ref dialogueextensions
|
aiextensions controlextensions extensions globalscripts ref dialogueextensions
|
||||||
animationextensions transformationextensions consoleextensions userextensions
|
animationextensions transformationextensions consoleextensions userextensions
|
||||||
@ -64,7 +64,7 @@ add_openmw_dir (mwmechanics
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwbase
|
add_openmw_dir (mwbase
|
||||||
environment world
|
environment world scriptmanager
|
||||||
)
|
)
|
||||||
|
|
||||||
# Main executable
|
# Main executable
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#include "mwgui/window_manager.hpp"
|
#include "mwgui/window_manager.hpp"
|
||||||
#include "mwgui/cursorreplace.hpp"
|
#include "mwgui/cursorreplace.hpp"
|
||||||
|
|
||||||
#include "mwscript/scriptmanager.hpp"
|
#include "mwscript/scriptmanagerimp.hpp"
|
||||||
#include "mwscript/extensions.hpp"
|
#include "mwscript/extensions.hpp"
|
||||||
|
|
||||||
#include "mwsound/soundmanager.hpp"
|
#include "mwsound/soundmanager.hpp"
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
#include "../mwinput/inputmanager.hpp"
|
#include "../mwinput/inputmanager.hpp"
|
||||||
|
|
||||||
#include "../mwscript/scriptmanager.hpp"
|
|
||||||
|
|
||||||
#include "../mwsound/soundmanager.hpp"
|
#include "../mwsound/soundmanager.hpp"
|
||||||
|
|
||||||
#include "../mwdialogue/dialoguemanager.hpp"
|
#include "../mwdialogue/dialoguemanager.hpp"
|
||||||
@ -15,6 +13,7 @@
|
|||||||
#include "../mwmechanics/mechanicsmanager.hpp"
|
#include "../mwmechanics/mechanicsmanager.hpp"
|
||||||
|
|
||||||
#include "world.hpp"
|
#include "world.hpp"
|
||||||
|
#include "scriptmanager.hpp"
|
||||||
|
|
||||||
MWBase::Environment *MWBase::Environment::sThis = 0;
|
MWBase::Environment *MWBase::Environment::sThis = 0;
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ void MWBase::Environment::setSoundManager (MWSound::SoundManager *soundManager)
|
|||||||
mSoundManager = soundManager;
|
mSoundManager = soundManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWBase::Environment::setScriptManager (MWScript::ScriptManager *scriptManager)
|
void MWBase::Environment::setScriptManager (ScriptManager *scriptManager)
|
||||||
{
|
{
|
||||||
mScriptManager = scriptManager;
|
mScriptManager = scriptManager;
|
||||||
}
|
}
|
||||||
@ -89,7 +88,7 @@ MWSound::SoundManager *MWBase::Environment::getSoundManager() const
|
|||||||
return mSoundManager;
|
return mSoundManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
MWScript::ScriptManager *MWBase::Environment::getScriptManager() const
|
MWBase::ScriptManager *MWBase::Environment::getScriptManager() const
|
||||||
{
|
{
|
||||||
assert (mScriptManager);
|
assert (mScriptManager);
|
||||||
return mScriptManager;
|
return mScriptManager;
|
||||||
|
@ -6,11 +6,6 @@ namespace MWSound
|
|||||||
class SoundManager;
|
class SoundManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWScript
|
|
||||||
{
|
|
||||||
class ScriptManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
{
|
{
|
||||||
class WindowManager;
|
class WindowManager;
|
||||||
@ -35,6 +30,7 @@ namespace MWInput
|
|||||||
namespace MWBase
|
namespace MWBase
|
||||||
{
|
{
|
||||||
class World;
|
class World;
|
||||||
|
class ScriptManager;
|
||||||
|
|
||||||
/// \brief Central hub for mw-subsystems
|
/// \brief Central hub for mw-subsystems
|
||||||
///
|
///
|
||||||
@ -48,7 +44,7 @@ namespace MWBase
|
|||||||
|
|
||||||
World *mWorld;
|
World *mWorld;
|
||||||
MWSound::SoundManager *mSoundManager;
|
MWSound::SoundManager *mSoundManager;
|
||||||
MWScript::ScriptManager *mScriptManager;
|
ScriptManager *mScriptManager;
|
||||||
MWGui::WindowManager *mWindowManager;
|
MWGui::WindowManager *mWindowManager;
|
||||||
MWMechanics::MechanicsManager *mMechanicsManager;
|
MWMechanics::MechanicsManager *mMechanicsManager;
|
||||||
MWDialogue::DialogueManager *mDialogueManager;
|
MWDialogue::DialogueManager *mDialogueManager;
|
||||||
@ -72,7 +68,7 @@ namespace MWBase
|
|||||||
|
|
||||||
void setSoundManager (MWSound::SoundManager *soundManager);
|
void setSoundManager (MWSound::SoundManager *soundManager);
|
||||||
|
|
||||||
void setScriptManager (MWScript::ScriptManager *scriptManager);
|
void setScriptManager (MWBase::ScriptManager *scriptManager);
|
||||||
|
|
||||||
void setWindowManager (MWGui::WindowManager *windowManager);
|
void setWindowManager (MWGui::WindowManager *windowManager);
|
||||||
|
|
||||||
@ -91,7 +87,7 @@ namespace MWBase
|
|||||||
|
|
||||||
MWSound::SoundManager *getSoundManager() const;
|
MWSound::SoundManager *getSoundManager() const;
|
||||||
|
|
||||||
MWScript::ScriptManager *getScriptManager() const;
|
MWBase::ScriptManager *getScriptManager() const;
|
||||||
|
|
||||||
MWGui::WindowManager *getWindowManager() const;
|
MWGui::WindowManager *getWindowManager() const;
|
||||||
|
|
||||||
|
62
apps/openmw/mwbase/scriptmanager.hpp
Normal file
62
apps/openmw/mwbase/scriptmanager.hpp
Normal file
@ -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/environment.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
#include "../mwbase/scriptmanager.hpp"
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "../mwworld/refdata.hpp"
|
#include "../mwworld/refdata.hpp"
|
||||||
@ -26,7 +27,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "../mwscript/extensions.hpp"
|
#include "../mwscript/extensions.hpp"
|
||||||
#include "../mwscript/scriptmanager.hpp"
|
|
||||||
|
|
||||||
#include <components/compiler/exception.hpp>
|
#include <components/compiler/exception.hpp>
|
||||||
#include <components/compiler/errorhandler.hpp>
|
#include <components/compiler/errorhandler.hpp>
|
||||||
|
@ -3,14 +3,15 @@
|
|||||||
|
|
||||||
#include <components/esm_store/store.hpp>
|
#include <components/esm_store/store.hpp>
|
||||||
|
|
||||||
|
#include <components/compiler/locals.hpp>
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
#include "../mwbase/scriptmanager.hpp"
|
||||||
|
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
|
||||||
#include "scriptmanager.hpp"
|
|
||||||
|
|
||||||
namespace MWScript
|
namespace MWScript
|
||||||
{
|
{
|
||||||
CompilerContext::CompilerContext (Type type)
|
CompilerContext::CompilerContext (Type type)
|
||||||
|
@ -6,13 +6,15 @@
|
|||||||
#include <components/esm_store/reclists.hpp>
|
#include <components/esm_store/reclists.hpp>
|
||||||
#include <components/esm_store/store.hpp>
|
#include <components/esm_store/store.hpp>
|
||||||
|
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/scriptmanager.hpp"
|
||||||
|
|
||||||
#include "interpretercontext.hpp"
|
#include "interpretercontext.hpp"
|
||||||
#include "scriptmanager.hpp"
|
|
||||||
|
|
||||||
namespace MWScript
|
namespace MWScript
|
||||||
{
|
{
|
||||||
GlobalScripts::GlobalScripts (const ESMS::ESMStore& store, ScriptManager& scriptManager)
|
GlobalScripts::GlobalScripts (const ESMS::ESMStore& store)
|
||||||
: mStore (store), mScriptManager (scriptManager)
|
: mStore (store)
|
||||||
{
|
{
|
||||||
addScript ("Main");
|
addScript ("Main");
|
||||||
|
|
||||||
@ -63,9 +65,8 @@ namespace MWScript
|
|||||||
{
|
{
|
||||||
MWScript::InterpreterContext interpreterContext (
|
MWScript::InterpreterContext interpreterContext (
|
||||||
&iter->second.second, MWWorld::Ptr());
|
&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
|
namespace MWScript
|
||||||
{
|
{
|
||||||
class ScriptManager;
|
|
||||||
|
|
||||||
class GlobalScripts
|
class GlobalScripts
|
||||||
{
|
{
|
||||||
const ESMS::ESMStore& mStore;
|
const ESMS::ESMStore& mStore;
|
||||||
ScriptManager& mScriptManager;
|
|
||||||
std::map<std::string, std::pair<bool, Locals> > mScripts; // running, local variables
|
std::map<std::string, std::pair<bool, Locals> > mScripts; // running, local variables
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GlobalScripts (const ESMS::ESMStore& store, ScriptManager& scriptManager);
|
GlobalScripts (const ESMS::ESMStore& store);
|
||||||
|
|
||||||
void addScript (const std::string& name);
|
void addScript (const std::string& name);
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
#include "../mwbase/scriptmanager.hpp"
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "../mwworld/player.hpp"
|
#include "../mwworld/player.hpp"
|
||||||
@ -18,7 +19,6 @@
|
|||||||
|
|
||||||
#include "locals.hpp"
|
#include "locals.hpp"
|
||||||
#include "globalscripts.hpp"
|
#include "globalscripts.hpp"
|
||||||
#include "scriptmanager.hpp"
|
|
||||||
|
|
||||||
namespace MWScript
|
namespace MWScript
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#include "scriptmanager.hpp"
|
#include "scriptmanagerimp.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -21,7 +21,7 @@ namespace MWScript
|
|||||||
Compiler::Context& compilerContext)
|
Compiler::Context& compilerContext)
|
||||||
: mErrorHandler (std::cerr), mStore (store), mVerbose (verbose),
|
: mErrorHandler (std::cerr), mStore (store), mVerbose (verbose),
|
||||||
mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext),
|
mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext),
|
||||||
mOpcodesInstalled (false), mGlobalScripts (store, *this)
|
mOpcodesInstalled (false), mGlobalScripts (store)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool ScriptManager::compile (const std::string& name)
|
bool ScriptManager::compile (const std::string& name)
|
@ -10,6 +10,8 @@
|
|||||||
#include <components/interpreter/interpreter.hpp>
|
#include <components/interpreter/interpreter.hpp>
|
||||||
#include <components/interpreter/types.hpp>
|
#include <components/interpreter/types.hpp>
|
||||||
|
|
||||||
|
#include "../mwbase/scriptmanager.hpp"
|
||||||
|
|
||||||
#include "globalscripts.hpp"
|
#include "globalscripts.hpp"
|
||||||
|
|
||||||
namespace ESMS
|
namespace ESMS
|
||||||
@ -30,7 +32,7 @@ namespace Interpreter
|
|||||||
|
|
||||||
namespace MWScript
|
namespace MWScript
|
||||||
{
|
{
|
||||||
class ScriptManager
|
class ScriptManager : public MWBase::ScriptManager
|
||||||
{
|
{
|
||||||
Compiler::StreamErrorHandler mErrorHandler;
|
Compiler::StreamErrorHandler mErrorHandler;
|
||||||
const ESMS::ESMStore& mStore;
|
const ESMS::ESMStore& mStore;
|
||||||
@ -51,23 +53,24 @@ namespace MWScript
|
|||||||
ScriptManager (const ESMS::ESMStore& store, bool verbose,
|
ScriptManager (const ESMS::ESMStore& store, bool verbose,
|
||||||
Compiler::Context& compilerContext);
|
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)
|
///< 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
|
///< Compile script with the given namen
|
||||||
/// \return Success?
|
/// \return Success?
|
||||||
|
|
||||||
std::pair<int, int> compileAll();
|
virtual std::pair<int, int> compileAll();
|
||||||
///< Compile all scripts
|
///< Compile all scripts
|
||||||
/// \return count, success
|
/// \return count, success
|
||||||
|
|
||||||
Compiler::Locals& getLocals (const std::string& name);
|
virtual Compiler::Locals& getLocals (const std::string& name);
|
||||||
///< Return locals for script \a 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
|
///< 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.
|
/// throw an exception, if there is no such script or variable or the type does not match.
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user