From 9238a59a00d2f55ee7e16f508950138c62784234 Mon Sep 17 00:00:00 2001 From: antopilo Date: Sun, 1 Dec 2024 02:08:32 -0500 Subject: [PATCH] Improved play mode startup time --- Editor/src/Windows/EditorInterface.cpp | 62 +++++++++++----------- Nuake/src/FileSystem/FileSystem.cpp | 8 ++- Nuake/src/Scripting/ScriptingEngineNet.cpp | 15 ++++-- Nuake/src/Scripting/ScriptingEngineNet.h | 2 + 4 files changed, 50 insertions(+), 37 deletions(-) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index aeeaa6f5..fe162454 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -352,48 +352,48 @@ namespace Nuake { SetStatusMessage(statusMessage); auto job = [this]() - { - this->errors = ScriptingEngineNet::Get().BuildProjectAssembly(Engine::GetProject()); - }; + { + auto project = Engine::GetProject(); + auto& scriptingEngine = ScriptingEngineNet::Get(); + const std::string& assemblyPath = scriptingEngine.GetGameAssemblyPath(project); + if (FileSystem::FileExists(assemblyPath) && FileSystem::GetFile(assemblyPath)->GetHasBeenModified()) + { + this->errors = ScriptingEngineNet::Get().BuildProjectAssembly(Engine::GetProject()); + FileSystem::GetFile(assemblyPath)->SetHasBeenModified(false); + } + }; Selection = EditorSelection(); JobSystem::Get().Dispatch(job, [this]() { - bool containsError = false; - std::find_if(errors.begin(), errors.end(), [](const CompilationError& error) { - return error.isWarning == false; + bool containsError = false; + std::find_if(errors.begin(), errors.end(), [](const CompilationError& error) { + return error.isWarning == false; }); - if (errors.size() > 0 && containsError) - { - SetStatusMessage("Failed to build scripts! See Logger for more info", { 1.0f, 0.1f, 0.1f, 1.0f }); - - Logger::Log("Build FAILED.", ".net", CRITICAL); - for (CompilationError error : errors) + if (errors.size() > 0 && containsError) { - const std::string errorMessage = error.file + "( line " + std::to_string(error.line) + "): " + error.message; - Logger::Log(errorMessage, ".net", CRITICAL); + SetStatusMessage("Failed to build scripts! See Logger for more info", { 1.0f, 0.1f, 0.1f, 1.0f }); + + Logger::Log("Build FAILED.", ".net", CRITICAL); + for (CompilationError error : errors) + { + const std::string errorMessage = error.file + "( line " + std::to_string(error.line) + "): " + error.message; + Logger::Log(errorMessage, ".net", CRITICAL); + } } - } - else - { - Engine::GetProject()->ExportEntitiesToTrenchbroom(); - - ImGui::SetWindowFocus("Logger"); - SetStatusMessage("Entering play mode..."); - - PushCommand(SetGameState(GameState::Playing)); - - for (CompilationError error : errors) + else { - const std::string errorMessage = error.file + "( line " + std::to_string(error.line) + "): " + error.message; - Logger::Log(errorMessage, ".net", WARNING); - } + Engine::GetProject()->ExportEntitiesToTrenchbroom(); - std::string statusMessage = ICON_FA_RUNNING + std::string(" Playing..."); - SetStatusMessage(statusMessage.c_str(), Engine::GetProject()->Settings.PrimaryColor); - } + ImGui::SetWindowFocus("Logger"); + SetStatusMessage("Entering play mode..."); + + PushCommand(SetGameState(GameState::Playing)); + std::string statusMessage = ICON_FA_RUNNING + std::string(" Playing..."); + SetStatusMessage(statusMessage.c_str(), Engine::GetProject()->Settings.PrimaryColor); + } }); } } diff --git a/Nuake/src/FileSystem/FileSystem.cpp b/Nuake/src/FileSystem/FileSystem.cpp index 784bcf43..cae2205e 100644 --- a/Nuake/src/FileSystem/FileSystem.cpp +++ b/Nuake/src/FileSystem/FileSystem.cpp @@ -219,8 +219,14 @@ Ref FileSystem::GetFileTree() return RootDirectory; } -Ref FileSystem::GetFile(const std::string& path) +Ref FileSystem::GetFile(const std::string& inPath) { + std::string path = inPath; + if (String::BeginsWith(path, "/") || String::BeginsWith(path, "\\")) + { + path = inPath.substr(1, inPath.size() - 1); + } + // Note, Might be broken on other platforms. auto splits = String::Split(path, '/'); diff --git a/Nuake/src/Scripting/ScriptingEngineNet.cpp b/Nuake/src/Scripting/ScriptingEngineNet.cpp index cf10a003..43d64293 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/src/Scripting/ScriptingEngineNet.cpp @@ -333,6 +333,13 @@ namespace Nuake return widgetUUIDToManagedObjects[std::make_pair(canvasUUID, uuid)]; } + std::string ScriptingEngineNet::GetGameAssemblyPath(Ref project) const + { + const std::string sanitizedProjectName = String::Sanitize(project->Name); + const std::string assemblyPath = "/bin/Debug/net8.0/" + sanitizedProjectName + ".dll"; + return assemblyPath; + } + std::vector ScriptingEngineNet::BuildProjectAssembly(Ref project) { const std::string sanitizedProjectName = String::Sanitize(project->Name); @@ -361,16 +368,14 @@ namespace Nuake return; } - const std::string sanitizedProjectName = String::Sanitize(project->Name); - const std::string assemblyPath = "/bin/Debug/net8.0/" + sanitizedProjectName + ".dll"; - - if (!FileSystem::FileExists(assemblyPath)) + const std::string gameAssemblyPath = GetGameAssemblyPath(project); + if (!FileSystem::FileExists(gameAssemblyPath)) { Logger::Log("Couldn't load .net assembly. Did you forget to build the .net project?", ".net", CRITICAL); return; } - const std::string absoluteAssemblyPath = FileSystem::Root + assemblyPath; + const std::string absoluteAssemblyPath = FileSystem::Root + gameAssemblyPath; gameAssembly = loadContext.LoadAssembly(absoluteAssemblyPath); prefabType = gameAssembly.GetType("Nuake.Net.Prefab"); diff --git a/Nuake/src/Scripting/ScriptingEngineNet.h b/Nuake/src/Scripting/ScriptingEngineNet.h index 6d5ea092..1b0dc8cf 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.h +++ b/Nuake/src/Scripting/ScriptingEngineNet.h @@ -118,6 +118,8 @@ namespace Nuake std::unordered_map GetPointEntities() const { return pointEntityTypes; } std::unordered_map GetUIWidgets() const { return uiWidgets; } + std::string GetGameAssemblyPath(Ref project) const; + OnGameAssemblyLoadedDelegate& OnUninitialize() { return onUninitializeDelegate; } OnUninitializeDelegate& OnGameAssemblyLoaded() { return onGameAssemblyLoadedDelegate; }