From a69fa0b00d0a61eafa6577a61a80dcee988418fb Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 17:13:36 +0200 Subject: [PATCH 01/21] Add optional command line argument define. --- Source/Engine/Engine/CommandLine.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Source/Engine/Engine/CommandLine.cpp b/Source/Engine/Engine/CommandLine.cpp index edfc9c268..eedc8d356 100644 --- a/Source/Engine/Engine/CommandLine.cpp +++ b/Source/Engine/Engine/CommandLine.cpp @@ -102,6 +102,23 @@ bool CommandLine::Parse(const Char* cmdLine) *(end - len) = 0; \ end -= len; \ } + +#define PARSE_ARG_OPT_SWITCH(text, field) \ + pos = (Char*)StringUtils::FindIgnoreCase(buffer.Get(), TEXT(text)); \ + if (pos) \ + { \ + len = ARRAY_COUNT(text) - 1; \ + if (ParseArg(pos + len, argStart, argEnd)) \ + Options.field = String::Empty; \ + else \ + { \ + Options.field = String(argStart, static_cast(argEnd - argStart)); \ + len = static_cast((argEnd - pos) + 1); \ + Platform::MemoryCopy(pos, pos + len, (end - pos - len) * 2); \ + *(end - len) = 0; \ + end -= len; \ + } \ + } PARSE_BOOL_SWITCH("-windowed ", Windowed); PARSE_BOOL_SWITCH("-fullscreen ", Fullscreen); From ec3972d511012ff6f7005277cc8459d4ba187b5b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 17:14:01 +0200 Subject: [PATCH 02/21] Add -game command line argument. --- Source/Engine/Engine/CommandLine.cpp | 1 + Source/Engine/Engine/CommandLine.h | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/Source/Engine/Engine/CommandLine.cpp b/Source/Engine/Engine/CommandLine.cpp index eedc8d356..6d282b6b2 100644 --- a/Source/Engine/Engine/CommandLine.cpp +++ b/Source/Engine/Engine/CommandLine.cpp @@ -151,6 +151,7 @@ bool CommandLine::Parse(const Char* cmdLine) PARSE_ARG_SWITCH("-build ", Build); PARSE_BOOL_SWITCH("-skipcompile ", SkipCompile); PARSE_BOOL_SWITCH("-shaderdebug ", ShaderDebug); + PARSE_ARG_OPT_SWITCH("-game ", Game); #endif diff --git a/Source/Engine/Engine/CommandLine.h b/Source/Engine/Engine/CommandLine.h index 278620bf5..f1dfc5c27 100644 --- a/Source/Engine/Engine/CommandLine.h +++ b/Source/Engine/Engine/CommandLine.h @@ -155,6 +155,11 @@ public: /// Nullable ShaderDebug; + /// + /// -game !scene! ( Scene to play, can be null to use default ) + /// + Nullable Game; + #endif }; From d3b920dfc17cd301ca94d50f30c6517ce31afcda Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 17:16:02 +0200 Subject: [PATCH 03/21] Prevent Mesh being rendered while uninitialised ( async task not executed yet ). --- Source/Engine/Graphics/Models/Mesh.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Graphics/Models/Mesh.cpp b/Source/Engine/Graphics/Models/Mesh.cpp index dddbd6a3e..8b7f601f8 100644 --- a/Source/Engine/Graphics/Models/Mesh.cpp +++ b/Source/Engine/Graphics/Models/Mesh.cpp @@ -363,7 +363,8 @@ void Mesh::GetDrawCallGeometry(DrawCall& drawCall) const void Mesh::Render(GPUContext* context) const { - ASSERT(IsInitialized()); + if (!IsInitialized()) + return; context->BindVB(ToSpan((GPUBuffer**)_vertexBuffers, 3)); context->BindIB(_indexBuffer); @@ -372,7 +373,7 @@ void Mesh::Render(GPUContext* context) const void Mesh::Draw(const RenderContext& renderContext, MaterialBase* material, const Matrix& world, StaticFlags flags, bool receiveDecals, DrawPass drawModes, float perInstanceRandom) const { - if (!material || !material->IsSurface()) + if (!material || !material->IsSurface() || !IsInitialized()) return; // Submit draw call @@ -403,6 +404,9 @@ void Mesh::Draw(const RenderContext& renderContext, MaterialBase* material, cons void Mesh::Draw(const RenderContext& renderContext, const DrawInfo& info, float lodDitherFactor) const { + if (!IsInitialized()) + return; + // Cache data const auto& entry = info.Buffer->At(_materialSlotIndex); if (!entry.Visible || !IsInitialized()) From 2293bd5fe0f683a0aef93c57d0c09326fa354340 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 17:17:53 +0200 Subject: [PATCH 04/21] Expose Simulation.RequestStartPlay() to cpp. --- Source/Editor/Editor.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index 9a9500b7b..811599d9c 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -1307,6 +1307,11 @@ namespace FlaxEditor AnimGraphDebugFlow?.Invoke(debugFlow); } + internal static void Internal_RequestStartPlay() + { + Instance.Simulation.RequestStartPlay(); + } + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern int Internal_ReadOutputLogs(string[] outMessages, byte[] outLogTypes, long[] outLogTimes); From 5601be630e56a6732300ac67f69ddb3f2fe8bf94 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 17:18:48 +0200 Subject: [PATCH 05/21] RequestStartPlay glue code. --- Source/Editor/Managed/ManagedEditor.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/Editor/Managed/ManagedEditor.cpp b/Source/Editor/Managed/ManagedEditor.cpp index 35219a906..59475110e 100644 --- a/Source/Editor/Managed/ManagedEditor.cpp +++ b/Source/Editor/Managed/ManagedEditor.cpp @@ -35,6 +35,7 @@ MMethod* Internal_GetGameWindowSize = nullptr; MMethod* Internal_OnAppExit = nullptr; MMethod* Internal_OnVisualScriptingDebugFlow = nullptr; MMethod* Internal_OnAnimGraphDebugFlow = nullptr; +MMethod* Internal_RequestStartPlay = nullptr; void OnLightmapsBake(ShadowsOfMordor::BuildProgressStep step, float stepProgress, float totalProgress, bool isProgressEvent) { @@ -481,6 +482,18 @@ bool ManagedEditor::OnAppExit() return MUtils::Unbox(Internal_OnAppExit->Invoke(GetManagedInstance(), nullptr, nullptr)); } +void ManagedEditor::RequestStartPlay() +{ + if (!HasManagedInstance()) + return; + if (Internal_RequestStartPlay == nullptr) + { + Internal_RequestStartPlay = GetClass()->GetMethod("Internal_RequestStartPlay"); + ASSERT(Internal_RequestStartPlay); + } + Internal_RequestStartPlay->Invoke(GetManagedInstance(), nullptr, nullptr); +} + void ManagedEditor::OnEditorAssemblyLoaded(MAssembly* assembly) { ASSERT(!HasManagedInstance()); From c01cd78225fa9b538570b63c23d456eef9b9db8b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 17:19:24 +0200 Subject: [PATCH 06/21] RequestStartPlay glue code. --- Source/Editor/Managed/ManagedEditor.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Editor/Managed/ManagedEditor.h b/Source/Editor/Managed/ManagedEditor.h index 5e0b612b5..ef58fd737 100644 --- a/Source/Editor/Managed/ManagedEditor.h +++ b/Source/Editor/Managed/ManagedEditor.h @@ -133,6 +133,11 @@ public: /// True if exit engine, otherwise false. bool OnAppExit(); + /// + /// Requests switch to play mode. + /// + void RequestStartPlay(); + private: void OnEditorAssemblyLoaded(MAssembly* assembly); From d7f03d2c7d1980f4ad0b317f4e05b30629103a44 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 17:20:00 +0200 Subject: [PATCH 07/21] Handle game argument. --- Source/Editor/Editor.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/Editor/Editor.cpp b/Source/Editor/Editor.cpp index 2284478dd..69963aa66 100644 --- a/Source/Editor/Editor.cpp +++ b/Source/Editor/Editor.cpp @@ -519,6 +519,11 @@ bool Editor::Init() return true; } + if (CommandLine::Options.Game.HasValue()) + { + CommandLine::Options.SkipCompile.SetValue(true); + } + // If during last lightmaps baking engine crashed we could try to restore the progress ShadowsOfMordor::Builder::Instance()->CheckIfRestoreState(); @@ -534,6 +539,11 @@ bool Editor::Init() // Initialize managed editor Managed->Init(); + if (CommandLine::Options.Game.HasValue()) + { + Managed->RequestStartPlay(); + } + return false; } From 66c12017865d82ea5d88323d9ae9ba7bef0ae4d4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 17:21:45 +0200 Subject: [PATCH 08/21] Load scene specified in -game argument. --- Source/Editor/Editor.cs | 17 ++++++++++++++++- Source/Editor/Managed/ManagedEditor.cpp | 8 +++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index 811599d9c..a775139a6 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -271,10 +271,14 @@ namespace FlaxEditor module.OnEndInit(); } - internal void Init(bool isHeadless, bool skipCompile) + private Guid _startupSceneArgument; + + internal void Init(bool isHeadless, bool skipCompile, Guid sceneId) { + Debug.Log("sceneId string : " + JsonSerializer.GetStringID(sceneId)); EnsureState(); _isHeadlessMode = isHeadless; + _startupSceneArgument = sceneId; Log("Editor init"); if (isHeadless) Log("Running in headless mode"); @@ -332,6 +336,17 @@ namespace FlaxEditor } // Load scene + + // scene cmd line argument + var scene = ContentDatabase.Find(_startupSceneArgument); + if (scene is SceneItem) + { + Editor.Log("Loading scene specified in command line"); + Scene.OpenScene(_startupSceneArgument); + return; + } + + // if no scene cmd line argument is provided var startupSceneMode = Options.Options.General.StartupSceneMode; if (startupSceneMode == GeneralOptions.StartupSceneModes.LastOpened && !ProjectCache.HasCustomData(ProjectDataLastScene)) { diff --git a/Source/Editor/Managed/ManagedEditor.cpp b/Source/Editor/Managed/ManagedEditor.cpp index 59475110e..cdae24a1d 100644 --- a/Source/Editor/Managed/ManagedEditor.cpp +++ b/Source/Editor/Managed/ManagedEditor.cpp @@ -210,7 +210,7 @@ ManagedEditor::~ManagedEditor() void ManagedEditor::Init() { // Note: editor modules should perform quite fast init, any longer things should be done in async during 'editor splash screen time - void* args[2]; + void* args[3]; MClass* mclass = GetClass(); if (mclass == nullptr) { @@ -231,6 +231,12 @@ void ManagedEditor::Init() bool skipCompile = CommandLine::Options.SkipCompile.IsTrue(); args[0] = &isHeadless; args[1] = &skipCompile; + Guid sceneId; + if (Guid::Parse(CommandLine::Options.Game.GetValue(), sceneId)) + { + sceneId = Guid::Empty; + } + args[2] = CommandLine::Options.Game.HasValue() ? &sceneId : nullptr; initMethod->Invoke(instance, args, &exception); if (exception) { From 9fb29529966813447024b0ef5bb36a8204662f42 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 17:28:55 +0200 Subject: [PATCH 09/21] Tweaks / Cleanup. --- Source/Editor/Editor.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index a775139a6..43f7428cd 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -46,6 +46,7 @@ namespace FlaxEditor private bool _isAfterInit, _areModulesInited, _areModulesAfterInitEnd, _isHeadlessMode; private string _projectToOpen; private float _lastAutoSaveTimer; + private Guid _startupSceneCmdLine; private const string ProjectDataLastScene = "LastScene"; private const string ProjectDataLastSceneSpawn = "LastSceneSpawn"; @@ -271,14 +272,11 @@ namespace FlaxEditor module.OnEndInit(); } - private Guid _startupSceneArgument; - - internal void Init(bool isHeadless, bool skipCompile, Guid sceneId) + internal void Init(bool isHeadless, bool skipCompile, Guid startupScene) { - Debug.Log("sceneId string : " + JsonSerializer.GetStringID(sceneId)); EnsureState(); _isHeadlessMode = isHeadless; - _startupSceneArgument = sceneId; + _startupSceneCmdLine = startupScene; Log("Editor init"); if (isHeadless) Log("Running in headless mode"); @@ -338,11 +336,11 @@ namespace FlaxEditor // Load scene // scene cmd line argument - var scene = ContentDatabase.Find(_startupSceneArgument); + var scene = ContentDatabase.Find(_startupSceneCmdLine); if (scene is SceneItem) { Editor.Log("Loading scene specified in command line"); - Scene.OpenScene(_startupSceneArgument); + Scene.OpenScene(_startupSceneCmdLine); return; } From 62b47fa65b40eaeff893b85282a300236b31855d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 17:30:43 +0200 Subject: [PATCH 10/21] Comments. --- Source/Editor/Editor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Editor/Editor.cpp b/Source/Editor/Editor.cpp index 69963aa66..1249e1b5e 100644 --- a/Source/Editor/Editor.cpp +++ b/Source/Editor/Editor.cpp @@ -519,6 +519,7 @@ bool Editor::Init() return true; } + // Skip compilation if play on start if (CommandLine::Options.Game.HasValue()) { CommandLine::Options.SkipCompile.SetValue(true); @@ -539,6 +540,7 @@ bool Editor::Init() // Initialize managed editor Managed->Init(); + // Start play if requested by cmd line if (CommandLine::Options.Game.HasValue()) { Managed->RequestStartPlay(); From 316590ec59700a769ca7d77a91d71a8f0e2344a7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 17:37:05 +0200 Subject: [PATCH 11/21] Tweak. --- Source/Engine/Engine/CommandLine.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Engine/CommandLine.h b/Source/Engine/Engine/CommandLine.h index f1dfc5c27..6283fc02e 100644 --- a/Source/Engine/Engine/CommandLine.h +++ b/Source/Engine/Engine/CommandLine.h @@ -156,7 +156,7 @@ public: Nullable ShaderDebug; /// - /// -game !scene! ( Scene to play, can be null to use default ) + /// -game !scene! ( Scene to play, can be empty to use default ) /// Nullable Game; From 8eb6fd2b6bd956265549a113b7f4a91adbcb9c11 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 20:03:58 +0200 Subject: [PATCH 12/21] Fix. --- Source/Editor/Editor.cs | 13 +++++++++++-- Source/Editor/Managed/ManagedEditor.cpp | 12 ++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index 43f7428cd..092875be1 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -1320,9 +1320,18 @@ namespace FlaxEditor AnimGraphDebugFlow?.Invoke(debugFlow); } - internal static void Internal_RequestStartPlay() + private static void RequestStartPlayOnStartup() { - Instance.Simulation.RequestStartPlay(); + if (Instance.StateMachine.IsEditMode) + { + Instance.Simulation.RequestStartPlay(); + Instance.StateMachine.StateChanged -= RequestStartPlayOnStartup; + } + } + + internal static void Internal_RequestStartPlayOnStartup() + { + Instance.StateMachine.StateChanged += RequestStartPlayOnStartup; } [MethodImpl(MethodImplOptions.InternalCall)] diff --git a/Source/Editor/Managed/ManagedEditor.cpp b/Source/Editor/Managed/ManagedEditor.cpp index cdae24a1d..6be85e0b9 100644 --- a/Source/Editor/Managed/ManagedEditor.cpp +++ b/Source/Editor/Managed/ManagedEditor.cpp @@ -35,7 +35,7 @@ MMethod* Internal_GetGameWindowSize = nullptr; MMethod* Internal_OnAppExit = nullptr; MMethod* Internal_OnVisualScriptingDebugFlow = nullptr; MMethod* Internal_OnAnimGraphDebugFlow = nullptr; -MMethod* Internal_RequestStartPlay = nullptr; +MMethod* Internal_RequestStartPlayOnStartup = nullptr; void OnLightmapsBake(ShadowsOfMordor::BuildProgressStep step, float stepProgress, float totalProgress, bool isProgressEvent) { @@ -232,7 +232,7 @@ void ManagedEditor::Init() args[0] = &isHeadless; args[1] = &skipCompile; Guid sceneId; - if (Guid::Parse(CommandLine::Options.Game.GetValue(), sceneId)) + if (CommandLine::Options.Game.HasValue() && Guid::Parse(CommandLine::Options.Game.GetValue(), sceneId)) { sceneId = Guid::Empty; } @@ -492,12 +492,12 @@ void ManagedEditor::RequestStartPlay() { if (!HasManagedInstance()) return; - if (Internal_RequestStartPlay == nullptr) + if (Internal_RequestStartPlayOnStartup == nullptr) { - Internal_RequestStartPlay = GetClass()->GetMethod("Internal_RequestStartPlay"); - ASSERT(Internal_RequestStartPlay); + Internal_RequestStartPlayOnStartup = GetClass()->GetMethod("Internal_RequestStartPlayOnStartup"); + ASSERT(Internal_RequestStartPlayOnStartup); } - Internal_RequestStartPlay->Invoke(GetManagedInstance(), nullptr, nullptr); + Internal_RequestStartPlayOnStartup->Invoke(GetManagedInstance(), nullptr, nullptr); } void ManagedEditor::OnEditorAssemblyLoaded(MAssembly* assembly) From 8ac8f9a6d17092c1a697155ab59755fedbad6af0 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 20:05:44 +0200 Subject: [PATCH 13/21] Tweaks. --- Source/Editor/Editor.cs | 2 +- Source/Editor/Managed/ManagedEditor.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index 092875be1..cfbbc93b1 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -1329,7 +1329,7 @@ namespace FlaxEditor } } - internal static void Internal_RequestStartPlayOnStartup() + internal static void Internal_RequestStartPlayOnEditMode() { Instance.StateMachine.StateChanged += RequestStartPlayOnStartup; } diff --git a/Source/Editor/Managed/ManagedEditor.cpp b/Source/Editor/Managed/ManagedEditor.cpp index 6be85e0b9..14da2bb41 100644 --- a/Source/Editor/Managed/ManagedEditor.cpp +++ b/Source/Editor/Managed/ManagedEditor.cpp @@ -35,7 +35,7 @@ MMethod* Internal_GetGameWindowSize = nullptr; MMethod* Internal_OnAppExit = nullptr; MMethod* Internal_OnVisualScriptingDebugFlow = nullptr; MMethod* Internal_OnAnimGraphDebugFlow = nullptr; -MMethod* Internal_RequestStartPlayOnStartup = nullptr; +MMethod* Internal_RequestStartPlayOnEditMode = nullptr; void OnLightmapsBake(ShadowsOfMordor::BuildProgressStep step, float stepProgress, float totalProgress, bool isProgressEvent) { @@ -492,12 +492,12 @@ void ManagedEditor::RequestStartPlay() { if (!HasManagedInstance()) return; - if (Internal_RequestStartPlayOnStartup == nullptr) + if (Internal_RequestStartPlayOnEditMode == nullptr) { - Internal_RequestStartPlayOnStartup = GetClass()->GetMethod("Internal_RequestStartPlayOnStartup"); - ASSERT(Internal_RequestStartPlayOnStartup); + Internal_RequestStartPlayOnEditMode = GetClass()->GetMethod("Internal_RequestStartPlayOnEditMode"); + ASSERT(Internal_RequestStartPlayOnEditMode); } - Internal_RequestStartPlayOnStartup->Invoke(GetManagedInstance(), nullptr, nullptr); + Internal_RequestStartPlayOnEditMode->Invoke(GetManagedInstance(), nullptr, nullptr); } void ManagedEditor::OnEditorAssemblyLoaded(MAssembly* assembly) From 9e2867ed7d2cd6c9aebef5340d36c8d3d218f06a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 20:07:39 +0200 Subject: [PATCH 14/21] Tweak. --- Source/Editor/Managed/ManagedEditor.cpp | 2 +- Source/Editor/Managed/ManagedEditor.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Managed/ManagedEditor.cpp b/Source/Editor/Managed/ManagedEditor.cpp index 14da2bb41..9ea0f9cfc 100644 --- a/Source/Editor/Managed/ManagedEditor.cpp +++ b/Source/Editor/Managed/ManagedEditor.cpp @@ -488,7 +488,7 @@ bool ManagedEditor::OnAppExit() return MUtils::Unbox(Internal_OnAppExit->Invoke(GetManagedInstance(), nullptr, nullptr)); } -void ManagedEditor::RequestStartPlay() +void ManagedEditor::RequestStartPlayOnEditMode() { if (!HasManagedInstance()) return; diff --git a/Source/Editor/Managed/ManagedEditor.h b/Source/Editor/Managed/ManagedEditor.h index ef58fd737..df05e87bd 100644 --- a/Source/Editor/Managed/ManagedEditor.h +++ b/Source/Editor/Managed/ManagedEditor.h @@ -134,9 +134,9 @@ public: bool OnAppExit(); /// - /// Requests switch to play mode. + /// Requests play mode when the editor is in edit mode ( once ). /// - void RequestStartPlay(); + void RequestStartPlayOnEditMode(); private: From 320a1a984e2679553f57f71cf28ff12c55473eac Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 20 May 2021 20:08:08 +0200 Subject: [PATCH 15/21] Fix. --- Source/Editor/Editor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Editor.cpp b/Source/Editor/Editor.cpp index 1249e1b5e..c90e80e70 100644 --- a/Source/Editor/Editor.cpp +++ b/Source/Editor/Editor.cpp @@ -543,7 +543,7 @@ bool Editor::Init() // Start play if requested by cmd line if (CommandLine::Options.Game.HasValue()) { - Managed->RequestStartPlay(); + Managed->RequestStartPlayOnEditMode(); } return false; From 3a68e2891e988e258e718914a45afd2bad25e6e7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Fri, 21 May 2021 18:18:11 +0200 Subject: [PATCH 16/21] Add null check. --- Source/Editor/Managed/ManagedEditor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Managed/ManagedEditor.cpp b/Source/Editor/Managed/ManagedEditor.cpp index 9ea0f9cfc..93f36f337 100644 --- a/Source/Editor/Managed/ManagedEditor.cpp +++ b/Source/Editor/Managed/ManagedEditor.cpp @@ -232,7 +232,7 @@ void ManagedEditor::Init() args[0] = &isHeadless; args[1] = &skipCompile; Guid sceneId; - if (CommandLine::Options.Game.HasValue() && Guid::Parse(CommandLine::Options.Game.GetValue(), sceneId)) + if (!CommandLine::Options.Game.HasValue() || (CommandLine::Options.Game.HasValue() && Guid::Parse(CommandLine::Options.Game.GetValue(), sceneId))) { sceneId = Guid::Empty; } From 6eb3bc0577e890247ab433444a34d7e4584a179c Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Fri, 21 May 2021 18:18:20 +0200 Subject: [PATCH 17/21] Tweak. --- Source/Editor/Editor.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index cfbbc93b1..749d7ac6e 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -1320,18 +1320,18 @@ namespace FlaxEditor AnimGraphDebugFlow?.Invoke(debugFlow); } - private static void RequestStartPlayOnStartup() + private static void RequestStartPlayOnEditMode() { if (Instance.StateMachine.IsEditMode) { Instance.Simulation.RequestStartPlay(); - Instance.StateMachine.StateChanged -= RequestStartPlayOnStartup; + Instance.StateMachine.StateChanged -= RequestStartPlayOnEditMode; } } internal static void Internal_RequestStartPlayOnEditMode() { - Instance.StateMachine.StateChanged += RequestStartPlayOnStartup; + Instance.StateMachine.StateChanged += RequestStartPlayOnEditMode; } [MethodImpl(MethodImplOptions.InternalCall)] From 566756ecf2c8841ba26276746598efdb1d8edefb Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sun, 23 May 2021 19:31:44 +0200 Subject: [PATCH 18/21] Remove duplicate IsInitialized. --- Source/Engine/Graphics/Models/Mesh.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/Engine/Graphics/Models/Mesh.cpp b/Source/Engine/Graphics/Models/Mesh.cpp index 8b7f601f8..35b5fe5fb 100644 --- a/Source/Engine/Graphics/Models/Mesh.cpp +++ b/Source/Engine/Graphics/Models/Mesh.cpp @@ -404,9 +404,6 @@ void Mesh::Draw(const RenderContext& renderContext, MaterialBase* material, cons void Mesh::Draw(const RenderContext& renderContext, const DrawInfo& info, float lodDitherFactor) const { - if (!IsInitialized()) - return; - // Cache data const auto& entry = info.Buffer->At(_materialSlotIndex); if (!entry.Visible || !IsInitialized()) From ce3caede6c5aaa328936ec0a227238a0d53d0184 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sun, 23 May 2021 19:32:45 +0200 Subject: [PATCH 19/21] Remove skipcompile when -play is used. --- Source/Editor/Editor.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Source/Editor/Editor.cpp b/Source/Editor/Editor.cpp index c90e80e70..1b18034c4 100644 --- a/Source/Editor/Editor.cpp +++ b/Source/Editor/Editor.cpp @@ -518,12 +518,6 @@ bool Editor::Init() exit(failed ? 1 : 0); return true; } - - // Skip compilation if play on start - if (CommandLine::Options.Game.HasValue()) - { - CommandLine::Options.SkipCompile.SetValue(true); - } // If during last lightmaps baking engine crashed we could try to restore the progress ShadowsOfMordor::Builder::Instance()->CheckIfRestoreState(); @@ -541,7 +535,7 @@ bool Editor::Init() Managed->Init(); // Start play if requested by cmd line - if (CommandLine::Options.Game.HasValue()) + if (CommandLine::Options.Play.HasValue()) { Managed->RequestStartPlayOnEditMode(); } From 1f3a86dca921a2861774986b8ceb307a4ab12628 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sun, 23 May 2021 19:33:36 +0200 Subject: [PATCH 20/21] Fix -play not working with compilation at start. --- Source/Editor/Editor.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index 749d7ac6e..0df2d8203 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -1323,12 +1323,11 @@ namespace FlaxEditor private static void RequestStartPlayOnEditMode() { if (Instance.StateMachine.IsEditMode) - { Instance.Simulation.RequestStartPlay(); + if (Instance.StateMachine.IsPlayMode) Instance.StateMachine.StateChanged -= RequestStartPlayOnEditMode; - } } - + internal static void Internal_RequestStartPlayOnEditMode() { Instance.StateMachine.StateChanged += RequestStartPlayOnEditMode; From 2f12642405701c23a3fabb0ae85a926bd46beb87 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sun, 23 May 2021 19:34:16 +0200 Subject: [PATCH 21/21] Rename -game to -play & Fix when play not used. --- Source/Editor/Managed/ManagedEditor.cpp | 4 ++-- Source/Engine/Engine/CommandLine.cpp | 2 +- Source/Engine/Engine/CommandLine.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Editor/Managed/ManagedEditor.cpp b/Source/Editor/Managed/ManagedEditor.cpp index 93f36f337..18a905d4b 100644 --- a/Source/Editor/Managed/ManagedEditor.cpp +++ b/Source/Editor/Managed/ManagedEditor.cpp @@ -232,11 +232,11 @@ void ManagedEditor::Init() args[0] = &isHeadless; args[1] = &skipCompile; Guid sceneId; - if (!CommandLine::Options.Game.HasValue() || (CommandLine::Options.Game.HasValue() && Guid::Parse(CommandLine::Options.Game.GetValue(), sceneId))) + if (!CommandLine::Options.Play.HasValue() || (CommandLine::Options.Play.HasValue() && Guid::Parse(CommandLine::Options.Play.GetValue(), sceneId))) { sceneId = Guid::Empty; } - args[2] = CommandLine::Options.Game.HasValue() ? &sceneId : nullptr; + args[2] = &sceneId; initMethod->Invoke(instance, args, &exception); if (exception) { diff --git a/Source/Engine/Engine/CommandLine.cpp b/Source/Engine/Engine/CommandLine.cpp index 6d282b6b2..45ab454e6 100644 --- a/Source/Engine/Engine/CommandLine.cpp +++ b/Source/Engine/Engine/CommandLine.cpp @@ -151,7 +151,7 @@ bool CommandLine::Parse(const Char* cmdLine) PARSE_ARG_SWITCH("-build ", Build); PARSE_BOOL_SWITCH("-skipcompile ", SkipCompile); PARSE_BOOL_SWITCH("-shaderdebug ", ShaderDebug); - PARSE_ARG_OPT_SWITCH("-game ", Game); + PARSE_ARG_OPT_SWITCH("-play ", Play); #endif diff --git a/Source/Engine/Engine/CommandLine.h b/Source/Engine/Engine/CommandLine.h index 6283fc02e..8b3f8324c 100644 --- a/Source/Engine/Engine/CommandLine.h +++ b/Source/Engine/Engine/CommandLine.h @@ -156,9 +156,9 @@ public: Nullable ShaderDebug; /// - /// -game !scene! ( Scene to play, can be empty to use default ) + /// -play !guid! ( Scene to play, can be empty to use default ) /// - Nullable Game; + Nullable Play; #endif };