Fix scripting reload without scenes loaded

#375
This commit is contained in:
Wojtek Figat
2021-03-22 23:41:21 +01:00
parent 319bee0838
commit fcd86bccf5
2 changed files with 24 additions and 16 deletions

View File

@@ -496,14 +496,8 @@ public:
// - load scenes (from temporary files)
// Note: we don't want to override original scene files
// If no scene loaded just reload scripting
if (!Level::IsAnySceneLoaded())
{
// Reload scripting
LOG(Info, "No scenes loaded, performing fast scripts reload");
Scripting::Reload(false);
return false;
}
LOG(Info, "Scripts reloading start");
const auto startTime = DateTime::NowUTC();
// Cache data
struct SceneData
@@ -538,8 +532,6 @@ public:
scenes[i].Init(Level::Scenes[i]);
// Fire event
LOG(Info, "Scripts reloading start");
const auto startTime = DateTime::NowUTC();
Level::ScriptsReloadStart();
// Save scenes (to memory)
@@ -566,9 +558,10 @@ public:
Scripting::Reload();
// Restore scenes (from memory)
LOG(Info, "Loading temporary scenes");
for (int32 i = 0; i < scenesCount; i++)
{
LOG(Info, "Restoring scene {0}", scenes[i].Name);
// Parse json
const auto& sceneData = scenes[i].Data;
ISerializable::SerializeDocument document;
@@ -590,8 +583,9 @@ public:
scenes.Resize(0);
// Initialize scenes (will link references and create managed objects using new assembly)
LOG(Info, "Prepare scene objects");
if (Level::Scenes.HasItems())
{
LOG(Info, "Prepare scene objects");
SceneBeginData beginData;
for (int32 i = 0; i < Level::Scenes.Count(); i++)
{
@@ -601,8 +595,7 @@ public:
}
// Fire event
const auto endTime = DateTime::NowUTC();
LOG(Info, "Scripts reloading end. Total time: {0}ms", static_cast<int32>((endTime - startTime).GetTotalMilliseconds()));
LOG(Info, "Scripts reloading end. Total time: {0}ms", static_cast<int32>((DateTime::NowUTC() - startTime).GetTotalMilliseconds()));
Level::ScriptsReloadEnd();
return false;