2018-03-17 19:31:06 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
* Copyright (c) 2014-2018 OpenRCT2 developers
|
|
|
|
|
*
|
|
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
|
|
|
|
*
|
|
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "../common.h"
|
2018-03-18 23:35:58 +00:00
|
|
|
#include "HookEngine.h"
|
2018-03-18 16:27:48 +00:00
|
|
|
#include "Plugin.h"
|
2018-03-17 19:31:06 +00:00
|
|
|
#include <future>
|
|
|
|
|
#include <queue>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
struct duk_hthread;
|
|
|
|
|
typedef struct duk_hthread duk_context;
|
|
|
|
|
|
|
|
|
|
class InteractiveConsole;
|
|
|
|
|
|
|
|
|
|
namespace OpenRCT2
|
|
|
|
|
{
|
|
|
|
|
interface IPlatformEnvironment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace OpenRCT2::Scripting
|
|
|
|
|
{
|
2018-03-18 23:35:58 +00:00
|
|
|
class ScriptExecutionInfo
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
Plugin * _plugin;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Plugin * GetCurrentPlugin() { return _plugin; }
|
|
|
|
|
void SetCurrentPlugin(Plugin * value) { _plugin = value; }
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-17 19:31:06 +00:00
|
|
|
class ScriptEngine
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
InteractiveConsole& _console;
|
|
|
|
|
IPlatformEnvironment& _env;
|
2018-03-17 23:26:55 +00:00
|
|
|
bool _initialised{};
|
|
|
|
|
duk_context * _context{};
|
2018-03-17 19:31:06 +00:00
|
|
|
std::queue<std::tuple<std::promise<void>, std::string>> _evalQueue;
|
2018-03-18 16:27:48 +00:00
|
|
|
std::vector<Plugin> _plugins;
|
2018-03-18 17:43:47 +00:00
|
|
|
uint32 _lastHotReloadCheckTick{};
|
2018-03-18 23:35:58 +00:00
|
|
|
HookEngine _hookEngine;
|
|
|
|
|
ScriptExecutionInfo _execInfo;
|
2018-03-17 19:31:06 +00:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
ScriptEngine(InteractiveConsole& console, IPlatformEnvironment& env);
|
2018-03-18 16:27:48 +00:00
|
|
|
ScriptEngine(ScriptEngine&) = delete;
|
2018-03-17 19:31:06 +00:00
|
|
|
~ScriptEngine();
|
|
|
|
|
|
2018-03-18 23:35:58 +00:00
|
|
|
HookEngine& GetHookEngine() { return _hookEngine; }
|
|
|
|
|
|
2018-03-17 19:31:06 +00:00
|
|
|
void Update();
|
|
|
|
|
std::future<void> Eval(const std::string &s);
|
2018-03-18 16:27:48 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void Initialise();
|
|
|
|
|
void LoadPlugins();
|
|
|
|
|
void StartPlugins();
|
2018-03-18 17:43:47 +00:00
|
|
|
void AutoReloadPlugins();
|
2018-03-17 19:31:06 +00:00
|
|
|
};
|
|
|
|
|
}
|