mirror of https://github.com/OpenRCT2/OpenRCT2.git
Improve and fix intransient plugin branch
This commit is contained in:
parent
dbf83f018c
commit
1128f76a97
|
@ -15,7 +15,7 @@
|
|||
// /// <reference path="/path/to/openrct2.d.ts" />
|
||||
//
|
||||
|
||||
export type PluginType = "local" | "remote" | intransient;
|
||||
export type PluginType = "local" | "remote" | "intransient";
|
||||
|
||||
declare global {
|
||||
/**
|
||||
|
|
|
@ -35,7 +35,8 @@ namespace OpenRCT2::Scripting
|
|||
Remote,
|
||||
|
||||
/**
|
||||
* Scripts that run when the game starts and never unload.
|
||||
* Scripts that run when the game starts and only unload explicitly rather than when the
|
||||
* park changes.
|
||||
*/
|
||||
Intransient,
|
||||
};
|
||||
|
|
|
@ -626,8 +626,11 @@ void ScriptEngine::LoadPlugin(std::shared_ptr<Plugin>& plugin)
|
|||
|
||||
void ScriptEngine::UnloadPlugin(std::shared_ptr<Plugin>& plugin)
|
||||
{
|
||||
plugin->Unload();
|
||||
LogPluginInfo(plugin, "Unloaded");
|
||||
if (plugin->IsLoaded())
|
||||
{
|
||||
plugin->Unload();
|
||||
LogPluginInfo(plugin, "Unloaded");
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::StartPlugin(std::shared_ptr<Plugin> plugin)
|
||||
|
@ -663,9 +666,21 @@ void ScriptEngine::StopPlugin(std::shared_ptr<Plugin> plugin)
|
|||
_hookEngine.UnsubscribeAll(plugin);
|
||||
|
||||
plugin->StopEnd();
|
||||
LogPluginInfo(plugin, "Stopped");
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::ReloadPlugin(std::shared_ptr<Plugin> plugin)
|
||||
{
|
||||
StopPlugin(plugin);
|
||||
{
|
||||
ScriptExecutionInfo::PluginScope scope(_execInfo, plugin, false);
|
||||
plugin->Load();
|
||||
LogPluginInfo(plugin, "Reloaded");
|
||||
}
|
||||
StartPlugin(plugin);
|
||||
}
|
||||
|
||||
void ScriptEngine::SetupHotReloading()
|
||||
{
|
||||
try
|
||||
|
@ -715,12 +730,7 @@ void ScriptEngine::AutoReloadPlugins()
|
|||
auto& plugin = *findResult;
|
||||
try
|
||||
{
|
||||
StopPlugin(plugin);
|
||||
|
||||
ScriptExecutionInfo::PluginScope scope(_execInfo, plugin, false);
|
||||
plugin->Load();
|
||||
LogPluginInfo(plugin, "Reloaded");
|
||||
plugin->Start();
|
||||
ReloadPlugin(plugin);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
|
@ -739,18 +749,17 @@ void ScriptEngine::UnloadTransientPlugins()
|
|||
{
|
||||
if (plugin->IsTransient())
|
||||
{
|
||||
if (plugin->HasStarted())
|
||||
{
|
||||
StopPlugin(plugin);
|
||||
LogPluginInfo(plugin, "Stopped");
|
||||
}
|
||||
StopPlugin(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
// Now unload them
|
||||
for (auto& plugin : _plugins)
|
||||
{
|
||||
UnloadPlugin(plugin);
|
||||
if (plugin->IsTransient())
|
||||
{
|
||||
UnloadPlugin(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
_transientPluginsEnabled = false;
|
||||
|
|
|
@ -261,6 +261,7 @@ namespace OpenRCT2::Scripting
|
|||
void UnloadPlugin(std::shared_ptr<Plugin>& plugin);
|
||||
void StartPlugin(std::shared_ptr<Plugin> plugin);
|
||||
void StopPlugin(std::shared_ptr<Plugin> plugin);
|
||||
void ReloadPlugin(std::shared_ptr<Plugin> plugin);
|
||||
void StopUnloadRegisterAllPlugins();
|
||||
static bool ShouldLoadScript(std::string_view path);
|
||||
bool ShouldStartPlugin(const std::shared_ptr<Plugin>& plugin);
|
||||
|
|
Loading…
Reference in New Issue