1 #ifndef GAME_SCRIPT_SCRIPTMANAGER_H
2 #define GAME_SCRIPT_SCRIPTMANAGER_H
3 
4 #include <map>
5 #include <string>
6 
7 #include <components/compiler/streamerrorhandler.hpp>
8 #include <components/compiler/fileparser.hpp>
9 
10 #include <components/interpreter/interpreter.hpp>
11 #include <components/interpreter/types.hpp>
12 
13 #include "../mwbase/scriptmanager.hpp"
14 
15 #include "globalscripts.hpp"
16 
17 namespace MWWorld
18 {
19     class ESMStore;
20 }
21 
22 namespace Compiler
23 {
24     class Context;
25 }
26 
27 namespace Interpreter
28 {
29     class Context;
30     class Interpreter;
31 }
32 
33 namespace MWScript
34 {
35     class ScriptManager : public MWBase::ScriptManager
36     {
37             Compiler::StreamErrorHandler mErrorHandler;
38             const MWWorld::ESMStore& mStore;
39             Compiler::Context& mCompilerContext;
40             Compiler::FileParser mParser;
41             Interpreter::Interpreter mInterpreter;
42             bool mOpcodesInstalled;
43 
44             struct CompiledScript
45             {
46                 std::vector<Interpreter::Type_Code> mByteCode;
47                 Compiler::Locals mLocals;
48                 bool mActive;
49 
CompiledScriptMWScript::ScriptManager::CompiledScript50                 CompiledScript(const std::vector<Interpreter::Type_Code>& code, const Compiler::Locals& locals)
51                 {
52                     mByteCode = code;
53                     mLocals = locals;
54                     mActive = true;
55                 }
56             };
57 
58             typedef std::map<std::string, CompiledScript> ScriptCollection;
59 
60             ScriptCollection mScripts;
61             GlobalScripts mGlobalScripts;
62             std::map<std::string, Compiler::Locals> mOtherLocals;
63             std::vector<std::string> mScriptBlacklist;
64 
65         public:
66 
67             ScriptManager (const MWWorld::ESMStore& store,
68                 Compiler::Context& compilerContext, int warningsMode,
69                 const std::vector<std::string>& scriptBlacklist);
70 
71             void clear() override;
72 
73             bool run (const std::string& name, Interpreter::Context& interpreterContext) override;
74             ///< Run the script with the given name (compile first, if not compiled yet)
75 
76             bool compile (const std::string& name) override;
77             ///< Compile script with the given namen
78             /// \return Success?
79 
80             std::pair<int, int> compileAll() override;
81             ///< Compile all scripts
82             /// \return count, success
83 
84             const Compiler::Locals& getLocals (const std::string& name) override;
85             ///< Return locals for script \a name.
86 
87             GlobalScripts& getGlobalScripts() override;
88     };
89 }
90 
91 #endif
92