Add auto-exit command line to editor

This commit is contained in:
Wojtek Figat
2024-12-04 18:41:36 +01:00
parent 2f16694529
commit 848dbdf532
6 changed files with 51 additions and 17 deletions

View File

@@ -176,7 +176,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[4];
void* args[2];
MClass* mclass = GetClass();
if (mclass == nullptr)
{
@@ -193,18 +193,22 @@ void ManagedEditor::Init()
LOG(Fatal, "Failed to create editor instance.");
}
MObject* exception = nullptr;
bool isHeadless = CommandLine::Options.Headless.IsTrue();
bool skipCompile = CommandLine::Options.SkipCompile.IsTrue();
bool newProject = CommandLine::Options.NewProject.IsTrue();
args[0] = &isHeadless;
args[1] = &skipCompile;
args[2] = &newProject;
StartupFlags flags = StartupFlags::None;
if (CommandLine::Options.Headless.IsTrue())
flags |= StartupFlags::Headless;
if (CommandLine::Options.SkipCompile.IsTrue())
flags |= StartupFlags::SkipCompile;
if (CommandLine::Options.NewProject.IsTrue())
flags |= StartupFlags::NewProject;
if (CommandLine::Options.Exit.IsTrue())
flags |= StartupFlags::Exit;
args[0] = &flags;
Guid sceneId;
if (!CommandLine::Options.Play.HasValue() || (CommandLine::Options.Play.HasValue() && Guid::Parse(CommandLine::Options.Play.GetValue(), sceneId)))
{
sceneId = Guid::Empty;
}
args[3] = &sceneId;
args[1] = &sceneId;
initMethod->Invoke(instance, args, &exception);
if (exception)
{
@@ -219,7 +223,7 @@ void ManagedEditor::Init()
WasExitCalled = false;
// Load scripts if auto-load on startup is disabled
if (!ManagedEditorOptions.ForceScriptCompilationOnStartup || skipCompile)
if (!ManagedEditorOptions.ForceScriptCompilationOnStartup || EnumHasAllFlags(flags, StartupFlags::SkipCompile))
{
LOG(Info, "Loading managed assemblies (due to disabled compilation on startup)");
Scripting::Load();

View File

@@ -22,6 +22,15 @@ API_CLASS(Namespace="FlaxEditor", Name="Editor", NoSpawn, NoConstructor) class M
DECLARE_SCRIPTING_TYPE_NO_SPAWN(ManagedEditor);
static Guid ObjectID;
API_ENUM(Attributes="Flags", Internal) enum class StartupFlags
{
None = 0,
Headless = 1,
SkipCompile = 2,
NewProject = 4,
Exit = 8,
};
struct InternalOptions
{
byte AutoReloadScriptsOnMainWindowFocus = 1;
@@ -258,3 +267,5 @@ public:
// [ScriptingObject]
void DestroyManaged() override;
};
DECLARE_ENUM_OPERATORS(ManagedEditor::StartupFlags);