From ffddbb455f36c65af0bd3a7f9662fd636265340f Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 9 Jul 2024 11:57:41 +0200 Subject: [PATCH] Add Scripting events to C++ api similar to C# ones --- Source/Engine/Scripting/Scripting.cpp | 10 +++++++-- Source/Engine/Scripting/Scripting.h | 30 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Scripting/Scripting.cpp b/Source/Engine/Scripting/Scripting.cpp index 67806a2ee..e5e5d1543 100644 --- a/Source/Engine/Scripting/Scripting.cpp +++ b/Source/Engine/Scripting/Scripting.cpp @@ -156,6 +156,12 @@ Action Scripting::ScriptsLoaded; Action Scripting::ScriptsUnload; Action Scripting::ScriptsReloading; Action Scripting::ScriptsReloaded; +Action Scripting::Update; +Action Scripting::LateUpdate; +Action Scripting::FixedUpdate; +Action Scripting::LateFixedUpdate; +Action Scripting::Draw; +Action Scripting::Exit; ThreadLocal Scripting::ObjectsLookupIdMapping; ScriptingService ScriptingServiceInstance; @@ -205,9 +211,9 @@ bool ScriptingService::Init() } #if COMPILE_WITHOUT_CSHARP -#define INVOKE_EVENT(name) +#define INVOKE_EVENT(name) Scripting::name(); #else -#define INVOKE_EVENT(name) \ +#define INVOKE_EVENT(name) Scripting::name(); \ if (!_isEngineAssemblyLoaded) return; \ if (_method_##name == nullptr) \ { \ diff --git a/Source/Engine/Scripting/Scripting.h b/Source/Engine/Scripting/Scripting.h index dad5a02fb..1a616ed79 100644 --- a/Source/Engine/Scripting/Scripting.h +++ b/Source/Engine/Scripting/Scripting.h @@ -44,6 +44,36 @@ public: /// static Delegate<> ScriptsReloaded; +public: + /// + /// Occurs on scripting update. + /// + static Delegate<> Update; + + /// + /// Occurs on scripting late update. + /// + static Delegate<> LateUpdate; + + /// + /// Occurs on scripting fixed update. + /// + static Delegate<> FixedUpdate; + + /// + /// Occurs on scripting late fixed update. + /// + static Delegate<> LateFixedUpdate; + + /// + /// Occurs on scripting draw update. Called during frame rendering and can be used to invoke custom rendering with GPUDevice. + /// + static Delegate<> Draw; + + /// + /// Occurs when scripting engine is disposing. Engine is during closing and some services may be unavailable (eg. loading scenes). This may be called after the engine fatal error event. + /// + static Delegate<> Exit; public: ///