From f7cca42e59a54b3b8204488cf7250adb21b49e4f Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Tue, 15 Nov 2022 13:53:15 +0800 Subject: [PATCH 01/23] Added shlog information source --- .../Libraries/Loaders/SHModelLoader.cpp | 2 +- .../Libraries/Loaders/SHTextBasedLoader.cpp | 4 ++-- .../Libraries/Loaders/SHTextureLoader.cpp | 4 ++-- SHADE_Engine/src/Assets/SHAssetManager.cpp | 22 +++++++++---------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.cpp b/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.cpp index 74aa5350..3978c02f 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.cpp @@ -52,7 +52,7 @@ namespace SHADE std::ifstream file{ path.string(), std::ios::in | std::ios::binary }; if (!file.is_open()) { - SHLOG_ERROR("Unable to open SHMesh File: {}", path.string()); + SHLOG_ERROR("[Model Loader] Unable to open SHModel File: {}", path.string()); return; } diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextBasedLoader.cpp b/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextBasedLoader.cpp index b23130f3..4858e639 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextBasedLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextBasedLoader.cpp @@ -26,7 +26,7 @@ namespace SHADE if (!file.is_open()) { - SHLOG_ERROR("Unable to open text File: {}", path.string()); + SHLOG_ERROR("[Text Loader] Unable to open text File: {}", path.string()); return nullptr; } std::stringstream stream; @@ -70,7 +70,7 @@ namespace SHADE if (!file.is_open()) { - SHLOG_ERROR("Unable to open text File: {}", path.string()); + SHLOG_ERROR("[Text Loader] Unable to open text File: {}", path.string()); return; } diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextureLoader.cpp b/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextureLoader.cpp index 423301dd..96dabf18 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextureLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHTextureLoader.cpp @@ -22,7 +22,7 @@ namespace SHADE std::ifstream file{ path.string(), std::ios::in | std::ios::binary }; if (!file.is_open()) { - SHLOG_ERROR("Error opening SHTexture file: {}", path.string()); + SHLOG_ERROR("[Texture Loader] Error opening SHTexture file: {}", path.string()); } auto const intBytes{ sizeof(uint32_t) }; @@ -61,7 +61,7 @@ namespace SHADE std::ofstream file{ path, std::ios::out | std::ios::binary }; if (!file.is_open()) { - SHLOG_ERROR("Unable to open file for writing texture file: {}", path.string()); + SHLOG_ERROR("[Texture Loader] Unable to open file for writing texture file: {}", path.string()); } auto asset = *dynamic_cast(data); diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index b4ea7d35..40cf9df6 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -197,7 +197,7 @@ namespace SHADE break; default: - SHLOG_ERROR("Asset type of {} not an internal asset type, cannot be created", name); + SHLOG_ERROR("[Asset Manager] Asset type of {} not an internal asset type, cannot be created", name); return 0; } @@ -249,14 +249,14 @@ namespace SHADE return true; } - SHLOG_ERROR("Asset data has not been written into, cannot be saved: {}", + SHLOG_ERROR("[Asset Manager] Asset data has not been written into, cannot be saved: {}", asset.path.filename().string()); return false; } } - SHLOG_WARNING("Asset id: {} not an internal asset type, save cannot be triggered", id); + SHLOG_WARNING("[Asset Manager] Asset id: {} not an internal asset type, save cannot be triggered", id); return false; } @@ -274,10 +274,10 @@ namespace SHADE { return (DeleteLocalFile(asset.path) && DeleteLocalFile(asset.path.string() + META_EXTENSION.data())); } - SHLOG_WARNING("Asset id: {} not an internal asset type, file deletion not allowed", id); + SHLOG_WARNING("[Asset Manager] Asset id: {} not an internal asset type, file deletion not allowed", id); } - SHLOG_WARNING("Asset id does not exist, nothing was deleted: {}", id); + SHLOG_WARNING("[Asset Manager] Asset id does not exist, nothing was deleted: {}", id); return false; } @@ -311,7 +311,7 @@ namespace SHADE std::filesystem::path const newPath{ GenerateLocalPath(path) }; if (newPath.empty()) { - SHLOG_WARNING("Unsupported file format for asset: {}", path.string()); + SHLOG_WARNING("[Asset Manager] Unsupported file format for asset: {}", path.string()); return 0; } @@ -363,7 +363,7 @@ namespace SHADE { if (!std::filesystem::exists(path)) { - SHLOG_ERROR("Path provided does not point to a file: {}", path.string()); + SHLOG_ERROR("[Asset Manager] Path provided does not point to a file: {}", path.string()); return; } AssetPath newPath; @@ -387,14 +387,14 @@ namespace SHADE auto pathGen = SHTextureCompiler::CompileTextureAsset(path); if (!pathGen.has_value()) { - SHLOG_ERROR("Texture Compilation Failed for: {}", path.string()); + SHLOG_ERROR("[Asset Manager] Texture Compilation Failed for: {}", path.string()); return; } newPath = pathGen.value(); } else { - SHLOG_WARNING("File Type compilation not yet Implemented: {}", path.string()); + SHLOG_WARNING("[Asset Manager] File Type compilation not yet Implemented: {}", path.string()); return; } @@ -479,7 +479,7 @@ namespace SHADE SHAssetData* data = loaders[static_cast(asset.type)]->Load(asset.path); if (data == nullptr) { - SHLOG_ERROR("Unable to load asset into memory: {}\n", asset.path.string()); + SHLOG_ERROR("[Asset Manager] Unable to load asset into memory: {}\n", asset.path.string()); } else { @@ -496,7 +496,7 @@ namespace SHADE if (parentData == nullptr) { - SHLOG_ERROR("Unable to load asset into memory: {}\n", parent.path.string()); + SHLOG_ERROR("[Asset Manager] Unable to load asset into memory: {}\n", parent.path.string()); } else { From f1ac689bb0fc333177bcd0de79a5e8471f316239 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Tue, 22 Nov 2022 00:37:09 +0800 Subject: [PATCH 02/23] Added Physics Materials to Inspector --- .../Inspector/SHEditorComponentView.hpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 80ae3331..30172f48 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -333,10 +333,10 @@ namespace SHADE auto cursorPos = ImGui::GetCursorPos(); //collider->IsTrigger - if (collider->GetType() == SHCollisionShape::Type::BOX) { SHEditorWidgets::BeginPanel(std::format("{} Box #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y }); + const auto* BOX = reinterpret_cast(collider->GetShape()); SHEditorWidgets::DragVec3 ( @@ -360,6 +360,15 @@ namespace SHADE } { + SHEditorWidgets::CheckBox("Is Trigger", [collider] { return collider->IsTrigger(); }, [collider](bool value) { collider->SetIsTrigger(value); }); + + if(ImGui::CollapsingHeader("Physics Material")) + { + SHEditorWidgets::DragFloat("Friction", [collider] { return collider->GetFriction(); }, [collider](float value) { collider->SetFriction(value); }, "Friction", 0.05f, 0.0f, 1.0f); + SHEditorWidgets::DragFloat("Bounciness", [collider] { return collider->GetBounciness(); }, [collider](float value) { collider->SetBounciness(value); }, "Bounciness", 0.05f, 0.0f, 1.0f); + SHEditorWidgets::DragFloat("Mass Density", [collider] { return collider->GetDensity(); }, [collider](float value) { collider->SetDensity(value); }, "Mass Density", 0.1f, 0.0f); + } + SHEditorWidgets::BeginPanel("Offsets",{ ImGui::GetContentRegionAvail().x, 30.0f }); SHEditorWidgets::DragVec3("Position", { "X", "Y", "Z" }, [&collider] {return collider->GetPositionOffset(); }, [&collider](SHVec3 const& vec) {collider->SetPositionOffset(vec); }); SHEditorWidgets::DragVec3("Rotation", { "X", "Y", "Z" }, @@ -375,8 +384,6 @@ namespace SHADE SHEditorWidgets::EndPanel(); } - SHEditorWidgets::CheckBox("Is Trigger", [collider] { return collider->IsTrigger(); }, [collider](bool value) { collider->SetIsTrigger(value); }); - if (ImGui::Button(std::format("{} Remove Collider #{}", ICON_MD_REMOVE, i).data())) { colliderToDelete = i; From 23bae3d515821896b68a4383dd58bbb55ccd3893 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Tue, 22 Nov 2022 00:46:32 +0800 Subject: [PATCH 03/23] Fixed bug with Bounciness failing to serialise --- SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp | 8 ++++++-- SHADE_Engine/src/Serialization/SHYAMLConverters.h | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp b/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp index c8a082a5..f597077f 100644 --- a/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp +++ b/SHADE_Engine/src/Physics/Interface/SHCollisionShape.cpp @@ -359,6 +359,10 @@ RTTR_REGISTRATION ); registration::class_("Collider") - .property("Position Offset", &SHCollisionShape::GetPositionOffset, &SHCollisionShape::SetPositionOffset) - .property("Rotation Offset", &SHCollisionShape::GetRotationOffset, &SHCollisionShape::SetRotationOffset) (metadata(META::angleInRad, true)); + .property("IsTrigger" , &SHCollisionShape::IsTrigger , &SHCollisionShape::SetIsTrigger ) + .property("Friction" , &SHCollisionShape::GetFriction , &SHCollisionShape::SetFriction ) + .property("Bounciness" , &SHCollisionShape::GetBounciness , &SHCollisionShape::SetBounciness ) + .property("Density" , &SHCollisionShape::GetDensity , &SHCollisionShape::SetDensity ) + .property("Position Offset" , &SHCollisionShape::GetPositionOffset, &SHCollisionShape::SetPositionOffset) + .property("Rotation Offset" , &SHCollisionShape::GetRotationOffset, &SHCollisionShape::SetRotationOffset) (metadata(META::angleInRad, true)); } \ No newline at end of file diff --git a/SHADE_Engine/src/Serialization/SHYAMLConverters.h b/SHADE_Engine/src/Serialization/SHYAMLConverters.h index 06c785ae..b17a9252 100644 --- a/SHADE_Engine/src/Serialization/SHYAMLConverters.h +++ b/SHADE_Engine/src/Serialization/SHYAMLConverters.h @@ -188,7 +188,7 @@ namespace YAML if (node[Friction].IsDefined()) rhs.SetFriction(node[Friction].as()); if (node[Bounciness].IsDefined()) - rhs.SetBounciness(rhs.GetBounciness()); + rhs.SetBounciness(node[Bounciness].as()); if (node[Density].IsDefined()) rhs.SetDensity(node[Density].as()); if (node[PositionOffset].IsDefined()) From 080c2c70d52ee0d9abb9c5b38863f0fb1f9ce0dd Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 13:09:40 +0800 Subject: [PATCH 04/23] Added canvas to serialization --- SHADE_Engine/src/Serialization/SHSerialization.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 607b4666..db3e3690 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -15,6 +15,7 @@ #include "Math/Transform/SHTransformComponent.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Physics/Interface/SHRigidBodyComponent.h" +#include "UI/SHCanvasComponent.h" #include "ECS_Base/Managers/SHSystemManager.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h" #include "Scripting/SHScriptEngine.h" @@ -212,6 +213,8 @@ namespace SHADE AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); + AddComponentToComponentNode(components, eid); + node[ComponentsNode] = components; @@ -264,6 +267,7 @@ namespace SHADE AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); + AddComponentID(componentIDList, componentsNode); return componentIDList; } @@ -341,6 +345,7 @@ namespace SHADE SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); + SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); } } From cf10724f3a34fb0d4f0a2a70870bd5e8b02e623f Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 13:17:45 +0800 Subject: [PATCH 05/23] Update SHSerialization.cpp --- SHADE_Engine/src/Serialization/SHSerialization.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 6e7912c2..931d3a4c 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -212,7 +212,7 @@ namespace SHADE AddComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); - AddConvComponentToComponentNode(components, eid); + AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); @@ -267,7 +267,7 @@ namespace SHADE AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); - AddComponentID(componentIDList, componentsNode); + AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); @@ -346,7 +346,7 @@ namespace SHADE SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); - SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); + SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); From 5d0414979734e0f8276dd03fa98741c1485f8333 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 14:02:45 +0800 Subject: [PATCH 06/23] buttons WIP --- SHADE_Engine/src/UI/SHButtonComponent.cpp | 15 +++++++++++ SHADE_Engine/src/UI/SHButtonComponent.h | 31 +++++++++++++++++++++++ SHADE_Engine/src/UI/SHUISystem.cpp | 4 +++ SHADE_Engine/src/UI/SHUISystem.h | 12 ++++++++- 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 SHADE_Engine/src/UI/SHButtonComponent.cpp create mode 100644 SHADE_Engine/src/UI/SHButtonComponent.h diff --git a/SHADE_Engine/src/UI/SHButtonComponent.cpp b/SHADE_Engine/src/UI/SHButtonComponent.cpp new file mode 100644 index 00000000..d711d682 --- /dev/null +++ b/SHADE_Engine/src/UI/SHButtonComponent.cpp @@ -0,0 +1,15 @@ +#include "SHpch.h" +#include "SHButtonComponent.h" + + +namespace SHADE +{ + SHButtonComponent::SHButtonComponent() + :size(0.0f), offset(0.0f), isHovered(false) + { + } + + + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHButtonComponent.h b/SHADE_Engine/src/UI/SHButtonComponent.h new file mode 100644 index 00000000..e68f354f --- /dev/null +++ b/SHADE_Engine/src/UI/SHButtonComponent.h @@ -0,0 +1,31 @@ +#pragma once + +#include "SH_API.h" +#include "ECS_Base/Components/SHComponent.h" +#include "Math/Vector/SHVec3.h" +#include "Math/Vector/SHVec2.h" + + +namespace SHADE +{ + class SH_API SHButtonComponent final: public SHComponent + { + public: + SHButtonComponent(); + ~SHButtonComponent() = default; + + SHVec2 size; + SHVec2 offset; + + + + private: + + bool isHovered; + + + + }; + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index d7dfe3c5..44730529 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -108,6 +108,10 @@ namespace SHADE } } + void SHUISystem::UpdateButtonComponent(SHButtonComponent& comp) noexcept + { + + } }//end namespace diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h index 3da7efb3..15b710aa 100644 --- a/SHADE_Engine/src/UI/SHUISystem.h +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -4,6 +4,7 @@ #include "ECS_Base/System/SHSystem.h" #include "ECS_Base/System/SHSystemRoutine.h" #include "SHUIComponent.h" +#include "SHButtonComponent.h" #include "SHCanvasComponent.h" #include "Scene/SHSceneGraph.h" #include "Scene/SHSceneManager.h" @@ -39,13 +40,22 @@ namespace SHADE friend class UpdateUIMatrixRoutine; + class SH_API UpdateButtonsRoutine final: public SHSystemRoutine + { + public: + UpdateButtonsRoutine() : SHSystemRoutine("Update Buttons Routine", true) {}; + virtual void Execute(double dt) noexcept override final; + }; + friend class UpdateButtonsRoutine; + + void Init(); void Exit(); private: void UpdateUIComponent(SHUIComponent& comp) noexcept; - + void UpdateButtonComponent(SHButtonComponent& comp) noexcept; From a78b3c0123e291a7a7b597fe509f110deef412da Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 22 Nov 2022 15:37:01 +0800 Subject: [PATCH 07/23] Reworked NativeAsset system --- SHADE_Engine/src/Resource/SHResourceManager.h | 3 +- .../src/Resource/SHResourceManagerWrapper.cpp | 34 ++++++++++ .../src/Resource/SHResourceManagerWrapper.h | 57 ++++++++++++++++ SHADE_Managed/src/Assets/Font.cxx | 45 ++++++++++++- SHADE_Managed/src/Assets/Font.hxx | 59 ++++++++++++++++- SHADE_Managed/src/Assets/Material.cxx | 43 +++++++++++- SHADE_Managed/src/Assets/Material.hxx | 57 +++++++++++++++- SHADE_Managed/src/Assets/Mesh.cxx | 45 +++++++++++-- SHADE_Managed/src/Assets/Mesh.hxx | 65 +++++++++++++++++-- SHADE_Managed/src/Assets/NativeAsset.cxx | 14 ++++ SHADE_Managed/src/Assets/NativeAsset.h++ | 44 ------------- SHADE_Managed/src/Assets/NativeAsset.hxx | 57 +++++++--------- 12 files changed, 425 insertions(+), 98 deletions(-) create mode 100644 SHADE_Engine/src/Resource/SHResourceManagerWrapper.cpp create mode 100644 SHADE_Engine/src/Resource/SHResourceManagerWrapper.h delete mode 100644 SHADE_Managed/src/Assets/NativeAsset.h++ diff --git a/SHADE_Engine/src/Resource/SHResourceManager.h b/SHADE_Engine/src/Resource/SHResourceManager.h index 6afdf2b0..5b98ffc3 100644 --- a/SHADE_Engine/src/Resource/SHResourceManager.h +++ b/SHADE_Engine/src/Resource/SHResourceManager.h @@ -49,7 +49,8 @@ namespace SHADE template<> struct SHResourceLoader { using AssetType = SHMaterialAsset; }; template<> struct SHResourceLoader { using AssetType = SHMaterialSpec; }; template<> struct SHResourceLoader { using AssetType = SHFontAsset; }; -/// + + /// /// Static class responsible for loading and caching runtime resources from their /// serialised Asset IDs. /// diff --git a/SHADE_Engine/src/Resource/SHResourceManagerWrapper.cpp b/SHADE_Engine/src/Resource/SHResourceManagerWrapper.cpp new file mode 100644 index 00000000..f99e2dc6 --- /dev/null +++ b/SHADE_Engine/src/Resource/SHResourceManagerWrapper.cpp @@ -0,0 +1,34 @@ +/************************************************************************************//*! +\file SHResourceManagerWrapper.cpp +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 22, 2022 +\brief Contains the definition of the functions of the SHResourceManagerWraper + static class. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Header +#include "SHpch.h" +// Primary Include +#include "SHResourceManagerWrapper.h" +// Project Includes +#include "SHResourceManager.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Query Functions */ + /*-----------------------------------------------------------------------------------*/ + std::optional SHResourceManagerWrapper::GetAssetID(Handle handle) + { + return SHResourceManager::GetAssetID(handle); + } + + std::optional SHResourceManagerWrapper::GetAssetName(Handle handle) + { + return SHResourceManager::GetAssetName(handle); + } +} diff --git a/SHADE_Engine/src/Resource/SHResourceManagerWrapper.h b/SHADE_Engine/src/Resource/SHResourceManagerWrapper.h new file mode 100644 index 00000000..9f34f74e --- /dev/null +++ b/SHADE_Engine/src/Resource/SHResourceManagerWrapper.h @@ -0,0 +1,57 @@ +/************************************************************************************//*! +\file SHResourceManagerWrapper.h +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 22, 2022 +\brief Contains the definition of the SHResourceManagerWrapper static class. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// STL Includes +#include +// Project Includes +#include "SH_API.h" +#include "Resource/SHHandle.h" +#include "Assets/SHAssetMacros.h" + +namespace SHADE +{ + /// + /// Static class providing access to non-templated functions of SHResourceManager for + /// SHADE_Managed. + /// + class SH_API SHResourceManagerWrapper + { + public: + /*---------------------------------------------------------------------------------*/ + /* Query Functions */ + /*---------------------------------------------------------------------------------*/ + /// + /// Retrieves the AssetID associated with a specified Handle. + /// Compared to the templated version, this function is slower as it requires + /// searching through the storage of all resource types. + /// + /// Handle to get the AssetID of. + /// + /// AssetID for the specified Handle. If the Handle is invalid, there will be no + /// value. + /// + static std::optional GetAssetID(Handle handle); + /// + /// Retrieves the name associated with the AssetID that is associated with the + /// specified Handle. + /// Compared to the templated version, this function is slower as it requires + /// searching through the storage of all resource types. + /// + /// Handle to get the name of. + /// + /// Name for the specified Handle. If the Handle is invalid, there will be no + /// value. + /// + static std::optional GetAssetName(Handle handle); + }; +} \ No newline at end of file diff --git a/SHADE_Managed/src/Assets/Font.cxx b/SHADE_Managed/src/Assets/Font.cxx index 782b0688..b21c7a02 100644 --- a/SHADE_Managed/src/Assets/Font.cxx +++ b/SHADE_Managed/src/Assets/Font.cxx @@ -15,18 +15,57 @@ of DigiPen Institute of Technology is prohibited. #include "SHpch.h" // Primary Header #include "Font.hxx" +// Project Headers +#include "Utility/Convert.hxx" namespace SHADE { /*---------------------------------------------------------------------------------*/ - /* Explicit Template Instantiation */ + /* Properties */ /*---------------------------------------------------------------------------------*/ - template ref class NativeAsset; + Handle Font::NativeObject::get() + try + { + return Handle(Convert::ToNative(asset.NativeObjectHandle)); + } + catch (const BadHandleCastException&) + { + return Handle(); + } + GenericHandle Font::NativeObjectHandle::get() + { + return asset.NativeObjectHandle; + } + AssetID Font::NativeAssetID::get() + { + return asset.NativeAssetID; + } /*---------------------------------------------------------------------------------*/ /* Constructors/Destructor */ /*---------------------------------------------------------------------------------*/ Font::Font(Handle font) - : NativeAsset { font } + : asset { Handle(font) } {} + + /*---------------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*---------------------------------------------------------------------------------*/ + Font::operator bool(Font asset) + { + return asset; + } + + /*---------------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*---------------------------------------------------------------------------------*/ + Font::operator Asset(Font nativeAsset) + { + return nativeAsset.asset; + } + + Font::operator Font(Asset asset) + { + return Font(Handle(Convert::ToNative(asset.NativeObjectHandle))); + } } diff --git a/SHADE_Managed/src/Assets/Font.hxx b/SHADE_Managed/src/Assets/Font.hxx index fd194d1a..4acc49e6 100644 --- a/SHADE_Managed/src/Assets/Font.hxx +++ b/SHADE_Managed/src/Assets/Font.hxx @@ -24,11 +24,36 @@ namespace SHADE { /// /// Managed counterpart of the native Font object that can be fed to TextRenderables - /// for rendering. + /// for rendering. /// - public ref class Font : public NativeAsset + public value struct Font { internal: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Copy of the Handle to the native object. + /// + property Handle NativeObject + { + Handle get(); + } + /// + /// Generic handle for the native object + /// + property GenericHandle NativeObjectHandle + { + GenericHandle get(); + } + /// + /// The raw asset ID of the asset. + /// + property AssetID NativeAssetID + { + AssetID get(); + } + /*-----------------------------------------------------------------------------*/ /* Constructors/Destructor */ /*-----------------------------------------------------------------------------*/ @@ -37,5 +62,35 @@ namespace SHADE /// /// Handle to the font object. Font(Handle font); + + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Font is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(Font asset); + + /*-----------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*-----------------------------------------------------------------------------*/ + /// + /// Conversion operator to enable casting from a Font to an Asset. + /// + /// Vector3 to convert from. + static explicit operator Asset(Font nativeAsset); + /// + /// Conversion operator to enable casting from a Asset to a Font. + /// + /// Vector2 to convert from. + static explicit operator Font(Asset vec); + + protected: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + Asset asset; }; } diff --git a/SHADE_Managed/src/Assets/Material.cxx b/SHADE_Managed/src/Assets/Material.cxx index f4262c2a..3caa5b22 100644 --- a/SHADE_Managed/src/Assets/Material.cxx +++ b/SHADE_Managed/src/Assets/Material.cxx @@ -53,15 +53,31 @@ namespace SHADE } /*---------------------------------------------------------------------------------*/ - /* Explicit Template Instantiation */ + /* Properties */ /*---------------------------------------------------------------------------------*/ - template ref class NativeAsset; + Handle Material::NativeObject::get() + try + { + return Handle(Convert::ToNative(asset.NativeObjectHandle)); + } + catch (const BadHandleCastException&) + { + return Handle(); + } + GenericHandle Material::NativeObjectHandle::get() + { + return asset.NativeObjectHandle; + } + AssetID Material::NativeAssetID::get() + { + return asset.NativeAssetID; + } /*---------------------------------------------------------------------------------*/ /* Constructors/Destructor */ /*---------------------------------------------------------------------------------*/ Material::Material(Handle material) - : NativeAsset{ material } + : asset { Handle(material) } {} /*---------------------------------------------------------------------------------*/ @@ -116,4 +132,25 @@ namespace SHADE throw gcnew System::ArgumentException("Attempted to retrieve an invalid property on a material."); } + + /*---------------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*---------------------------------------------------------------------------------*/ + Material::operator bool(Material asset) + { + return asset; + } + + /*---------------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*---------------------------------------------------------------------------------*/ + Material::operator Asset(Material nativeAsset) + { + return nativeAsset.asset; + } + + Material::operator Material(Asset asset) + { + return Material(Handle(Convert::ToNative(asset.NativeObjectHandle))); + } } diff --git a/SHADE_Managed/src/Assets/Material.hxx b/SHADE_Managed/src/Assets/Material.hxx index 25cc96a6..14cf557e 100644 --- a/SHADE_Managed/src/Assets/Material.hxx +++ b/SHADE_Managed/src/Assets/Material.hxx @@ -26,9 +26,34 @@ namespace SHADE /// Managed counterpart of the native MaterialInstance object containing material /// data that can be fed to Renderables for rendering. /// - public ref class Material : public NativeAsset + public value struct Material { internal: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Copy of the Handle to the native object. + /// + property Handle NativeObject + { + Handle get(); + } + /// + /// Generic handle for the native object + /// + property GenericHandle NativeObjectHandle + { + GenericHandle get(); + } + /// + /// The raw asset ID of the asset. + /// + property AssetID NativeAssetID + { + AssetID get(); + } + /*-----------------------------------------------------------------------------*/ /* Constructors/Destructor */ /*-----------------------------------------------------------------------------*/ @@ -77,5 +102,35 @@ namespace SHADE /// generic T GetProperty(System::String^ name); + + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Material is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(Material asset); + + /*-----------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*-----------------------------------------------------------------------------*/ + /// + /// Conversion operator to enable casting from a Material to an Asset. + /// + /// Vector3 to convert from. + static explicit operator Asset(Material nativeAsset); + /// + /// Conversion operator to enable casting from a Asset to a Material. + /// + /// Vector2 to convert from. + static explicit operator Material(Asset vec); + + protected: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + Asset asset; }; } diff --git a/SHADE_Managed/src/Assets/Mesh.cxx b/SHADE_Managed/src/Assets/Mesh.cxx index 95a61ff6..bcfeac36 100644 --- a/SHADE_Managed/src/Assets/Mesh.cxx +++ b/SHADE_Managed/src/Assets/Mesh.cxx @@ -21,14 +21,51 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { /*---------------------------------------------------------------------------------*/ - /* Explicit Template Instantiation */ + /* Properties */ /*---------------------------------------------------------------------------------*/ - template ref class NativeAsset; + Handle Mesh::NativeObject::get() + try + { + return Handle(Convert::ToNative(asset.NativeObjectHandle)); + } + catch (const BadHandleCastException&) + { + return Handle(); + } + GenericHandle Mesh::NativeObjectHandle::get() + { + return asset.NativeObjectHandle; + } + AssetID Mesh::NativeAssetID::get() + { + return asset.NativeAssetID; + } /*---------------------------------------------------------------------------------*/ /* Constructors/Destructor */ /*---------------------------------------------------------------------------------*/ - Mesh::Mesh(Handle mesh) - : NativeAsset { mesh } + Mesh::Mesh(Handle Mesh) + : asset{ Handle(Mesh) } {} + + /*---------------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*---------------------------------------------------------------------------------*/ + Mesh::operator bool(Mesh asset) + { + return asset; + } + + /*---------------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*---------------------------------------------------------------------------------*/ + Mesh::operator Asset(Mesh nativeAsset) + { + return nativeAsset.asset; + } + + Mesh::operator Mesh(Asset asset) + { + return Mesh(Handle(Convert::ToNative(asset.NativeObjectHandle))); + } } diff --git a/SHADE_Managed/src/Assets/Mesh.hxx b/SHADE_Managed/src/Assets/Mesh.hxx index 8cd356ba..7403ae83 100644 --- a/SHADE_Managed/src/Assets/Mesh.hxx +++ b/SHADE_Managed/src/Assets/Mesh.hxx @@ -26,16 +26,71 @@ namespace SHADE /// Managed counterpart of the native Mesh object containing vertex data that can /// be fed to Renderables for rendering. /// - public ref class Mesh : public NativeAsset + public value struct Mesh { - internal: + internal: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Copy of the Handle to the native object. + /// + property Handle NativeObject + { + Handle get(); + } + /// + /// Generic handle for the native object + /// + property GenericHandle NativeObjectHandle + { + GenericHandle get(); + } + /// + /// The raw asset ID of the asset. + /// + property AssetID NativeAssetID + { + AssetID get(); + } + /*-----------------------------------------------------------------------------*/ /* Constructors/Destructor */ /*-----------------------------------------------------------------------------*/ /// - /// Constructor for the Mesh + /// Constructor for the Mesh. /// - /// Handle to the mesh object. - Mesh(Handle mesh); + /// Handle to the Mesh object. + Mesh(Handle Mesh); + + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Mesh is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(Mesh asset); + + /*-----------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*-----------------------------------------------------------------------------*/ + /// + /// Conversion operator to enable casting from a Mesh to an Asset. + /// + /// Vector3 to convert from. + static explicit operator Asset(Mesh nativeAsset); + /// + /// Conversion operator to enable casting from a Asset to a Mesh. + /// + /// Vector2 to convert from. + static explicit operator Mesh(Asset vec); + + protected: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + Asset asset; }; } diff --git a/SHADE_Managed/src/Assets/NativeAsset.cxx b/SHADE_Managed/src/Assets/NativeAsset.cxx index 9cdb1840..3f827fea 100644 --- a/SHADE_Managed/src/Assets/NativeAsset.cxx +++ b/SHADE_Managed/src/Assets/NativeAsset.cxx @@ -17,6 +17,8 @@ of DigiPen Institute of Technology is prohibited. #include "NativeAsset.hxx" // Project Includes #include "Engine/GenericHandle.hxx" +#include "Utility/Convert.hxx" +#include "Resource/SHResourceManagerWrapper.h" namespace SHADE { @@ -27,6 +29,10 @@ namespace SHADE { return nativeObjHandle; } + AssetID Asset::NativeAssetID::get() + { + return SHResourceManagerWrapper::GetAssetID(Convert::ToNative(nativeObjHandle)).value_or(INVALID_ASSET_ID); + } /*---------------------------------------------------------------------------------*/ /* Constructors */ @@ -34,4 +40,12 @@ namespace SHADE Asset::Asset(Handle nativeHandle) : nativeObjHandle { Convert::ToCLI(Handle(nativeHandle)) } {} + + /*---------------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*---------------------------------------------------------------------------------*/ + Asset::operator bool(Asset asset) + { + return asset.nativeObjHandle && asset.NativeAssetID != INVALID_ASSET_ID; + } } \ No newline at end of file diff --git a/SHADE_Managed/src/Assets/NativeAsset.h++ b/SHADE_Managed/src/Assets/NativeAsset.h++ deleted file mode 100644 index 05be83b4..00000000 --- a/SHADE_Managed/src/Assets/NativeAsset.h++ +++ /dev/null @@ -1,44 +0,0 @@ -/************************************************************************************//*! -\file NativeAsset.h++ -\author Tng Kah Wei, kahwei.tng, 390009620 -\par email: kahwei.tng\@digipen.edu -\date Oct 28, 2022 -\brief Contains the definition of templated functions for the managed - NativeAsset classes. - - Note: This file is written in C++17/CLI. - -Copyright (C) 2022 DigiPen Institute of Technology. -Reproduction or disclosure of this file or its contents without the prior written consent -of DigiPen Institute of Technology is prohibited. -*//*************************************************************************************/ -#pragma once - -// Primary Include -#include "NativeAsset.hxx" -#include "Utility/Convert.hxx" - -namespace SHADE -{ - /*---------------------------------------------------------------------------------*/ - /* Properties */ - /*---------------------------------------------------------------------------------*/ - template - Handle NativeAsset::NativeObject::get() - try - { - return Handle(Convert::ToNative(nativeObjHandle)); - } - catch (const BadHandleCastException&) - { - return Handle(); // Null handle - } - - /*---------------------------------------------------------------------------------*/ - /* Constructors */ - /*---------------------------------------------------------------------------------*/ - template - NativeAsset::NativeAsset(Handle nativeObj) - : Asset { Handle(nativeObj) } - {} -} diff --git a/SHADE_Managed/src/Assets/NativeAsset.hxx b/SHADE_Managed/src/Assets/NativeAsset.hxx index 4d53ce6b..7ce9c6ed 100644 --- a/SHADE_Managed/src/Assets/NativeAsset.hxx +++ b/SHADE_Managed/src/Assets/NativeAsset.hxx @@ -14,14 +14,17 @@ of DigiPen Institute of Technology is prohibited. *//*************************************************************************************/ #pragma once +// External Dependencies +#include "Assets/SHAssetMacros.h" +// Project Includes #include "Engine/GenericHandle.hxx" namespace SHADE { /// - /// Abstract base class that all Native Assets will inherit from. + /// Struct that contains native asset information. /// - public ref class Asset abstract + public value struct Asset { internal: /*-----------------------------------------------------------------------------*/ @@ -34,6 +37,13 @@ namespace SHADE { GenericHandle get(); } + /// + /// The raw asset ID of the asset. + /// + property AssetID NativeAssetID + { + AssetID get(); + } /*-----------------------------------------------------------------------------*/ /* Constructors/Destructor */ @@ -44,43 +54,20 @@ namespace SHADE /// Native asset object handle. Asset(Handle nativeHandle); + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Asset is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(Asset asset); + protected: /*-----------------------------------------------------------------------------*/ /* Data Members */ /*-----------------------------------------------------------------------------*/ GenericHandle nativeObjHandle; }; - - /// - /// Generalised template class for a managed representation of a native asset - /// - /// - /// The type of the asset's native representation. - /// - template - public ref class NativeAsset abstract : Asset - { - internal: - /*-----------------------------------------------------------------------------*/ - /* Properties */ - /*-----------------------------------------------------------------------------*/ - /// - /// Copy of the Handle to the native object. - /// - property Handle NativeObject - { - Handle get(); - } - - /*-----------------------------------------------------------------------------*/ - /* Constructors/Destructor */ - /*-----------------------------------------------------------------------------*/ - /// - /// Constructor for the native asset - /// - /// Native asset object handle. - NativeAsset(Handle ptr); - }; } - -#include "NativeAsset.h++" From 719d29dec3f97ddfa86a399e9ddb9e4276b7a4d1 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 22 Nov 2022 16:51:07 +0800 Subject: [PATCH 08/23] Renamed Mesh and Font structs in Managed to MeshAsset and FontAsset and reworked them to be a abstraction for asset IDs --- .../Resource/SHResourceManagerInterface.cpp | 59 ++++++++++ .../src/Resource/SHResourceManagerInterface.h | 111 ++++++++++++++++++ .../src/Resource/SHResourceManagerWrapper.cpp | 34 ------ .../src/Resource/SHResourceManagerWrapper.h | 57 --------- .../src/Assets/{Font.cxx => FontAsset.cxx} | 26 ++-- .../src/Assets/{Font.hxx => FontAsset.hxx} | 21 ++-- .../src/Assets/{Mesh.cxx => MeshAsset.cxx} | 26 ++-- .../src/Assets/{Mesh.hxx => MeshAsset.hxx} | 21 ++-- SHADE_Managed/src/Assets/NativeAsset.cxx | 13 +- SHADE_Managed/src/Assets/NativeAsset.hxx | 13 +- SHADE_Managed/src/Components/Renderable.cxx | 6 +- SHADE_Managed/src/Components/Renderable.hxx | 8 +- .../src/Components/TextRenderable.cxx | 6 +- .../src/Components/TextRenderable.hxx | 8 +- 14 files changed, 229 insertions(+), 180 deletions(-) create mode 100644 SHADE_Engine/src/Resource/SHResourceManagerInterface.cpp create mode 100644 SHADE_Engine/src/Resource/SHResourceManagerInterface.h delete mode 100644 SHADE_Engine/src/Resource/SHResourceManagerWrapper.cpp delete mode 100644 SHADE_Engine/src/Resource/SHResourceManagerWrapper.h rename SHADE_Managed/src/Assets/{Font.cxx => FontAsset.cxx} (79%) rename SHADE_Managed/src/Assets/{Font.hxx => FontAsset.hxx} (86%) rename SHADE_Managed/src/Assets/{Mesh.cxx => MeshAsset.cxx} (79%) rename SHADE_Managed/src/Assets/{Mesh.hxx => MeshAsset.hxx} (86%) diff --git a/SHADE_Engine/src/Resource/SHResourceManagerInterface.cpp b/SHADE_Engine/src/Resource/SHResourceManagerInterface.cpp new file mode 100644 index 00000000..d89a7b16 --- /dev/null +++ b/SHADE_Engine/src/Resource/SHResourceManagerInterface.cpp @@ -0,0 +1,59 @@ +/************************************************************************************//*! +\file SHResourceManagerInterface.cpp +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 22, 2022 +\brief Contains the definition of the functions of the + SHResourceManagerInterface static class. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Header +#include "SHpch.h" +// Primary Include +#include "SHResourceManagerInterface.h" +// Project Includes +#include "SHResourceManager.h" + +namespace SHADE +{ + Handle SHResourceManagerInterface::LoadOrGetMesh(AssetID assetId) + { + return SHResourceManager::LoadOrGet(assetId); + } + Handle SHResourceManagerInterface::LoadOrGetTexture(AssetID assetId) + { + return SHResourceManager::LoadOrGet(assetId); + } + Handle SHResourceManagerInterface::LoadOrGetShaderModule(AssetID assetId) + { + return SHResourceManager::LoadOrGet(assetId); + } + Handle SHResourceManagerInterface::LoadOrGetMaterialSpec(AssetID assetId) + { + return SHResourceManager::LoadOrGet(assetId); + } + Handle SHResourceManagerInterface::LoadOrGetMaterial(AssetID assetId) + { + return SHResourceManager::LoadOrGet(assetId); + } + Handle SHResourceManagerInterface::LoadOrGetFont(AssetID assetId) + { + return SHResourceManager::LoadOrGet(assetId); + } + + /*-----------------------------------------------------------------------------------*/ + /* Query Functions */ + /*-----------------------------------------------------------------------------------*/ + std::optional SHResourceManagerInterface::GetAssetID(Handle handle) + { + return SHResourceManager::GetAssetID(handle); + } + + std::optional SHResourceManagerInterface::GetAssetName(Handle handle) + { + return SHResourceManager::GetAssetName(handle); + } +} diff --git a/SHADE_Engine/src/Resource/SHResourceManagerInterface.h b/SHADE_Engine/src/Resource/SHResourceManagerInterface.h new file mode 100644 index 00000000..359bd7c8 --- /dev/null +++ b/SHADE_Engine/src/Resource/SHResourceManagerInterface.h @@ -0,0 +1,111 @@ +/************************************************************************************//*! +\file SHResourceManagerInterface.h +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 22, 2022 +\brief Contains the definition of the SHResourceManagerInterface static class. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// STL Includes +#include +// Project Includes +#include "SH_API.h" +#include "Resource/SHHandle.h" +#include "Assets/SHAssetMacros.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Forward Declarations */ + /*-----------------------------------------------------------------------------------*/ + class SHMesh; + class SHTexture; + class SHVkShaderModule; + struct SHMaterialSpec; + class SHMaterial; + class SHFont; + + /*-----------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------------*/ + /// + /// Static class providing access to non-templated functions of SHResourceManager for + /// SHADE_Managed. + /// + class SH_API SHResourceManagerInterface + { + public: + /*---------------------------------------------------------------------------------*/ + /* Loading Functions */ + /*---------------------------------------------------------------------------------*/ + + /// + /// Wrapper for SHResourceManager::LoadOrGet(). + /// + /// Asset ID of the resource to load. + /// Handle to the resource to retrieve. + static Handle LoadOrGetMesh(AssetID assetId); + /// + /// Wrapper for SHResourceManager::LoadOrGet(). + /// + /// + /// Handle to the resource to retrieve. + static Handle LoadOrGetTexture(AssetID assetId); + /// + /// Wrapper for SHResourceManager::LoadOrGet(). + /// + /// Asset ID of the resource to load. + /// Handle to the resource to retrieve. + static Handle LoadOrGetShaderModule(AssetID assetId); + /// + /// Wrapper for SHResourceManager::LoadOrGet(). + /// + /// Asset ID of the resource to load. + /// Handle to the resource to retrieve. + static Handle LoadOrGetMaterialSpec (AssetID assetId); + /// + /// Wrapper for SHResourceManager::LoadOrGet(). + /// + /// Asset ID of the resource to load. + /// Handle to the resource to retrieve. + static Handle LoadOrGetMaterial(AssetID assetId); + /// + /// Wrapper for SHResourceManager::LoadOrGet(). + /// + /// Asset ID of the resource to load. + /// Handle to the resource to retrieve. + static Handle LoadOrGetFont(AssetID assetId); + + /*---------------------------------------------------------------------------------*/ + /* Query Functions */ + /*---------------------------------------------------------------------------------*/ + /// + /// Retrieves the AssetID associated with a specified Handle. + /// Compared to the templated version, this function is slower as it requires + /// searching through the storage of all resource types. + /// + /// Handle to get the AssetID of. + /// + /// AssetID for the specified Handle. If the Handle is invalid, there will be no + /// value. + /// + static std::optional GetAssetID(Handle handle); + /// + /// Retrieves the name associated with the AssetID that is associated with the + /// specified Handle. + /// Compared to the templated version, this function is slower as it requires + /// searching through the storage of all resource types. + /// + /// Handle to get the name of. + /// + /// Name for the specified Handle. If the Handle is invalid, there will be no + /// value. + /// + static std::optional GetAssetName(Handle handle); + }; +} \ No newline at end of file diff --git a/SHADE_Engine/src/Resource/SHResourceManagerWrapper.cpp b/SHADE_Engine/src/Resource/SHResourceManagerWrapper.cpp deleted file mode 100644 index f99e2dc6..00000000 --- a/SHADE_Engine/src/Resource/SHResourceManagerWrapper.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/************************************************************************************//*! -\file SHResourceManagerWrapper.cpp -\author Tng Kah Wei, kahwei.tng, 390009620 -\par email: kahwei.tng\@digipen.edu -\date Nov 22, 2022 -\brief Contains the definition of the functions of the SHResourceManagerWraper - static class. - -Copyright (C) 2022 DigiPen Institute of Technology. -Reproduction or disclosure of this file or its contents without the prior written consent -of DigiPen Institute of Technology is prohibited. -*//*************************************************************************************/ -// Precompiled Header -#include "SHpch.h" -// Primary Include -#include "SHResourceManagerWrapper.h" -// Project Includes -#include "SHResourceManager.h" - -namespace SHADE -{ - /*-----------------------------------------------------------------------------------*/ - /* Query Functions */ - /*-----------------------------------------------------------------------------------*/ - std::optional SHResourceManagerWrapper::GetAssetID(Handle handle) - { - return SHResourceManager::GetAssetID(handle); - } - - std::optional SHResourceManagerWrapper::GetAssetName(Handle handle) - { - return SHResourceManager::GetAssetName(handle); - } -} diff --git a/SHADE_Engine/src/Resource/SHResourceManagerWrapper.h b/SHADE_Engine/src/Resource/SHResourceManagerWrapper.h deleted file mode 100644 index 9f34f74e..00000000 --- a/SHADE_Engine/src/Resource/SHResourceManagerWrapper.h +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************************************************//*! -\file SHResourceManagerWrapper.h -\author Tng Kah Wei, kahwei.tng, 390009620 -\par email: kahwei.tng\@digipen.edu -\date Nov 22, 2022 -\brief Contains the definition of the SHResourceManagerWrapper static class. - -Copyright (C) 2022 DigiPen Institute of Technology. -Reproduction or disclosure of this file or its contents without the prior written consent -of DigiPen Institute of Technology is prohibited. -*//*************************************************************************************/ -#pragma once - -// STL Includes -#include -// Project Includes -#include "SH_API.h" -#include "Resource/SHHandle.h" -#include "Assets/SHAssetMacros.h" - -namespace SHADE -{ - /// - /// Static class providing access to non-templated functions of SHResourceManager for - /// SHADE_Managed. - /// - class SH_API SHResourceManagerWrapper - { - public: - /*---------------------------------------------------------------------------------*/ - /* Query Functions */ - /*---------------------------------------------------------------------------------*/ - /// - /// Retrieves the AssetID associated with a specified Handle. - /// Compared to the templated version, this function is slower as it requires - /// searching through the storage of all resource types. - /// - /// Handle to get the AssetID of. - /// - /// AssetID for the specified Handle. If the Handle is invalid, there will be no - /// value. - /// - static std::optional GetAssetID(Handle handle); - /// - /// Retrieves the name associated with the AssetID that is associated with the - /// specified Handle. - /// Compared to the templated version, this function is slower as it requires - /// searching through the storage of all resource types. - /// - /// Handle to get the name of. - /// - /// Name for the specified Handle. If the Handle is invalid, there will be no - /// value. - /// - static std::optional GetAssetName(Handle handle); - }; -} \ No newline at end of file diff --git a/SHADE_Managed/src/Assets/Font.cxx b/SHADE_Managed/src/Assets/FontAsset.cxx similarity index 79% rename from SHADE_Managed/src/Assets/Font.cxx rename to SHADE_Managed/src/Assets/FontAsset.cxx index b21c7a02..e49568fc 100644 --- a/SHADE_Managed/src/Assets/Font.cxx +++ b/SHADE_Managed/src/Assets/FontAsset.cxx @@ -14,7 +14,9 @@ of DigiPen Institute of Technology is prohibited. // Precompiled Headers #include "SHpch.h" // Primary Header -#include "Font.hxx" +#include "FontAsset.hxx" +// External Dependencies +#include "Resource/SHResourceManagerInterface.h" // Project Headers #include "Utility/Convert.hxx" @@ -23,20 +25,16 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Properties */ /*---------------------------------------------------------------------------------*/ - Handle Font::NativeObject::get() + Handle FontAsset::NativeObject::get() try { - return Handle(Convert::ToNative(asset.NativeObjectHandle)); + return SHResourceManagerInterface::LoadOrGetFont(asset.NativeAssetID); } catch (const BadHandleCastException&) { return Handle(); } - GenericHandle Font::NativeObjectHandle::get() - { - return asset.NativeObjectHandle; - } - AssetID Font::NativeAssetID::get() + AssetID FontAsset::NativeAssetID::get() { return asset.NativeAssetID; } @@ -44,14 +42,14 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Constructors/Destructor */ /*---------------------------------------------------------------------------------*/ - Font::Font(Handle font) - : asset { Handle(font) } + FontAsset::FontAsset(AssetID fontId) + : asset { fontId } {} /*---------------------------------------------------------------------------------*/ /* Operator Overloads */ /*---------------------------------------------------------------------------------*/ - Font::operator bool(Font asset) + FontAsset::operator bool(FontAsset asset) { return asset; } @@ -59,13 +57,13 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Conversion Operators */ /*---------------------------------------------------------------------------------*/ - Font::operator Asset(Font nativeAsset) + FontAsset::operator Asset(FontAsset nativeAsset) { return nativeAsset.asset; } - Font::operator Font(Asset asset) + FontAsset::operator FontAsset(Asset asset) { - return Font(Handle(Convert::ToNative(asset.NativeObjectHandle))); + return FontAsset(asset.NativeAssetID); } } diff --git a/SHADE_Managed/src/Assets/Font.hxx b/SHADE_Managed/src/Assets/FontAsset.hxx similarity index 86% rename from SHADE_Managed/src/Assets/Font.hxx rename to SHADE_Managed/src/Assets/FontAsset.hxx index 4acc49e6..89239224 100644 --- a/SHADE_Managed/src/Assets/Font.hxx +++ b/SHADE_Managed/src/Assets/FontAsset.hxx @@ -26,7 +26,7 @@ namespace SHADE /// Managed counterpart of the native Font object that can be fed to TextRenderables /// for rendering. /// - public value struct Font + public value struct FontAsset { internal: /*-----------------------------------------------------------------------------*/ @@ -40,13 +40,6 @@ namespace SHADE Handle get(); } /// - /// Generic handle for the native object - /// - property GenericHandle NativeObjectHandle - { - GenericHandle get(); - } - /// /// The raw asset ID of the asset. /// property AssetID NativeAssetID @@ -60,8 +53,8 @@ namespace SHADE /// /// Constructor for the Font. /// - /// Handle to the font object. - Font(Handle font); + /// AssetID to the font asset. + FontAsset(AssetID fontId); /*-----------------------------------------------------------------------------*/ /* Operator Overloads */ @@ -71,7 +64,7 @@ namespace SHADE /// /// Asset to check. /// True if the Asset is valid. - static operator bool(Font asset); + static operator bool(FontAsset asset); /*-----------------------------------------------------------------------------*/ /* Conversion Operators */ @@ -80,12 +73,12 @@ namespace SHADE /// Conversion operator to enable casting from a Font to an Asset. /// /// Vector3 to convert from. - static explicit operator Asset(Font nativeAsset); + static explicit operator Asset(FontAsset nativeAsset); /// /// Conversion operator to enable casting from a Asset to a Font. /// - /// Vector2 to convert from. - static explicit operator Font(Asset vec); + /// + static explicit operator FontAsset(Asset asset); protected: /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Assets/Mesh.cxx b/SHADE_Managed/src/Assets/MeshAsset.cxx similarity index 79% rename from SHADE_Managed/src/Assets/Mesh.cxx rename to SHADE_Managed/src/Assets/MeshAsset.cxx index bcfeac36..d24ad20d 100644 --- a/SHADE_Managed/src/Assets/Mesh.cxx +++ b/SHADE_Managed/src/Assets/MeshAsset.cxx @@ -14,7 +14,9 @@ of DigiPen Institute of Technology is prohibited. // Precompiled Headers #include "SHpch.h" // Primary Header -#include "Mesh.hxx" +#include "MeshAsset.hxx" +// External Dependencies +#include "Resource/SHResourceManagerInterface.h" // Project Headers #include "Utility/Convert.hxx" @@ -23,20 +25,16 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Properties */ /*---------------------------------------------------------------------------------*/ - Handle Mesh::NativeObject::get() + Handle MeshAsset::NativeObject::get() try { - return Handle(Convert::ToNative(asset.NativeObjectHandle)); + return SHResourceManagerInterface::LoadOrGetMesh(asset.NativeAssetID); } catch (const BadHandleCastException&) { return Handle(); } - GenericHandle Mesh::NativeObjectHandle::get() - { - return asset.NativeObjectHandle; - } - AssetID Mesh::NativeAssetID::get() + AssetID MeshAsset::NativeAssetID::get() { return asset.NativeAssetID; } @@ -44,14 +42,14 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Constructors/Destructor */ /*---------------------------------------------------------------------------------*/ - Mesh::Mesh(Handle Mesh) - : asset{ Handle(Mesh) } + MeshAsset::MeshAsset(AssetID meshId) + : asset{ meshId } {} /*---------------------------------------------------------------------------------*/ /* Operator Overloads */ /*---------------------------------------------------------------------------------*/ - Mesh::operator bool(Mesh asset) + MeshAsset::operator bool(MeshAsset asset) { return asset; } @@ -59,13 +57,13 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Conversion Operators */ /*---------------------------------------------------------------------------------*/ - Mesh::operator Asset(Mesh nativeAsset) + MeshAsset::operator Asset(MeshAsset nativeAsset) { return nativeAsset.asset; } - Mesh::operator Mesh(Asset asset) + MeshAsset::operator MeshAsset(Asset asset) { - return Mesh(Handle(Convert::ToNative(asset.NativeObjectHandle))); + return MeshAsset(asset.NativeAssetID); } } diff --git a/SHADE_Managed/src/Assets/Mesh.hxx b/SHADE_Managed/src/Assets/MeshAsset.hxx similarity index 86% rename from SHADE_Managed/src/Assets/Mesh.hxx rename to SHADE_Managed/src/Assets/MeshAsset.hxx index 7403ae83..26625c1a 100644 --- a/SHADE_Managed/src/Assets/Mesh.hxx +++ b/SHADE_Managed/src/Assets/MeshAsset.hxx @@ -26,7 +26,7 @@ namespace SHADE /// Managed counterpart of the native Mesh object containing vertex data that can /// be fed to Renderables for rendering. /// - public value struct Mesh + public value struct MeshAsset { internal: /*-----------------------------------------------------------------------------*/ @@ -40,13 +40,6 @@ namespace SHADE Handle get(); } /// - /// Generic handle for the native object - /// - property GenericHandle NativeObjectHandle - { - GenericHandle get(); - } - /// /// The raw asset ID of the asset. /// property AssetID NativeAssetID @@ -60,8 +53,8 @@ namespace SHADE /// /// Constructor for the Mesh. /// - /// Handle to the Mesh object. - Mesh(Handle Mesh); + /// AssetID to the Mesh asset. + MeshAsset(AssetID meshId); /*-----------------------------------------------------------------------------*/ /* Operator Overloads */ @@ -71,7 +64,7 @@ namespace SHADE /// /// Asset to check. /// True if the Asset is valid. - static operator bool(Mesh asset); + static operator bool(MeshAsset asset); /*-----------------------------------------------------------------------------*/ /* Conversion Operators */ @@ -80,12 +73,12 @@ namespace SHADE /// Conversion operator to enable casting from a Mesh to an Asset. /// /// Vector3 to convert from. - static explicit operator Asset(Mesh nativeAsset); + static explicit operator Asset(MeshAsset nativeAsset); /// /// Conversion operator to enable casting from a Asset to a Mesh. /// - /// Vector2 to convert from. - static explicit operator Mesh(Asset vec); + /// + static explicit operator MeshAsset(Asset asset); protected: /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Assets/NativeAsset.cxx b/SHADE_Managed/src/Assets/NativeAsset.cxx index 3f827fea..9480b02a 100644 --- a/SHADE_Managed/src/Assets/NativeAsset.cxx +++ b/SHADE_Managed/src/Assets/NativeAsset.cxx @@ -18,27 +18,22 @@ of DigiPen Institute of Technology is prohibited. // Project Includes #include "Engine/GenericHandle.hxx" #include "Utility/Convert.hxx" -#include "Resource/SHResourceManagerWrapper.h" namespace SHADE { /*---------------------------------------------------------------------------------*/ /* Properties */ /*---------------------------------------------------------------------------------*/ - GenericHandle Asset::NativeObjectHandle::get() - { - return nativeObjHandle; - } AssetID Asset::NativeAssetID::get() { - return SHResourceManagerWrapper::GetAssetID(Convert::ToNative(nativeObjHandle)).value_or(INVALID_ASSET_ID); + return assetId; } /*---------------------------------------------------------------------------------*/ /* Constructors */ /*---------------------------------------------------------------------------------*/ - Asset::Asset(Handle nativeHandle) - : nativeObjHandle { Convert::ToCLI(Handle(nativeHandle)) } + Asset::Asset(AssetID id) + : assetId { id } {} /*---------------------------------------------------------------------------------*/ @@ -46,6 +41,6 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ Asset::operator bool(Asset asset) { - return asset.nativeObjHandle && asset.NativeAssetID != INVALID_ASSET_ID; + return asset.NativeAssetID != INVALID_ASSET_ID; } } \ No newline at end of file diff --git a/SHADE_Managed/src/Assets/NativeAsset.hxx b/SHADE_Managed/src/Assets/NativeAsset.hxx index 7ce9c6ed..40f7e628 100644 --- a/SHADE_Managed/src/Assets/NativeAsset.hxx +++ b/SHADE_Managed/src/Assets/NativeAsset.hxx @@ -31,13 +31,6 @@ namespace SHADE /* Properties */ /*-----------------------------------------------------------------------------*/ /// - /// Generic handle for the native object - /// - property GenericHandle NativeObjectHandle - { - GenericHandle get(); - } - /// /// The raw asset ID of the asset. /// property AssetID NativeAssetID @@ -51,8 +44,8 @@ namespace SHADE /// /// Constructor for the asset. /// - /// Native asset object handle. - Asset(Handle nativeHandle); + /// Native asset ID to construct this asset from. + explicit Asset(AssetID id); /*-----------------------------------------------------------------------------*/ /* Operator Overloads */ @@ -68,6 +61,6 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Data Members */ /*-----------------------------------------------------------------------------*/ - GenericHandle nativeObjHandle; + AssetID assetId; }; } diff --git a/SHADE_Managed/src/Components/Renderable.cxx b/SHADE_Managed/src/Components/Renderable.cxx index bc01bc03..b4efe26e 100644 --- a/SHADE_Managed/src/Components/Renderable.cxx +++ b/SHADE_Managed/src/Components/Renderable.cxx @@ -30,11 +30,11 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Properties */ /*---------------------------------------------------------------------------------*/ - SHADE::Mesh^ Renderable::Mesh::get() + SHADE::MeshAsset^ Renderable::Mesh::get() { - return gcnew SHADE::Mesh(GetNativeComponent()->GetMesh()); + return gcnew SHADE::MeshAsset(GetNativeComponent()->GetMesh()); } - void Renderable::Mesh::set(SHADE::Mesh^ value) + void Renderable::Mesh::set(SHADE::MeshAsset^ value) { if (value == nullptr) { diff --git a/SHADE_Managed/src/Components/Renderable.hxx b/SHADE_Managed/src/Components/Renderable.hxx index e8f11ef6..be7d107f 100644 --- a/SHADE_Managed/src/Components/Renderable.hxx +++ b/SHADE_Managed/src/Components/Renderable.hxx @@ -20,7 +20,7 @@ of DigiPen Institute of Technology is prohibited. #include "Math/Quaternion.hxx" // External Dependencies #include "Graphics/MiddleEnd/Interface/SHRenderable.h" -#include "Assets/Mesh.hxx" +#include "Assets/MeshAsset.hxx" #include "Assets/Material.hxx" namespace SHADE @@ -48,10 +48,10 @@ namespace SHADE /// /// Mesh used to render this Renderable. /// - property SHADE::Mesh^ Mesh + property SHADE::MeshAsset^ Mesh { - SHADE::Mesh^ get(); - void set(SHADE::Mesh^ value); + SHADE::MeshAsset^ get(); + void set(SHADE::MeshAsset^ value); } /// /// Material used to render this Renderable. diff --git a/SHADE_Managed/src/Components/TextRenderable.cxx b/SHADE_Managed/src/Components/TextRenderable.cxx index c5859854..e34592ae 100644 --- a/SHADE_Managed/src/Components/TextRenderable.cxx +++ b/SHADE_Managed/src/Components/TextRenderable.cxx @@ -39,11 +39,11 @@ namespace SHADE { GetNativeComponent()->SetText(Convert::ToNative(value)); } - SHADE::Font^ TextRenderable::Font::get() + SHADE::FontAsset^ TextRenderable::Font::get() { - return gcnew SHADE::Font(GetNativeComponent()->GetFont()); + return gcnew SHADE::FontAsset(GetNativeComponent()->GetFont()); } - void TextRenderable::Font::set(SHADE::Font^ value) + void TextRenderable::Font::set(SHADE::FontAsset^ value) { if (value == nullptr) { diff --git a/SHADE_Managed/src/Components/TextRenderable.hxx b/SHADE_Managed/src/Components/TextRenderable.hxx index 5418b6e5..bcd99bcf 100644 --- a/SHADE_Managed/src/Components/TextRenderable.hxx +++ b/SHADE_Managed/src/Components/TextRenderable.hxx @@ -20,7 +20,7 @@ of DigiPen Institute of Technology is prohibited. #include "Components/Component.hxx" #include "Math/Vector3.hxx" #include "Math/Quaternion.hxx" -#include "Assets/Font.hxx" +#include "Assets/FontAsset.hxx" namespace SHADE { @@ -55,10 +55,10 @@ namespace SHADE /// /// Font to use to render using this TextRenderable. /// - property SHADE::Font^ Font + property SHADE::FontAsset^ Font { - SHADE::Font^ get(); - void set(SHADE::Font^ value); + SHADE::FontAsset^ get(); + void set(SHADE::FontAsset^ value); } }; } From 7d692061fbbf2e64930ea580c67193cbef60bcd5 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 22 Nov 2022 17:23:50 +0800 Subject: [PATCH 09/23] Reworked how Materials are handled on C# --- .../MiddleEnd/Interface/SHRenderable.cpp | 6 ++ .../MiddleEnd/Interface/SHRenderable.h | 1 + SHADE_Managed/src/Assets/MaterialAsset.cxx | 70 +++++++++++++++ SHADE_Managed/src/Assets/MaterialAsset.hxx | 89 +++++++++++++++++++ SHADE_Managed/src/Components/Renderable.cxx | 10 ++- SHADE_Managed/src/Components/Renderable.hxx | 13 ++- .../src/Components/TextRenderable.cxx | 2 +- .../src/{Assets => Graphics}/Material.cxx | 26 ++---- .../src/{Assets => Graphics}/Material.hxx | 18 +--- 9 files changed, 197 insertions(+), 38 deletions(-) create mode 100644 SHADE_Managed/src/Assets/MaterialAsset.cxx create mode 100644 SHADE_Managed/src/Assets/MaterialAsset.hxx rename SHADE_Managed/src/{Assets => Graphics}/Material.cxx (90%) rename SHADE_Managed/src/{Assets => Graphics}/Material.hxx (86%) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp index e22de5ab..c7578137 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp @@ -76,6 +76,12 @@ namespace SHADE sharedMaterial = materialInstance; } + void SHRenderable::SetMaterial(Handle material) + { + SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem(); + SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(material)); + } + Handle SHRenderable::GetMaterial() const { if (material) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h index f1455ef4..39132ca0 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h @@ -48,6 +48,7 @@ namespace SHADE /*-------------------------------------------------------------------------------*/ /* Material Functions */ /*-------------------------------------------------------------------------------*/ + void SetMaterial(Handle material); void SetMaterial(Handle materialInstance); Handle GetMaterial() const; Handle GetModifiableMaterial(); diff --git a/SHADE_Managed/src/Assets/MaterialAsset.cxx b/SHADE_Managed/src/Assets/MaterialAsset.cxx new file mode 100644 index 00000000..16f6a929 --- /dev/null +++ b/SHADE_Managed/src/Assets/MaterialAsset.cxx @@ -0,0 +1,70 @@ +/************************************************************************************//*! +\file MaterialAsset.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 22, 2022 +\brief Contains the implementation of the functions of the managed Material + struct. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "MaterialAsset.hxx" +// External Dependencies +#include "Resource/SHResourceManagerInterface.h" +// Project Headers +#include "Utility/Convert.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + Handle MaterialAsset::NativeObject::get() + try + { + return SHResourceManagerInterface::LoadOrGetMaterial(asset.NativeAssetID); + } + catch (const BadHandleCastException&) + { + return Handle(); + } + AssetID MaterialAsset::NativeAssetID::get() + { + return asset.NativeAssetID; + } + + /*---------------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*---------------------------------------------------------------------------------*/ + MaterialAsset::MaterialAsset(AssetID MaterialId) + : asset { MaterialId } + {} + + /*---------------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*---------------------------------------------------------------------------------*/ + MaterialAsset::operator bool(MaterialAsset asset) + { + return asset; + } + + /*---------------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*---------------------------------------------------------------------------------*/ + MaterialAsset::operator Asset(MaterialAsset nativeAsset) + { + return nativeAsset.asset; + } + + MaterialAsset::operator MaterialAsset(Asset asset) + { + return MaterialAsset(asset.NativeAssetID); + } +} diff --git a/SHADE_Managed/src/Assets/MaterialAsset.hxx b/SHADE_Managed/src/Assets/MaterialAsset.hxx new file mode 100644 index 00000000..5380b286 --- /dev/null +++ b/SHADE_Managed/src/Assets/MaterialAsset.hxx @@ -0,0 +1,89 @@ +/************************************************************************************//*! +\file MaterialAsset.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 22, 2022 +\brief Contains the definition of the managed MaterialAsset struct. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// External Dependencies +#include "Resource/SHHandle.h" +#include "Graphics/MiddleEnd/Interface/SHMaterial.h" +// Project Includes +#include "NativeAsset.hxx" +#include "Engine/GenericHandle.hxx" + +namespace SHADE +{ + /// + /// Managed counterpart of the native Material object that can be fed to TextRenderables + /// for rendering. + /// + public value struct MaterialAsset + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Copy of the Handle to the native object. + /// + property Handle NativeObject + { + Handle get(); + } + /// + /// The raw asset ID of the asset. + /// + property AssetID NativeAssetID + { + AssetID get(); + } + + /*-----------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor for the Material. + /// + /// AssetID to the Material asset. + MaterialAsset(AssetID MaterialId); + + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Material is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(MaterialAsset asset); + + /*-----------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*-----------------------------------------------------------------------------*/ + /// + /// Conversion operator to enable casting from a Material to an Asset. + /// + /// Vector3 to convert from. + static explicit operator Asset(MaterialAsset nativeAsset); + /// + /// Conversion operator to enable casting from a Asset to a Material. + /// + /// + static explicit operator MaterialAsset(Asset asset); + + protected: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + Asset asset; + }; +} diff --git a/SHADE_Managed/src/Components/Renderable.cxx b/SHADE_Managed/src/Components/Renderable.cxx index b4efe26e..819760e6 100644 --- a/SHADE_Managed/src/Components/Renderable.cxx +++ b/SHADE_Managed/src/Components/Renderable.cxx @@ -42,7 +42,7 @@ namespace SHADE } else { - GetNativeComponent()->SetMesh(Handle(Convert::ToNative(value->NativeObjectHandle))); + GetNativeComponent()->SetMesh(value->NativeObject); } } SHADE::Material^ Renderable::Material::get() @@ -64,4 +64,12 @@ namespace SHADE { return GetNativeComponent()->GetLightLayer(); } + + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + void Renderable::SetMaterial(MaterialAsset materialAsset) + { + GetNativeComponent()->SetMaterial(materialAsset.NativeObject); + } } diff --git a/SHADE_Managed/src/Components/Renderable.hxx b/SHADE_Managed/src/Components/Renderable.hxx index be7d107f..d52a01e5 100644 --- a/SHADE_Managed/src/Components/Renderable.hxx +++ b/SHADE_Managed/src/Components/Renderable.hxx @@ -21,7 +21,8 @@ of DigiPen Institute of Technology is prohibited. // External Dependencies #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Assets/MeshAsset.hxx" -#include "Assets/Material.hxx" +#include "Graphics/Material.hxx" +#include "Assets/MaterialAsset.hxx" namespace SHADE { @@ -68,6 +69,16 @@ namespace SHADE { System::Byte get(); } + + /*-----------------------------------------------------------------------------*/ + /* Usage functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Sets the Material used by this Renderable to be an instance of the specified + /// base MaterialAsset. + /// + /// Material to set. + void SetMaterial(MaterialAsset materialAsset); }; } diff --git a/SHADE_Managed/src/Components/TextRenderable.cxx b/SHADE_Managed/src/Components/TextRenderable.cxx index e34592ae..88e43823 100644 --- a/SHADE_Managed/src/Components/TextRenderable.cxx +++ b/SHADE_Managed/src/Components/TextRenderable.cxx @@ -51,7 +51,7 @@ namespace SHADE } else { - GetNativeComponent()->SetFont(Handle(Convert::ToNative(value->NativeObjectHandle))); + GetNativeComponent()->SetFont(value->NativeObject); } } } diff --git a/SHADE_Managed/src/Assets/Material.cxx b/SHADE_Managed/src/Graphics/Material.cxx similarity index 90% rename from SHADE_Managed/src/Assets/Material.cxx rename to SHADE_Managed/src/Graphics/Material.cxx index 3caa5b22..e646b34d 100644 --- a/SHADE_Managed/src/Assets/Material.cxx +++ b/SHADE_Managed/src/Graphics/Material.cxx @@ -20,6 +20,7 @@ of DigiPen Institute of Technology is prohibited. #include // Project Includes #include "Utility/Convert.hxx" +#include "Resource/SHResourceManagerInterface.h" namespace SHADE { @@ -58,7 +59,7 @@ namespace SHADE Handle Material::NativeObject::get() try { - return Handle(Convert::ToNative(asset.NativeObjectHandle)); + return Handle(Convert::ToNative(matInstHandle)); } catch (const BadHandleCastException&) { @@ -66,18 +67,18 @@ namespace SHADE } GenericHandle Material::NativeObjectHandle::get() { - return asset.NativeObjectHandle; + return matInstHandle; } AssetID Material::NativeAssetID::get() { - return asset.NativeAssetID; + return SHResourceManagerInterface::GetAssetID(Convert::ToNative(matInstHandle)).value_or(INVALID_ASSET_ID); } /*---------------------------------------------------------------------------------*/ /* Constructors/Destructor */ /*---------------------------------------------------------------------------------*/ Material::Material(Handle material) - : asset { Handle(material) } + : matInstHandle{ Handle(material) } {} /*---------------------------------------------------------------------------------*/ @@ -136,21 +137,8 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Operator Overloads */ /*---------------------------------------------------------------------------------*/ - Material::operator bool(Material asset) + Material::operator bool(Material materialInstance) { - return asset; - } - - /*---------------------------------------------------------------------------------*/ - /* Conversion Operators */ - /*---------------------------------------------------------------------------------*/ - Material::operator Asset(Material nativeAsset) - { - return nativeAsset.asset; - } - - Material::operator Material(Asset asset) - { - return Material(Handle(Convert::ToNative(asset.NativeObjectHandle))); + return materialInstance; } } diff --git a/SHADE_Managed/src/Assets/Material.hxx b/SHADE_Managed/src/Graphics/Material.hxx similarity index 86% rename from SHADE_Managed/src/Assets/Material.hxx rename to SHADE_Managed/src/Graphics/Material.hxx index 14cf557e..12664658 100644 --- a/SHADE_Managed/src/Assets/Material.hxx +++ b/SHADE_Managed/src/Graphics/Material.hxx @@ -16,8 +16,8 @@ of DigiPen Institute of Technology is prohibited. // External Dependencies #include "Resource/SHHandle.h" #include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h" +#include "Assets/SHAssetMacros.h" // Project Includes -#include "NativeAsset.hxx" #include "Engine/GenericHandle.hxx" namespace SHADE @@ -113,24 +113,10 @@ namespace SHADE /// True if the Asset is valid. static operator bool(Material asset); - /*-----------------------------------------------------------------------------*/ - /* Conversion Operators */ - /*-----------------------------------------------------------------------------*/ - /// - /// Conversion operator to enable casting from a Material to an Asset. - /// - /// Vector3 to convert from. - static explicit operator Asset(Material nativeAsset); - /// - /// Conversion operator to enable casting from a Asset to a Material. - /// - /// Vector2 to convert from. - static explicit operator Material(Asset vec); - protected: /*-----------------------------------------------------------------------------*/ /* Data Members */ /*-----------------------------------------------------------------------------*/ - Asset asset; + GenericHandle matInstHandle; }; } From 4478b6db62d8dc309f949665e364e4b41b89dd3b Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 22 Nov 2022 17:48:01 +0800 Subject: [PATCH 10/23] Added editor support for FontAsset, MeshAsset and MaterialAsset. --- Assets/Scripts/RaccoonShowcase.cs | 4 +- SHADE_Engine/src/Editor/SHEditorUI.cpp | 49 ++++++++++++++++++++++ SHADE_Engine/src/Editor/SHEditorUI.h | 11 +++++ SHADE_Managed/src/Assets/FontAsset.cxx | 2 +- SHADE_Managed/src/Assets/MaterialAsset.cxx | 2 +- SHADE_Managed/src/Assets/MeshAsset.cxx | 2 +- SHADE_Managed/src/Editor/Editor.cxx | 10 ++++- SHADE_Managed/src/Editor/Editor.h++ | 39 +++++++++++++++++ 8 files changed, 113 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/RaccoonShowcase.cs b/Assets/Scripts/RaccoonShowcase.cs index 3c767f7f..1da191fd 100644 --- a/Assets/Scripts/RaccoonShowcase.cs +++ b/Assets/Scripts/RaccoonShowcase.cs @@ -23,7 +23,9 @@ public class RaccoonShowcase : Script [Range(-5, 5)] public List intList = new List(new int[] { 2, 8, 2, 6, 8, 0, 1 }); public List enumList = new List(new Light.Type[] { Light.Type.Point, Light.Type.Directional, Light.Type.Ambient }); - + public FontAsset fontAsset; + public MeshAsset mesh; + public MaterialAsset matAsset; protected override void awake() { Transform = GetComponent(); diff --git a/SHADE_Engine/src/Editor/SHEditorUI.cpp b/SHADE_Engine/src/Editor/SHEditorUI.cpp index 9fdcbde7..caa6e5a2 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.cpp +++ b/SHADE_Engine/src/Editor/SHEditorUI.cpp @@ -15,8 +15,10 @@ of DigiPen Institute of Technology is prohibited. #include "SHEditorUI.h" // External Dependencies #include +// Project Includes #include "SHEditorWidgets.hpp" #include "ECS_Base/Managers/SHEntityManager.h" +#include "Assets/SHAssetManager.h" namespace SHADE { @@ -351,6 +353,53 @@ namespace SHADE return changed; } + bool SHEditorUI::InputAssetField(const std::string& label, AssetID& value, AssetType type, bool* isHovered, bool alwaysNull) + { + // Label + if (!label.empty()) + { + ImGui::Text(label.c_str()); + ImGui::SameLine(); + } + // Hover tracking + if (isHovered) + *isHovered = ImGui::IsItemHovered(); + ImGui::SameLine(); + + // Attempt to get the asset's data for rendering editor + auto asset = SHAssetManager::GetAsset(value); + std::string assetName; + if (asset.has_value()) + { + assetName = asset.value().name; + } + + // Editor + bool changed = ImGui::InputText("##", &assetName, ImGuiInputTextFlags_ReadOnly); + if (SHDragDrop::BeginTarget()) + { + if (AssetID* payload = SHDragDrop::AcceptPayload(SHDragDrop::DRAG_RESOURCE)) + { + // Check if type matches + auto draggedAsset = SHAssetManager::GetAsset(*payload); + if (draggedAsset.has_value() && draggedAsset.value().type == type) + { + value = draggedAsset.value().id; + changed = true; + } + SHDragDrop::EndTarget(); + } + } + ImGui::SameLine(); + if (ImGui::Button("Clear")) + { + value = INVALID_ASSET_ID; + changed = true; + } + + return changed; + } + bool SHEditorUI::InputEnumCombo(const std::string& label, int& v, const std::vector& enumNames, bool* isHovered) { // Clamp input value diff --git a/SHADE_Engine/src/Editor/SHEditorUI.h b/SHADE_Engine/src/Editor/SHEditorUI.h index f450ac0d..ce26b39e 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.h +++ b/SHADE_Engine/src/Editor/SHEditorUI.h @@ -19,6 +19,7 @@ of DigiPen Institute of Technology is prohibited. #include "Math/Vector/SHVec3.h" #include "Math/Vector/SHVec4.h" #include "Math/SHMatrix.h" +#include "Assets/SHAssetMacros.h" namespace SHADE { @@ -310,6 +311,16 @@ namespace SHADE /// True if the value was changed. static bool InputGameObjectField(const std::string& label, uint32_t& value, bool* isHovered = nullptr, bool alwaysNull = false); /// + /// + /// + /// + /// + /// + /// + /// + /// + static bool InputAssetField(const std::string& label, AssetID& value, AssetType type, bool* isHovered = nullptr, bool alwaysNull = false); + /// /// Creates a combo box for enumeration input. /// /// The type of enum to input. diff --git a/SHADE_Managed/src/Assets/FontAsset.cxx b/SHADE_Managed/src/Assets/FontAsset.cxx index e49568fc..19d256cb 100644 --- a/SHADE_Managed/src/Assets/FontAsset.cxx +++ b/SHADE_Managed/src/Assets/FontAsset.cxx @@ -51,7 +51,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ FontAsset::operator bool(FontAsset asset) { - return asset; + return asset.asset; } /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Assets/MaterialAsset.cxx b/SHADE_Managed/src/Assets/MaterialAsset.cxx index 16f6a929..48cbfd83 100644 --- a/SHADE_Managed/src/Assets/MaterialAsset.cxx +++ b/SHADE_Managed/src/Assets/MaterialAsset.cxx @@ -52,7 +52,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ MaterialAsset::operator bool(MaterialAsset asset) { - return asset; + return asset.asset; } /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Assets/MeshAsset.cxx b/SHADE_Managed/src/Assets/MeshAsset.cxx index d24ad20d..6301fcee 100644 --- a/SHADE_Managed/src/Assets/MeshAsset.cxx +++ b/SHADE_Managed/src/Assets/MeshAsset.cxx @@ -51,7 +51,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ MeshAsset::operator bool(MeshAsset asset) { - return asset; + return asset.asset; } /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Editor/Editor.cxx b/SHADE_Managed/src/Editor/Editor.cxx index beb667e3..29e3da36 100644 --- a/SHADE_Managed/src/Editor/Editor.cxx +++ b/SHADE_Managed/src/Editor/Editor.cxx @@ -176,7 +176,10 @@ namespace SHADE renderSpecificField(field, object, SHEditorUI::InputVec3 , &isHovered) || renderSpecificField(field, object, nullptr , &isHovered) || renderSpecificField(field, object, nullptr , &isHovered) || - renderSpecificField(field, object, nullptr , &isHovered); + renderSpecificField(field, object, nullptr , &isHovered) || + renderSpecificField(field, object, nullptr , &isHovered) || + renderSpecificField(field, object, nullptr , &isHovered) || + renderSpecificField(field, object, nullptr , &isHovered); if (!MODIFIED_PRIMITIVE) { @@ -319,7 +322,10 @@ namespace SHADE renderFieldEditor(fieldName, object, SHEditorUI::InputVec3 , nullptr, rangeAttrib, modified) || renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || - renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified); + renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified); return modified; } diff --git a/SHADE_Managed/src/Editor/Editor.h++ b/SHADE_Managed/src/Editor/Editor.h++ index a186d7ea..352431fd 100644 --- a/SHADE_Managed/src/Editor/Editor.h++ +++ b/SHADE_Managed/src/Editor/Editor.h++ @@ -20,6 +20,9 @@ of DigiPen Institute of Technology is prohibited. #include "Editor/SHEditorUI.h" // Project Includes #include "Utility/Convert.hxx" +#include "Assets/FontAsset.hxx" +#include "Assets/MeshAsset.hxx" +#include "Assets/MaterialAsset.hxx" namespace SHADE { @@ -198,6 +201,42 @@ namespace SHADE return true; } + return false; + } + template<> + bool Editor::renderFieldEditorInternal(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, bool* isHovered, RangeAttribute^) + { + uint32_t assetId = managedValPtr->NativeAssetID; + if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::FONT, isHovered, !(*managedValPtr))) + { + *managedValPtr = FontAsset(assetId); + return true; + } + + return false; + } + template<> + bool Editor::renderFieldEditorInternal(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, bool* isHovered, RangeAttribute^) + { + uint32_t assetId = managedValPtr->NativeAssetID; + if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MESH, isHovered, !(*managedValPtr))) + { + *managedValPtr = MeshAsset(assetId); + return true; + } + + return false; + } + template<> + bool Editor::renderFieldEditorInternal(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, bool* isHovered, RangeAttribute^) + { + uint32_t assetId = managedValPtr->NativeAssetID; + if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MATERIAL, isHovered, !(*managedValPtr))) + { + *managedValPtr = MaterialAsset(assetId); + return true; + } + return false; } } From 9a7bf335bb732743dd0cac0b568a2be8eefa0f01 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 22 Nov 2022 17:58:07 +0800 Subject: [PATCH 11/23] Added serialization and deserialization of MeshAsset, FontAsset and MaterialAsset --- .../Serialisation/SerialisationUtilities.cxx | 23 +++++++++++++--- .../Serialisation/SerialisationUtilities.h++ | 27 +++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx b/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx index cfa94540..8a36613c 100644 --- a/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx +++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx @@ -18,6 +18,9 @@ of DigiPen Institute of Technology is prohibited. #include "Serialisation/SerialisationUtilities.hxx" // Project Includes #include "ReflectionUtilities.hxx" +#include "Assets/FontAsset.hxx" +#include "Assets/MaterialAsset.hxx" +#include "Assets/MeshAsset.hxx" /*-------------------------------------------------------------------------------------*/ /* File-Level Constants */ @@ -129,7 +132,10 @@ namespace SHADE fieldInsertYaml(fieldInfo, object, fieldNode) || fieldInsertYaml(fieldInfo, object, fieldNode) || fieldInsertYaml(fieldInfo, object, fieldNode) || - fieldInsertYaml(fieldInfo, object, fieldNode); + fieldInsertYaml(fieldInfo, object, fieldNode) || + fieldInsertYaml(fieldInfo, object, fieldNode) || + fieldInsertYaml(fieldInfo, object, fieldNode) || + fieldInsertYaml(fieldInfo, object, fieldNode); // Serialization of more complex types if (!PRIMITIVE_SERIALIZED) @@ -190,7 +196,10 @@ namespace SHADE varInsertYamlInternal(object, fieldNode) || varInsertYamlInternal(object, fieldNode) || varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode); + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode); return INSERTED; } @@ -214,7 +223,10 @@ namespace SHADE fieldAssignYaml(fieldInfo, object, node) || fieldAssignYaml (fieldInfo, object, node) || fieldAssignYaml (fieldInfo, object, node) || - fieldAssignYaml (fieldInfo, object, node); + fieldAssignYaml (fieldInfo, object, node) || + fieldAssignYaml (fieldInfo, object, node) || + fieldAssignYaml (fieldInfo, object, node) || + fieldAssignYaml (fieldInfo, object, node); if (!ASSIGNED) { if (ReflectionUtilities::FieldIsList(fieldInfo)) @@ -277,7 +289,10 @@ namespace SHADE varAssignYamlInternal(object, node) || varAssignYamlInternal (object, node) || varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node); + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node); return DESERIALISED; } } diff --git a/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ index 2c943452..04c87ef4 100644 --- a/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ +++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ @@ -60,6 +60,12 @@ namespace SHADE { fieldNode = MAX_EID; } + else if constexpr (std::is_same_v || + std::is_same_v || + std::is_same_v) + { + fieldNode = INVALID_ASSET_ID; + } else { fieldNode = FieldType(); @@ -122,6 +128,17 @@ namespace SHADE return true; } } + else if constexpr (std::is_same_v || + std::is_same_v || + std::is_same_v) + { + if (object->GetType() == FieldType::typeid) + { + FieldType asset = safe_cast(object); + fieldNode = asset.NativeAssetID; + return true; + } + } else { if (object->GetType() == FieldType::typeid) @@ -229,6 +246,16 @@ namespace SHADE const uint32_t EID = node.as(); object = (EID == MAX_EID ? GameObject() : GameObject(EID)); } + else if constexpr (std::is_same_v || + std::is_same_v || + std::is_same_v) + { + if (object->GetType() == FieldType::typeid) + { + object = FieldType(node.as()); + return true; + } + } else { object = node.as(); From 6afcaa92638624bdffc40a0a2097a7b798512e63 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 22 Nov 2022 18:09:50 +0800 Subject: [PATCH 12/23] Enabled state of scripts are now serialised --- SHADE_Managed/src/Scripts/Script.cxx | 8 +++++ SHADE_Managed/src/Scripts/Script.hxx | 9 ++++++ SHADE_Managed/src/Scripts/ScriptStore.cxx | 2 +- .../Serialisation/SerialisationUtilities.cxx | 30 +++++++++++++++++-- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/SHADE_Managed/src/Scripts/Script.cxx b/SHADE_Managed/src/Scripts/Script.cxx index 2ee7dbf7..294f4096 100644 --- a/SHADE_Managed/src/Scripts/Script.cxx +++ b/SHADE_Managed/src/Scripts/Script.cxx @@ -258,6 +258,14 @@ namespace SHADE Script::Script() : OnGizmosDrawOverriden { false } {} + + /*---------------------------------------------------------------------------------*/ + /* Manipulation Functions */ + /*---------------------------------------------------------------------------------*/ + void Script::SetEnabledWithoutEvents(bool enable) + { + enabled = enable; + } /*---------------------------------------------------------------------------------*/ /* Virtual "All-Time" Lifecycle Functions */ diff --git a/SHADE_Managed/src/Scripts/Script.hxx b/SHADE_Managed/src/Scripts/Script.hxx index 62c5015c..8fc36544 100644 --- a/SHADE_Managed/src/Scripts/Script.hxx +++ b/SHADE_Managed/src/Scripts/Script.hxx @@ -326,6 +326,15 @@ namespace SHADE /// Information on the collision event. void OnTriggerExit(CollisionInfo collision); + /*-----------------------------------------------------------------------------*/ + /* Manipulation Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Function to set the enabled state of this script without triggering events. + /// + /// Whether to enable or disable the script. + void SetEnabledWithoutEvents(bool enable); + protected: /*-----------------------------------------------------------------------------*/ /* Constructors */ diff --git a/SHADE_Managed/src/Scripts/ScriptStore.cxx b/SHADE_Managed/src/Scripts/ScriptStore.cxx index 96eb7361..d3d989cc 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.cxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.cxx @@ -744,7 +744,7 @@ namespace SHADE for (YAML::Node& node : *yamlNode) { // Get the name of the script - if (!node["Type"]) + if (!node["Type"].IsDefined()) { Debug::LogWarning("[ScriptStore] Script with no type detected, skipping."); continue; diff --git a/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx b/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx index 8a36613c..2bf05bc5 100644 --- a/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx +++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx @@ -21,11 +21,13 @@ of DigiPen Institute of Technology is prohibited. #include "Assets/FontAsset.hxx" #include "Assets/MaterialAsset.hxx" #include "Assets/MeshAsset.hxx" +#include "Scripts/Script.hxx" /*-------------------------------------------------------------------------------------*/ /* File-Level Constants */ /*-------------------------------------------------------------------------------------*/ static const std::string_view SCRIPT_TYPE_YAMLTAG = "Type"; +static const std::string_view SCRIPT_ENABLED_YAMLTAG = "Enabled"; /*-------------------------------------------------------------------------------------*/ /* Function Definitions */ @@ -39,10 +41,19 @@ namespace SHADE { using namespace System::Reflection; + // Obtain script + Script^ script = safe_cast(object); + if (script == nullptr) + { + Debug::LogWarning("[SerialisationUtilities] Attempted to serialise an object that is not a script!"); + return; + } + // Create YAML object YAML::Node scriptNode; scriptNode.SetStyle(YAML::EmitterStyle::Block); scriptNode[SCRIPT_TYPE_YAMLTAG.data()] = Convert::ToNative(object->GetType()->FullName); + scriptNode[SCRIPT_ENABLED_YAMLTAG.data()] = script->Enabled; // Get all fields System::Collections::Generic::IEnumerable^ fields = ReflectionUtilities::GetInstanceFields(object); @@ -72,7 +83,7 @@ namespace SHADE { using namespace System::Reflection; - // Load the YAML + // Error Checking if (!yamlNode.IsMap()) { // Invalid @@ -83,6 +94,21 @@ namespace SHADE ); return; } + + // Get the script + Script^ script = safe_cast(object); + if (script == nullptr) + { + Debug::LogWarning("[SerialisationUtilities] Attempted to deserialise an object that is not a script!"); + return; + } + + // Set enabled state + if (yamlNode[SCRIPT_ENABLED_YAMLTAG.data()].IsDefined()) + { + script->SetEnabledWithoutEvents(yamlNode[SCRIPT_ENABLED_YAMLTAG.data()].as()); + } + // Get all fields System::Collections::Generic::IEnumerable^ fields = ReflectionUtilities::GetInstanceFields(object); for each (FieldInfo^ field in fields) @@ -95,7 +121,7 @@ namespace SHADE // Deserialise const std::string FIELD_NAME = Convert::ToNative(field->Name); - if (yamlNode[FIELD_NAME]) + if (yamlNode[FIELD_NAME].IsDefined()) { writeYamlIntoField(field, object, yamlNode[FIELD_NAME]); } From 9964d5dfce3c17199bf2cf62df0c85499ebcff3b Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 22 Nov 2022 18:17:24 +0800 Subject: [PATCH 13/23] Fixed missing comments for SHEditorUI --- SHADE_Engine/src/Editor/SHEditorUI.cpp | 2 +- SHADE_Engine/src/Editor/SHEditorUI.h | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/SHADE_Engine/src/Editor/SHEditorUI.cpp b/SHADE_Engine/src/Editor/SHEditorUI.cpp index caa6e5a2..b9783020 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.cpp +++ b/SHADE_Engine/src/Editor/SHEditorUI.cpp @@ -353,7 +353,7 @@ namespace SHADE return changed; } - bool SHEditorUI::InputAssetField(const std::string& label, AssetID& value, AssetType type, bool* isHovered, bool alwaysNull) + bool SHEditorUI::InputAssetField(const std::string& label, AssetID& value, AssetType type, bool* isHovered) { // Label if (!label.empty()) diff --git a/SHADE_Engine/src/Editor/SHEditorUI.h b/SHADE_Engine/src/Editor/SHEditorUI.h index ce26b39e..cd87f46b 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.h +++ b/SHADE_Engine/src/Editor/SHEditorUI.h @@ -299,7 +299,7 @@ namespace SHADE /// True if the value was changed. static bool InputTextField(const std::string& label, std::string& value, bool* isHovered = nullptr); /// - /// Creates a drag field widget for int input. + /// Creates a drag field widget for GameObject input. /// /// Label used to identify this widget. /// Reference to the variable to store the result. @@ -311,15 +311,12 @@ namespace SHADE /// True if the value was changed. static bool InputGameObjectField(const std::string& label, uint32_t& value, bool* isHovered = nullptr, bool alwaysNull = false); /// - /// + /// Creates a drag field widget for Asset input. /// - /// - /// - /// - /// - /// - /// - static bool InputAssetField(const std::string& label, AssetID& value, AssetType type, bool* isHovered = nullptr, bool alwaysNull = false); + /// Label used to identify this widget. + /// Reference to the variable to store the result. + /// fixedDT; accumulatedTime += dt; + testFunction(); + int count = 0; while (accumulatedTime > FIXED_DT) { @@ -315,7 +318,7 @@ namespace SHADE if (physicsObject.GetRigidBody()->isActive()) physicsObject.prevTransform = CURRENT_TF; - // Sync with rigid bodies + // Sync with rigid bodies. If an object doesn't have a rigidbody, no update is needed here as it is done in pre-update. if (rigidBodyComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) { // Skip static bodies @@ -336,20 +339,25 @@ namespace SHADE rigidBodyComponent->position = CURRENT_TF.getPosition(); rigidBodyComponent->orientation = CURRENT_TF.getOrientation(); - } - // Sync with colliders - if (colliderComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) - { - colliderComponent->position = CURRENT_TF.getPosition(); - colliderComponent->orientation = CURRENT_TF.getOrientation(); - } + // Sync with colliders + if (colliderComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) + { + // Skip colliders without rigidbody components. If any transform was updated, it was done in pre-update. + + colliderComponent->position = CURRENT_TF.getPosition(); + colliderComponent->orientation = CURRENT_TF.getOrientation(); + } - // Set transform for rendering - if (transformComponent) - { - transformComponent->SetWorldPosition(renderPos); - transformComponent->SetWorldOrientation(renderRot); + // Set transform for rendering + if (transformComponent) + { + transformComponent->SetWorldPosition(renderPos); + transformComponent->SetWorldOrientation(renderRot); + } } } -} // namespace SHADE \ No newline at end of file +} // namespace SHADE + + + From fb25d2b71447e07769a5b0c2e573ff526d058ca3 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 22 Nov 2022 19:44:07 +0800 Subject: [PATCH 15/23] Fixed compilation error in Editor.h++ --- SHADE_Managed/src/Editor/Editor.h++ | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SHADE_Managed/src/Editor/Editor.h++ b/SHADE_Managed/src/Editor/Editor.h++ index 352431fd..37d5c27d 100644 --- a/SHADE_Managed/src/Editor/Editor.h++ +++ b/SHADE_Managed/src/Editor/Editor.h++ @@ -207,7 +207,7 @@ namespace SHADE bool Editor::renderFieldEditorInternal(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, bool* isHovered, RangeAttribute^) { uint32_t assetId = managedValPtr->NativeAssetID; - if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::FONT, isHovered, !(*managedValPtr))) + if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::FONT, isHovered)) { *managedValPtr = FontAsset(assetId); return true; @@ -219,7 +219,7 @@ namespace SHADE bool Editor::renderFieldEditorInternal(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, bool* isHovered, RangeAttribute^) { uint32_t assetId = managedValPtr->NativeAssetID; - if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MESH, isHovered, !(*managedValPtr))) + if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MESH, isHovered)) { *managedValPtr = MeshAsset(assetId); return true; @@ -231,7 +231,7 @@ namespace SHADE bool Editor::renderFieldEditorInternal(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, bool* isHovered, RangeAttribute^) { uint32_t assetId = managedValPtr->NativeAssetID; - if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MATERIAL, isHovered, !(*managedValPtr))) + if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MATERIAL, isHovered)) { *managedValPtr = MaterialAsset(assetId); return true; From dab51ee4cf6b128a4b5bdfd2a070c1c95360d635 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Tue, 22 Nov 2022 20:00:58 +0800 Subject: [PATCH 16/23] Readded testing function in physics routines for future use --- .../System/SHPhysicsSystemRoutines.cpp | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp index 8ddbbcc9..45f236f3 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp @@ -21,6 +21,13 @@ #include "Input/SHInputManager.h" +/*-------------------------------------------------------------------------------------*/ +/* Local Functions */ +/*-------------------------------------------------------------------------------------*/ + +void testFunction(); + +///////////////////////////////////////////////////////////////////////////////////////// namespace SHADE { @@ -135,7 +142,7 @@ namespace SHADE const double FIXED_DT = physicsSystem->fixedDT; accumulatedTime += dt; - testFunction(); + //testFunction(); int count = 0; while (accumulatedTime > FIXED_DT) @@ -359,5 +366,32 @@ namespace SHADE } } // namespace SHADE +///////////////////////////////////////////////////////////////////////////////////////// +void testFunction() +{ + using namespace SHADE; + // Test movement + const float forceModifier = 25.0f; + EntityID eid = 65538; + + if (SHEntityManager::IsValidEID(eid)) + { + auto* rb = SHComponentManager::GetComponent_s(eid); + if (rb) + { + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::W)) + rb->AddForce(-SHVec3::UnitZ * forceModifier); + + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::A)) + rb->AddForce(-SHVec3::UnitX * forceModifier); + + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::S)) + rb->AddForce(SHVec3::UnitZ * forceModifier); + + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::D)) + rb->AddForce(SHVec3::UnitX * forceModifier); + } + } +} From 57a0bbdb8c50fea1447b0515c663fea826599f98 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Tue, 22 Nov 2022 20:14:21 +0800 Subject: [PATCH 17/23] Added entity count at the bottom bar of editor Changed colour of bottom bar --- .../src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index 2912a0bc..a1335e19 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -20,6 +20,7 @@ #include "Assets/SHAssetManager.h" #include "Assets/Asset Types/SHSceneAsset.h" +#include "ECS_Base/Managers/SHEntityManager.h" #include "Scene/SHSceneManager.h" #include "Serialization/SHSerialization.h" #include "Serialization/Configurations/SHConfigurationManager.h" @@ -256,11 +257,13 @@ namespace SHADE ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { ImVec2(0.0f, 0.0f) }); + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); if (ImGui::BeginViewportSideBar("MainStatusBar", ImGui::GetMainViewport(), ImGuiDir_Down, menuBarHeight, editorMenuBarFlags)) { - ImGui::Text("Entity count: "); + ImGui::Text("Entity count: %zu", SHEntityManager::GetEntityCount()); } ImGui::End(); + ImGui::PopStyleColor(); ImGui::PopStyleVar(3); } From a612e71f0c298acd50dac1b64bf5ca78630dcd5d Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 20:39:15 +0800 Subject: [PATCH 18/23] Added Buttons, Added Canvas Scaling matrix, Added Serialization of buttons and camera arm --- Assets/Scenes/M2Scene.shade | 35 ++++++ .../src/Application/SBApplication.cpp | 2 + SHADE_Engine/src/Camera/SHCameraDirector.cpp | 17 +++ SHADE_Engine/src/Camera/SHCameraDirector.h | 2 + SHADE_Engine/src/Camera/SHCameraSystem.cpp | 4 + .../Inspector/SHEditorInspector.cpp | 6 + SHADE_Engine/src/Editor/SHEditorWidgets.hpp | 6 +- .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 3 +- .../MiddleEnd/Batching/SHSuperBatch.cpp | 6 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 2 +- .../MiddleEnd/Interface/SHRenderable.cpp | 8 +- .../src/Serialization/SHSerialization.cpp | 8 ++ SHADE_Engine/src/UI/SHButtonComponent.cpp | 47 +++++++- SHADE_Engine/src/UI/SHButtonComponent.h | 23 +++- SHADE_Engine/src/UI/SHUISystem.cpp | 110 +++++++++++++++++- SHADE_Engine/src/UI/SHUISystem.h | 10 +- 16 files changed, 272 insertions(+), 17 deletions(-) diff --git a/Assets/Scenes/M2Scene.shade b/Assets/Scenes/M2Scene.shade index 8b61dc67..aeb4eaed 100644 --- a/Assets/Scenes/M2Scene.shade +++ b/Assets/Scenes/M2Scene.shade @@ -13,6 +13,7 @@ Near: 0.00999999978 Far: 10000 Perspective: true + IsActive: true Light Component: Position: {x: 0, y: 0, z: 0} Type: Directional @@ -20,6 +21,7 @@ Color: {x: 0.951541841, y: 0.921719015, z: 0.553319454, w: 1} Layer: 4294967295 Strength: 0 + IsActive: true Scripts: ~ - EID: 7 Name: BigBoi @@ -30,9 +32,11 @@ Translate: {x: 0, y: -16.8647861, z: -14.039052} Rotate: {x: -0, y: 0, z: -0} Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975} + IsActive: true Renderable Component: Mesh: 149697411 Material: 126974645 + IsActive: true Scripts: ~ - EID: 8 Name: AmbientLight @@ -46,4 +50,35 @@ Color: {x: 1, y: 1, z: 1, w: 1} Layer: 4294967295 Strength: 0.25 + IsActive: true + Scripts: ~ +- EID: 6 + Name: Default + IsActive: true + NumberOfChildren: 1 + Components: + Canvas Component: + Canvas Width: 10 + Canvas Height: 10 + IsActive: true + Scripts: ~ +- EID: 5 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 129340704 + IsActive: true + Button Component: + Default Texture: 0 + Hovered Texture: 0 + Clicked Texture: 0 + IsActive: true Scripts: ~ \ No newline at end of file diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 1a00941f..06c42d2d 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -126,7 +126,9 @@ namespace Sandbox //SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); + SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); + SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); #ifdef SHEDITOR diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.cpp b/SHADE_Engine/src/Camera/SHCameraDirector.cpp index 29e2dcde..650315a0 100644 --- a/SHADE_Engine/src/Camera/SHCameraDirector.cpp +++ b/SHADE_Engine/src/Camera/SHCameraDirector.cpp @@ -89,5 +89,22 @@ namespace SHADE return SHMatrix::Identity; } + float SHCameraDirector::GetWidth() noexcept + { + SHCameraComponent* camComponent = GetMainCameraComponent(); + if (camComponent) + return camComponent->GetWidth(); + else + return 0.0f; + } + + float SHCameraDirector::GetHeight() noexcept + { + SHCameraComponent* camComponent = GetMainCameraComponent(); + if (camComponent) + return camComponent->GetHeight(); + else + return 0.0f; + } } diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.h b/SHADE_Engine/src/Camera/SHCameraDirector.h index 8538a824..381531d6 100644 --- a/SHADE_Engine/src/Camera/SHCameraDirector.h +++ b/SHADE_Engine/src/Camera/SHCameraDirector.h @@ -30,6 +30,8 @@ namespace SHADE void SetMainCamera(SHCameraComponent& cam) noexcept; SHMatrix const& GetOrthoMatrix() noexcept; SHMatrix const& GetPerspectiveMatrix() noexcept; + float GetWidth() noexcept; + float GetHeight() noexcept; private: SHMatrix viewMatrix; diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 489b05a1..30bdec29 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -57,6 +57,8 @@ namespace SHADE //std::cout << camera.yaw << std::endl; + + camera.pitch -= mouseY * dt * camera.turnSpeed.x; camera.yaw -= mouseX * dt * camera.turnSpeed.y; camera.dirtyView = true; @@ -150,6 +152,8 @@ namespace SHADE void SHCameraSystem::UpdateCameraComponent(SHCameraComponent& camera) noexcept { + + if (camera.isActive == false) return; diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index c4287e6f..83647da7 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -20,6 +20,7 @@ #include "Camera/SHCameraArmComponent.h" #include "UI/SHUIComponent.h" #include "UI/SHCanvasComponent.h" +#include "UI/SHButtonComponent.h" #include "SHEditorComponentView.h" #include "AudioSystem/SHAudioListenerComponent.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" @@ -149,6 +150,10 @@ namespace SHADE { DrawComponent(textRendererComponent); } + if (auto buttonComponent = SHComponentManager::GetComponent_s(eid)) + { + DrawComponent(buttonComponent); + } ImGui::Separator(); // Render Scripts SHScriptEngine* scriptEngine = static_cast(SHSystemManager::GetSystem()); @@ -161,6 +166,7 @@ namespace SHADE DrawAddComponentButton(eid); DrawAddComponentButton(eid); DrawAddComponentButton(eid); + DrawAddComponentButton(eid); // Components that require Transforms diff --git a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp index 2681e916..403992cc 100644 --- a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp +++ b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp @@ -454,12 +454,12 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - const bool hasChange = ImGui::DragScalar("##dragScalar", data_type, &value, speed, &p_min, &p_max, displayFormat, flags); + const bool hasChange = ImGui::InputScalar("##dragScalar", data_type, &value); static bool startRecording = false; if (hasChange) { SHCommandManager::PerformCommand(std::reinterpret_pointer_cast(std::make_shared>(get(), value, set)), startRecording); - if (!startRecording) + if (!startRecording && ImGui::IsMouseDown(ImGuiMouseButton_Left)) startRecording = true; } if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) @@ -477,7 +477,7 @@ namespace SHADE ImGui::EndTooltip(); } } - return hasChange; + return false; } static bool DragFloat(const std::string_view& label, std::function get, std::function set, std::string_view const& tooltip = {}, diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 9b4b02b0..afa2f9e0 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -313,7 +313,8 @@ namespace SHADE auto uiComp = SHComponentManager::GetComponent_s(rendId); if (uiComp) { - transformData.emplace_back(uiComp->GetMatrix()); + if(uiComp->isActive) + transformData.emplace_back(uiComp->GetMatrix()); } else transformData.emplace_back(transform->GetTRS()); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp index ec19691f..58993026 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp @@ -55,7 +55,11 @@ namespace SHADE void SHSuperBatch::Remove(const SHRenderable* renderable) noexcept { - Handle baseMat = (renderable->HasMaterialChanged() ? renderable->GetPrevMaterial() : renderable->GetMaterial())->GetBaseMaterial(); + Handle matInst = renderable->HasMaterialChanged() ? renderable->GetPrevMaterial() : renderable->GetMaterial(); + if (!matInst) + return; + + Handle baseMat = matInst->GetBaseMaterial(); const Handle PIPELINE = baseMat->HasPipelineChanged() ? baseMat->GetPrevPipeline() : baseMat->GetPipeline(); // Check if we have a Batch with the same pipeline yet diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index af09c819..03ca0b3d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -968,7 +968,7 @@ namespace SHADE for (auto& renderable : renderables) { // Check if the material instance is now unused - renderable.CleanUpMaterials(); + renderable.CleanUpMaterials(); if (!renderable.HasChanged()) continue; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp index e22de5ab..9a180575 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp @@ -34,9 +34,10 @@ namespace SHADE void SHRenderable::OnDestroy() { // Remove from SuperBatch - if (sharedMaterial) + auto currMat = GetMaterial(); + if (currMat) { - Handle superBatch = sharedMaterial->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch(); + Handle superBatch = currMat->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch(); superBatch->Remove(this); } @@ -64,7 +65,6 @@ namespace SHADE if (material) { oldMaterial = material; - material.Free(); material = {}; } else if (sharedMaterial) @@ -144,6 +144,8 @@ namespace SHADE { matChanged = false; meshChanged = false; + if (oldMaterial) + oldMaterial.Free(); oldMaterial = {}; oldMesh = {}; } diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 931d3a4c..99e4fa41 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -12,10 +12,12 @@ #include "Assets/Asset Types/SHSceneAsset.h" #include "Camera/SHCameraComponent.h" +#include "Camera/SHCameraArmComponent.h" #include "Math/Transform/SHTransformComponent.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Physics/Interface/SHRigidBodyComponent.h" #include "UI/SHCanvasComponent.h" +#include "UI/SHButtonComponent.h" #include "ECS_Base/Managers/SHSystemManager.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h" #include "Scripting/SHScriptEngine.h" @@ -208,12 +210,14 @@ namespace SHADE AddComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); + AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); + AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); @@ -263,12 +267,14 @@ namespace SHADE AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); + AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); + AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); return componentIDList; @@ -343,11 +349,13 @@ namespace SHADE return; SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); + SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); + SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); } diff --git a/SHADE_Engine/src/UI/SHButtonComponent.cpp b/SHADE_Engine/src/UI/SHButtonComponent.cpp index d711d682..7b275128 100644 --- a/SHADE_Engine/src/UI/SHButtonComponent.cpp +++ b/SHADE_Engine/src/UI/SHButtonComponent.cpp @@ -5,11 +5,54 @@ namespace SHADE { SHButtonComponent::SHButtonComponent() - :size(0.0f), offset(0.0f), isHovered(false) + :size(1.0f), offset(0.0f), isHovered(false), isClicked(false), + defaultTexture(0), hoveredTexture(0), clickedTexture(0) { } - + AssetID SHButtonComponent::GetDefaultTexture() const noexcept + { + return defaultTexture; + } + + AssetID SHButtonComponent::GetHoveredTexture() const noexcept + { + return hoveredTexture; + } + + AssetID SHButtonComponent::GetClickedTexture() const noexcept + { + return clickedTexture; + } + + void SHButtonComponent::SetDefaultTexture(AssetID texture) noexcept + { + defaultTexture = texture; + } + + void SHButtonComponent::SetHoveredTexture(AssetID texture) noexcept + { + hoveredTexture = texture; + } + + void SHButtonComponent::SetClickedTexture(AssetID texture) noexcept + { + clickedTexture = texture; + } + +} + + +RTTR_REGISTRATION +{ + using namespace SHADE; + using namespace rttr; + + registration::class_("Button Component") + .property("Default Texture", &SHButtonComponent::GetDefaultTexture, &SHButtonComponent::SetDefaultTexture) + .property("Hovered Texture", &SHButtonComponent::GetHoveredTexture, &SHButtonComponent::SetHoveredTexture) + .property("Clicked Texture", &SHButtonComponent::GetClickedTexture, &SHButtonComponent::SetClickedTexture) + ; } \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHButtonComponent.h b/SHADE_Engine/src/UI/SHButtonComponent.h index e68f354f..39790b6a 100644 --- a/SHADE_Engine/src/UI/SHButtonComponent.h +++ b/SHADE_Engine/src/UI/SHButtonComponent.h @@ -1,30 +1,47 @@ #pragma once +#include + #include "SH_API.h" #include "ECS_Base/Components/SHComponent.h" #include "Math/Vector/SHVec3.h" #include "Math/Vector/SHVec2.h" - +#include "Assets/SHAssetMacros.h" namespace SHADE { + class SH_API SHButtonComponent final: public SHComponent { public: SHButtonComponent(); - ~SHButtonComponent() = default; + virtual ~SHButtonComponent() = default; SHVec2 size; SHVec2 offset; + AssetID GetClickedTexture() const noexcept; + AssetID GetDefaultTexture() const noexcept; + AssetID GetHoveredTexture() const noexcept; + void SetDefaultTexture(AssetID texture) noexcept; + void SetHoveredTexture(AssetID texture) noexcept; + void SetClickedTexture(AssetID texture) noexcept; + + + + friend class SHUISystem; private: bool isHovered; + bool isClicked; + AssetID defaultTexture; + AssetID hoveredTexture; + AssetID clickedTexture; - + RTTR_ENABLE() }; diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 44730529..a499a475 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -3,6 +3,12 @@ #include "ECS_Base/Managers/SHComponentManager.h" #include "ECS_Base/Managers/SHSystemManager.h" #include "Math/Transform/SHTransformComponent.h" +#include "Graphics/MiddleEnd/Interface/SHRenderable.h" +#include "Camera/SHCameraSystem.h" +#include "Editor/EditorWindow/SHEditorWindowManager.h" +#include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h" +#include "Resource/SHResourceManager.h" +#include "Input/SHInputManager.h" namespace SHADE { @@ -12,6 +18,7 @@ namespace SHADE SystemFamily::GetID(); SHComponentManager::CreateComponentSparseSet(); SHComponentManager::CreateComponentSparseSet(); + SHComponentManager::CreateComponentSparseSet(); } void SHUISystem::Exit() @@ -95,7 +102,7 @@ namespace SHADE { auto transform = SHComponentManager::GetComponent(comp.GetEID()); if (canvasComp != nullptr) - comp.localToCanvasMatrix = canvasComp->GetMatrix() * transform->GetTRS(); + comp.localToCanvasMatrix = canvasComp->GetMatrix()* transform->GetTRS(); else comp.localToCanvasMatrix = transform->GetTRS(); } @@ -108,10 +115,109 @@ namespace SHADE } } - void SHUISystem::UpdateButtonComponent(SHButtonComponent& comp) noexcept + void SHUISystem::UpdateCanvasComponent(SHCanvasComponent& comp) noexcept { + auto cameraSystem = SHSystemManager::GetSystem(); + + comp.canvasMatrix = SHMatrix::Identity; + comp.canvasMatrix(0, 0) = cameraSystem->GetDirector(0)->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f ); + comp.canvasMatrix(1, 1) = cameraSystem->GetDirector(0)->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f ); + } + void SHUISystem::UpdateCanvasMatrixRoutine::Execute(double dt) noexcept + { + SHUISystem* system = (SHUISystem*)GetSystem(); + auto& dense = SHComponentManager::GetDense(); + for (auto& comp : dense) + { + if(SHSceneManager::CheckNodeAndComponentsActive(comp.GetEID())) + system->UpdateCanvasComponent(comp); + } } + void SHUISystem::UpdateButtonComponent(SHButtonComponent& comp) noexcept + { + if (!SHComponentManager::HasComponent(comp.GetEID()) || !SHComponentManager::HasComponent(comp.GetEID())) + { + return; + } + auto cameraSystem = SHSystemManager::GetSystem(); + auto uiComp = SHComponentManager::GetComponent(comp.GetEID()); + + SHVec4 topExtent4 = uiComp->GetMatrix() * SHVec4(-comp.size.x * 0.5f, comp.size.y * 0.5f , 0.0f,1.0f); + SHVec4 btmExtent4 = uiComp->GetMatrix() * SHVec4(comp.size.x * 0.5f , -comp.size.y * 0.5f , 0.0f, 1.0f); + + SHVec2 topExtent{ topExtent4.x,-topExtent4.y }; + SHVec2 btmExtent{ btmExtent4.x,-btmExtent4.y }; + + + + SHVec2 windowSize; + SHVec2 mousePos; +#ifdef SHEDITOR + + windowSize = SHEditorWindowManager::GetEditorWindow()->windowSize; + mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; + + + +#endif + + + + SHVec2 camSize{ cameraSystem->GetDirector(0)->GetWidth() , cameraSystem->GetDirector(0)->GetHeight() }; + + topExtent += camSize * 0.5f; + btmExtent += camSize * 0.5f; + + //Convert everything to using ratios + topExtent /= camSize; + btmExtent /= camSize; + + mousePos /= windowSize; + + //SHLOG_INFO("mousePos: {} , {}", mousePos.x, mousePos.y); + comp.isClicked = false; + if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x + && mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y) + { + comp.isHovered = true; + if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + { + comp.isClicked = true; + } + //SHLOG_INFO("BUTTON HOVERED"); + + + } + else + { + comp.isHovered = false; + + //SHLOG_INFO("BUTTON NOT HOVERED") + } + + + if (SHComponentManager::HasComponent(comp.GetEID())) + { + //auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); + //auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); + + //auto material = renderable->GetModifiableMaterial(); + //material->SetProperty("texture", comp.GetDefaultTexture()); + } + } + + void SHUISystem::UpdateButtonsRoutine::Execute(double dt) noexcept + { + SHUISystem* system = (SHUISystem*)GetSystem(); + auto& dense = SHComponentManager::GetDense(); + for (auto& comp : dense) + { + if (SHSceneManager::CheckNodeAndComponentsActive(comp.GetEID())) + system->UpdateButtonComponent(comp); + } + } + }//end namespace diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h index 15b710aa..04e057ad 100644 --- a/SHADE_Engine/src/UI/SHUISystem.h +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -39,6 +39,14 @@ namespace SHADE }; friend class UpdateUIMatrixRoutine; + class SH_API UpdateCanvasMatrixRoutine final: public SHSystemRoutine + { + public: + UpdateCanvasMatrixRoutine() :SHSystemRoutine("Update Canvas Matrix Routine", true) {}; + virtual void Execute(double dt) noexcept override final; + }; + friend class UpdateCanvasMatrixRoutine; + class SH_API UpdateButtonsRoutine final: public SHSystemRoutine { @@ -56,7 +64,7 @@ namespace SHADE private: void UpdateUIComponent(SHUIComponent& comp) noexcept; void UpdateButtonComponent(SHButtonComponent& comp) noexcept; - + void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept; }; From 62c4b3837d42e8831877dc53fdc11ba2d40a9bbc Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Tue, 22 Nov 2022 20:46:05 +0800 Subject: [PATCH 19/23] Fixed bug where transform dirty flags were not being properly cleared. This was preventing bodies from going to sleep and transforms always updating. --- .../src/Math/Transform/SHTransformSystem.cpp | 4 ++-- .../src/Physics/System/SHPhysicsSystemRoutines.cpp | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp index 94c133dd..38d44984 100644 --- a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp +++ b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp @@ -47,14 +47,14 @@ namespace SHADE { // Get the current scene graph to traverse and update const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); - UpdateEntity(SCENE_GRAPH.GetRoot(), !IsRunInEditorPause); + UpdateEntity(SCENE_GRAPH.GetRoot(), false); } void SHTransformSystem::TransformPostPhysicsUpdate::Execute(double) noexcept { // Get the current scene graph to traverse and update const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); - UpdateEntity(SCENE_GRAPH.GetRoot(), IsRunInEditorPause); + UpdateEntity(SCENE_GRAPH.GetRoot(), true); } void SHTransformSystem::Init() diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp index 45f236f3..24bd2f81 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp @@ -302,9 +302,12 @@ namespace SHADE { colliderComponent->position = WORLD_POS; colliderComponent->orientation = WORLD_ROT; - colliderComponent->scale = WORLD_SCL; - colliderComponent->RecomputeCollisionShapes(); + if (colliderComponent->scale != WORLD_SCL) + { + colliderComponent->scale = WORLD_SCL; + colliderComponent->RecomputeCollisionShapes(); + } } } @@ -325,7 +328,11 @@ namespace SHADE if (physicsObject.GetRigidBody()->isActive()) physicsObject.prevTransform = CURRENT_TF; - // Sync with rigid bodies. If an object doesn't have a rigidbody, no update is needed here as it is done in pre-update. + // Skip sleeping objects + if (physicsObject.GetRigidBody()->isSleeping()) + return; + + // Sync with rigid bodies if (rigidBodyComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) { // Skip static bodies From 142f025692a562426c11434d4145f893b9474ec2 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 20:54:16 +0800 Subject: [PATCH 20/23] Added check for editor camera. --- Assets/Application.SHConfig | 2 +- Assets/Scenes/UI Test.shade | 79 ++++++++++++++++++++++++++++++ Assets/Scenes/UI Test.shade.shmeta | 3 ++ SHADE_Engine/src/UI/SHUISystem.cpp | 19 ++++++- 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 Assets/Scenes/UI Test.shade create mode 100644 Assets/Scenes/UI Test.shade.shmeta diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index 3f7a4ac0..c9b34a7a 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 94283040 +Starting Scene ID: 94246101 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/Assets/Scenes/UI Test.shade b/Assets/Scenes/UI Test.shade new file mode 100644 index 00000000..b6aab1a1 --- /dev/null +++ b/Assets/Scenes/UI Test.shade @@ -0,0 +1,79 @@ +- EID: 0 + Name: Canvas + IsActive: true + NumberOfChildren: 1 + Components: + Canvas Component: + Canvas Width: 10 + Canvas Height: 10 + IsActive: true + Scripts: ~ +- EID: 6 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 129340704 + IsActive: true + Scripts: ~ +- EID: 1 + Name: Camera + IsActive: true + NumberOfChildren: 0 + Components: + Camera Component: + Position: {x: 0, y: 3, z: 8} + Pitch: 0 + Yaw: 0 + Roll: 0 + Width: 1920 + Height: 1080 + Near: 0.00999999978 + Far: 10000 + Perspective: true + IsActive: true + Light Component: + Position: {x: 0, y: 0, z: 0} + Type: Directional + Direction: {x: 1.79999995, y: 0, z: 1} + Color: {x: 0.951541841, y: 0.921719015, z: 0.553319454, w: 1} + Layer: 4294967295 + Strength: 0 + IsActive: true + Scripts: ~ +- EID: 7 + Name: BigBoi + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: -16.8647861, z: -14.039052} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975} + IsActive: true + Renderable Component: + Mesh: 149697411 + Material: 126974645 + IsActive: true + Scripts: ~ +- EID: 8 + Name: AmbientLight + IsActive: true + NumberOfChildren: 0 + Components: + Light Component: + Position: {x: 0, y: 0, z: 0} + Type: Ambient + Direction: {x: 0, y: 0, z: 1} + Color: {x: 1, y: 1, z: 1, w: 1} + Layer: 4294967295 + Strength: 0.25 + IsActive: true + Scripts: ~ \ No newline at end of file diff --git a/Assets/Scenes/UI Test.shade.shmeta b/Assets/Scenes/UI Test.shade.shmeta new file mode 100644 index 00000000..0e80f988 --- /dev/null +++ b/Assets/Scenes/UI Test.shade.shmeta @@ -0,0 +1,3 @@ +Name: UI Test +ID: 96139961 +Type: 5 diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index a499a475..247eb6cc 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -7,6 +7,7 @@ #include "Camera/SHCameraSystem.h" #include "Editor/EditorWindow/SHEditorWindowManager.h" #include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h" +#include "Editor/SHEditor.h" #include "Resource/SHResourceManager.h" #include "Input/SHInputManager.h" @@ -118,10 +119,26 @@ namespace SHADE void SHUISystem::UpdateCanvasComponent(SHCanvasComponent& comp) noexcept { auto cameraSystem = SHSystemManager::GetSystem(); - +#ifdef SHEDITOR + auto editor = SHSystemManager::GetSystem(); + if (editor->editorState != SHEditor::State::PLAY) + { + comp.canvasMatrix = SHMatrix::Identity; + comp.canvasMatrix(0, 0) = cameraSystem->GetEditorCamera()->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f); + comp.canvasMatrix(1, 1) = cameraSystem->GetEditorCamera()->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f); + } + else + { + comp.canvasMatrix = SHMatrix::Identity; + comp.canvasMatrix(0, 0) = cameraSystem->GetDirector(0)->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f); + comp.canvasMatrix(1, 1) = cameraSystem->GetDirector(0)->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f); + } + +#else comp.canvasMatrix = SHMatrix::Identity; comp.canvasMatrix(0, 0) = cameraSystem->GetDirector(0)->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f ); comp.canvasMatrix(1, 1) = cameraSystem->GetDirector(0)->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f ); +#endif } void SHUISystem::UpdateCanvasMatrixRoutine::Execute(double dt) noexcept From ac09007862561b6091b85b7fbeb606d49873a6c2 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 22 Nov 2022 20:59:17 +0800 Subject: [PATCH 21/23] Disabled xmldoc build, admin mode no longer required to build the engine --- SHADE_CSharp/premake5.lua | 15 ++++++++------- SHADE_Managed/premake5.lua | 18 +++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/SHADE_CSharp/premake5.lua b/SHADE_CSharp/premake5.lua index 8844b84c..f735b515 100644 --- a/SHADE_CSharp/premake5.lua +++ b/SHADE_CSharp/premake5.lua @@ -53,15 +53,16 @@ project "SHADE_CSharp" function configElementCS(cfg) _p(2,'Debug;Release;Publish') end - function docsElementCS(cfg) - _p(2,'true') - end - function docsLocationElementCS(cfg) - _p(2,'$(OutDir)') - end + -- function docsElementCS(cfg) + -- _p(2,'true') + -- end + -- function docsLocationElementCS(cfg) + -- _p(2,'$(OutDir)') + -- end premake.override(premake.vstudio.cs2005.elements, "projectProperties", function (oldfn, cfg) return table.join(oldfn(cfg), { - platformsElementCS, configElementCS, docsElementCS, docsLocationElementCS, +-- platformsElementCS, configElementCS, docsElementCS, docsLocationElementCS, + platformsElementCS, configElementCS, }) end) \ No newline at end of file diff --git a/SHADE_Managed/premake5.lua b/SHADE_Managed/premake5.lua index 463e80b8..9253c81b 100644 --- a/SHADE_Managed/premake5.lua +++ b/SHADE_Managed/premake5.lua @@ -119,14 +119,14 @@ project "SHADE_Managed" links{"librttr_core.lib"} links{"fmodstudio_vc.lib", "fmod_vc.lib"} - require "vstudio" + -- require "vstudio" - function docsElementCPP(cfg) - _p(3,'true') - end + -- function docsElementCPP(cfg) + -- _p(3,'true') + -- end - premake.override(premake.vstudio.vc2010.elements, "clCompile", function (oldfn, cfg) - return table.join(oldfn(cfg), { - docsElementCPP, - }) - end) \ No newline at end of file + -- premake.override(premake.vstudio.vc2010.elements, "clCompile", function (oldfn, cfg) + -- return table.join(oldfn(cfg), { + -- docsElementCPP, + -- }) + -- end) \ No newline at end of file From 7c36886669172c2a61eb0dfcc945dced1b6d6c3e Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 21:03:53 +0800 Subject: [PATCH 22/23] Fix for Canvas scaler --- Assets/Scenes/UI Test.shade | 5 +++++ Assets/Scenes/UI Test.shade.shmeta | 2 +- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 20 ++++++++++++++++++ SHADE_Engine/src/Camera/SHCameraSystem.h | 3 +++ SHADE_Engine/src/UI/SHUISystem.cpp | 24 ++++------------------ 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Assets/Scenes/UI Test.shade b/Assets/Scenes/UI Test.shade index b6aab1a1..e8ee4df2 100644 --- a/Assets/Scenes/UI Test.shade +++ b/Assets/Scenes/UI Test.shade @@ -22,6 +22,11 @@ Mesh: 141771688 Material: 129340704 IsActive: true + Button Component: + Default Texture: 0 + Hovered Texture: 0 + Clicked Texture: 0 + IsActive: true Scripts: ~ - EID: 1 Name: Camera diff --git a/Assets/Scenes/UI Test.shade.shmeta b/Assets/Scenes/UI Test.shade.shmeta index 0e80f988..cf38916e 100644 --- a/Assets/Scenes/UI Test.shade.shmeta +++ b/Assets/Scenes/UI Test.shade.shmeta @@ -1,3 +1,3 @@ Name: UI Test -ID: 96139961 +ID: 87707373 Type: 5 diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 30bdec29..a2e83767 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -8,6 +8,8 @@ #include "Math/Transform/SHTransformComponent.h" #include #include "Scene/SHSceneManager.h" +#include "ECS_Base/Managers/SHSystemManager.h" +#include "Editor/SHEditor.h" namespace SHADE { @@ -440,4 +442,22 @@ namespace SHADE SetCameraViewMatrix(camera, viewMtx); } + SHVec2 SHCameraSystem::GetCameraWidthHeight(size_t index) noexcept + { +#ifdef SHEDITOR + auto editor = SHSystemManager::GetSystem(); + if (editor->editorState != SHEditor::State::PLAY) + { + return SHVec2{ GetEditorCamera()->GetWidth(), GetEditorCamera()->GetHeight() }; + } + else + { + return SHVec2{ GetDirector(index)->GetWidth(),GetDirector(index)->GetHeight() }; + } + +#else + return SHVec2{ GetDirector(index)->GetWidth(),GetDirector(index)->GetHeight() }; +#endif + } + } diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.h b/SHADE_Engine/src/Camera/SHCameraSystem.h index 9c8157f4..d40f9a6c 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.h +++ b/SHADE_Engine/src/Camera/SHCameraSystem.h @@ -27,6 +27,7 @@ namespace SHADE void UpdateCameraComponent(SHCameraComponent& camera) noexcept; void UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept; + public: @@ -57,6 +58,8 @@ namespace SHADE void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept; void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept; void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept; + + SHVec2 GetCameraWidthHeight(size_t index) noexcept; }; diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 247eb6cc..1387bc6b 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -119,26 +119,10 @@ namespace SHADE void SHUISystem::UpdateCanvasComponent(SHCanvasComponent& comp) noexcept { auto cameraSystem = SHSystemManager::GetSystem(); -#ifdef SHEDITOR - auto editor = SHSystemManager::GetSystem(); - if (editor->editorState != SHEditor::State::PLAY) - { - comp.canvasMatrix = SHMatrix::Identity; - comp.canvasMatrix(0, 0) = cameraSystem->GetEditorCamera()->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f); - comp.canvasMatrix(1, 1) = cameraSystem->GetEditorCamera()->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f); - } - else - { - comp.canvasMatrix = SHMatrix::Identity; - comp.canvasMatrix(0, 0) = cameraSystem->GetDirector(0)->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f); - comp.canvasMatrix(1, 1) = cameraSystem->GetDirector(0)->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f); - } - -#else + SHVec2 camSize = cameraSystem->GetCameraWidthHeight(0); comp.canvasMatrix = SHMatrix::Identity; - comp.canvasMatrix(0, 0) = cameraSystem->GetDirector(0)->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f ); - comp.canvasMatrix(1, 1) = cameraSystem->GetDirector(0)->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f ); -#endif + comp.canvasMatrix(0, 0) = camSize.x * 0.5f / (comp.GetCanvasWidth() * 0.5f); + comp.canvasMatrix(1, 1) = camSize.y * 0.5f / (comp.GetCanvasHeight() * 0.5f); } void SHUISystem::UpdateCanvasMatrixRoutine::Execute(double dt) noexcept @@ -183,7 +167,7 @@ namespace SHADE - SHVec2 camSize{ cameraSystem->GetDirector(0)->GetWidth() , cameraSystem->GetDirector(0)->GetHeight() }; + SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0).x , cameraSystem->GetCameraWidthHeight(0).y }; topExtent += camSize * 0.5f; btmExtent += camSize * 0.5f; From cc2587a7bd2d8af2c2f6e94b1ead82e01984e490 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Tue, 22 Nov 2022 21:54:51 +0800 Subject: [PATCH 23/23] Added recognition for material and prefab types when generating meta files --- SHADE_Engine/src/Assets/SHAssetManager.cpp | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 67924abf..2aaf226b 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -653,6 +653,34 @@ namespace SHADE return newAsset.id; } + else if(ext == MATERIAL_EXTENSION) + { + SHAsset newAsset{ + path.stem().string(), + GenerateAssetID(AssetType::MATERIAL), + AssetType::MATERIAL, + path, + false + }; + assetCollection.emplace(newAsset.id, newAsset); + SHAssetMetaHandler::WriteMetaData(newAsset); + + return newAsset.id; + } + else if (ext == PREFAB_EXTENSION) + { + SHAsset newAsset{ + path.stem().string(), + GenerateAssetID(AssetType::PREFAB), + AssetType::PREFAB, + path, + false + }; + assetCollection.emplace(newAsset.id, newAsset); + SHAssetMetaHandler::WriteMetaData(newAsset); + + return newAsset.id; + } else if (ext == FONT_EXTENSION) { SHAsset newAsset{