diff --git a/SHADE_Application/premake5.lua b/SHADE_Application/premake5.lua index 35ea2c10..395c3a48 100644 --- a/SHADE_Application/premake5.lua +++ b/SHADE_Application/premake5.lua @@ -37,7 +37,8 @@ project "SHADE_Application" "%{IncludeDir.VULKAN}/include", "%{IncludeDir.spdlog}/include", "%{IncludeDir.tinyddsloader}", - "%{IncludeDir.reactphysics3d}\\include" + "%{IncludeDir.reactphysics3d}\\include", + "%{IncludeDir.yamlcpp}" } externalwarnings "Off" @@ -51,6 +52,7 @@ project "SHADE_Application" { "SHADE_Engine", "SHADE_Managed", + "yaml-cpp", "SDL2.lib", "SDL2main.lib" } diff --git a/SHADE_Engine/src/Camera/SHCameraComponent.cpp b/SHADE_Engine/src/Camera/SHCameraComponent.cpp index 650ed3c5..7ba6855c 100644 --- a/SHADE_Engine/src/Camera/SHCameraComponent.cpp +++ b/SHADE_Engine/src/Camera/SHCameraComponent.cpp @@ -7,7 +7,7 @@ namespace SHADE { SHCameraComponent::SHCameraComponent() :yaw(0.0f), pitch(0.0f), roll(0.0f) - , width(1920.0f), height(1080.0f), zNear(0.01f), zFar(10000.0f), fov(90.0f), movementSpeed(1.0f), turnSpeed(1.0f) + , width(1920.0f), height(1080.0f), zNear(0.01f), zFar(10000.0f), fov(90.0f), movementSpeed(1.0f), turnSpeed(0.5f) , perspProj(true), dirtyView(true), dirtyProj(true) , viewMatrix(), projMatrix() , position() diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 9c97131a..a9b356de 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -2,6 +2,7 @@ #include "SHCameraSystem.h" #include "Math/SHMathHelpers.h" #include "Input/SHInputManager.h" +#include "Math/Vector/SHVec2.h" @@ -12,56 +13,51 @@ namespace SHADE { SHCameraSystem* system = static_cast(GetSystem()); auto& camera = system->editorCamera; - SHVec3 target{ 0.0f,0.0f,-1.0f }; - SHVec3 up = { 0.0f,1.0f,0.0f }; - - - SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw)); - SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch)); - target += camera.position; - ////SHVec3::RotateZ(target, SHMath::DegreesToRadians(camera.roll)); - - //target = SHVec3::Normalise(target); - - SHVec3::RotateZ(up, camera.roll); - up = SHVec3::Normalise(up); - - - SHVec3 view = target - camera.position; view = SHVec3::Normalise(view); - SHVec3 right = SHVec3::Cross(view, up); right = SHVec3::Normalise(right); - const SHVec3 UP = SHVec3::Cross(view, right); - + SHVec3 view, right, UP; + system->GetCameraAxis(camera, view, right, UP); if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::A)) { - system->editorCamera.position -= right * dt * camera.movementSpeed; - system->editorCamera.dirtyView = true; + camera.position -= right * dt * camera.movementSpeed; + camera.dirtyView = true; } if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::D)) { - system->editorCamera.position += right * dt * camera.movementSpeed; - system->editorCamera.dirtyView = true; + camera.position += right * dt * camera.movementSpeed; + camera.dirtyView = true; } if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::W)) { - system->editorCamera.position += view * dt * camera.movementSpeed; - system->editorCamera.dirtyView = true; + camera.position += view * dt * camera.movementSpeed; + camera.dirtyView = true; } if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::S)) { - system->editorCamera.position -= view * dt * camera.movementSpeed; - system->editorCamera.dirtyView = true; + camera.position -= view * dt * camera.movementSpeed; + camera.dirtyView = true; } if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::Q)) { - system->editorCamera.position += UP * dt * camera.movementSpeed; - system->editorCamera.dirtyView = true; + camera.position += UP * dt * camera.movementSpeed; + camera.dirtyView = true; } if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::E)) { - system->editorCamera.position -= UP * dt * camera.movementSpeed; - system->editorCamera.dirtyView = true; + camera.position -= UP * dt * camera.movementSpeed; + camera.dirtyView = true; } + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::RMB)) + { + double mouseX, mouseY; + SHInputManager::GetMouseVelocity(&mouseX,&mouseY); + + //std::cout << camera.yaw << std::endl; + + camera.pitch -= mouseY * dt * camera.turnSpeed.x; + camera.yaw -= mouseX * dt * camera.turnSpeed.y; + camera.dirtyView = true; + } + system->UpdateCameraComponent(system->editorCamera); } @@ -89,24 +85,9 @@ namespace SHADE { if (camera.dirtyView) { - SHVec3 target{ 0.0f,0.0f,-1.0f }; - SHVec3 up = { 0.0f,1.0f,0.0f }; - - - SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw)); - SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch)); - target += camera.position; - ////SHVec3::RotateZ(target, SHMath::DegreesToRadians(camera.roll)); - - //target = SHVec3::Normalise(target); - - SHVec3::RotateZ(up, camera.roll); - up = SHVec3::Normalise(up); - - - SHVec3 view = target - camera.position; view = SHVec3::Normalise(view); - SHVec3 right = SHVec3::Cross(view, up); right = SHVec3::Normalise(right); - const SHVec3 UP = SHVec3::Cross(view, right); + + SHVec3 view, right, UP; + GetCameraAxis(camera, view, right, UP); camera.viewMatrix = SHMatrix::Identity; camera.viewMatrix(0, 0) = right[0]; @@ -142,38 +123,51 @@ namespace SHADE camera.projMatrix(3, 2) = 1.0f; camera.projMatrix(2, 3) = -(camera.zFar * camera.zNear) / (camera.zFar - camera.zNear); - //const float fov_rad = SHMath::DegreesToRadians(camera.fov); - //const float focal_length = 1.0f / tan(fov_rad * 0.5f); - - //camera.projMatrix(0,0) = focal_length / camera.GetAspectRatio(); - //camera.projMatrix(1,1) = -focal_length; - //camera.projMatrix(2,2) = camera.zNear / (camera.zFar - camera.zNear); - //camera.projMatrix(2,3) = camera.zFar * (camera.zNear / (camera.zFar - camera.zNear)); - //camera.projMatrix(3,2) = -1.0f; - //camera.projMatrix(3,3) = 0.0f; - - //camera.projMatrix = SHMatrix::Inverse(camera.projMatrix); - + camera.dirtyProj = false; } else { - const float R = camera.width * 0.5f; - const float L = -R; - const float T = camera.height * 0.5f; - const float B = -T; + //const float R = camera.width * 0.5f; + //const float L = -R; + //const float T = camera.height * 0.5f; + //const float B = -T; - camera.projMatrix = SHMatrix::Identity; - camera.projMatrix(0, 0) = 2.0f / (R - L); - camera.projMatrix(1, 1) = 2.0f / (B - T); - camera.projMatrix(2, 2) = 1.0f / (camera.zFar - camera.zNear); - camera.projMatrix(3, 0) = -(R + L) / (R - L); - camera.projMatrix(3, 1) = -(B + T) / (B - T); - camera.projMatrix(3, 2) = -camera.zNear / (camera.zFar - camera.zNear); + //camera.projMatrix = SHMatrix::Identity; + //camera.projMatrix(0, 0) = 2.0f / (R - L); + //camera.projMatrix(1, 1) = 2.0f / (B - T); + //camera.projMatrix(2, 2) = 1.0f / (camera.zFar - camera.zNear); + //camera.projMatrix(3, 0) = -(R + L) / (R - L); + //camera.projMatrix(3, 1) = -(B + T) / (B - T); + //camera.projMatrix(3, 2) = -camera.zNear / (camera.zFar - camera.zNear); camera.dirtyProj = false; } } } + void SHCameraSystem::GetCameraAxis(SHCameraComponent const& camera, SHVec3& forward, SHVec3& right, SHVec3& upVec) const noexcept + { + SHVec3 target{ 0.0f,0.0f,-1.0f }; + SHVec3 up = { 0.0f,1.0f,0.0f }; + + + target = SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw)); + target =SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch)); + std::cout << "Target vec: " << target.x<<", "<entityID; } diff --git a/SHADE_Engine/src/Editor/SHEditor.hpp b/SHADE_Engine/src/Editor/SHEditor.hpp index 5603e9f4..34405390 100644 --- a/SHADE_Engine/src/Editor/SHEditor.hpp +++ b/SHADE_Engine/src/Editor/SHEditor.hpp @@ -13,7 +13,7 @@ #include "ECS_Base/SHECSMacros.h" #include "ECS_Base/System/SHSystem.h" #include "ECS_Base/System/SHSystemRoutine.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "EditorWindow/SHEditorWindow.h" #include "Tools/SHLogger.h" #include "Gizmos/SHTransformGizmo.h" diff --git a/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.h b/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.h index e931fec5..aeda7d18 100644 --- a/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.h +++ b/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.h @@ -3,7 +3,7 @@ #include "Graphics/SHVulkanIncludes.h" #include "vk_mem_alloc.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h index 9416a1aa..deb1131c 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h @@ -4,7 +4,7 @@ #include "Graphics/SHVulkanIncludes.h" #include "Graphics/SHVulkanDefines.h" #include "SHCommandPoolResetMode.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHResourceLibrary.h" #include "Graphics/Pipeline/SHVkPipelineLayout.h" namespace SHADE @@ -36,7 +36,7 @@ namespace SHADE class SHVkCommandBuffer { friend class SHVkCommandPool; - friend class ResourceLibrary; + friend class SHResourceLibrary; static constexpr uint16_t PUSH_CONSTANT_SIZE = 512; private: diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandPool.cpp b/SHADE_Engine/src/Graphics/Commands/SHVkCommandPool.cpp index e1470898..375ece4d 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandPool.cpp +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandPool.cpp @@ -2,7 +2,7 @@ #include "SHVkCommandPool.h" #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Instance/SHVkInstance.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHResourceLibrary.h" #include "Tools/SHLogger.h" namespace SHADE diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandPool.h b/SHADE_Engine/src/Graphics/Commands/SHVkCommandPool.h index 2bb290a7..fcc0ce41 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandPool.h +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandPool.h @@ -6,7 +6,7 @@ #include "Graphics/Queues/SHVkQueue.h" #include "SHCommandPoolResetMode.h" #include "SHVkCommandBuffer.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHResourceLibrary.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorPool.h b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorPool.h index 9a533d06..c822829a 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorPool.h +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorPool.h @@ -2,7 +2,7 @@ // Project Includes #include "Graphics/SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h index f2b886e8..b2536de8 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.h @@ -4,7 +4,7 @@ // Project Includes #include "Graphics/SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "Graphics/Shaders/SHShaderReflected.h" #include "SHDescriptorSetUpdater.h" diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetLayout.h b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetLayout.h index 4fffbc96..1639901d 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetLayout.h +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetLayout.h @@ -2,7 +2,7 @@ // Project Includes #include "Graphics/SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h index 6f7048b8..3d59d5c6 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h @@ -8,8 +8,8 @@ #include "Graphics/SHVulkanIncludes.h" #include "Graphics/Devices/SHVkPhysicalDevice.h" #include "Graphics/Queues/SHVkQueue.h" -#include "Resource/Handle.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHHandle.h" +#include "Resource/SHResourceLibrary.h" #include "Graphics/Swapchain/SHSwapchainParams.h" #include "Graphics/Commands/SHCommandPoolResetMode.h" #include "Graphics/Commands/SHVkCommandPool.h" diff --git a/SHADE_Engine/src/Graphics/Framebuffer/SHVkFramebuffer.h b/SHADE_Engine/src/Graphics/Framebuffer/SHVkFramebuffer.h index 47bfcf99..4a02408c 100644 --- a/SHADE_Engine/src/Graphics/Framebuffer/SHVkFramebuffer.h +++ b/SHADE_Engine/src/Graphics/Framebuffer/SHVkFramebuffer.h @@ -2,7 +2,7 @@ #define SH_VK_FRAMEBUFFER_H #include "Graphics/SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include namespace SHADE diff --git a/SHADE_Engine/src/Graphics/Images/SHVkImage.h b/SHADE_Engine/src/Graphics/Images/SHVkImage.h index 51b71b26..4fb16017 100644 --- a/SHADE_Engine/src/Graphics/Images/SHVkImage.h +++ b/SHADE_Engine/src/Graphics/Images/SHVkImage.h @@ -3,7 +3,7 @@ #include "SHImageViewDetails.h" #include "Graphics/SHVulkanDefines.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHResourceLibrary.h" #include "vk_mem_alloc.h" namespace SHADE diff --git a/SHADE_Engine/src/Graphics/Images/SHVkImageView.h b/SHADE_Engine/src/Graphics/Images/SHVkImageView.h index ae23d7a7..79bb5dca 100644 --- a/SHADE_Engine/src/Graphics/Images/SHVkImageView.h +++ b/SHADE_Engine/src/Graphics/Images/SHVkImageView.h @@ -2,7 +2,7 @@ #define SH_VK_IMAGE_VIEW_H #include "Graphics/SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "SHImageViewDetails.h" namespace SHADE diff --git a/SHADE_Engine/src/Graphics/Images/SHVkSampler.h b/SHADE_Engine/src/Graphics/Images/SHVkSampler.h index bb878a69..3a989553 100644 --- a/SHADE_Engine/src/Graphics/Images/SHVkSampler.h +++ b/SHADE_Engine/src/Graphics/Images/SHVkSampler.h @@ -15,7 +15,7 @@ of DigiPen Institute of Technology is prohibited. #include // Project Includes #include "Graphics/SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/Instance/SHVkInstance.cpp b/SHADE_Engine/src/Graphics/Instance/SHVkInstance.cpp index 6688f9a6..191bc563 100644 --- a/SHADE_Engine/src/Graphics/Instance/SHVkInstance.cpp +++ b/SHADE_Engine/src/Graphics/Instance/SHVkInstance.cpp @@ -15,7 +15,7 @@ namespace SHADE bool SHVkInstance::validationLayersOn; vk::Instance SHVkInstance::vkInstance; SHVkDebugMessenger SHVkInstance::debugMessenger; - ResourceManager SHVkInstance::resourceManager; + SHResourceHub SHVkInstance::resourceManager; /***************************************************************************/ /*! @@ -258,7 +258,7 @@ namespace SHADE return vkInstance; } - ResourceManager& SHVkInstance::GetResourceManager(void) noexcept + SHResourceHub& SHVkInstance::GetResourceManager(void) noexcept { return resourceManager; } diff --git a/SHADE_Engine/src/Graphics/Instance/SHVkInstance.h b/SHADE_Engine/src/Graphics/Instance/SHVkInstance.h index a6fb4f0f..55adc774 100644 --- a/SHADE_Engine/src/Graphics/Instance/SHVkInstance.h +++ b/SHADE_Engine/src/Graphics/Instance/SHVkInstance.h @@ -18,7 +18,7 @@ written consent of DigiPen Institute of Technology is prohibited. #include "Graphics/Debugging/SHVkDebugMessenger.h" #include "Graphics/Devices/SHVkPhysicalDevice.h" #include "Graphics/Devices/SHVkLogicalDevice.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHResourceLibrary.h" namespace SHADE @@ -61,7 +61,7 @@ namespace SHADE static SHVkDebugMessenger debugMessenger; //! Resource management for vulkan project - static ResourceManager resourceManager; + static SHResourceHub resourceManager; /*-----------------------------------------------------------------------*/ /* PRIVATE MEMBER FUNCTIONS */ @@ -85,7 +85,7 @@ namespace SHADE /* Getters and Setters */ /*-----------------------------------------------------------------------*/ static vk::Instance const& GetVkInstance (void) noexcept; - static ResourceManager& GetResourceManager(void) noexcept; + static SHResourceHub& GetResourceManager(void) noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h index 37c57396..193fff0d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h @@ -18,7 +18,7 @@ of DigiPen Institute of Technology is prohibited. // External Dependencies #include "Graphics/SHVulkanIncludes.h" // Project Includes -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "Graphics/MiddleEnd/Interface/SHMaterial.h" #include "Math/SHMatrix.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatcher.h b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatcher.h index 8074899d..f299906c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatcher.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatcher.h @@ -15,7 +15,7 @@ of DigiPen Institute of Technology is prohibited. // STL Includes #include // Project Includes -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h index 9743e7dc..9877e04e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h @@ -15,7 +15,7 @@ of DigiPen Institute of Technology is prohibited. // External Dependencies #include "Graphics/SHVulkanIncludes.h" // Project Includes -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "SHBatch.h" #include "Graphics/Pipeline/SHVkPipeline.h" diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 7d0fa3ab..29429703 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -17,7 +17,7 @@ of DigiPen Institute of Technology is prohibited. #include // Project Includes -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "Graphics/SHVulkanIncludes.h" #include "Graphics/MiddleEnd/PerFrame/SHRenderContext.h" #include "Graphics/RenderGraph/SHRenderGraph.h" @@ -313,7 +313,7 @@ namespace SHADE SHWindow* window = nullptr; // Middle End Resources - ResourceManager resourceManager; + SHResourceHub resourceManager; SHMeshLibrary meshLibrary; SHTextureLibrary texLibrary; SHSamplerCache samplerCache; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.h index 348efb07..ec546fd5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.h @@ -15,7 +15,7 @@ of DigiPen Institute of Technology is prohibited. // STL Includes #include // Project Includes -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "SHCommonTypes.h" namespace SHADE diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.h index d111acb9..b6fcc830 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.h @@ -13,7 +13,7 @@ of DigiPen Institute of Technology is prohibited. // STL Includes #include // Project Includes -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "Graphics/Shaders/BlockInterface/SHShaderBlockInterface.h" #include "SH_API.h" diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMeshLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMeshLibrary.h index e9923385..72ac1878 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMeshLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMeshLibrary.h @@ -15,8 +15,8 @@ of DigiPen Institute of Technology is prohibited. // STL Includes #include // Project Includes -#include "Resource/Handle.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHHandle.h" +#include "Resource/SHResourceLibrary.h" #include "Math/SHMath.h" namespace SHADE @@ -167,7 +167,7 @@ namespace SHADE std::vector meshAddJobs; std::vector> meshRemoveJobs; // Tracking - ResourceLibrary meshes{}; + SHResourceLibrary meshes{}; std::vector> meshOrder; // CPU Storage std::vector vertPosStorage; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHPostOffscreenRenderSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHPostOffscreenRenderSystem.h index d3360b87..7a236eaf 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHPostOffscreenRenderSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHPostOffscreenRenderSystem.h @@ -1,6 +1,6 @@ #pragma once -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h index 3bb7cfda..bc885ca2 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h @@ -12,7 +12,7 @@ of DigiPen Institute of Technology is prohibited. #pragma once // Project Includes -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" //#include "SHTransform.h" #include "ECS_Base/Components/SHComponent.h" #include "Math/SHMatrix.h" diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h index 57c63e7f..dbd1e415 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h @@ -17,7 +17,7 @@ of DigiPen Institute of Technology is prohibited. // Project Includes #include "SHCamera.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "Graphics/RenderGraph/SHRenderGraph.h" #include "Math/SHMath.h" #include diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp index f47920e0..df9e244e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp @@ -17,7 +17,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/Instance/SHVkInstance.h" #include "Tools/SHLogger.h" #include "SHRenderer.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHResourceLibrary.h" #include "Graphics/RenderGraph/SHRenderGraph.h" namespace SHADE @@ -49,7 +49,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Renderer Registration Functions */ /*---------------------------------------------------------------------------------*/ - Handle SHViewport::AddRenderer(ResourceManager& resourceManager, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle renderGraph) + Handle SHViewport::AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle renderGraph) { // Create the renderer auto renderer = resourceManager.Create(device, numFrames, cmdPools, descriptorPool, cameraDescLayout, GetHandle(), renderGraph); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h index 04b39f00..26c0a6bd 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h @@ -17,7 +17,7 @@ of DigiPen Institute of Technology is prohibited. // External Dependencies #include "Graphics/SHVulkanIncludes.h" // Project Includes -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { @@ -28,7 +28,7 @@ namespace SHADE class SHVkCommandBuffer; class SHVkLogicalDevice; class SHVkImageView; - class ResourceManager; + class SHResourceHub; class SHRenderGraph; class SHVkDescriptorPool; class SHVkDescriptorSetLayout; @@ -59,7 +59,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Renderers Registration Functions */ /*-----------------------------------------------------------------------------*/ - Handle AddRenderer(ResourceManager& resourceManager, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle renderGraph); + Handle AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle renderGraph); void RemoveRenderer(Handle renderer); /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialInstanceCache.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialInstanceCache.cpp index ed3d27c3..624956da 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialInstanceCache.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialInstanceCache.cpp @@ -14,7 +14,7 @@ of DigiPen Institute of Technology is prohibited. #include "SHMaterialInstanceCache.h" #include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHResourceLibrary.h" namespace SHADE @@ -22,7 +22,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Usage Functions */ /*---------------------------------------------------------------------------------*/ - SHADE::Handle SHMaterialInstanceCache::CreateOrGet(ResourceManager& manager, Handle material) + SHADE::Handle SHMaterialInstanceCache::CreateOrGet(SHResourceHub& manager, Handle material) { // Check if there is already an existing instance auto matInst = cache.find(material); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialInstanceCache.h b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialInstanceCache.h index d85cb553..6612faf6 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialInstanceCache.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Materials/SHMaterialInstanceCache.h @@ -15,7 +15,7 @@ of DigiPen Institute of Technology is prohibited. // STL Includes #include // Project Includes -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { @@ -24,7 +24,7 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ class SHMaterial; class SHMaterialInstance; - class ResourceManager; + class SHResourceHub; /*-----------------------------------------------------------------------------------*/ /* Type Definitions */ @@ -56,7 +56,7 @@ namespace SHADE */ /***********************************************************************************/ - Handle CreateOrGet(ResourceManager& manager, Handle material); + Handle CreateOrGet(SHResourceHub& manager, Handle material); /***********************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h index c2eb85ec..935a7a4d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h @@ -17,8 +17,8 @@ of DigiPen Institute of Technology is prohibited. // External Dependencies #include "tinyddsloader.h" // Project Includes -#include "Resource/Handle.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHHandle.h" +#include "Resource/SHResourceLibrary.h" #include "Math/SHMath.h" #include "Graphics/SHVulkanIncludes.h" @@ -156,7 +156,7 @@ namespace SHADE std::vector addJobs; std::vector> removeJobs; // Tracking - ResourceManager resourceManager; + SHResourceHub resourceManager; std::vector> texOrder; // CPU Storage std::vector, Handle, vk::ImageLayout>> combinedImageSamplers; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHVkSamplerCache.h b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHVkSamplerCache.h index c1529577..1adbcb8c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHVkSamplerCache.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHVkSamplerCache.h @@ -16,7 +16,7 @@ of DigiPen Institute of Technology is prohibited. // External Dependencies #include "Graphics/SHVulkanIncludes.h" // Project Includes -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineLayoutParams.h b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineLayoutParams.h index 093e03d4..d696e4a3 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineLayoutParams.h +++ b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineLayoutParams.h @@ -2,7 +2,7 @@ #define SH_PIPELINE_LAYOUT_PARAMS_H #include "Graphics/SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "Graphics/Descriptors/SHVkDescriptorSetLayout.h" namespace SHADE diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipeline.h b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipeline.h index fe55a41e..1103d3d0 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipeline.h +++ b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipeline.h @@ -3,7 +3,7 @@ #include "SHPipelineState.h" #include "SHPipelineType.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "Graphics/Pipeline/SHVkPipelineLayout.h" namespace SHADE diff --git a/SHADE_Engine/src/Graphics/Queues/SHVkQueue.h b/SHADE_Engine/src/Graphics/Queues/SHVkQueue.h index 9d865ee9..a647cb72 100644 --- a/SHADE_Engine/src/Graphics/Queues/SHVkQueue.h +++ b/SHADE_Engine/src/Graphics/Queues/SHVkQueue.h @@ -3,7 +3,7 @@ #include "Graphics/SHVulkanIncludes.h" #include "Graphics/SHVulkanDefines.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHAttachmentDescInitParams.h b/SHADE_Engine/src/Graphics/RenderGraph/SHAttachmentDescInitParams.h index 20e924cb..845a19a4 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHAttachmentDescInitParams.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHAttachmentDescInitParams.h @@ -1,6 +1,6 @@ #pragma once -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index 98cb6709..0bc2c98b 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -367,7 +367,7 @@ namespace SHADE , graphResources{} , resourceManager{nullptr} { - resourceManager = std::make_shared(); + resourceManager = std::make_shared(); } SHRenderGraph::SHRenderGraph(SHRenderGraph&& rhs) noexcept diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index 952c6d8f..a919c4ff 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -2,7 +2,7 @@ #define SH_RENDER_GRAPH_H #include "Graphics/Renderpass/SHVkRenderpass.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHResourceLibrary.h" #include "SH_API.h" #include "Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h" #include "Graphics/MiddleEnd/Batching/SHSuperBatch.h" @@ -71,7 +71,7 @@ namespace SHADE std::unordered_map> graphResources; //! Resource library for graph handles - std::shared_ptr resourceManager; + std::shared_ptr resourceManager; public: /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index ec184386..5950426e 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -104,7 +104,7 @@ namespace SHADE */ /***************************************************************************/ - SHRenderGraphNode::SHRenderGraphNode(std::shared_ptr rm, Handle const& logicalDevice, Handle const& swapchain, std::vector attDescInitParams, std::vector> predecessors, std::unordered_map> const* resources) noexcept + SHRenderGraphNode::SHRenderGraphNode(std::shared_ptr rm, Handle const& logicalDevice, Handle const& swapchain, std::vector attDescInitParams, std::vector> predecessors, std::unordered_map> const* resources) noexcept : logicalDeviceHdl{ logicalDevice } , renderpass{} , framebuffers{} diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index 77861108..3cb1c4ee 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -13,7 +13,7 @@ namespace SHADE { - class ResourceManager; + class SHResourceHub; class SHVkFramebuffer; class SHRenderGraphResource; class SHVkLogicalDevice; @@ -26,7 +26,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PRIVATE MEMBER VARIABLES */ /*-----------------------------------------------------------------------*/ - std::shared_ptr resourceManager; + std::shared_ptr resourceManager; //! For Vulkan object creation Handle logicalDeviceHdl; @@ -88,7 +88,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* CTORS AND DTORS */ /*-----------------------------------------------------------------------*/ - SHRenderGraphNode(std::shared_ptr rm, Handle const& logicalDevice, Handle const& swapchain, std::vector attDescInitParams, std::vector> predecessors, std::unordered_map> const* resources) noexcept; + SHRenderGraphNode(std::shared_ptr rm, Handle const& logicalDevice, Handle const& swapchain, std::vector attDescInitParams, std::vector> predecessors, std::unordered_map> const* resources) noexcept; SHRenderGraphNode(SHRenderGraphNode&& rhs) noexcept; SHRenderGraphNode& operator= (SHRenderGraphNode&& rhs) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h index efaf9bf5..fc8b05f7 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h @@ -3,7 +3,7 @@ #include #include "SHAttachmentDescriptionType.h" #include -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "Graphics/SHVulkanIncludes.h" #include "SH_API.h" diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index ffbe4ff0..7c5021f8 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -182,7 +182,7 @@ namespace SHADE exteriorDrawCalls.push_back(newDrawCall); } - void SHSubpass::Init(ResourceManager& resourceManager) noexcept + void SHSubpass::Init(SHResourceHub& resourceManager) noexcept { superBatch = resourceManager.Create(GetHandle()); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index c567a897..e5094708 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -3,7 +3,7 @@ #include "SHAttachmentDescriptionType.h" #include #include "SH_API.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "Graphics/SHVulkanIncludes.h" @@ -78,7 +78,7 @@ namespace SHADE void Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; void AddExteriorDrawCalls(std::function&)> const& newDrawCall) noexcept; - void Init(ResourceManager& resourceManager) noexcept; + void Init(SHResourceHub& resourceManager) noexcept; /*-----------------------------------------------------------------------*/ /* GETTERS AND SETTERS */ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpassCompute.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpassCompute.h index 3ebc5676..7bbbe051 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpassCompute.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpassCompute.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/Renderpass/SHVkAttachDescGen.h b/SHADE_Engine/src/Graphics/Renderpass/SHVkAttachDescGen.h index a44f4f27..8cbf72af 100644 --- a/SHADE_Engine/src/Graphics/Renderpass/SHVkAttachDescGen.h +++ b/SHADE_Engine/src/Graphics/Renderpass/SHVkAttachDescGen.h @@ -2,7 +2,7 @@ #define SH_VK_ATTACHMENT_DESC_GEN_H #include "Graphics/SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.h b/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.h index 70a04bbf..c265e603 100644 --- a/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.h +++ b/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.h @@ -3,7 +3,7 @@ #include "SHVkAttachDescGen.h" #include "SHVkSubpassParams.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include namespace SHADE diff --git a/SHADE_Engine/src/Graphics/Renderpass/SHVkSubpassParams.h b/SHADE_Engine/src/Graphics/Renderpass/SHVkSubpassParams.h index bf789c54..6f722f5a 100644 --- a/SHADE_Engine/src/Graphics/Renderpass/SHVkSubpassParams.h +++ b/SHADE_Engine/src/Graphics/Renderpass/SHVkSubpassParams.h @@ -2,7 +2,7 @@ #define SH_VK_SUBPASS_PARAMS_H #include "Graphics/SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include namespace SHADE diff --git a/SHADE_Engine/src/Graphics/SHVkUtil.h b/SHADE_Engine/src/Graphics/SHVkUtil.h index ca3b6f83..dbf17826 100644 --- a/SHADE_Engine/src/Graphics/SHVkUtil.h +++ b/SHADE_Engine/src/Graphics/SHVkUtil.h @@ -3,7 +3,7 @@ #include "SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/Shaders/SHVkShaderModule.h b/SHADE_Engine/src/Graphics/Shaders/SHVkShaderModule.h index 2973d734..492710f2 100644 --- a/SHADE_Engine/src/Graphics/Shaders/SHVkShaderModule.h +++ b/SHADE_Engine/src/Graphics/Shaders/SHVkShaderModule.h @@ -2,7 +2,7 @@ #define SH_VK_SHADER_MODULE_H #include "Graphics/SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" #include "SHShaderReflected.h" #include diff --git a/SHADE_Engine/src/Graphics/Swapchain/SHVkSwapchain.h b/SHADE_Engine/src/Graphics/Swapchain/SHVkSwapchain.h index 28bd7a4e..384665d3 100644 --- a/SHADE_Engine/src/Graphics/Swapchain/SHVkSwapchain.h +++ b/SHADE_Engine/src/Graphics/Swapchain/SHVkSwapchain.h @@ -4,7 +4,7 @@ #include #include #include "Graphics/SHVulkanIncludes.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHResourceLibrary.h" #include "Graphics/Swapchain/SHSwapchainParams.h" namespace SHADE diff --git a/SHADE_Engine/src/Graphics/Synchronization/SHVkFence.h b/SHADE_Engine/src/Graphics/Synchronization/SHVkFence.h index 02445d42..7c48a5f6 100644 --- a/SHADE_Engine/src/Graphics/Synchronization/SHVkFence.h +++ b/SHADE_Engine/src/Graphics/Synchronization/SHVkFence.h @@ -2,7 +2,7 @@ #define SH_VK_FENCE_H #include "Graphics/SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/Synchronization/SHVkSemaphore.h b/SHADE_Engine/src/Graphics/Synchronization/SHVkSemaphore.h index 57f7d7df..f03cad65 100644 --- a/SHADE_Engine/src/Graphics/Synchronization/SHVkSemaphore.h +++ b/SHADE_Engine/src/Graphics/Synchronization/SHVkSemaphore.h @@ -2,7 +2,7 @@ #define SH_VK_SEMAPHORE_H #include "Graphics/SHVulkanIncludes.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/Windowing/Surface/SHVkSurface.h b/SHADE_Engine/src/Graphics/Windowing/Surface/SHVkSurface.h index 0328fecc..bf01dc9c 100644 --- a/SHADE_Engine/src/Graphics/Windowing/Surface/SHVkSurface.h +++ b/SHADE_Engine/src/Graphics/Windowing/Surface/SHVkSurface.h @@ -3,7 +3,7 @@ #include #include "Graphics/SHVulkanIncludes.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHResourceLibrary.h" namespace SHADE { diff --git a/SHADE_Engine/src/Resource/Handle.h b/SHADE_Engine/src/Resource/SHHandle.h similarity index 97% rename from SHADE_Engine/src/Resource/Handle.h rename to SHADE_Engine/src/Resource/SHHandle.h index 9579063c..ffc8ae6b 100644 --- a/SHADE_Engine/src/Resource/Handle.h +++ b/SHADE_Engine/src/Resource/SHHandle.h @@ -9,7 +9,7 @@ namespace SHADE /* Forward Declarations */ /*---------------------------------------------------------------------------------*/ template - class ResourceLibrary; + class SHResourceLibrary; /*---------------------------------------------------------------------------------*/ /* Type Definitions */ @@ -140,12 +140,12 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Data Members */ /*-----------------------------------------------------------------------------*/ - ResourceLibrary* library = nullptr; + SHResourceLibrary* library = nullptr; /*-----------------------------------------------------------------------------*/ /* Friend Declarations */ /*-----------------------------------------------------------------------------*/ - friend class ResourceLibrary; + friend class SHResourceLibrary; }; /// @@ -183,7 +183,7 @@ namespace SHADE /// /// Required to lock usage to ResourceLibrary only. /// Handle to set. - void SetHandle(const ResourceLibrary& rscLib, Handle hdl); + void SetHandle(const SHResourceLibrary& rscLib, Handle hdl); private: /*-----------------------------------------------------------------------------*/ @@ -220,4 +220,4 @@ namespace std }; } -#include "Handle.hpp" \ No newline at end of file +#include "SHHandle.hpp" \ No newline at end of file diff --git a/SHADE_Engine/src/Resource/Handle.hpp b/SHADE_Engine/src/Resource/SHHandle.hpp similarity index 96% rename from SHADE_Engine/src/Resource/Handle.hpp rename to SHADE_Engine/src/Resource/SHHandle.hpp index 45468ec1..6f6ea31f 100644 --- a/SHADE_Engine/src/Resource/Handle.hpp +++ b/SHADE_Engine/src/Resource/SHHandle.hpp @@ -1,7 +1,7 @@ #pragma once // Primary Header -#include "Handle.h" -#include "ResourceLibrary.h" +#include "SHHandle.h" +#include "SHResourceLibrary.h" namespace SHADE { @@ -96,7 +96,7 @@ namespace SHADE return handle; } template - inline void ISelfHandle::SetHandle(const ResourceLibrary&, Handle hdl) + inline void ISelfHandle::SetHandle(const SHResourceLibrary&, Handle hdl) { handle = hdl; } diff --git a/SHADE_Engine/src/Resource/ResourceLibrary.cpp b/SHADE_Engine/src/Resource/SHResourceLibrary.cpp similarity index 87% rename from SHADE_Engine/src/Resource/ResourceLibrary.cpp rename to SHADE_Engine/src/Resource/SHResourceLibrary.cpp index b215b591..db4a8f48 100644 --- a/SHADE_Engine/src/Resource/ResourceLibrary.cpp +++ b/SHADE_Engine/src/Resource/SHResourceLibrary.cpp @@ -1,11 +1,11 @@ #include "SHPch.h" -#include "ResourceLibrary.h" +#include "SHResourceLibrary.h" namespace SHADE { /*-----------------------------------------------------------------------------*/ /* Constructors/Destructors */ /*-----------------------------------------------------------------------------*/ - ResourceManager::~ResourceManager() + SHResourceHub::~SHResourceHub() { // Delete all resources libraries for (auto iter = deleters.rbegin(); iter != deleters.rend(); ++iter) diff --git a/SHADE_Engine/src/Resource/ResourceLibrary.h b/SHADE_Engine/src/Resource/SHResourceLibrary.h similarity index 96% rename from SHADE_Engine/src/Resource/ResourceLibrary.h rename to SHADE_Engine/src/Resource/SHResourceLibrary.h index a5bf0a67..c83cf321 100644 --- a/SHADE_Engine/src/Resource/ResourceLibrary.h +++ b/SHADE_Engine/src/Resource/SHResourceLibrary.h @@ -6,7 +6,7 @@ #include // Project Headers -#include "Handle.h" +#include "SHHandle.h" #include "Resource/SparseSet.h" namespace SHADE @@ -17,13 +17,13 @@ namespace SHADE /// /// Type of resources that this library stores. template - class ResourceLibrary + class SHResourceLibrary { public: /*-----------------------------------------------------------------------------*/ /* Constructor */ /*-----------------------------------------------------------------------------*/ - ResourceLibrary(); + SHResourceLibrary(); /*-----------------------------------------------------------------------------*/ /* Usage Functions */ @@ -75,13 +75,13 @@ namespace SHADE /// /// Manages all resources in multiple ResourceLibraries. /// - class ResourceManager final + class SHResourceHub final { public: /*-----------------------------------------------------------------------------*/ /* Constructors/Destructors */ /*-----------------------------------------------------------------------------*/ - ~ResourceManager(); + ~SHResourceHub(); /*-----------------------------------------------------------------------------*/ /* Usage Functions */ @@ -136,10 +136,10 @@ namespace SHADE /* Helper Functions */ /*-----------------------------------------------------------------------------*/ template - ResourceLibrary& getLibrary(); + SHResourceLibrary& getLibrary(); template - const ResourceLibrary& getLibrary() const; + const SHResourceLibrary& getLibrary() const; }; } -#include "ResourceLibrary.hpp" \ No newline at end of file +#include "SHResourceLibrary.hpp" \ No newline at end of file diff --git a/SHADE_Engine/src/Resource/ResourceLibrary.hpp b/SHADE_Engine/src/Resource/SHResourceLibrary.hpp similarity index 83% rename from SHADE_Engine/src/Resource/ResourceLibrary.hpp rename to SHADE_Engine/src/Resource/SHResourceLibrary.hpp index 9aa72ead..54120a94 100644 --- a/SHADE_Engine/src/Resource/ResourceLibrary.hpp +++ b/SHADE_Engine/src/Resource/SHResourceLibrary.hpp @@ -1,6 +1,6 @@ #pragma once // Primary Header -#include "ResourceLibrary.h" +#include "SHResourceLibrary.h" // Standard Library #include @@ -10,7 +10,7 @@ namespace SHADE /* ResourceLibrary - Constructor */ /*---------------------------------------------------------------------------------*/ template - ResourceLibrary::ResourceLibrary() + SHResourceLibrary::SHResourceLibrary() { // Type Checking //static_assert(std::is_copy_assignable_v, "Resource Library's resources must be copy assignable."); @@ -24,7 +24,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ template template - Handle ResourceLibrary::Create(Args&&... args) + Handle SHResourceLibrary::Create(Args&&... args) { // Create the handle Handle handle; @@ -55,7 +55,7 @@ namespace SHADE } template - void ResourceLibrary::Free(Handle handle) + void SHResourceLibrary::Free(Handle handle) { assertHandleValid(handle); @@ -63,7 +63,7 @@ namespace SHADE } template - T& ResourceLibrary::Get(Handle handle) + T& SHResourceLibrary::Get(Handle handle) { assertHandleValid(handle); @@ -71,7 +71,7 @@ namespace SHADE } template - const T& ResourceLibrary::Get(Handle handle) const + const T& SHResourceLibrary::Get(Handle handle) const { assertHandleValid(handle); @@ -82,14 +82,14 @@ namespace SHADE /* ResourceLibrary - Helper Functions */ /*---------------------------------------------------------------------------------*/ template - void ResourceLibrary::assertHandleValid(Handle handle) const + void SHResourceLibrary::assertHandleValid(Handle handle) const { if (!handle || handle.id.Data.Version != versionCounts[handle.id.Data.Index]) throw std::invalid_argument("Invalid handle provided!"); } template - inline uint32_t ResourceLibrary::getAvailableFreeIndex() + inline uint32_t SHResourceLibrary::getAvailableFreeIndex() { // Get from the free list if present if (!freeList.empty()) @@ -107,25 +107,25 @@ namespace SHADE /* ResourceManager - Usage Functions */ /*---------------------------------------------------------------------------------*/ template - Handle ResourceManager::Create(Args&&... args) + Handle SHResourceHub::Create(Args&&... args) { return getLibrary().Create(std::forward(args) ...); } template - void ResourceManager::Free(Handle handle) + void SHResourceHub::Free(Handle handle) { getLibrary().Free(handle); } template - T& ResourceManager::Get(Handle handle) + T& SHResourceHub::Get(Handle handle) { return getLibrary().Get(handle); } template - const T& ResourceManager::Get(Handle handle) const + const T& SHResourceHub::Get(Handle handle) const { return getLibrary().Get(handle); } @@ -134,18 +134,18 @@ namespace SHADE /* ResourceManager - Helper Functions */ /*-----------------------------------------------------------------------------*/ template - ResourceLibrary& ResourceManager::getLibrary() + SHResourceLibrary& SHResourceHub::getLibrary() { // Attempt to retrieve the library const std::type_index RSC_TYPE = typeid(T); if (resourceLibs.contains(RSC_TYPE)) { - return *static_cast*>(resourceLibs.at(RSC_TYPE)); + return *static_cast*>(resourceLibs.at(RSC_TYPE)); } else { // Construct library if doesn't exist - ResourceLibrary* lib = new ResourceLibrary(); + SHResourceLibrary* lib = new SHResourceLibrary(); resourceLibs.emplace(RSC_TYPE, static_cast(lib)); // Construct deleter to properly delete objects with void* @@ -156,8 +156,8 @@ namespace SHADE } template - const ResourceLibrary& ResourceManager::getLibrary() const + const SHResourceLibrary& SHResourceHub::getLibrary() const { - return const_cast(this).getLibrary(); + return const_cast(this).getLibrary(); } } diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index d7a090a4..fea59353 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -115,34 +115,22 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Script Serialisation Functions */ /*---------------------------------------------------------------------------------*/ - std::string SHScriptEngine::SerialiseScripts(EntityID entity) const + bool SHScriptEngine::SerialiseScripts(EntityID entity, YAML::Node& scriptsNode) const { - // Create buffer needed to store serialised script data - constexpr int BUFFER_SIZE = 10240; - std::unique_ptr buffer { new char[BUFFER_SIZE] }; - std::memset(buffer.get(), 0, BUFFER_SIZE); - // Attempt to serialise the script - std::string result; - if (csScriptsSerialise(entity, buffer.get(), BUFFER_SIZE)) - { - result = std::string(buffer.get()); - } - else - { - SHLOG_ERROR("[ScriptEngine] Failed to serialise scripts as string buffer is too small!"); - } + if (csScriptsSerialiseYaml(entity, &scriptsNode)) + return true; - // Return an empty string since we failed to serialise - return result; + SHLOG_ERROR("[ScriptEngine] Failed to serialise scripts for entity #{}.", entity); + return false; } /*-----------------------------------------------------------------------------------*/ /* Script Serialisation Functions */ /*-----------------------------------------------------------------------------------*/ - void SHScriptEngine::DeserialiseScript(EntityID entity, const std::string& yaml) const + bool SHScriptEngine::DeserialiseScripts(EntityID entity, const YAML::Node& scriptsNode) const { - csScriptDeserialise(entity, yaml.c_str()); + return csScriptsDeserialiseYaml(entity, &scriptsNode); } /*-----------------------------------------------------------------------------------*/ @@ -380,30 +368,18 @@ namespace SHADE DEFAULT_CSHARP_NAMESPACE + ".ScriptStore", "RemoveAllScriptsImmediately" ); - /*csScriptsSerialise = dotNet.GetFunctionPtr + csScriptsSerialiseYaml = dotNet.GetFunctionPtr ( DEFAULT_CSHARP_LIB_NAME, DEFAULT_CSHARP_NAMESPACE + ".ScriptStore", "SerialiseScripts" ); - csScriptsSerialiseYaml = dotNet.GetFunctionPtr + csScriptsDeserialiseYaml = dotNet.GetFunctionPtr ( DEFAULT_CSHARP_LIB_NAME, DEFAULT_CSHARP_NAMESPACE + ".ScriptStore", - "SerialiseScriptsYaml" + "DeserialiseScripts" ); - csScriptDeserialise = dotNet.GetFunctionPtr - ( - DEFAULT_CSHARP_LIB_NAME, - DEFAULT_CSHARP_NAMESPACE + ".ScriptStore", - "DeserialiseScript" - ); - csScriptDeserialiseYaml = dotNet.GetFunctionPtr - ( - DEFAULT_CSHARP_LIB_NAME, - DEFAULT_CSHARP_NAMESPACE + ".ScriptStore", - "SerialiseScriptsYaml" - );*/ csEditorRenderScripts = dotNet.GetFunctionPtr ( DEFAULT_CSHARP_LIB_NAME, diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.h b/SHADE_Engine/src/Scripting/SHScriptEngine.h index 60723425..137d978f 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.h +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.h @@ -13,7 +13,8 @@ of DigiPen Institute of Technology is prohibited. // STL Includes #include - +// External Dependencies +#include // Project Headers #include "SH_API.h" #include "SHDotNetRuntime.h" @@ -141,23 +142,26 @@ namespace SHADE /* Script Serialisation Functions */ /*-----------------------------------------------------------------------------*/ /// - /// Generates a JSON string that represents the set of Scripts attached to the - /// specified Entity. + /// Performs serialization of all scripts for the specified entity into the + /// YAML::Node specified. This node will contain all serialised scripts after + /// calling this function. /// - /// The Entity to Serialise. - /// - /// String that represents the set of scripts attached to the specified Entity. - /// - std::string SerialiseScripts(EntityID entity) const; + /// The Entity to Serialise. + /// + /// YAML Node that will store the serialised scripts. + /// + /// True if successfully serialised. + bool SerialiseScripts(EntityID entity, YAML::Node& scriptsNode) const; /// - /// Loads the specified JSON string and creates a Script for the specified Entity - /// based on the specified JSON string. + /// Creates scripts and sets fields for the specified Entity based on the specified + /// YAML node. /// /// The Entity to deserialise a Script on to. - /// - /// The YAML string that represents the Script to load into the Entity. + /// + /// YAML Node that contains the serialised script data. /// - void DeserialiseScript(EntityID entity, const std::string& yaml) const; + /// True if successfully deserialised. + bool DeserialiseScripts(EntityID entity, const YAML::Node& scriptsNode) const; /*-----------------------------------------------------------------------------*/ /* Script Editor Functions */ @@ -207,14 +211,13 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Type Definitions */ /*-----------------------------------------------------------------------------*/ - using CsFuncPtr = void(*)(void); - using CsScriptManipFuncPtr = bool(*)(EntityID, const char*); - using CsScriptBasicFuncPtr = void(*)(EntityID); - using CsScriptOptionalFuncPtr = void(*)(EntityID, bool); - using CsScriptSerialiseFuncPtr = bool(*)(EntityID, char*, int); - using CsScriptDeserialiseFuncPtr = bool(*)(EntityID, const char*); - using CsScriptSerialiseYamlFuncPtr = bool(*)(EntityID, void*); - using CsScriptEditorFuncPtr = void(*)(EntityID); + using CsFuncPtr = void(*)(void); + using CsScriptManipFuncPtr = bool(*)(EntityID, const char*); + using CsScriptBasicFuncPtr = void(*)(EntityID); + using CsScriptOptionalFuncPtr = void(*)(EntityID, bool); + using CsScriptSerialiseYamlFuncPtr = bool(*)(EntityID, void*); + using CsScriptDeserialiseYamlFuncPtr = bool(*)(EntityID, const void*); + using CsScriptEditorFuncPtr = void(*)(EntityID); /*-----------------------------------------------------------------------------*/ /* Constants */ @@ -228,31 +231,29 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Data Members */ /*-----------------------------------------------------------------------------*/ - SHDotNetRuntime dotNet { false }; + SHDotNetRuntime dotNet { false }; // Function Pointers to CLR Code // - Engine Lifecycle - CsFuncPtr csEngineInit = nullptr; - CsFuncPtr csEngineLoadScripts = nullptr; - CsFuncPtr csEngineUnloadScripts = nullptr; - CsFuncPtr csEngineReloadScripts = nullptr; - CsFuncPtr csEngineExit = nullptr; + CsFuncPtr csEngineInit = nullptr; + CsFuncPtr csEngineLoadScripts = nullptr; + CsFuncPtr csEngineUnloadScripts = nullptr; + CsFuncPtr csEngineReloadScripts = nullptr; + CsFuncPtr csEngineExit = nullptr; // - Scripts Store - CsFuncPtr csScriptsFrameSetUp = nullptr; - CsFuncPtr csScriptsExecuteFixedUpdate = nullptr; - CsFuncPtr csScriptsExecuteUpdate = nullptr; - CsFuncPtr csScriptsExecuteLateUpdate = nullptr; - CsFuncPtr csScriptsFrameCleanUp = nullptr; - CsScriptManipFuncPtr csScriptsAdd = nullptr; - CsScriptBasicFuncPtr csScriptsRemoveAll = nullptr; - CsScriptOptionalFuncPtr csScriptsRemoveAllImmediately = nullptr; - CsScriptSerialiseFuncPtr csScriptsSerialise = nullptr; - CsScriptDeserialiseFuncPtr csScriptDeserialise = nullptr; - CsScriptSerialiseYamlFuncPtr csScriptsSerialiseYaml = nullptr; - CsScriptSerialiseYamlFuncPtr csScriptDeserialiseYaml = nullptr; + CsFuncPtr csScriptsFrameSetUp = nullptr; + CsFuncPtr csScriptsExecuteFixedUpdate = nullptr; + CsFuncPtr csScriptsExecuteUpdate = nullptr; + CsFuncPtr csScriptsExecuteLateUpdate = nullptr; + CsFuncPtr csScriptsFrameCleanUp = nullptr; + CsScriptManipFuncPtr csScriptsAdd = nullptr; + CsScriptBasicFuncPtr csScriptsRemoveAll = nullptr; + CsScriptOptionalFuncPtr csScriptsRemoveAllImmediately = nullptr; + CsScriptSerialiseYamlFuncPtr csScriptsSerialiseYaml = nullptr; + CsScriptDeserialiseYamlFuncPtr csScriptsDeserialiseYaml = nullptr; // - Editor - CsScriptEditorFuncPtr csEditorRenderScripts = nullptr; - CsFuncPtr csEditorUndo = nullptr; - CsFuncPtr csEditorRedo = nullptr; + CsScriptEditorFuncPtr csEditorRenderScripts = nullptr; + CsFuncPtr csEditorUndo = nullptr; + CsFuncPtr csEditorRedo = nullptr; /*-----------------------------------------------------------------------------*/ /* Event Handler Functions */ diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index f6d29066..3804db95 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -13,6 +13,8 @@ #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Math/Transform/SHTransformComponent.h" #include "Physics/Components/SHRigidBodyComponent.h" +#include "ECS_Base/Managers/SHSystemManager.h" +#include "Scripting/SHScriptEngine.h" namespace SHADE { @@ -79,7 +81,10 @@ namespace SHADE } } } - return eid; + + // Deserialise scripts + if (node[ScriptsNode]) + SHSystemManager::GetSystem()->DeserialiseScripts(eid, node[ScriptsNode]); } void SHSerialization::DeserializeSceneFromFile(std::filesystem::path const& path) @@ -166,7 +171,7 @@ namespace SHADE node = YAML::Null; return node; } - node.SetStyle(YAML::EmitterStyle::Block); + node.SetStyle(YAML::EmitterStyle::Block); node[EIDNode] = eid; node[EntityNameNode] = entity->name; node[IsActiveNode] = sceneNode->IsActive(); @@ -188,6 +193,11 @@ namespace SHADE components[rttr::type::get().get_name().data()] = SHSerializationHelper::SerializeComponentToNode(rigidbody); } node[ComponentsNode] = components; + + YAML::Node scripts; + SHSystemManager::GetSystem()->SerialiseScripts(eid, scripts); + node[ScriptsNode] = scripts; + return node; } diff --git a/SHADE_Engine/src/Serialization/SHSerialization.h b/SHADE_Engine/src/Serialization/SHSerialization.h index 6b078dba..018bf0c3 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.h +++ b/SHADE_Engine/src/Serialization/SHSerialization.h @@ -21,6 +21,7 @@ namespace SHADE constexpr const char* EIDNode = "EID"; constexpr const char* IsActiveNode = "IsActive"; constexpr const char* NumberOfChildrenNode = "NumberOfChildren"; + constexpr const char* ScriptsNode = "Scripts"; struct SH_API SHSerialization { diff --git a/SHADE_Managed/src/Scripts/ScriptStore.cxx b/SHADE_Managed/src/Scripts/ScriptStore.cxx index 252ab071..b6bc1815 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.cxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.cxx @@ -26,6 +26,7 @@ of DigiPen Institute of Technology is prohibited. #include "Utility/Convert.hxx" #include "Script.hxx" #include "Engine/Entity.hxx" +#include "Serialisation/ReflectionUtilities.hxx" namespace SHADE { @@ -470,72 +471,90 @@ namespace SHADE } SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore") } - bool ScriptStore::SerialiseScripts(Entity entity, System::Text::StringBuilder^ buffer, int bufferSize) + + bool ScriptStore::SerialiseScripts(Entity entity, System::IntPtr yamlNodePtr) { SAFE_NATIVE_CALL_BEGIN - // Create a buffer that we can work with temporarily - System::Text::StringBuilder^ jsonString = gcnew System::Text::StringBuilder(); + // Convert to pointer + YAML::Node* yamlNode = reinterpret_cast(yamlNodePtr.ToPointer()); + // Check if yamlNode is valid + if (yamlNode == nullptr) + { + Debug::LogWarning("[ScriptStore] Attempted to serialise scripts with an invalid YAML Node! Skipping."); + return false; + } + // Check if entity exists, otherwise nothing if (!EntityUtils::IsValid(entity)) - return true; - + { + Debug::LogWarning("[ScriptStore] Attempted to serialise scripts for an invalid Entity! Skipping."); + return false; + } + // Check if entity exists in the script storage - if (!scripts.ContainsKey(entity)) + if (!scripts.ContainsKey(entity)) return true; // Serialise each script + yamlNode->SetStyle(YAML::EmitterStyle::Block); System::Collections::Generic::List^ scriptList = scripts[entity]; - for (int i = 0; i < scriptList->Count; ++i) + for each (Script^ script in scriptList) { - throw gcnew System::NotImplementedException; - //jsonString->Append(ReflectionUtilities::Serialise(scriptList[i])); - - // Only add separator if is not last script - if (i != scriptList->Count - 1) - { - jsonString->Append(",\r\n"); - } + ReflectionUtilities::Serialise(script, *yamlNode); } - // Check if the size is too big - if (jsonString->Length > bufferSize) - return false; - - // Otherwise we copy it over - buffer->Clear(); - buffer->Append(jsonString->ToString()); return true; SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore") return false; } - bool ScriptStore::DeserialiseScript(Entity entity, System::String^ yaml) + bool ScriptStore::DeserialiseScripts(Entity entity, System::IntPtr yamlNodePtr) { SAFE_NATIVE_CALL_BEGIN + // Convert to pointer + YAML::Node* yamlNode = reinterpret_cast(yamlNodePtr.ToPointer()); + + // Check if yamlNode is valid + if (yamlNode == nullptr) + { + Debug::LogWarning("[ScriptStore] Attempted to deserialise scripts with an invalid YAML Node! Skipping."); + return false; + } + // Check if entity exists, otherwise nothing if (!EntityUtils::IsValid(entity)) - return false; - - // Get the name of the script - const int FIRST_QUOTE = yaml->IndexOf('\"'); - const int FIRST_COLON = yaml->IndexOf(':'); - if (FIRST_QUOTE < 0 || FIRST_COLON < 0) // No script name, it's invalid - return false; - const int SCRIPT_NAME_START = FIRST_QUOTE + 1; - const int SCRIPT_NAME_END = FIRST_COLON - 1; - System::String^ typeName = yaml->Substring(SCRIPT_NAME_START, SCRIPT_NAME_END - SCRIPT_NAME_START); - - // Create the script - Script^ script; - if (AddScriptViaNameWithRef(entity, typeName, script)) { - // Copy the data in - throw gcnew System::NotImplementedException; - //ReflectionUtilities::Deserialise(json, script); - return true; + Debug::LogWarning("[ScriptStore] Attempted to deserialise scripts for an invalid Entity! Skipping."); + return false; } + // Go through all elements in the node + for (YAML::Node& node : *yamlNode) + { + // Get the name of the script + if (!node["Type"]) + { + Debug::LogWarning("[ScriptStore] Script with no type detected, skipping."); + continue; + } + + System::String^ typeName = Convert::ToCLI(node["Type"].as()); + + // Create + Script^ script; + if (AddScriptViaNameWithRef(entity, typeName, script)) + { + // Copy the data in + ReflectionUtilities::Deserialise(script, node); + } + else + { + Debug::LogWarning("[ScriptStore] Script with unloaded type detected, skipping."); + } + } + return true; + SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore") return false; } diff --git a/SHADE_Managed/src/Scripts/ScriptStore.hxx b/SHADE_Managed/src/Scripts/ScriptStore.hxx index cc0c1db5..4a9be721 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.hxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.hxx @@ -17,6 +17,7 @@ of DigiPen Institute of Technology is prohibited. // Project Includes #include "Engine/Entity.hxx" #include "Script.hxx" +#include "Serialization/SHSerialization.h" namespace SHADE { @@ -237,27 +238,23 @@ namespace SHADE /* Serialisation Functions */ /*-----------------------------------------------------------------------------*/ /// - /// Generates a JSON string that represents the set of Scripts attached - /// to the specified Entity. + /// Populates a YAML node with the scripts for a specified Entity. ///

/// This function should only be called from native unmanaged code. ///
/// The Entity to Serialise. - /// - /// StringBuilder handle that maps to a native char array that will contain the - /// serialised string. - /// - /// - /// The size of the char array. + /// + /// Pointer to a YAML::Node that will be populated with all of the serialised + /// scripts and their associated fields. /// /// /// True if serialisation is successful. False if the buffer is too small for /// the serialised output. /// - static bool SerialiseScripts(Entity entity, System::Text::StringBuilder^ buffer, int bufferSize); + static bool SerialiseScripts(Entity entity, System::IntPtr yamlNode); /// - /// Processes a JSON string that represents a single Script and attaches - /// it onto the specified Entity. + /// Processes a YAML node that contains a list of multiple scripts to be loaded + /// into the specified Entity. ///

/// This function should only be called from native unmanaged code. ///
@@ -265,10 +262,10 @@ namespace SHADE /// The Entity to attach the deserialised Scripts to. /// /// - /// JSON string that describes the Script to serialise. + /// Pointer to the YAML::Node that contains serialized script data. /// /// - static bool DeserialiseScript(Entity entity, System::String^ yaml); + static bool DeserialiseScripts(Entity entity, System::IntPtr yamlNode); private: /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Serialisation/ReflectionUtilities.cxx b/SHADE_Managed/src/Serialisation/ReflectionUtilities.cxx index 2a9cc57c..3e963818 100644 --- a/SHADE_Managed/src/Serialisation/ReflectionUtilities.cxx +++ b/SHADE_Managed/src/Serialisation/ReflectionUtilities.cxx @@ -38,6 +38,11 @@ if (iter != jsonValue.MemberEnd()) \ vec.MEMBER = iter->value.GetDouble(); \ } \ +/*-------------------------------------------------------------------------------------*/ +/* File-Level Constants */ +/*-------------------------------------------------------------------------------------*/ +static const std::string_view SCRIPT_TYPE_YAMLTAG = "Type"; + /*-------------------------------------------------------------------------------------*/ /* Function Definitions */ /*-------------------------------------------------------------------------------------*/ @@ -61,13 +66,14 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Serialisation Functions */ /*---------------------------------------------------------------------------------*/ - void ReflectionUtilities::Serialise(System::Object^ object, YAML::Emitter& yaml) + void ReflectionUtilities::Serialise(System::Object^ object, YAML::Node& scriptListNode) { using namespace System::Reflection; // Create YAML object - yaml << YAML::Key << Convert::ToNative(object->GetType()->FullName); - yaml << YAML::BeginMap; + YAML::Node scriptNode; + scriptNode.SetStyle(YAML::EmitterStyle::Block); + scriptNode[SCRIPT_TYPE_YAMLTAG.data()] = Convert::ToNative(object->GetType()->FullName); // Get all fields System::Collections::Generic::IEnumerable^ fields = GetInstanceFields(object); @@ -78,12 +84,12 @@ namespace SHADE continue; // Serialise - writeFieldIntoYaml(field, object, yaml); + writeFieldIntoYaml(field, object, scriptNode); } - yaml << YAML::EndMap; + scriptListNode.push_back(scriptNode); } - void ReflectionUtilities::Deserialise(YAML::Node& yamlNode, Object^ object) + void ReflectionUtilities::Deserialise(Object^ object, YAML::Node& yamlNode) { using namespace System::Reflection; @@ -117,53 +123,63 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Serialization Helper Functions */ /*---------------------------------------------------------------------------------*/ - void ReflectionUtilities::writeFieldIntoYaml(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Emitter& yaml) + void ReflectionUtilities::writeFieldIntoYaml(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& yamlNode) { - // Field Name - yaml << YAML::Key << Convert::ToNative(fieldInfo->Name); - - // Field Value - yaml << YAML::Value; - if (fieldInsertYaml (fieldInfo, object, yaml) || - fieldInsertYaml (fieldInfo, object, yaml) || - fieldInsertYaml (fieldInfo, object, yaml) || - fieldInsertYaml(fieldInfo, object, yaml) || - fieldInsertYaml(fieldInfo, object, yaml) || - fieldInsertYaml(fieldInfo, object, yaml) || - fieldInsertYaml (fieldInfo, object, yaml) || - fieldInsertYaml (fieldInfo, object, yaml) || - fieldInsertYaml (fieldInfo, object, yaml) || - fieldInsertYaml (fieldInfo, object, yaml)) + // Field YAML Node + YAML::Node fieldNode; + + // Retrieve string for the YAML + const bool PRIMITIVE_SERIALIZED = 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) || + fieldInsertYaml(fieldInfo, object, fieldNode) || + fieldInsertYaml(fieldInfo, object, fieldNode); + + // Serialization of more complex types + if (!PRIMITIVE_SERIALIZED) { - return; - } - else if (fieldInfo->FieldType->IsSubclassOf(System::Enum::typeid)) - { - yaml << safe_cast(fieldInfo->GetValue(object)); - } - else if (fieldInfo->FieldType == System::String::typeid) - { - System::String^ str = safe_cast(fieldInfo->GetValue(object)); - yaml << Convert::ToNative(str); - } - else if (fieldInfo->FieldType == Vector2::typeid) - { - Vector2 vec = safe_cast(fieldInfo->GetValue(object)); - yaml << YAML::BeginSeq << YAML::Flow << vec.x << vec.y << YAML::EndSeq; - } - else if (fieldInfo->FieldType == Vector3::typeid) - { - Vector3 vec = safe_cast(fieldInfo->GetValue(object)); - yaml << YAML::BeginSeq << YAML::Flow << vec.x << vec.y << vec.z << YAML::EndSeq; - } - else // Not any of the supported types - { - Debug::LogWarning(Convert::ToNative(System::String::Format - ( - "[ReflectionUtilities] Failed to parse \"{0}\" of \"{1}\" type for serialization.", - fieldInfo->Name, fieldInfo->FieldType) - )); + if (fieldInfo->FieldType->IsSubclassOf(System::Enum::typeid)) + { + fieldNode = std::to_string(safe_cast(fieldInfo->GetValue(object))); + } + else if (fieldInfo->FieldType == System::String::typeid) + { + System::String^ str = safe_cast(fieldInfo->GetValue(object)); + fieldNode = Convert::ToNative(str); + } + else if (fieldInfo->FieldType == Vector2::typeid) + { + Vector2 vec = safe_cast(fieldInfo->GetValue(object)); + fieldNode.SetStyle(YAML::EmitterStyle::Flow); + fieldNode.push_back(vec.x); + fieldNode.push_back(vec.y); + } + else if (fieldInfo->FieldType == Vector3::typeid) + { + Vector3 vec = safe_cast(fieldInfo->GetValue(object)); + fieldNode.SetStyle(YAML::EmitterStyle::Flow); + fieldNode.push_back(vec.x); + fieldNode.push_back(vec.y); + fieldNode.push_back(vec.z); + } + else // Not any of the supported types + { + Debug::LogWarning(Convert::ToNative(System::String::Format + ( + "[ReflectionUtilities] Failed to parse \"{0}\" of \"{1}\" type for serialization.", + fieldInfo->Name, fieldInfo->FieldType) + )); + return; + } } + + // Store the field into YAML + yamlNode[Convert::ToNative(fieldInfo->Name)] = fieldNode; } void ReflectionUtilities::writeYamlIntoField(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& node) diff --git a/SHADE_Managed/src/Serialisation/ReflectionUtilities.h++ b/SHADE_Managed/src/Serialisation/ReflectionUtilities.h++ index 88469b34..7c39232a 100644 --- a/SHADE_Managed/src/Serialisation/ReflectionUtilities.h++ +++ b/SHADE_Managed/src/Serialisation/ReflectionUtilities.h++ @@ -23,11 +23,12 @@ namespace SHADE /* Serialization Helper Functions */ /*---------------------------------------------------------------------------------*/ template - bool ReflectionUtilities::fieldInsertYaml(System::Reflection::FieldInfo^ fieldInfo, System::Object^ object, YAML::Emitter& emitter) + bool ReflectionUtilities::fieldInsertYaml(System::Reflection::FieldInfo^ fieldInfo, System::Object^ object, YAML::Node& fieldNode) { if (fieldInfo->FieldType == FieldType::typeid) { - emitter << safe_cast(fieldInfo->GetValue(object)); + const FieldType VALUE = safe_cast(fieldInfo->GetValue(object)); + fieldNode = static_cast(VALUE); return true; } @@ -37,7 +38,7 @@ namespace SHADE template bool ReflectionUtilities::fieldAssignYaml(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& node) { - return fieldAssignYaml(fieldInfo, object, node); + return fieldAssignYaml>(fieldInfo, object, node); } template diff --git a/SHADE_Managed/src/Serialisation/ReflectionUtilities.hxx b/SHADE_Managed/src/Serialisation/ReflectionUtilities.hxx index 53f8fa1d..403c913c 100644 --- a/SHADE_Managed/src/Serialisation/ReflectionUtilities.hxx +++ b/SHADE_Managed/src/Serialisation/ReflectionUtilities.hxx @@ -52,24 +52,24 @@ namespace SHADE /// attribute will be serialised. /// /// The object to serialise. - static void Serialise(System::Object^ object, YAML::Emitter& yaml); + static void Serialise(System::Object^ object, YAML::Node& yamlNode); /// /// Deserialises a YAML node that contains a map of Scripts and copies the /// deserialised data into the specified object if there are matching fields. /// /// - /// The JSON string that contains the data to copy into this PlushieScript - /// object. + /// The JSON string that contains the data to copy into this Script object. /// /// The object to copy deserialised data into. - static void Deserialise(YAML::Node& yamlNode, Object^ object); + static void Deserialise(System::Object^ object, YAML::Node& yamlNode); + private: /*-----------------------------------------------------------------------------*/ /* Serialization Helper Functions */ /*-----------------------------------------------------------------------------*/ - static void writeFieldIntoYaml(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Emitter& yaml); + static void writeFieldIntoYaml(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& yamlNode); template - static bool fieldInsertYaml(System::Reflection::FieldInfo^ fieldInfo, System::Object^ object, YAML::Emitter& emitter); + static bool fieldInsertYaml(System::Reflection::FieldInfo^ fieldInfo, System::Object^ object, YAML::Node& fieldNode); static void writeYamlIntoField(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& node); template static bool fieldAssignYaml(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& node); diff --git a/SHADE_Managed/src/Utility/Convert.hxx b/SHADE_Managed/src/Utility/Convert.hxx index b41ffef4..f04cbf4b 100644 --- a/SHADE_Managed/src/Utility/Convert.hxx +++ b/SHADE_Managed/src/Utility/Convert.hxx @@ -91,4 +91,68 @@ namespace SHADE /// Managed copy of a native std::string. static System::String^ ToCLI(const std::string& str); }; + + /// + /// Type Transformer for managed types to native types. + /// + /// + /// Managed type to get the native type for. + /// + template + struct ToNativeType + { + public: + using Value = void; + }; + template<> struct ToNativeType { using Value = int16_t; }; + template<> struct ToNativeType { using Value = int32_t; }; + template<> struct ToNativeType { using Value = int64_t; }; + template<> struct ToNativeType { using Value = uint16_t; }; + template<> struct ToNativeType { using Value = uint32_t; }; + template<> struct ToNativeType { using Value = uint64_t; }; + template<> struct ToNativeType { using Value = int8_t; }; + template<> struct ToNativeType { using Value = bool; }; + template<> struct ToNativeType { using Value = double; }; + template<> struct ToNativeType { using Value = float; }; + + /// + /// Alias for ToNativeType::Value + /// + /// + /// Managed type to get the native type for. + /// + template + using ToNativeType_T = typename ToNativeType::Value; + + /// + /// Type Transformer for native types to managed types. + /// + /// + /// Managed type to get the native type for. + /// + template + struct ToManagedType + { + public: + using Value = void; + }; + template<> struct ToManagedType { using Value = System::Byte; }; + template<> struct ToManagedType { using Value = System::Int16; }; + template<> struct ToManagedType { using Value = System::Int32; }; + template<> struct ToManagedType { using Value = System::Int64; }; + template<> struct ToManagedType { using Value = System::UInt16; }; + template<> struct ToManagedType { using Value = System::UInt32; }; + template<> struct ToManagedType { using Value = System::UInt64; }; + template<> struct ToManagedType { using Value = bool; }; + template<> struct ToManagedType { using Value = double; }; + template<> struct ToManagedType { using Value = float; }; + + /// + /// Alias for ToManagedType::Value + /// + /// + /// Managed type to get the native type for. + /// + template + using ToManagedType_T = typename ToManagedType::Value; }