mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 07:43:01 +01:00
Add hot reloading support
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "../core/FileScanner.h"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../interface/InteractiveConsole.h"
|
||||
#include "../platform/Platform2.h"
|
||||
#include "../PlatformEnvironment.h"
|
||||
#include <dukglue/dukglue.h>
|
||||
#include <duktape.h>
|
||||
@@ -67,6 +68,7 @@ void ScriptEngine::LoadPlugins()
|
||||
{
|
||||
Plugin p(_context, path);
|
||||
p.Load();
|
||||
p.EnableHotReload();
|
||||
_plugins.push_back(std::move(p));
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
@@ -76,6 +78,25 @@ void ScriptEngine::LoadPlugins()
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::AutoReloadPlugins()
|
||||
{
|
||||
for (auto& plugin : _plugins)
|
||||
{
|
||||
if (plugin.ShouldHotReload())
|
||||
{
|
||||
try
|
||||
{
|
||||
plugin.Load();
|
||||
plugin.Start();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
_console.WriteLineError(e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::StartPlugins()
|
||||
{
|
||||
for (auto& plugin : _plugins)
|
||||
@@ -111,6 +132,13 @@ void ScriptEngine::Update()
|
||||
// Signal the promise so caller can continue
|
||||
promise.set_value();
|
||||
}
|
||||
|
||||
auto tick = Platform::GetTicks();
|
||||
if (tick - _lastHotReloadCheckTick > 1000)
|
||||
{
|
||||
AutoReloadPlugins();
|
||||
_lastHotReloadCheckTick = tick;
|
||||
}
|
||||
}
|
||||
|
||||
std::future<void> ScriptEngine::Eval(const std::string &s)
|
||||
|
||||
Reference in New Issue
Block a user