diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index acd7d014..0fb8adf9 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -33,6 +33,7 @@ #include "Physics/System/SHPhysicsSystem.h" #include "Physics/System/SHPhysicsDebugDrawSystem.h" #include "Scripting/SHScriptEngine.h" +#include "UI/SHUISystem.h" // Components #include "Graphics/MiddleEnd/Interface/SHRenderable.h" @@ -77,6 +78,7 @@ namespace Sandbox SHSystemManager::CreateSystem(); SHSystemManager::CreateSystem(); + SHSystemManager::CreateSystem(); SHSystemManager::CreateSystem(); @@ -120,6 +122,8 @@ namespace Sandbox SHSystemManager::RegisterRoutine(); //SHSystemManager::RegisterRoutine(); + SHSystemManager::RegisterRoutine(); + SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); #ifdef SHEDITOR diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index f9b5cf41..1569a13c 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -143,6 +143,18 @@ namespace SHADE return result; } + AssetType SHAssetManager::GetType(AssetID id) noexcept + { + if (assetCollection.contains(id)) + { + return assetCollection[id].type; + } + + SHLOG_WARNING("AssetID {}, does not belong to an asset", id) + + return AssetType::INVALID; + } + std::optional SHAssetManager::GetAsset(AssetID id) noexcept { if (assetCollection.contains(id)) diff --git a/SHADE_Engine/src/Assets/SHAssetManager.h b/SHADE_Engine/src/Assets/SHAssetManager.h index 9d0a0bf4..6cac6c71 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.h +++ b/SHADE_Engine/src/Assets/SHAssetManager.h @@ -52,6 +52,8 @@ namespace SHADE static std::vector GetAllAssets() noexcept; static std::optional GetAsset(AssetID id) noexcept; + static AssetType GetType(AssetID id) noexcept; + /**************************************************************************** * \brief Create record for new resource. CAN ONLY CREATE FOR CUSTOM * RESOURCES CREATED BY THE ENGINE. diff --git a/SHADE_Engine/src/Camera/SHCameraComponent.cpp b/SHADE_Engine/src/Camera/SHCameraComponent.cpp index ac451df5..7fc71db1 100644 --- a/SHADE_Engine/src/Camera/SHCameraComponent.cpp +++ b/SHADE_Engine/src/Camera/SHCameraComponent.cpp @@ -12,7 +12,7 @@ namespace SHADE :yaw(0.0f), pitch(0.0f), roll(0.0f) , width(1920.0f), height(1080.0f), zNear(0.01f), zFar(10000.0f), fov(90.0f), movementSpeed(1.0f), turnSpeed(0.5f) , perspProj(true), dirtyView(true), dirtyProj(true) - , viewMatrix(), projMatrix() + , viewMatrix(), perspProjMatrix(), orthoProjMatrix() , position(), offset() { ComponentFamily::GetID(); @@ -213,9 +213,22 @@ namespace SHADE const SHMatrix& SHCameraComponent::GetProjMatrix() const noexcept { - return projMatrix; + if (perspProj) + return perspProjMatrix; + else + return orthoProjMatrix; } + const SHMatrix& SHCameraComponent::GetOrthoMatrix() const noexcept + { + return orthoProjMatrix; + } + + const SHMatrix& SHCameraComponent::GetPerspectiveMatrix() const noexcept + { + return orthoProjMatrix; + } + //void SHCameraComponent::SetMainCamera(size_t directorCameraIndex) noexcept //{ // auto system = SHSystemManager::GetSystem(); diff --git a/SHADE_Engine/src/Camera/SHCameraComponent.h b/SHADE_Engine/src/Camera/SHCameraComponent.h index b778b8fa..b0999fe9 100644 --- a/SHADE_Engine/src/Camera/SHCameraComponent.h +++ b/SHADE_Engine/src/Camera/SHCameraComponent.h @@ -29,12 +29,14 @@ namespace SHADE SHMatrix viewMatrix; - SHMatrix projMatrix; + SHMatrix perspProjMatrix; + SHMatrix orthoProjMatrix; SHVec3 position; bool perspProj; SHVec3 offset; + public: @@ -78,6 +80,8 @@ namespace SHADE const SHMatrix& GetViewMatrix() const noexcept; const SHMatrix& GetProjMatrix() const noexcept; + const SHMatrix& GetOrthoMatrix() const noexcept; + const SHMatrix& GetPerspectiveMatrix() const noexcept; //void SetMainCamera(size_t cameraDirectorIndex = 0) noexcept; diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.cpp b/SHADE_Engine/src/Camera/SHCameraDirector.cpp index 9e9ddb5c..ec539fa1 100644 --- a/SHADE_Engine/src/Camera/SHCameraDirector.cpp +++ b/SHADE_Engine/src/Camera/SHCameraDirector.cpp @@ -15,36 +15,42 @@ namespace SHADE } - SHMatrix SHCameraDirector::GetViewMatrix() const noexcept + SHMatrix const& SHCameraDirector::GetViewMatrix() const noexcept { return viewMatrix; } - SHMatrix SHCameraDirector::GetProjMatrix() const noexcept + SHMatrix const& SHCameraDirector::GetProjMatrix() const noexcept { return projMatrix; } - SHMatrix SHCameraDirector::GetVPMatrix() const noexcept + SHMatrix const& SHCameraDirector::GetVPMatrix() const noexcept { return projMatrix * viewMatrix; } + SHCameraComponent* SHCameraDirector::GetMainCameraComponent() noexcept + { + if (mainCameraEID == MAX_EID) + { + auto& dense = SHComponentManager::GetDense(); + if (dense.size() == 0) + { + return nullptr; + } + mainCameraEID = dense[0].GetEID(); + } + SHCameraComponent* camComponent = SHComponentManager::GetComponent_s(mainCameraEID); + if (!camComponent) + { + SHLOG_WARNING("Camera Director warning: Entity does not have a camera"); + } + } + + void SHCameraDirector::UpdateMatrix() noexcept { - if (mainCameraEID == MAX_EID) - { - auto& dense = SHComponentManager::GetDense(); - if (dense.size() == 0) - { - return; - } - mainCameraEID = dense[0].GetEID(); - } - SHCameraComponent* camComponent = SHComponentManager::GetComponent_s(mainCameraEID); - if (!camComponent) - { - SHLOG_WARNING("Camera Director warning: Entity does not have a camera"); - } - else + SHCameraComponent* camComponent = GetMainCameraComponent(); + if(camComponent) { viewMatrix = camComponent->GetViewMatrix(); projMatrix = camComponent->GetProjMatrix(); @@ -62,6 +68,24 @@ namespace SHADE mainCameraEID = camera.GetEID(); } + SHMatrix const& SHCameraDirector::GetOrthoMatrix() noexcept + { + + SHCameraComponent* camComponent = GetMainCameraComponent(); + if (camComponent) + return camComponent->GetOrthoMatrix(); + else + return SHMatrix::Identity; + } + + SHMatrix const& SHCameraDirector::GetPerspectiveMatrix() noexcept + { + SHCameraComponent* camComponent = GetMainCameraComponent(); + if (camComponent) + return camComponent->GetPerspectiveMatrix(); + else + return SHMatrix::Identity; + } } diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.h b/SHADE_Engine/src/Camera/SHCameraDirector.h index 6d5404c5..8538a824 100644 --- a/SHADE_Engine/src/Camera/SHCameraDirector.h +++ b/SHADE_Engine/src/Camera/SHCameraDirector.h @@ -23,20 +23,20 @@ namespace SHADE EntityID transitionCameraEID; - SHMatrix GetViewMatrix() const noexcept; - SHMatrix GetProjMatrix() const noexcept; - SHMatrix GetVPMatrix() const noexcept; + SHMatrix const& GetViewMatrix() const noexcept; + SHMatrix const& GetProjMatrix() const noexcept; + SHMatrix const& GetVPMatrix() const noexcept; void UpdateMatrix() noexcept; void SetMainCamera(SHCameraComponent& cam) noexcept; - + SHMatrix const& GetOrthoMatrix() noexcept; + SHMatrix const& GetPerspectiveMatrix() noexcept; private: + SHMatrix viewMatrix; + SHMatrix projMatrix; + SHCameraComponent* GetMainCameraComponent() noexcept; - protected: - SHMatrix viewMatrix; - SHMatrix projMatrix; - }; typedef Handle DirectorHandle; diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index ff942666..78dabc37 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -107,7 +107,11 @@ namespace SHADE editorCamera.SetPitch(0.0f); editorCamera.SetYaw(0.0f); editorCamera.SetRoll(0.0f); + editorCamera.SetWidth(1080.0f); + editorCamera.SetHeight(720.0f); + editorCamera.SetFar(10000000.0f); editorCamera.movementSpeed = 2.0f; + editorCamera.perspProj = true; SHComponentManager::CreateComponentSparseSet(); SHComponentManager::CreateComponentSparseSet(); @@ -210,39 +214,43 @@ namespace SHADE } if (camera.dirtyProj == true) { - if (camera.perspProj == true) - { + //Perspective projection matrix. const float ASPECT_RATIO = (camera.GetAspectRatio()); const float TAN_HALF_FOV = tan(SHMath::DegreesToRadians(camera.fov) * 0.5f); - camera.projMatrix = SHMatrix::Identity; - camera.projMatrix(0, 0) = 1.0f / (ASPECT_RATIO * TAN_HALF_FOV); - camera.projMatrix(1, 1) = 1.0f / TAN_HALF_FOV; - camera.projMatrix(2, 2) = camera.zFar / (camera.zFar - camera.zNear); - camera.projMatrix(3, 3) = 0.0f; - - camera.projMatrix(3, 2) = 1.0f; - camera.projMatrix(2, 3) = -(camera.zFar * camera.zNear) / (camera.zFar - camera.zNear); + camera.perspProjMatrix = SHMatrix::Identity; + camera.perspProjMatrix(0, 0) = 1.0f / (ASPECT_RATIO * TAN_HALF_FOV); + camera.perspProjMatrix(1, 1) = 1.0f / TAN_HALF_FOV; + camera.perspProjMatrix(2, 2) = camera.zFar / (camera.zFar - camera.zNear); + camera.perspProjMatrix(3, 3) = 0.0f; + + camera.perspProjMatrix(3, 2) = 1.0f; + camera.perspProjMatrix(2, 3) = -(camera.zFar * camera.zNear) / (camera.zFar - camera.zNear); - camera.dirtyProj = false; - } - else - { - //const float R = camera.width * 0.5f; - //const float L = -R; - //const float T = camera.height * 0.5f; - //const float B = -T; + + //Orthographic projection matrix - //camera.projMatrix = SHMatrix::Identity; - //camera.projMatrix(0, 0) = 2.0f / (R - L); - //camera.projMatrix(1, 1) = 2.0f / (B - T); - //camera.projMatrix(2, 2) = 1.0f / (camera.zFar - camera.zNear); - //camera.projMatrix(3, 0) = -(R + L) / (R - L); - //camera.projMatrix(3, 1) = -(B + T) / (B - T); - //camera.projMatrix(3, 2) = -camera.zNear / (camera.zFar - camera.zNear); + const float right = camera.GetWidth() * 0.5f; + const float left = -right; + const float top = camera.GetHeight() * 0.5f; + const float btm = -top; + const float n = camera.GetNear(); + const float f = camera.GetFar(); + + camera.orthoProjMatrix = SHMatrix::Identity; + camera.orthoProjMatrix(0, 0) = 2.0f / (right - left); + camera.orthoProjMatrix(1, 1) = 2.0f / (btm - top); + camera.orthoProjMatrix(2, 2) = 1.0f / (f-n); + camera.orthoProjMatrix(0, 3) = -(right + left) / (right - left); + camera.orthoProjMatrix(1, 3) = -(btm + top) / (btm - top); + camera.orthoProjMatrix(2, 3) = -n / (f-n); + camera.orthoProjMatrix(3, 3) = 1.0f; + + camera.orthoProjMatrix = SHMatrix::OrthographicRH(camera.GetWidth(), camera.GetHeight(), camera.GetNear(), camera.GetFar()); + //camera.projMatrix.Transpose(); camera.dirtyProj = false; - } + } } @@ -252,8 +260,6 @@ namespace SHADE SHVec3 up = { 0.0f,1.0f,0.0f }; - - target = SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch)); target = SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw)); target += camera.position; @@ -287,6 +293,9 @@ namespace SHADE if (SHSceneManager::CheckNodeAndComponentsActive(cam.GetEID())) system->UpdateCameraComponent(cam); } + + + for (auto& handle : system->directorHandleList) { handle->UpdateMatrix(); diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.h b/SHADE_Engine/src/Camera/SHCameraSystem.h index fc6e9166..9c8157f4 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.h +++ b/SHADE_Engine/src/Camera/SHCameraSystem.h @@ -37,8 +37,6 @@ namespace SHADE void Exit (void); - friend class EditorCameraUpdate; - class SH_API CameraSystemUpdate final: public SHSystemRoutine { public: diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp b/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp index 6ce4f277..19eb5168 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp +++ b/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp @@ -218,7 +218,7 @@ namespace SHADE EntityID result = MAX_EID; for (auto& entity : entityVec) { - if (entity->name == name) + if (entity && entity->name == name) result = entity->GetEID(); } return result; diff --git a/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.cpp b/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.cpp index 97fd8a22..4c56d032 100644 --- a/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.cpp +++ b/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.cpp @@ -5,6 +5,7 @@ namespace SHADE { bool SHDragDrop::hasDragDrop = false; + SHDragDrop::DragDropTag SHDragDrop::currentDragDropTag{}; bool SHDragDrop::BeginSource(ImGuiDragDropFlags const flags) { return ImGui::BeginDragDropSource(flags); } @@ -16,6 +17,10 @@ namespace SHADE { return ImGui::BeginDragDropTarget(); } void SHDragDrop::EndTarget() - { ImGui::EndDragDropTarget(); hasDragDrop = false;} + { + ImGui::EndDragDropTarget(); + hasDragDrop = false; + currentDragDropTag = {}; + } } diff --git a/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.hpp b/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.hpp index ce0615e1..f111eaeb 100644 --- a/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.hpp +++ b/SHADE_Engine/src/Editor/DragDrop/SHDragDrop.hpp @@ -19,9 +19,13 @@ namespace SHADE static void EndSource(); template - static bool SetPayload(std::string_view const type, T* object, ImGuiCond const cond = 0) + static bool SetPayload(DragDropTag const& type, T* object, ImGuiCond const cond = 0) { - hasDragDrop = ImGui::SetDragDropPayload(type.data(), static_cast(object), sizeof(T), cond); + ImGui::SetDragDropPayload(type.data(), static_cast(object), sizeof(T), cond); + + hasDragDrop = true; + currentDragDropTag = type; + return hasDragDrop; } @@ -32,13 +36,16 @@ namespace SHADE static void EndTarget(); template - static T* AcceptPayload(std::string_view const type, ImGuiDragDropFlags const flags = 0) + static T* AcceptPayload(DragDropTag const& type, ImGuiDragDropFlags const flags = 0) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(type.data(), flags)) + { return static_cast(payload->Data); + } return nullptr; } static bool hasDragDrop; + static DragDropTag currentDragDropTag; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp index 889c24cc..66b3c962 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp @@ -109,7 +109,7 @@ namespace SHADE ImVec2 vertLineEnd = vertLineStart; for (auto const& subFolder : subFolders) { - const float horizontalLineSize = 8.0f; + const float horizontalLineSize = (subFolder->subFolders.empty() && subFolder->files.empty()) ? 25.0f : 8.0f; const ImRect childRect = RecursivelyDrawTree(subFolder); const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f; drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1); @@ -117,7 +117,7 @@ namespace SHADE } for (auto& file : files) { - const float horizontalLineSize = 25.0f; + const float horizontalLineSize = (file.assetMeta && !file.assetMeta->subAssets.empty()) ? 8.0f : 25.0f; const ImRect childRect = DrawFile(file); const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f; drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1); @@ -182,7 +182,10 @@ namespace SHADE return nodeRect; } if(file.assetMeta) - DrawAsset(file.assetMeta, file.ext); + { + const ImRect childRect = DrawAsset(file.assetMeta, file.ext); + return childRect; + } } ImRect SHAssetBrowser::DrawAsset(SHAsset const* const asset, FileExt const& ext /*= ""*/) noexcept diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp index cf545223..2235f831 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp @@ -117,9 +117,12 @@ namespace SHADE { if(ImGui::IsDragDropActive()) { - ParentSelectedEntities(MAX_EID, draggingEntities); - draggingEntities.clear(); - ImGui::ClearDragDrop(); + if (SHDragDrop::currentDragDropTag == SHDragDrop::DRAG_EID) + { + ParentSelectedEntities(MAX_EID, draggingEntities); + draggingEntities.clear(); + ImGui::ClearDragDrop(); + } } } ImGui::End(); @@ -233,8 +236,9 @@ namespace SHADE { ParentSelectedEntities(eid, draggingEntities); draggingEntities.clear(); - SHDragDrop::EndTarget(); + //ImGui::ClearDragDrop(); } + SHDragDrop::EndTarget(); } //Context menu @@ -342,17 +346,12 @@ namespace SHADE SHEntityManager::CreateEntity(MAX_EID, "DefaultChild", parentEID); } - void SHHierarchyPanel::ParentSelectedEntities(EntityID parentEID, std::vector const& entities) const noexcept + void SHHierarchyPanel::ParentSelectedEntities(EntityID parentEID, std::vector const& entities) noexcept { auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); - std::vector entitiesToParent{}; - std::ranges::copy_if(entities, std::back_inserter(entitiesToParent), [&sceneGraph](EntityID const& eid) - { - if (sceneGraph.GetParent(eid)->GetEntityID() == MAX_EID) - return true; - return false; - }); + std::vector entitiesToParent = CleanUpEIDList(entities); + //auto const editor = SHSystemManager::GetSystem(); SHEntityParentCommand::EntityParentData entityParentData; std::vector parentedEIDS; @@ -419,14 +418,7 @@ namespace SHADE void SHHierarchyPanel::CopySelectedEntities() { const auto editor = SHSystemManager::GetSystem(); - auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); - std::vector entitiesToCopy{}; - std::ranges::copy_if(editor->selectedEntities, std::back_inserter(entitiesToCopy), [&sceneGraph](EntityID const& eid) - { - if(sceneGraph.GetParent(eid)->GetEntityID() == MAX_EID) - return true; - return false; - }); + std::vector entitiesToCopy = CleanUpEIDList(editor->selectedEntities); SHClipboardUtilities::WriteToClipboard(SHSerialization::SerializeEntitiesToString(entitiesToCopy)); } @@ -439,19 +431,25 @@ namespace SHADE void SHHierarchyPanel::DeleteSelectedEntities() { const auto editor = SHSystemManager::GetSystem(); + std::vector entitiesToDelete = CleanUpEIDList(editor->selectedEntities); + SHCommandManager::PerformCommand(std::make_shared(entitiesToDelete)); + } + + std::vector SHHierarchyPanel::CleanUpEIDList(std::vector const& entities) + { + std::vector result; auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); - std::vector entitiesToDelete{}; - std::ranges::copy_if(editor->selectedEntities, std::back_inserter(entitiesToDelete), [&sceneGraph, &selectedEntities = editor->selectedEntities](EntityID const& eid) + std::ranges::copy_if(entities, std::back_inserter(result), [&sceneGraph, &entities](EntityID const& eid) { EntityID parentEID = sceneGraph.GetParent(eid)->GetEntityID(); if (parentEID == MAX_EID) return true; - else if(std::ranges::find(selectedEntities, parentEID) == selectedEntities.end()) + if (std::ranges::find(entities, parentEID) == entities.end()) return true; return false; }); - SHCommandManager::PerformCommand(std::make_shared(entitiesToDelete)); + return result; } }//namespace SHADE diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h index 66b9ca2f..9278a0a3 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h @@ -27,12 +27,13 @@ namespace SHADE void DrawMenuBar() const noexcept; ImRect RecursivelyDrawEntityNode(SHSceneNode* const); void CreateChildEntity(EntityID parentEID) const noexcept; - void ParentSelectedEntities(EntityID parentEID, std::vector const& entities) const noexcept; + void ParentSelectedEntities(EntityID parentEID, std::vector const& entities) noexcept; void SelectRangeOfEntities(EntityID beginEID, EntityID EndEID); void SelectAllEntities(); void CopySelectedEntities(); void PasteEntities(EntityID parentEID = MAX_EID); void DeleteSelectedEntities(); + std::vector CleanUpEIDList(std::vector const& entities); bool skipFrame = false; std::string filter; bool isAnyNodeSelected = false; diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 1044cc1a..46ffd3bf 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -455,6 +455,11 @@ namespace SHADE }, [component](AssetID const& id) { + if(SHAssetManager::GetType(id) != AssetType::MESH) + { + SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!") + return; + } component->SetMesh(SHResourceManager::LoadOrGet(id)); SHResourceManager::FinaliseChanges(); }, SHDragDrop::DRAG_RESOURCE); @@ -470,6 +475,11 @@ namespace SHADE }, [component](AssetID const& id) { + if (SHAssetManager::GetType(id) != AssetType::MATERIAL) + { + SHLOG_WARNING("Attempted to assign non material asset to Renderable Mesh property!") + return; + } auto gfxSystem = SHSystemManager::GetSystem(); component->SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(SHResourceManager::LoadOrGet(id))); }, SHDragDrop::DRAG_RESOURCE); diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index f240e321..3a5a15b5 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -18,6 +18,8 @@ #include "Physics/Interface/SHColliderComponent.h" #include "Camera/SHCameraComponent.h" #include "Camera/SHCameraArmComponent.h" +#include "UI/SHUIComponent.h" +#include "UI/SHCanvasComponent.h" #include "SHEditorComponentView.h" namespace SHADE @@ -132,6 +134,14 @@ namespace SHADE { DrawComponent(cameraArmComponent); } + if (auto canvasComponent= SHComponentManager::GetComponent_s(eid)) + { + DrawComponent(canvasComponent); + } + if (auto uiComponent = SHComponentManager::GetComponent_s(eid)) + { + DrawComponent(uiComponent); + } ImGui::Separator(); // Render Scripts SHScriptEngine* scriptEngine = static_cast(SHSystemManager::GetSystem()); @@ -143,6 +153,7 @@ namespace SHADE DrawAddComponentButton(eid); DrawAddComponentButton(eid); DrawAddComponentButton(eid); + DrawAddComponentButton(eid); // Components that require Transforms diff --git a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp index 564731d6..93f4a615 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp @@ -14,6 +14,7 @@ #include "Camera/SHCameraSystem.h" #include "FRC/SHFramerateController.h" +#include "../../SHEditorWidgets.hpp" constexpr std::string_view windowName = "\xef\x80\x95 Viewport"; @@ -193,6 +194,13 @@ namespace SHADE if (isScale) ImGui::PopStyleColor(); ImGui::EndDisabled(); + + auto camSystem = SHSystemManager::GetSystem(); + auto editorCamera = camSystem->GetEditorCamera(); + //ImGui::SetNextItemWidth(10.0f); + SHEditorWidgets::SliderFloat("CamSpeed", 0.0f, 5.0f, [editorCamera] {return editorCamera->movementSpeed; }, [editorCamera](float const& value) {editorCamera->movementSpeed = value; }); + SHEditorWidgets::DragVec3("TurnSpeed", { "X", "Y", "Z" }, [editorCamera] {return editorCamera->turnSpeed; }, [editorCamera](SHVec3 const& value) {editorCamera->turnSpeed = value; }); + ImGui::EndMenuBar(); } } diff --git a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp index bfde7525..2681e916 100644 --- a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp +++ b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp @@ -422,7 +422,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - bool changed = ImGui::InputText("##", &text, ImGuiInputTextFlags_ReadOnly, nullptr, nullptr); + bool changed = ImGui::InputText("##inputText", &text, ImGuiInputTextFlags_ReadOnly, nullptr, nullptr); if(SHDragDrop::BeginTarget()) { if(T* payload = SHDragDrop::AcceptPayload(dragDropTag)) @@ -454,7 +454,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - const bool hasChange = ImGui::DragScalar("##", data_type, &value, speed, &p_min, &p_max, displayFormat, flags); + const bool hasChange = ImGui::DragScalar("##dragScalar", data_type, &value, speed, &p_min, &p_max, displayFormat, flags); static bool startRecording = false; if (hasChange) { @@ -487,7 +487,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - const bool hasChange = ImGui::DragFloat("##", &value, speed, p_min, p_max, displayFormat, flags); + const bool hasChange = ImGui::DragFloat("##dragFloat", &value, speed, p_min, p_max, displayFormat, flags); static bool startRecording = false; if (hasChange) { @@ -520,7 +520,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - const bool hasChange = ImGui::DragInt("##", &value, speed, p_min, p_max, displayFormat, flags); + const bool hasChange = ImGui::DragInt("##dragInt", &value, speed, p_min, p_max, displayFormat, flags); static bool startRecording = false; if (hasChange) { @@ -553,7 +553,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - bool const hasChange = ImGui::SliderScalar("##", data_type, &value, &min, &max, displayFormat, flags); + bool const hasChange = ImGui::SliderScalar("##sliderScalar", data_type, &value, &min, &max, displayFormat, flags); static bool startRecording = false; if (hasChange) { @@ -587,7 +587,8 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - bool const hasChange = ImGui::SliderFloat("##", &value, min, max, displayFormat, flags); + ImGui::SetNextItemWidth(ImGui::CalcTextSize(displayFormat).x + ImGui::GetStyle().ItemInnerSpacing.x * 2.0f); + bool const hasChange = ImGui::SliderFloat("##sliderFloat", &value, min, max, displayFormat, flags); static bool startRecording = false; if (hasChange) { @@ -621,7 +622,7 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - bool const hasChange = ImGui::SliderInt("##", &value, min, max, displayFormat, flags); + bool const hasChange = ImGui::SliderInt("##sliderInt", &value, min, max, displayFormat, flags); static bool startRecording = false; if (hasChange) { diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index 0db11c7a..84b50373 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -58,10 +58,9 @@ namespace SHADE loadFunctions(); // Generate script assembly if it hasn't been before - if (!fileExists(std::string(MANAGED_SCRIPT_LIB_NAME) + ".dll")) - { - BuildScriptAssembly(); - } +#ifndef _PUBLISH + BuildScriptAssembly(); +#endif // Initialise the CSharp Engine csEngineInit(); @@ -307,7 +306,7 @@ namespace SHADE SHEventHandle SHScriptEngine::onEntityDestroyed(SHEventPtr eventPtr) { auto eventData = reinterpret_cast*>(eventPtr.get()); - csScriptsRemoveAll(eventData->data->eid); + csScriptsRemoveAllImmediately(eventData->data->eid, true); return eventData->handle; } diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 6933fbb5..3ed96d7d 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -12,8 +12,8 @@ #include "Assets/Asset Types/SHSceneAsset.h" #include "Camera/SHCameraComponent.h" -#include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Math/Transform/SHTransformComponent.h" +#include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Physics/Interface/SHRigidBodyComponent.h" #include "ECS_Base/Managers/SHSystemManager.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h" diff --git a/SHADE_Engine/src/UI/SHCanvasComponent.cpp b/SHADE_Engine/src/UI/SHCanvasComponent.cpp new file mode 100644 index 00000000..1ffc7a19 --- /dev/null +++ b/SHADE_Engine/src/UI/SHCanvasComponent.cpp @@ -0,0 +1,60 @@ +#include "SHpch.h" + +#include "SHCanvasComponent.h" + +namespace SHADE +{ + + SHCanvasComponent::SHCanvasComponent() + :width(1),height(1), dirtyMatrix(false), canvasMatrix() + { + + } + + void SHCanvasComponent::SetCanvasSize(CanvasSizeType width, CanvasSizeType height) noexcept + { + this->width = width; + this->height = height; + } + + void SHCanvasComponent::SetCanvasWidth(CanvasSizeType val) noexcept + { + width = val; + } + + void SHCanvasComponent::SetCanvasHeight(CanvasSizeType val) noexcept + { + height = val; + } + + + SHCanvasComponent::CanvasSizeType SHCanvasComponent::GetCanvasWidth() const noexcept + { + return width; + } + + SHCanvasComponent::CanvasSizeType SHCanvasComponent::GetCanvasHeight() const noexcept + { + return height; + } + + SHMatrix const& SHCanvasComponent::GetMatrix() const noexcept + { + return canvasMatrix; + } + +} + + +RTTR_REGISTRATION +{ + using namespace SHADE; + using namespace rttr; + + registration::class_("Canvas Component") + .property("Canvas Width", &SHCanvasComponent::GetCanvasWidth, &SHCanvasComponent::SetCanvasWidth) + .property("Canvas Height", &SHCanvasComponent::GetCanvasHeight, &SHCanvasComponent::SetCanvasHeight) + ; + + +} diff --git a/SHADE_Engine/src/UI/SHCanvasComponent.h b/SHADE_Engine/src/UI/SHCanvasComponent.h index 2e9a54f1..145b3cb3 100644 --- a/SHADE_Engine/src/UI/SHCanvasComponent.h +++ b/SHADE_Engine/src/UI/SHCanvasComponent.h @@ -1,7 +1,10 @@ #pragma once +#include + #include "SH_API.h" #include "ECS_Base/Components/SHComponent.h" +#include "Math/SHMatrix.h" namespace SHADE @@ -13,6 +16,9 @@ namespace SHADE public: + friend class SHUISystem; + + SHCanvasComponent(); ~SHCanvasComponent() = default; @@ -20,15 +26,18 @@ namespace SHADE void SetCanvasWidth(CanvasSizeType width) noexcept; void SetCanvasHeight(CanvasSizeType height) noexcept; - CanvasSizeType const GetCanvasWidth() const noexcept; - CanvasSizeType const GetCanvasHeight() const noexcept; + CanvasSizeType GetCanvasWidth() const noexcept; + CanvasSizeType GetCanvasHeight() const noexcept; + SHMatrix const& GetMatrix() const noexcept; private: CanvasSizeType width; CanvasSizeType height; - - + bool dirtyMatrix; + SHMatrix canvasMatrix; + + RTTR_ENABLE() }; diff --git a/SHADE_Engine/src/UI/SHUIComponent.cpp b/SHADE_Engine/src/UI/SHUIComponent.cpp new file mode 100644 index 00000000..8131d081 --- /dev/null +++ b/SHADE_Engine/src/UI/SHUIComponent.cpp @@ -0,0 +1,43 @@ +#include "SHpch.h" +#include "SHUIComponent.h" + + + +namespace SHADE +{ + + SHUIComponent::SHUIComponent() + { + + } + + + SHMatrix const& SHUIComponent::GetMatrix()const noexcept + { + return localToCanvasMatrix; + } + + EntityID SHUIComponent::GetCanvasID() const noexcept + { + return canvasID; + } + + void SHUIComponent::SetCanvasID(EntityID id) noexcept + { + (void)id; + } + +} + + +RTTR_REGISTRATION +{ + using namespace SHADE; + using namespace rttr; + + registration::class_("UI Component") + .property("Canvas ID", &SHUIComponent::GetCanvasID, &SHUIComponent::SetCanvasID) + ; + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHUIComponent.h b/SHADE_Engine/src/UI/SHUIComponent.h new file mode 100644 index 00000000..5a9290cc --- /dev/null +++ b/SHADE_Engine/src/UI/SHUIComponent.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +#include "SH_API.h" +#include "ECS_Base/Components/SHComponent.h" +#include "Math/SHMatrix.h" + + +namespace SHADE +{ + class SH_API SHUIComponent final: public SHComponent + { + public: + friend class SHUISystem; + + SHUIComponent(); + ~SHUIComponent() = default; + + SHMatrix const& GetMatrix() const noexcept; + EntityID GetCanvasID() const noexcept; + void SetCanvasID(EntityID id) noexcept; + + private: + SHMatrix localToCanvasMatrix; + EntityID canvasID; + + + RTTR_ENABLE() + }; + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp new file mode 100644 index 00000000..d7dfe3c5 --- /dev/null +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -0,0 +1,113 @@ +#include "SHpch.h" +#include "SHUISystem.h" +#include "ECS_Base/Managers/SHComponentManager.h" +#include "ECS_Base/Managers/SHSystemManager.h" +#include "Math/Transform/SHTransformComponent.h" + +namespace SHADE +{ + + void SHUISystem::Init() + { + SystemFamily::GetID(); + SHComponentManager::CreateComponentSparseSet(); + SHComponentManager::CreateComponentSparseSet(); + } + + void SHUISystem::Exit() + { + + } + + + void SHUISystem::AddUIComponentRoutine::Execute(double dt) noexcept + { + auto& dense = SHComponentManager::GetDense(); + auto& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); + + //Go through all the canvases and make sure all the children has a UIComponent. + for (auto& canvas : dense) + { + auto& children = sceneGraph.GetChildren(canvas.GetEID()); + for (auto& child : children) + { + RecurssiveUIComponentCheck(child, canvas); + } + } + + //Go through all the UI Component and make sure the parent has a UI or Canvas Component + std::vector entitiesToRemove; + auto& UIDense = SHComponentManager::GetDense(); + for (auto& ui : UIDense) + { + SHSceneNode* parentNode = sceneGraph.GetParent(ui.GetEID()); + if (parentNode == nullptr || !(SHComponentManager::HasComponent(parentNode->GetEntityID()) || SHComponentManager::HasComponent(parentNode->GetEntityID()))) + entitiesToRemove.push_back(ui.GetEID()); + } + + for (auto& id : entitiesToRemove) + { + SHComponentManager::RemoveComponent(id); + } + + + } + + void SHUISystem::AddUIComponentRoutine::RecurssiveUIComponentCheck(SHSceneNode* node, SHCanvasComponent& canvas) noexcept + { + if (node == nullptr) + return; + + EntityID eid = node->GetEntityID(); + + if(SHComponentManager::HasComponent(eid) == false) + SHComponentManager::AddComponent(eid); + else + { + SHComponentManager::GetComponent(eid)->canvasID = canvas.GetEID(); + } + + auto& children = SHSceneManager::GetCurrentSceneGraph().GetChildren(eid); + for (auto& child : children) + { + RecurssiveUIComponentCheck(child, canvas); + } + + } + + + void SHUISystem::UpdateUIMatrixRoutine::Execute(double dt) noexcept + { + SHUISystem* system = (SHUISystem* )GetSystem(); + auto& dense = SHComponentManager::GetDense(); + for (auto& comp : dense) + { + system->UpdateUIComponent(comp); + } + + + } + + void SHUISystem::UpdateUIComponent(SHUIComponent& comp) noexcept + { + auto canvasComp = SHComponentManager::GetComponent_s(comp.canvasID); + if (SHComponentManager::HasComponent(comp.GetEID())) + { + auto transform = SHComponentManager::GetComponent(comp.GetEID()); + if (canvasComp != nullptr) + comp.localToCanvasMatrix = canvasComp->GetMatrix() * transform->GetTRS(); + else + comp.localToCanvasMatrix = transform->GetTRS(); + } + else //If for some reason UI Components entities does not have a transform. + { + if (canvasComp != nullptr) + comp.localToCanvasMatrix = canvasComp->GetMatrix(); + else + comp.localToCanvasMatrix = SHMatrix::Identity; + } + } + + + +}//end namespace diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h new file mode 100644 index 00000000..3da7efb3 --- /dev/null +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -0,0 +1,55 @@ +#pragma once + +#include "SH_API.h" +#include "ECS_Base/System/SHSystem.h" +#include "ECS_Base/System/SHSystemRoutine.h" +#include "SHUIComponent.h" +#include "SHCanvasComponent.h" +#include "Scene/SHSceneGraph.h" +#include "Scene/SHSceneManager.h" + +namespace SHADE +{ + class SH_API SHUISystem final: public SHSystem + { + public: + + SHUISystem() = default; + ~SHUISystem() = default; + + class SH_API AddUIComponentRoutine final: public SHSystemRoutine + { + public: + AddUIComponentRoutine() :SHSystemRoutine("Add UI Component Routine", true) {}; + virtual void Execute(double dt) noexcept override final; + + private: + + void RecurssiveUIComponentCheck(SHSceneNode* node, SHCanvasComponent& canvas) noexcept; + }; + friend class AddUIComponentRoutine; + + class SH_API UpdateUIMatrixRoutine final: public SHSystemRoutine + { + public: + UpdateUIMatrixRoutine() : SHSystemRoutine("Update UI Matrix Routine", true) {}; + virtual void Execute(double dt) noexcept override final; + + }; + friend class UpdateUIMatrixRoutine; + + + void Init(); + void Exit(); + + + private: + void UpdateUIComponent(SHUIComponent& comp) noexcept; + + + + + }; + + +} diff --git a/SHADE_Managed/src/Scripts/ScriptStore.cxx b/SHADE_Managed/src/Scripts/ScriptStore.cxx index d57122ee..29ba6e52 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.cxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.cxx @@ -402,8 +402,8 @@ namespace SHADE System::Collections::Generic::List^ scriptList = scripts[entity]; for each (Script ^ script in scriptList) { - // Call OnDestroy only if indicated and also in play mode - if (callOnDestroy) + // Call OnDestroy only if indicated and also if the game has run + if (callOnDestroy && Application::IsPlaying || Application::IsPaused) { script->OnDestroy(); } @@ -469,7 +469,7 @@ namespace SHADE script->OnDestroy(); } auto entity = script->Owner.GetEntity(); - auto scriptList = scripts[script->Owner.GetEntity()]; + auto scriptList = scripts[script->Owner.GetEntity()]; // Unable to find here scriptList->Remove(script); if (scriptList->Count <= 0) { diff --git a/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx b/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx index 147591a5..cfa94540 100644 --- a/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx +++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx @@ -45,12 +45,22 @@ namespace SHADE System::Collections::Generic::IEnumerable^ fields = ReflectionUtilities::GetInstanceFields(object); for each (FieldInfo^ field in fields) { - // Ignore private and non-SerialiseField - if (!ReflectionUtilities::FieldIsSerialisable(field)) - continue; + try + { + // Ignore private and non-SerialiseField + if (!ReflectionUtilities::FieldIsSerialisable(field)) + continue; - // Serialise - writeFieldIntoYaml(field, object, scriptNode); + // Serialise + writeFieldIntoYaml(field, object, scriptNode); + } + catch (System::Exception^ e) + { + Debug::LogError + ( + System::String::Format("[SerialisationUtilities] Failed to serialise field ({0}): {1}", field->Name, e->ToString()) + ); + } } scriptListNode.push_back(scriptNode); @@ -74,15 +84,25 @@ namespace SHADE System::Collections::Generic::IEnumerable^ fields = ReflectionUtilities::GetInstanceFields(object); for each (FieldInfo^ field in fields) { - // Ignore private and non-SerialiseField - if (!ReflectionUtilities::FieldIsSerialisable(field)) - continue; - - // Deserialise - const std::string FIELD_NAME = Convert::ToNative(field->Name); - if (yamlNode[FIELD_NAME]) + try { - writeYamlIntoField(field, object, yamlNode[FIELD_NAME]); + // Ignore private and non-SerialiseField + if (!ReflectionUtilities::FieldIsSerialisable(field)) + continue; + + // Deserialise + const std::string FIELD_NAME = Convert::ToNative(field->Name); + if (yamlNode[FIELD_NAME]) + { + writeYamlIntoField(field, object, yamlNode[FIELD_NAME]); + } + } + catch (System::Exception^ e) + { + Debug::LogError + ( + System::String::Format("[SerialisationUtilities] Failed to deserialise field ({0}): {1}", field->Name, e->ToString()) + ); } } } diff --git a/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ index dde6705a..2c943452 100644 --- a/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ +++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ @@ -142,6 +142,31 @@ namespace SHADE bool SerialisationUtilities::fieldAssignYaml(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& node) { System::Object^ valueObj = fieldInfo->GetValue(object); + if (valueObj == nullptr) + { + if constexpr (std::is_same_v) + { + if (fieldInfo->FieldType->IsSubclassOf(System::Enum::typeid)) + { + valueObj = 0; + } + } + else + { + if (fieldInfo->FieldType == FieldType::typeid) + { + if constexpr (std::is_same_v) + { + valueObj = ""; + } + else + { + valueObj = FieldType(); + } + } + } + } + if (varAssignYamlInternal(valueObj, node)) { fieldInfo->SetValue(object, valueObj);