From 03de914dbcf1a496316069cfb7bbbc2748666eee Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 7 Aug 2024 12:16:07 -0500 Subject: [PATCH 1/2] Add Requesting engine exit event. Expose Fatal erro and requesting exit to c# --- Source/Engine/Engine/Base/GameBase.cpp | 1 + Source/Engine/Engine/Engine.cpp | 3 +++ Source/Engine/Engine/Engine.h | 5 +++++ Source/Engine/Engine/Globals.h | 13 ++++++++++++- Source/Engine/Platform/Base/PlatformBase.cpp | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Engine/Base/GameBase.cpp b/Source/Engine/Engine/Base/GameBase.cpp index 5fb28a118..ea4201142 100644 --- a/Source/Engine/Engine/Base/GameBase.cpp +++ b/Source/Engine/Engine/Base/GameBase.cpp @@ -199,6 +199,7 @@ void GameBaseImpl::OnMainWindowClosed() // Request engine exit Globals::IsRequestingExit = true; + Engine::RequestingExit(); } void GameBaseImpl::OnPostRender(GPUContext* context, RenderContext& renderContext) diff --git a/Source/Engine/Engine/Engine.cpp b/Source/Engine/Engine/Engine.cpp index af62e0b6e..b26cbd25a 100644 --- a/Source/Engine/Engine/Engine.cpp +++ b/Source/Engine/Engine/Engine.cpp @@ -70,6 +70,7 @@ Action Engine::LateFixedUpdate; Action Engine::Draw; Action Engine::Pause; Action Engine::Unpause; +Action Engine::RequestingExit; Window* Engine::MainWindow = nullptr; int32 Engine::Main(const Char* cmdLine) @@ -259,10 +260,12 @@ void Engine::RequestExit(int32 exitCode) { Globals::IsRequestingExit = true; Globals::ExitCode = exitCode; + RequestingExit(); } #else Globals::IsRequestingExit = true; Globals::ExitCode = exitCode; + RequestingExit(); #endif } diff --git a/Source/Engine/Engine/Engine.h b/Source/Engine/Engine/Engine.h index 15285a07e..85ffefda0 100644 --- a/Source/Engine/Engine/Engine.h +++ b/Source/Engine/Engine/Engine.h @@ -79,6 +79,11 @@ public: /// static Action Unpause; + /// + /// Event called when the engine is requesting exit. + /// + API_EVENT() static Action RequestingExit; + public: /// diff --git a/Source/Engine/Engine/Globals.h b/Source/Engine/Engine/Globals.h index 79b4955a3..670eecd4c 100644 --- a/Source/Engine/Engine/Globals.h +++ b/Source/Engine/Engine/Globals.h @@ -2,6 +2,7 @@ #pragma once +#include "Engine/Core/Delegate.h" #include "Engine/Scripting/ScriptingType.h" #include "Engine/Input/Enums.h" @@ -59,9 +60,19 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Globals); // True if fatal error occurred (engine is exiting) static bool FatalErrorOccurred; - // True if engine need to be closed + // True if engine needs to be closed static bool IsRequestingExit; + /// + /// True if engine needs to be closed + /// + API_PROPERTY() FORCE_INLINE static bool GetIsRequestingExit() { return IsRequestingExit; } + + /// + /// True if fatal error occurred (engine is exiting) + /// + API_PROPERTY() FORCE_INLINE static bool GetFatalErrorOccurred() { return FatalErrorOccurred; } + // Exit code static int32 ExitCode; diff --git a/Source/Engine/Platform/Base/PlatformBase.cpp b/Source/Engine/Platform/Base/PlatformBase.cpp index 8a6baf4bc..6efa3c8b4 100644 --- a/Source/Engine/Platform/Base/PlatformBase.cpp +++ b/Source/Engine/Platform/Base/PlatformBase.cpp @@ -271,6 +271,7 @@ void PlatformBase::Fatal(const Char* msg, void* context) Globals::FatalErrorOccurred = true; Globals::IsRequestingExit = true; Globals::ExitCode = -1; + Engine::RequestingExit(); // Collect crash info (platform-dependant implementation that might collect stack trace and/or create memory dump) { From a6b4f2fc63d4b520d63bf4ccd66825a33becc0a7 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 15 Aug 2024 08:07:04 -0500 Subject: [PATCH 2/2] Remove extra include. --- Source/Engine/Engine/Globals.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Engine/Engine/Globals.h b/Source/Engine/Engine/Globals.h index 670eecd4c..5e58d5039 100644 --- a/Source/Engine/Engine/Globals.h +++ b/Source/Engine/Engine/Globals.h @@ -2,7 +2,6 @@ #pragma once -#include "Engine/Core/Delegate.h" #include "Engine/Scripting/ScriptingType.h" #include "Engine/Input/Enums.h"