2010-07-02 16:18:25 +02:00
|
|
|
#ifndef GAME_SCRIPT_SCRIPTMANAGER_H
|
|
|
|
#define GAME_SCRIPT_SCRIPTMANAGER_H
|
|
|
|
|
|
|
|
#include <map>
|
2021-02-14 16:25:38 +01:00
|
|
|
#include <set>
|
2010-07-02 16:18:25 +02:00
|
|
|
#include <string>
|
|
|
|
|
2010-07-02 17:21:27 +02:00
|
|
|
#include <components/compiler/streamerrorhandler.hpp>
|
|
|
|
#include <components/compiler/fileparser.hpp>
|
|
|
|
|
2011-05-18 16:01:19 +02:00
|
|
|
#include <components/interpreter/interpreter.hpp>
|
2010-07-02 16:18:25 +02:00
|
|
|
#include <components/interpreter/types.hpp>
|
|
|
|
|
2012-08-08 15:18:55 +02:00
|
|
|
#include "../mwbase/scriptmanager.hpp"
|
|
|
|
|
2012-04-23 11:15:47 +02:00
|
|
|
#include "globalscripts.hpp"
|
|
|
|
|
2012-10-01 19:17:04 +04:00
|
|
|
namespace MWWorld
|
2010-07-02 16:18:25 +02:00
|
|
|
{
|
2015-03-06 21:36:42 +13:00
|
|
|
class ESMStore;
|
2010-07-02 16:18:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Compiler
|
|
|
|
{
|
|
|
|
class Context;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Interpreter
|
|
|
|
{
|
|
|
|
class Context;
|
2010-07-03 12:12:13 +02:00
|
|
|
class Interpreter;
|
2010-07-02 16:18:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWScript
|
2010-10-06 14:52:53 +02:00
|
|
|
{
|
2012-08-08 15:18:55 +02:00
|
|
|
class ScriptManager : public MWBase::ScriptManager
|
2010-07-02 16:18:25 +02:00
|
|
|
{
|
2010-07-02 17:21:27 +02:00
|
|
|
Compiler::StreamErrorHandler mErrorHandler;
|
2012-10-01 19:17:04 +04:00
|
|
|
const MWWorld::ESMStore& mStore;
|
2010-07-02 17:21:27 +02:00
|
|
|
Compiler::Context& mCompilerContext;
|
|
|
|
Compiler::FileParser mParser;
|
2011-05-18 16:01:19 +02:00
|
|
|
Interpreter::Interpreter mInterpreter;
|
|
|
|
bool mOpcodesInstalled;
|
2010-10-06 14:52:53 +02:00
|
|
|
|
2020-07-14 10:53:01 +04:00
|
|
|
struct CompiledScript
|
|
|
|
{
|
|
|
|
std::vector<Interpreter::Type_Code> mByteCode;
|
|
|
|
Compiler::Locals mLocals;
|
2021-02-14 16:25:38 +01:00
|
|
|
std::set<std::string> mInactive;
|
2020-07-14 10:53:01 +04:00
|
|
|
|
2021-06-23 23:36:43 +02:00
|
|
|
CompiledScript(const std::vector<Interpreter::Type_Code>& code, const Compiler::Locals& locals):
|
|
|
|
mByteCode(code), mLocals(locals)
|
|
|
|
{}
|
2020-07-14 10:53:01 +04:00
|
|
|
};
|
|
|
|
|
2012-03-05 16:56:14 +01:00
|
|
|
typedef std::map<std::string, CompiledScript> ScriptCollection;
|
|
|
|
|
|
|
|
ScriptCollection mScripts;
|
2012-04-23 11:15:47 +02:00
|
|
|
GlobalScripts mGlobalScripts;
|
2013-02-23 14:40:56 +01:00
|
|
|
std::map<std::string, Compiler::Locals> mOtherLocals;
|
2014-07-21 09:34:10 +02:00
|
|
|
std::vector<std::string> mScriptBlacklist;
|
2010-10-06 14:52:53 +02:00
|
|
|
|
2010-07-02 16:18:25 +02:00
|
|
|
public:
|
2010-10-06 14:52:53 +02:00
|
|
|
|
2017-02-20 21:09:15 +01:00
|
|
|
ScriptManager (const MWWorld::ESMStore& store,
|
2014-07-21 09:34:10 +02:00
|
|
|
Compiler::Context& compilerContext, int warningsMode,
|
|
|
|
const std::vector<std::string>& scriptBlacklist);
|
2010-10-06 14:52:53 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void clear() override;
|
2020-07-14 10:53:01 +04:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
bool run (const std::string& name, Interpreter::Context& interpreterContext) override;
|
2010-10-06 14:52:53 +02:00
|
|
|
///< Run the script with the given name (compile first, if not compiled yet)
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
bool compile (const std::string& name) override;
|
2010-10-06 14:52:53 +02:00
|
|
|
///< Compile script with the given namen
|
|
|
|
/// \return Success?
|
2011-10-09 12:05:13 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
std::pair<int, int> compileAll() override;
|
2011-10-09 12:05:13 +02:00
|
|
|
///< Compile all scripts
|
|
|
|
/// \return count, success
|
2012-03-05 16:56:14 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
const Compiler::Locals& getLocals (const std::string& name) override;
|
2012-03-05 16:56:14 +01:00
|
|
|
///< Return locals for script \a name.
|
2012-04-23 11:15:47 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
GlobalScripts& getGlobalScripts() override;
|
2021-07-07 18:48:25 +02:00
|
|
|
|
|
|
|
const Compiler::Extensions& getExtensions() const override;
|
2010-07-02 16:18:25 +02:00
|
|
|
};
|
2012-10-09 17:10:25 +02:00
|
|
|
}
|
2010-07-02 16:18:25 +02:00
|
|
|
|
|
|
|
#endif
|