From 7c58c9a23dbd74af34fe975cea0f4796af7f6bdc Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 24 Nov 2022 22:56:55 +0800 Subject: [PATCH 01/10] Fixed crash caused when building scripts in debug mode when a debugger is attached --- SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 23 +++++++++++++++++-- SHADE_Engine/src/Scripting/SHScriptEngine.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index 90121994..3746d1d0 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -197,12 +197,18 @@ namespace SHADE if (BUILD_SUCCESS) { // Copy to built dll to the working directory and replace - std::filesystem::copy_file("./tmp/SHADE_Scripting.dll", "SHADE_Scripting.dll", std::filesystem::copy_options::overwrite_existing); + if (!copyFile("./tmp/SHADE_Scripting.dll", "SHADE_Scripting.dll", std::filesystem::copy_options::overwrite_existing)) + { + SHLOG_ERROR("[ScriptEngine] Failed to replace scripts assembly. Scripts will remain outdated."); + } // If debug, we want to copy the PDB so that we can do script debugging if (debug) { - std::filesystem::copy_file("./tmp/SHADE_Scripting.pdb", "SHADE_Scripting.pdb", std::filesystem::copy_options::overwrite_existing); + if (!copyFile("./tmp/SHADE_Scripting.pdb", "SHADE_Scripting.pdb", std::filesystem::copy_options::overwrite_existing)) + { + SHLOG_WARNING("[ScriptEngine] Breakpoint debugging will not work as PDB cannot be updated. If you are currently debugging, stop the debugger first."); + } } oss << "[ScriptEngine] Successfully built Managed Script Assembly (" << MANAGED_SCRIPT_LIB_NAME << ")!"; @@ -591,6 +597,19 @@ namespace SHADE return false; } + bool SHScriptEngine::copyFile(const std::filesystem::path& from, const std::filesystem::path& to, const std::filesystem::copy_options options) noexcept + { + try + { + return std::filesystem::copy_file(from, to, options); + } + catch (std::exception& e) + { + SHLOG_ERROR("[ScriptEngine] Failed to copy file {} ({})", to.string(), std::string(e.what())); + return false; + } + } + DWORD SHScriptEngine::execProcess(const std::wstring& path, const std::wstring& args) { STARTUPINFOW startInfo; diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.h b/SHADE_Engine/src/Scripting/SHScriptEngine.h index ef778627..1a38a678 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.h +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.h @@ -319,6 +319,7 @@ namespace SHADE /// File path to the file to check. /// True if the file exists static bool fileExists(const std::filesystem::path& filePath); + static bool copyFile(const std::filesystem::path& from, const std::filesystem::path& to, const std::filesystem::copy_options options) noexcept; static DWORD execProcess(const std::wstring& path, const std::wstring& args); static std::wstring generateBuildCommand(bool debug); }; From 72c8a504c545b7ea53bc790a28a47ffc70738264 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 24 Nov 2022 23:22:02 +0800 Subject: [PATCH 02/10] Fixed crash from adding an element to a list of strings in the script inspector --- SHADE_Managed/src/Editor/Editor.cxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SHADE_Managed/src/Editor/Editor.cxx b/SHADE_Managed/src/Editor/Editor.cxx index 80c73d4f..8b53db1b 100644 --- a/SHADE_Managed/src/Editor/Editor.cxx +++ b/SHADE_Managed/src/Editor/Editor.cxx @@ -200,7 +200,16 @@ namespace SHADE { if (SHEditorUI::Button("Add Item")) { - System::Object^ obj = System::Activator::CreateInstance(listType); + System::Object^ obj; + if (listType == System::String::typeid) + { + // Special case for string + obj = gcnew System::String(""); + } + else + { + obj = System::Activator::CreateInstance(listType); + } iList->Add(obj); registerUndoListAddAction(listType, iList, iList->Count - 1, obj); } From 9ada99815110207e51106d881377a6e35438ebcf Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 24 Nov 2022 23:27:13 +0800 Subject: [PATCH 03/10] Fixed bug where lists failed to be deserialized correctly --- .../src/Serialisation/SerialisationUtilities.cxx | 10 +++++++++- .../src/Serialisation/SerialisationUtilities.h++ | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx b/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx index 2bf05bc5..83da64b8 100644 --- a/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx +++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx @@ -279,7 +279,15 @@ namespace SHADE for (int i = 0; i < LIST_SIZE; ++i) { // Create the object - System::Object^ obj = System::Activator::CreateInstance(elemType); + System::Object^ obj; + if (elemType == System::String::typeid) + { + obj = gcnew System::String(""); + } + else + { + obj = System::Activator::CreateInstance(elemType); + } // Set it's value if (varAssignYaml(obj, node[i])) diff --git a/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ index 04c87ef4..d2043f6b 100644 --- a/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ +++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ @@ -167,6 +167,10 @@ namespace SHADE { valueObj = 0; } + else + { + return false; + } } else { @@ -181,6 +185,10 @@ namespace SHADE valueObj = FieldType(); } } + else + { + return false; + } } } From 50232cd15faf0ec934b71a200ead3e10bdfaf1e9 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 25 Nov 2022 00:07:19 +0800 Subject: [PATCH 04/10] Fixed bug where scripts loaded after a scene change would not have serialised data --- SHADE_Managed/src/Scripts/ScriptStore.cxx | 15 ++++++++++++++- SHADE_Managed/src/Scripts/ScriptStore.hxx | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/SHADE_Managed/src/Scripts/ScriptStore.cxx b/SHADE_Managed/src/Scripts/ScriptStore.cxx index 3ffb72b2..a5a0ebc7 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.cxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.cxx @@ -74,7 +74,7 @@ namespace SHADE // Add the script in script->Initialize(GameObject(entity)); entityScriptList->Insert(System::Math::Clamp(index, 0, entityScriptList->Count), script); - if (Application::IsPlaying && !SHSceneManager::HasSceneChanged()) + if (Application::IsPlaying && !isDeserialising) { // Only call immediately if we are in game and is not loading another scene script->Awake(); @@ -423,6 +423,8 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ void ScriptStore::Init() { + isDeserialising = false; + // Create an enumerable list of script types refreshScriptTypeList(); // Get stored methods for interop variants of functions @@ -724,6 +726,10 @@ namespace SHADE bool ScriptStore::DeserialiseScripts(Entity entity, System::IntPtr yamlNodePtr) { SAFE_NATIVE_CALL_BEGIN + + // Flag that deserialization processs is ongoing + isDeserialising = true; + // Convert to pointer YAML::Node* yamlNode = reinterpret_cast(yamlNodePtr.ToPointer()); @@ -765,9 +771,16 @@ namespace SHADE Debug::LogWarning("[ScriptStore] Script with unloaded type detected, skipping."); } } + + // Unset flag for deserialization process + isDeserialising = false; + return true; SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore") + + // Unset flag for deserialization process + isDeserialising = false; return false; } diff --git a/SHADE_Managed/src/Scripts/ScriptStore.hxx b/SHADE_Managed/src/Scripts/ScriptStore.hxx index 78f8c787..f31836d8 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.hxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.hxx @@ -337,6 +337,7 @@ namespace SHADE static ScriptSet disposalQueue; static System::Collections::Generic::IEnumerable^ scriptTypeList; static System::Reflection::MethodInfo^ addScriptMethod; + static bool isDeserialising; /*-----------------------------------------------------------------------------*/ /* Helper Functions */ From 428f8f29c640aaa3ce21f8c7be7032012fefe8f0 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Fri, 25 Nov 2022 10:06:02 +0800 Subject: [PATCH 05/10] Camera collision. WIP --- Assets/Application.SHConfig | 2 +- Assets/Scenes/MainGame.shade | 1 + .../src/Camera/SHCameraArmComponent.cpp | 14 ++-- .../src/Camera/SHCameraArmComponent.h | 14 +++- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 73 +++++++++++++++++-- SHADE_Engine/src/Camera/SHCameraSystem.h | 2 +- SHADE_Managed/src/Components/CameraArm.cxx | 10 +++ SHADE_Managed/src/Components/CameraArm.hxx | 6 ++ 8 files changed, 106 insertions(+), 16 deletions(-) diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index 5673556d..370665d2 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 97158628 +Starting Scene ID: 86098106 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index 600c6161..39738932 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -8599,6 +8599,7 @@ Arm Length: 1 Look At Camera Origin: true Target Offset: {x: 0, y: 0, z: 0} + Camera Collision: true IsActive: true Scripts: - Type: SHADE_Scripting.ThirdPersonCamera diff --git a/SHADE_Engine/src/Camera/SHCameraArmComponent.cpp b/SHADE_Engine/src/Camera/SHCameraArmComponent.cpp index a0434b12..ed24e6a7 100644 --- a/SHADE_Engine/src/Camera/SHCameraArmComponent.cpp +++ b/SHADE_Engine/src/Camera/SHCameraArmComponent.cpp @@ -7,8 +7,8 @@ namespace SHADE { SHCameraArmComponent::SHCameraArmComponent() - :pitch(0.0f), yaw(0.0f), armLength(1.0f),offset(), dirty(true), lookAtCameraOrigin(true) - , targetOffset(0.0f) + :pitch(0.0f), yaw(0.0f), armLength(1.0f), offset(), enableCameraCollision(false), lookAtCameraOrigin(true) + , targetOffset(0.0f),ray() { } @@ -39,22 +39,23 @@ namespace SHADE return targetOffset; } + void SHCameraArmComponent::SetPitch(float pitch) noexcept { this->pitch = pitch; - dirty = true; + } void SHCameraArmComponent::SetYaw(float yaw) noexcept { this->yaw = yaw; - dirty = true; + //dirty = true; } void SHCameraArmComponent::SetArmLength(float length) noexcept { this->armLength = length; - dirty = true; + //dirty = true; } void SHCameraArmComponent::SetTargetOffset(SHVec3 offset) noexcept @@ -62,6 +63,8 @@ namespace SHADE this->targetOffset = offset; } + + }//namespace SHADE @@ -76,6 +79,7 @@ RTTR_REGISTRATION .property("Arm Length", &SHCameraArmComponent::GetArmLength, &SHCameraArmComponent::SetArmLength) .property("Look At Camera Origin", &SHCameraArmComponent::lookAtCameraOrigin) .property("Target Offset", &SHCameraArmComponent::GetTargetOffset, &SHCameraArmComponent::SetTargetOffset) + .property("Camera Collision", &SHCameraArmComponent::enableCameraCollision) ; } \ No newline at end of file diff --git a/SHADE_Engine/src/Camera/SHCameraArmComponent.h b/SHADE_Engine/src/Camera/SHCameraArmComponent.h index 0dc74299..9d8ec853 100644 --- a/SHADE_Engine/src/Camera/SHCameraArmComponent.h +++ b/SHADE_Engine/src/Camera/SHCameraArmComponent.h @@ -5,9 +5,14 @@ #include "ECS_Base/Components/SHComponent.h" #include "Math/SHMatrix.h" #include "SH_API.h" +#include "Math/SHRay.h" namespace SHADE { + + class SHBox; + class SHRay; + class SH_API SHCameraArmComponent final: public SHComponent { private: @@ -15,15 +20,18 @@ namespace SHADE float yaw; float armLength; - bool dirty; + SHVec3 offset; SHVec3 targetOffset; + SHRay ray; + public: friend class SHCameraSystem; SHCameraArmComponent(); virtual ~SHCameraArmComponent() = default; bool lookAtCameraOrigin; + bool enableCameraCollision; //Getters //SHMatrix const& GetMatrix() const noexcept; SHVec3 const& GetOffset() const noexcept; @@ -31,12 +39,14 @@ namespace SHADE float GetYaw() const noexcept; float GetArmLength() const noexcept; SHVec3 GetTargetOffset() const noexcept; + //Setters void SetPitch(float pitch) noexcept; void SetYaw(float yaw) noexcept; void SetArmLength(float length) noexcept; - void SetTargetOffset(SHVec3 offset)noexcept; + void SetTargetOffset(SHVec3 offset) noexcept; + protected: diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index a312f1a8..8ef7ff64 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -10,6 +10,10 @@ #include "Scene/SHSceneManager.h" #include "ECS_Base/Managers/SHSystemManager.h" #include "Editor/SHEditor.h" +#include "Math/Geometry/SHBox.h" +#include "Math/SHRay.h" +#include "Physics/System/SHPhysicsSystem.h" + namespace SHADE { @@ -96,7 +100,7 @@ namespace SHADE if (editorCameraArm.armLength < 1.0f) editorCameraArm.armLength = 1.0f; - UpdatePivotArmComponent(editorCameraArm); + UpdateCameraArmComponent(editorCameraArm); editorCamera.offset = editorCameraArm.GetOffset(); @@ -132,10 +136,12 @@ namespace SHADE return &editorCamera; } - void SHCameraSystem::UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept + void SHCameraSystem::UpdateCameraArmComponent(SHCameraArmComponent& pivot) noexcept { - if (pivot.dirty) - { + + + + SHVec3 offset{ 0.0f,0.0f, pivot.GetArmLength() }; offset = SHVec3::RotateX(offset, -(SHMath::DegreesToRadians(pivot.GetPitch()))); @@ -145,10 +151,61 @@ namespace SHADE //pivot.rtMatrix = SHMatrix::RotateX(SHMath::DegreesToRadians(pivot.GetPitch())) // * SHMatrix::RotateY(SHMath::DegreesToRadians(pivot.GetYaw())) // * SHMatrix::Translate(SHVec3(0.0f , 0.0f, pivot.GetArmLength())); - pivot.offset = offset; + if (!pivot.enableCameraCollision) + { + + return; + } + + SHCameraComponent* camera = SHComponentManager::GetComponent_s(pivot.GetEID()); + SHTransformComponent* transform = SHComponentManager::GetComponent_s(pivot.GetEID()); + auto physicsSystem = SHSystemManager::GetSystem(); + + + + + if (camera == nullptr || transform == nullptr) + return; + + + /*if (SHComponentManager::HasComponent(camera->GetEID()) == true && camera != &editorCamera) + { + auto transform = SHComponentManager::GetComponent(camera->GetEID()); + SHVec3 rotation = transform->GetWorldRotation(); + camera->pitch = SHMath::RadiansToDegrees(rotation.x); + camera->yaw = SHMath::RadiansToDegrees(rotation.y); + camera->roll = SHMath::RadiansToDegrees(rotation.z); + camera->position = transform->GetWorldPosition(); + camera->dirtyView = true; + }*/ + + + pivot.ray.position = camera->GetPosition() + pivot.targetOffset; + pivot.ray.direction = SHVec3::Normalise((camera->position + offset)- pivot.ray.position); + + //SHLOG_INFO("Ray position: {},{},{} direction:{},{},{}",pivot.ray.position.x, pivot.ray.position.y, pivot.ray.position.z,pivot.ray.direction.x, pivot.ray.direction.y, pivot.ray.direction.z) + + auto result = physicsSystem->Raycast(pivot.ray ); + if (result && result.distance < pivot.GetArmLength()) + { + + SHVec3 newOffset = SHVec3{ 0.0f,0.0f, result.distance * 0.8f }; + newOffset = SHVec3::RotateX(newOffset, -(SHMath::DegreesToRadians(pivot.GetPitch()))); + newOffset = SHVec3::RotateY(newOffset, (SHMath::DegreesToRadians(pivot.GetYaw()))); + pivot.offset = newOffset; + //SHLOG_INFO("CAMERA COLLISION HIT, {}", result.distance); + } + else + { + //SHLOG_INFO("CAMERA COLLISION CANT HIT CAMERA"); + } + + + + // pivot.rtMatrix = SHMatrix::Inverse(pivot.rtMatrix); - } + } @@ -291,7 +348,7 @@ namespace SHADE for (auto& pivot : pivotDense) { if(SHSceneManager::CheckNodeAndComponentsActive(pivot.GetEID())) - system->UpdatePivotArmComponent(pivot); + system->UpdateCameraArmComponent(pivot); } for (auto& cam : dense) @@ -390,7 +447,9 @@ namespace SHADE } void SHCameraSystem::SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept { + SHVec3 pos; DecomposeViewMatrix(viewMatrix, camera.pitch, camera.yaw, camera.roll, camera.position); + camera.dirtyView = true; } diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.h b/SHADE_Engine/src/Camera/SHCameraSystem.h index d40f9a6c..ee93f9a9 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.h +++ b/SHADE_Engine/src/Camera/SHCameraSystem.h @@ -26,7 +26,7 @@ namespace SHADE void UpdateCameraComponent(SHCameraComponent& camera) noexcept; - void UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept; + void UpdateCameraArmComponent(SHCameraArmComponent& pivot) noexcept; diff --git a/SHADE_Managed/src/Components/CameraArm.cxx b/SHADE_Managed/src/Components/CameraArm.cxx index dc2bc42d..7658663e 100644 --- a/SHADE_Managed/src/Components/CameraArm.cxx +++ b/SHADE_Managed/src/Components/CameraArm.cxx @@ -49,6 +49,16 @@ namespace SHADE GetNativeComponent()->lookAtCameraOrigin = val; } + bool CameraArm::EnableCameraCollision::get() + { + return GetNativeComponent()->enableCameraCollision; + } + + void CameraArm::EnableCameraCollision::set(bool val) + { + GetNativeComponent()->enableCameraCollision = val; + } + Vector3 CameraArm::TargetOffset::get() { return Convert::ToCLI(GetNativeComponent()->GetTargetOffset()); diff --git a/SHADE_Managed/src/Components/CameraArm.hxx b/SHADE_Managed/src/Components/CameraArm.hxx index 7ea36bf0..09a4b6df 100644 --- a/SHADE_Managed/src/Components/CameraArm.hxx +++ b/SHADE_Managed/src/Components/CameraArm.hxx @@ -36,6 +36,12 @@ namespace SHADE void set(bool val); } + property bool EnableCameraCollision + { + bool get(); + void set(bool val); + } + property Vector3 TargetOffset { Vector3 get(); From d72a53262348b1c4bc5477dbe3298cadab094a5a Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Fri, 25 Nov 2022 12:09:03 +0800 Subject: [PATCH 06/10] Added object checks in leaf scripts --- Assets/Scenes/MainGame.shade | 10 +--------- .../AIBehaviour/Implemented/LeafNodes/LeafAttack.cs | 10 ++++++++-- .../AIBehaviour/Implemented/LeafNodes/LeafPatrol.cs | 8 +++++++- Assets/Scripts/SC_MainMenu.cs | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index 39738932..718c2f03 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -8676,15 +8676,7 @@ Scripts: - Type: Homeowner1 Enabled: true - player: 2 - waypoints: - - [2.70000005, 0, -2] - - [-0.300000012, 0, -2.70000005] - - [-2, 0, -3.79999995] - - [-4, 0, -2.0999999] - - [-2.9000001, 0, 2.4000001] - - [-1, 0, 4] - - [2.70000005, 0, 4] + waypointsPool: 51000 patrolSpeed: 1 chaseSpeed: 2 turningSpeed: 5 diff --git a/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafAttack.cs b/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafAttack.cs index e64b63ad..15c0ed67 100644 --- a/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafAttack.cs +++ b/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafAttack.cs @@ -40,8 +40,14 @@ public partial class LeafAttack : BehaviourTreeNode onEnter(BehaviourTreeNodeStatus.RUNNING); - //Succeed when stand in hurt box for long enough - float captureTime = (float)GetNodeData("captureTimeLeft"); + //Succeed when stand in hurt box for long enough + object timeObj = GetNodeData("captureTimeLeft"); + if (timeObj == null) + { + return BehaviourTreeNodeStatus.FAILURE; + } + + float captureTime = (float)GetNodeData("captureTimeLeft"); captureTime -= Time.DeltaTimeF; SetNodeData("captureTimeLeft", captureTime); //Debug.Log(captureTime.ToString()); diff --git a/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafPatrol.cs b/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafPatrol.cs index 248fa8b9..802157cf 100644 --- a/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafPatrol.cs +++ b/Assets/Scripts/AIBehaviour/Implemented/LeafNodes/LeafPatrol.cs @@ -83,7 +83,13 @@ public partial class LeafPatrol : BehaviourTreeNode return; } - waypoints = (List)GetNodeData("waypoints"); + object waypoint = GetNodeData("waypoints"); + if (waypoint == null) + { + return; + } + + waypoints = (List)waypoint; Vector3 targetPosition = waypoints[currentWaypointIndex].GetComponent().GlobalPosition; //Reach waypoint by X and Z being near enough diff --git a/Assets/Scripts/SC_MainMenu.cs b/Assets/Scripts/SC_MainMenu.cs index 0cc5d0dd..05b72ef3 100644 --- a/Assets/Scripts/SC_MainMenu.cs +++ b/Assets/Scripts/SC_MainMenu.cs @@ -12,7 +12,7 @@ public class MainMenu : Script if (Input.GetKey(Input.KeyCode.Space)) { Audio.PlaySFXOnce2D("event:/UI/mouse_down_element"); - SceneManager.ChangeScene(86098106); + SceneManager.ChangeScene(89830755); Audio.StopAllSounds(); } From 300647afa6e7b09b0b21a65834bdb387a8b70c53 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Fri, 25 Nov 2022 12:24:13 +0800 Subject: [PATCH 07/10] Stopped camera from running when editor is in pause --- SHADE_Engine/src/Camera/SHCameraSystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.h b/SHADE_Engine/src/Camera/SHCameraSystem.h index ee93f9a9..db680adb 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.h +++ b/SHADE_Engine/src/Camera/SHCameraSystem.h @@ -41,7 +41,7 @@ namespace SHADE class SH_API CameraSystemUpdate final: public SHSystemRoutine { public: - CameraSystemUpdate() : SHSystemRoutine("Camera System Update", true) {}; + CameraSystemUpdate() : SHSystemRoutine("Camera System Update", false) {}; virtual void Execute(double dt)noexcept override final; }; friend class CameraSystemUpdate; From 73d0486fc81230ca76ceb7945099707afc46690d Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 25 Nov 2022 13:05:35 +0800 Subject: [PATCH 08/10] Added support for enabling and disabling components --- SHADE_Managed/src/Components/Component.cxx | 8 ++++++++ SHADE_Managed/src/Components/Component.hxx | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/SHADE_Managed/src/Components/Component.cxx b/SHADE_Managed/src/Components/Component.cxx index 7f56fad3..91fb73bb 100644 --- a/SHADE_Managed/src/Components/Component.cxx +++ b/SHADE_Managed/src/Components/Component.cxx @@ -22,6 +22,14 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + GameObject BaseComponent::Owner::get() + { + return owner; + } + /*---------------------------------------------------------------------------------*/ /* Component Access Functions */ /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Components/Component.hxx b/SHADE_Managed/src/Components/Component.hxx index a1d83eaf..9f3702e1 100644 --- a/SHADE_Managed/src/Components/Component.hxx +++ b/SHADE_Managed/src/Components/Component.hxx @@ -36,7 +36,7 @@ namespace SHADE /// property GameObject Owner { - GameObject get() { return owner; } + GameObject get(); } /*-----------------------------------------------------------------------------*/ @@ -166,6 +166,19 @@ namespace SHADE template public ref class Component : public BaseComponent { + public: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Whether or not the Component is active and being updated by the engine. + /// + property bool Enabled + { + bool get() { return GetNativeComponent()->isActive; } + void set(bool value) { GetNativeComponent()->isActive = value; } + } + internal: /*-----------------------------------------------------------------------------*/ /* Type Definitions */ From 43a5cb4deba05367dd95b60aab4668bcc1564139 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Fri, 25 Nov 2022 14:05:43 +0800 Subject: [PATCH 09/10] Reverted world extents computation --- SHADE_Engine/src/Physics/Interface/SHColliderComponent.cpp | 2 ++ SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp | 2 +- .../src/Physics/System/SHPhysicsSystemRoutines.cpp | 7 ++----- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/SHADE_Engine/src/Physics/Interface/SHColliderComponent.cpp b/SHADE_Engine/src/Physics/Interface/SHColliderComponent.cpp index 135e7e42..d7db2c64 100644 --- a/SHADE_Engine/src/Physics/Interface/SHColliderComponent.cpp +++ b/SHADE_Engine/src/Physics/Interface/SHColliderComponent.cpp @@ -107,6 +107,7 @@ namespace SHADE const SHVec3& RELATIVE_EXTENTS = box->GetRelativeExtents(); // Recompute world extents based on new scale and fixed relative extents + const SHVec3 WORLD_EXTENTS = RELATIVE_EXTENTS * (scale * 0.5f); box->SetWorldExtents(WORLD_EXTENTS); @@ -118,6 +119,7 @@ namespace SHADE const float RELATIVE_RADIUS = sphere->GetRelativeRadius(); // Recompute world radius based on new scale and fixed radius + const float MAX_SCALE = SHMath::Max({ scale.x, scale.y, scale.z }); const float WORLD_RADIUS = RELATIVE_RADIUS * MAX_SCALE * 0.5f; sphere->SetWorldRadius(WORLD_RADIUS); diff --git a/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp b/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp index 43906c22..f597077f 100644 --- a/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp +++ b/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp @@ -206,7 +206,7 @@ namespace SHADE } // Set the half extents relative to world scale - const SHVec3 WORLD_EXTENTS = correctedHalfExtents * COLLIDER->GetScale(); + const SHVec3 WORLD_EXTENTS = correctedHalfExtents * COLLIDER->GetScale() * 0.5f; if (type != Type::BOX) { diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp index 6168d673..89224628 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp @@ -309,12 +309,9 @@ namespace SHADE { colliderComponent->position = WORLD_POS; colliderComponent->orientation = WORLD_ROT; + colliderComponent->scale = WORLD_SCL; - if (colliderComponent->scale != WORLD_SCL) - { - colliderComponent->scale = WORLD_SCL; - colliderComponent->RecomputeCollisionShapes(); - } + colliderComponent->RecomputeCollisionShapes(); } } From afd2abf036e4270178670f11a84256f1d6e5dad8 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Fri, 25 Nov 2022 14:06:20 +0800 Subject: [PATCH 10/10] Fixed pre & post physics transforms update routines --- Assets/Scenes/M2Scene.shade | 10 +------- SHADE_Engine/src/Math/SHMathHelpers.hpp | 2 +- .../src/Math/Transform/SHTransformSystem.cpp | 24 ++++++++++++++++++- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Assets/Scenes/M2Scene.shade b/Assets/Scenes/M2Scene.shade index ff5e5fd6..76ed77af 100644 --- a/Assets/Scenes/M2Scene.shade +++ b/Assets/Scenes/M2Scene.shade @@ -82,7 +82,7 @@ Transform Component: Translate: {x: 0, y: 4.28833103, z: 0} Rotate: {x: -0, y: 0, z: -0} - Scale: {x: 1, y: 1, z: 1} + Scale: {x: 1, y: 0, z: 1} IsActive: true RigidBody Component: Type: Dynamic @@ -108,14 +108,6 @@ Density: 1 Position Offset: {x: 0, y: 0, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} - - Is Trigger: false - Type: Box - Half Extents: {x: 2, y: 2, z: 2} - Friction: 0.400000006 - Bounciness: 0 - Density: 1 - Position Offset: {x: 0, y: 0, z: 0} - Rotation Offset: {x: 0, y: 0, z: 0} IsActive: true Scripts: ~ - EID: 65537 diff --git a/SHADE_Engine/src/Math/SHMathHelpers.hpp b/SHADE_Engine/src/Math/SHMathHelpers.hpp index cdbe1643..554fa317 100644 --- a/SHADE_Engine/src/Math/SHMathHelpers.hpp +++ b/SHADE_Engine/src/Math/SHMathHelpers.hpp @@ -53,7 +53,7 @@ namespace SHADE for (auto value : values) { - max = Min(max, value); + max = Max(max, value); } return max; diff --git a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp index 38d44984..03de360d 100644 --- a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp +++ b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp @@ -18,6 +18,7 @@ #include "ECS_Base/Managers/SHComponentManager.h" #include "ECS_Base/Managers/SHEntityManager.h" #include "ECS_Base/Managers/SHSystemManager.h" +#include "Editor/SHEditor.h" #include "Math/SHMathHelpers.h" namespace SHADE @@ -35,7 +36,7 @@ namespace SHADE {} SHTransformSystem::TransformPostPhysicsUpdate::TransformPostPhysicsUpdate() - : SHSystemRoutine { "Transform Post-Physics Update", false } + : SHSystemRoutine { "Transform Post-Physics Update", true } {} @@ -54,7 +55,28 @@ namespace SHADE { // Get the current scene graph to traverse and update const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); + +#ifdef SHEDITOR + + // When editor is not in play, only clear all dirty flags. No update required. + + const auto* EDITOR = SHSystemManager::GetSystem(); + if (EDITOR && EDITOR->editorState != SHEditor::State::PLAY) + { + auto& transformsSet = SHComponentManager::GetDense(); + for (auto& tfComp : transformsSet) + tfComp.dirty = false; + } + else + { + UpdateEntity(SCENE_GRAPH.GetRoot(), true); + } + +#else + UpdateEntity(SCENE_GRAPH.GetRoot(), true); + +#endif } void SHTransformSystem::Init()