From f8391d6c9e6bf3ae48bf2b8dbe1e84a06e36c566 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 23 Sep 2022 16:45:06 +0800 Subject: [PATCH] Modified TestScene space bar input to not destroy the object, only remove scripts --- SHADE_Application/src/Scenes/SBTestScene.cpp | 7 +++++-- SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 12 ++++++------ SHADE_Engine/src/Scripting/SHScriptEngine.h | 6 +++--- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index 1c4af3a7..f5985715 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -47,7 +47,7 @@ namespace Sandbox renderable.SetMaterial(matInst); SHADE::SHScriptEngine* scriptEngine = static_cast(SHADE::SHSystemManager::GetSystem()); - scriptEngine->AddScript(*SHADE::SHEntityManager::GetEntityByID(testObj), "TestScript"); + scriptEngine->AddScript(testObj, "TestScript"); } void SBTestScene::Update(float dt) @@ -61,7 +61,10 @@ namespace Sandbox // Destroy entity if space is pressed if (GetKeyState(VK_SPACE) & 0x8000) - SHADE::SHEntityManager::DestroyEntity(testObj); + { + SHADE::SHScriptEngine* scriptEngine = static_cast(SHADE::SHSystemManager::GetSystem()); + scriptEngine->RemoveAllScripts(testObj); + } } void SBTestScene::Render() diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index fada5b70..0c508a34 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -103,17 +103,17 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ /* Script Manipulation Functions */ /*-----------------------------------------------------------------------------------*/ - bool SHScriptEngine::AddScript(const SHEntity& entity, const std::string_view& scriptName) + bool SHScriptEngine::AddScript(EntityID entity, const std::string_view& scriptName) { - return csScriptsAdd(entity.GetEID(), scriptName.data()); + return csScriptsAdd(entity, scriptName.data()); } - void SHScriptEngine::RemoveAllScripts(const SHEntity& entity) + void SHScriptEngine::RemoveAllScripts(EntityID entity) { - csScriptsRemoveAll(entity.GetEID()); + csScriptsRemoveAll(entity); } - void SHScriptEngine::RemoveAllScriptsImmediately(const SHEntity& entity, bool callOnDestroy) + void SHScriptEngine::RemoveAllScriptsImmediately(EntityID entity, bool callOnDestroy) { - csScriptsRemoveAllImmediately(entity.GetEID(), callOnDestroy); + csScriptsRemoveAllImmediately(entity, callOnDestroy); } /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.h b/SHADE_Engine/src/Scripting/SHScriptEngine.h index 0994bb5d..08852e90 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.h +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.h @@ -116,14 +116,14 @@ namespace SHADE /// True if successfully added. False otherwise with the error logged to the /// console. /// - bool AddScript(const SHEntity& entity, const std::string_view& scriptName); + bool AddScript(EntityID entity, const std::string_view& scriptName); /// /// Removes all Scripts attached to the specified Entity. Does not do anything /// if the specified Entity is invalid or does not have any Scripts /// attached. /// /// The entity to remove the scripts from. - void RemoveAllScripts(const SHEntity& entity); + void RemoveAllScripts(EntityID entity); /// /// Removes all Scripts attached to the specified Entity. Unlike /// RemoveAllScripts(), this removes all the scripts immediately. @@ -135,7 +135,7 @@ namespace SHADE /// Whether or not to call OnDestroy on the scripts. This is ignored if not in /// play mode. /// - void RemoveAllScriptsImmediately(const SHEntity& entity, bool callOnDestroy); + void RemoveAllScriptsImmediately(EntityID entity, bool callOnDestroy); /*-----------------------------------------------------------------------------*/ /* Script Serialisation Functions */