2010-07-02 14:18:25 +00:00
|
|
|
#ifndef GAME_SCRIPT_SCRIPTMANAGER_H
|
|
|
|
#define GAME_SCRIPT_SCRIPTMANAGER_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2010-07-02 15:21:27 +00:00
|
|
|
#include <components/compiler/streamerrorhandler.hpp>
|
|
|
|
#include <components/compiler/fileparser.hpp>
|
|
|
|
|
2011-05-18 14:01:19 +00:00
|
|
|
#include <components/interpreter/interpreter.hpp>
|
2010-07-02 14:18:25 +00:00
|
|
|
#include <components/interpreter/types.hpp>
|
|
|
|
|
2012-08-08 13:18:55 +00:00
|
|
|
#include "../mwbase/scriptmanager.hpp"
|
|
|
|
|
2012-04-23 09:15:47 +00:00
|
|
|
#include "globalscripts.hpp"
|
|
|
|
|
2012-10-01 15:17:04 +00:00
|
|
|
namespace MWWorld
|
2010-07-02 14:18:25 +00:00
|
|
|
{
|
|
|
|
struct ESMStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Compiler
|
|
|
|
{
|
|
|
|
class Context;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Interpreter
|
|
|
|
{
|
|
|
|
class Context;
|
2010-07-03 10:12:13 +00:00
|
|
|
class Interpreter;
|
2010-07-02 14:18:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWScript
|
2010-10-06 12:52:53 +00:00
|
|
|
{
|
2012-08-08 13:18:55 +00:00
|
|
|
class ScriptManager : public MWBase::ScriptManager
|
2010-07-02 14:18:25 +00:00
|
|
|
{
|
2010-07-02 15:21:27 +00:00
|
|
|
Compiler::StreamErrorHandler mErrorHandler;
|
2012-10-01 15:17:04 +00:00
|
|
|
const MWWorld::ESMStore& mStore;
|
2010-07-02 14:18:25 +00:00
|
|
|
bool mVerbose;
|
2010-07-02 15:21:27 +00:00
|
|
|
Compiler::Context& mCompilerContext;
|
|
|
|
Compiler::FileParser mParser;
|
2011-05-18 14:01:19 +00:00
|
|
|
Interpreter::Interpreter mInterpreter;
|
|
|
|
bool mOpcodesInstalled;
|
2010-10-06 12:52:53 +00:00
|
|
|
|
2012-03-05 15:56:14 +00:00
|
|
|
typedef std::pair<std::vector<Interpreter::Type_Code>, Compiler::Locals> CompiledScript;
|
|
|
|
typedef std::map<std::string, CompiledScript> ScriptCollection;
|
|
|
|
|
|
|
|
ScriptCollection mScripts;
|
2012-04-23 09:15:47 +00:00
|
|
|
GlobalScripts mGlobalScripts;
|
2013-02-23 13:40:56 +00:00
|
|
|
std::map<std::string, Compiler::Locals> mOtherLocals;
|
2010-10-06 12:52:53 +00:00
|
|
|
|
2010-07-02 14:18:25 +00:00
|
|
|
public:
|
2010-10-06 12:52:53 +00:00
|
|
|
|
2012-10-01 15:17:04 +00:00
|
|
|
ScriptManager (const MWWorld::ESMStore& store, bool verbose,
|
2010-07-02 15:21:27 +00:00
|
|
|
Compiler::Context& compilerContext);
|
2010-10-06 12:52:53 +00:00
|
|
|
|
2012-08-08 13:18:55 +00:00
|
|
|
virtual void run (const std::string& name, Interpreter::Context& interpreterContext);
|
2010-10-06 12:52:53 +00:00
|
|
|
///< Run the script with the given name (compile first, if not compiled yet)
|
|
|
|
|
2012-08-08 13:18:55 +00:00
|
|
|
virtual bool compile (const std::string& name);
|
2010-10-06 12:52:53 +00:00
|
|
|
///< Compile script with the given namen
|
|
|
|
/// \return Success?
|
2011-10-09 10:05:13 +00:00
|
|
|
|
2013-05-15 15:54:18 +00:00
|
|
|
virtual void resetGlobalScripts();
|
|
|
|
|
2012-08-08 13:18:55 +00:00
|
|
|
virtual std::pair<int, int> compileAll();
|
2011-10-09 10:05:13 +00:00
|
|
|
///< Compile all scripts
|
|
|
|
/// \return count, success
|
2012-03-05 15:56:14 +00:00
|
|
|
|
2012-08-08 13:18:55 +00:00
|
|
|
virtual Compiler::Locals& getLocals (const std::string& name);
|
2012-03-05 15:56:14 +00:00
|
|
|
///< Return locals for script \a name.
|
2012-04-23 09:15:47 +00:00
|
|
|
|
2012-08-08 13:18:55 +00:00
|
|
|
virtual GlobalScripts& getGlobalScripts();
|
2012-06-07 09:59:45 +00:00
|
|
|
|
2012-08-08 13:18:55 +00:00
|
|
|
virtual int getLocalIndex (const std::string& scriptId, const std::string& variable,
|
|
|
|
char type);
|
2012-06-07 09:59:45 +00:00
|
|
|
///< 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.
|
2010-07-02 14:18:25 +00:00
|
|
|
};
|
2012-10-09 15:10:25 +00:00
|
|
|
}
|
2010-07-02 14:18:25 +00:00
|
|
|
|
|
|
|
#endif
|