Restructured Asset Manager with Generalised Template Types for Asset Data #111
|
@ -0,0 +1,48 @@
|
|||
[Window][MainStatusBar]
|
||||
Pos=0,1060
|
||||
Size=1920,20
|
||||
Collapsed=0
|
||||
|
||||
[Window][SHEditorMenuBar]
|
||||
Pos=0,48
|
||||
Size=1920,1012
|
||||
Collapsed=0
|
||||
|
||||
[Window][Hierarchy Panel]
|
||||
Pos=0,142
|
||||
Size=571,918
|
||||
Collapsed=0
|
||||
DockId=0x00000004,0
|
||||
|
||||
[Window][Debug##Default]
|
||||
Pos=60,60
|
||||
Size=400,400
|
||||
Collapsed=0
|
||||
|
||||
[Window][Inspector]
|
||||
Pos=1649,48
|
||||
Size=271,1012
|
||||
Collapsed=0
|
||||
DockId=0x00000006,0
|
||||
|
||||
[Window][Profiler]
|
||||
Pos=0,48
|
||||
Size=571,92
|
||||
Collapsed=0
|
||||
DockId=0x00000003,0
|
||||
|
||||
[Window][Viewport]
|
||||
Pos=573,48
|
||||
Size=1074,1012
|
||||
Collapsed=0
|
||||
DockId=0x00000002,0
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=8,79 Size=1920,1012 Split=X
|
||||
DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1992,1036 Split=X
|
||||
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=571,1036 Split=Y Selected=0x1E6EB881
|
||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,94 Selected=0x1E6EB881
|
||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=225,940 Selected=0xE096E5AE
|
||||
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1074,1036 CentralNode=1 Selected=0x13926F0B
|
||||
DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=271,1036 Selected=0xE7039252
|
||||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "Input/SHInputManager.h"
|
||||
#include "FRC/SHFramerateController.h"
|
||||
#include "AudioSystem/SHAudioSystem.h"
|
||||
#include "Camera/SHCameraSystem.h"
|
||||
|
||||
// Components
|
||||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||
|
@ -67,6 +68,7 @@ namespace Sandbox
|
|||
SHSystemManager::CreateSystem<SHTransformSystem>();
|
||||
SHGraphicsSystem* graphicsSystem = static_cast<SHGraphicsSystem*>(SHSystemManager::GetSystem<SHGraphicsSystem>());
|
||||
SHSystemManager::CreateSystem<SHAudioSystem>();
|
||||
SHSystemManager::CreateSystem<SHCameraSystem>();
|
||||
|
||||
#ifdef SHEDITOR
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
@ -89,6 +91,8 @@ namespace Sandbox
|
|||
|
||||
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BatcherDispatcherRoutine>();
|
||||
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BeginRoutine>();
|
||||
|
||||
SHSystemManager::RegisterRoutine<SHCameraSystem, SHCameraSystem::EditorCameraUpdate>();
|
||||
|
||||
#ifdef SHEDITOR
|
||||
SHSystemManager::RegisterRoutine<SHEditor, SHEditor::EditorRoutine>();
|
||||
|
@ -101,6 +105,7 @@ namespace Sandbox
|
|||
SHComponentManager::CreateComponentSparseSet<SHColliderComponent>();
|
||||
SHComponentManager::CreateComponentSparseSet<SHTransformComponent>();
|
||||
SHComponentManager::CreateComponentSparseSet<SHRenderable>();
|
||||
SHComponentManager::CreateComponentSparseSet<SHCameraComponent>();
|
||||
|
||||
//TODO: REMOVE AFTER PRESENTATION
|
||||
//SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "SBpch.h"
|
||||
#include "SBpch.h"
|
||||
#include "SBTestScene.h"
|
||||
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
|
@ -17,6 +17,7 @@
|
|||
#include "Assets/Asset Types/SHTextureAsset.h"
|
||||
|
||||
#include "Assets/SHAssetManager.h"
|
||||
#include "Resource/SHResourceManager.h"
|
||||
|
||||
using namespace SHADE;
|
||||
|
||||
|
@ -45,24 +46,22 @@ namespace Sandbox
|
|||
auto assets = SHAssetManager::GetAllAssets();
|
||||
|
||||
//Test Racoon mesh
|
||||
auto mesh = SHAssetManager::GetData<SHMeshAsset>(107348815);
|
||||
Handle<SHMesh> handle;
|
||||
handle = (graphicsSystem->AddMesh(
|
||||
mesh->header.vertexCount,
|
||||
mesh->vertexPosition.data(),
|
||||
mesh->texCoords.data(),
|
||||
mesh->vertexTangent.data(),
|
||||
mesh->vertexNormal.data(),
|
||||
mesh->header.indexCount,
|
||||
mesh->indices.data()
|
||||
));
|
||||
graphicsSystem->BuildMeshBuffers();
|
||||
|
||||
// Load Textures
|
||||
auto texture = SHAssetManager::GetData<SHTextureAsset>(91918845);
|
||||
Handle<SHTexture> texHandle;
|
||||
texHandle = graphicsSystem->Add(*texture);
|
||||
graphicsSystem->BuildTextures();
|
||||
std::vector<Handle<SHMesh>> handles;
|
||||
std::vector<Handle<SHTexture>> texHandles;
|
||||
for (const auto& asset : SHAssetManager::GetAllAssets())
|
||||
{
|
||||
switch (asset.type)
|
||||
{
|
||||
case AssetType::MESH:
|
||||
if (asset.name == "Cube.012")
|
||||
handles.emplace_back(SHResourceManager::LoadOrGet<SHMesh>(asset.id));
|
||||
break;
|
||||
case AssetType::TEXTURE:
|
||||
texHandles.emplace_back(SHResourceManager::LoadOrGet<SHTexture>(asset.id));
|
||||
break;
|
||||
}
|
||||
}
|
||||
SHResourceManager::FinaliseChanges();
|
||||
|
||||
// Create Materials
|
||||
auto matInst = graphicsSystem->AddOrGetBaseMaterialInstance();
|
||||
|
@ -73,8 +72,8 @@ namespace Sandbox
|
|||
|
||||
// Create Stress Test Objects
|
||||
static const SHVec3 TEST_OBJ_SCALE = SHVec3::One * 0.5f;
|
||||
constexpr int NUM_ROWS = 10;
|
||||
constexpr int NUM_COLS = 10;
|
||||
constexpr int NUM_ROWS = 0;
|
||||
constexpr int NUM_COLS = 0;
|
||||
static const SHVec3 TEST_OBJ_SPACING = { 0.1f, 0.1f, 0.1f };
|
||||
static const SHVec3 TEST_OBJ_START_POS = { -(NUM_COLS / 2 * TEST_OBJ_SPACING.x) + 1.0f, -2.0f, -1.0f };
|
||||
|
||||
|
@ -111,7 +110,7 @@ namespace Sandbox
|
|||
auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(raccoonSpin);
|
||||
auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(raccoonSpin);
|
||||
|
||||
renderable.Mesh = handle;
|
||||
renderable.Mesh = handles.front();
|
||||
renderable.SetMaterial(customMat);
|
||||
renderable.GetModifiableMaterial()->SetProperty("data.color", SHVec4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
renderable.GetModifiableMaterial()->SetProperty("data.alpha", 1.0f);
|
||||
|
@ -152,7 +151,7 @@ namespace Sandbox
|
|||
auto& renderableShowcase = *SHComponentManager::GetComponent_s<SHRenderable>(raccoonShowcase);
|
||||
auto& transformShowcase = *SHComponentManager::GetComponent_s<SHTransformComponent>(raccoonShowcase);
|
||||
|
||||
renderableShowcase.Mesh = handle;
|
||||
renderableShowcase.Mesh = handles.front();
|
||||
renderableShowcase.SetMaterial(customMat);
|
||||
renderableShowcase.GetModifiableMaterial()->SetProperty("data.color", SHVec4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
renderableShowcase.GetModifiableMaterial()->SetProperty("data.alpha", 1.0f);
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
#include "SHMeshAsset.h"
|
||||
#include "SHTextureAsset.h"
|
|
@ -62,7 +62,12 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
AssetPath SHAssetManager::GenerateLocalPath(AssetPath path) noexcept
|
||||
void SHAssetManager::Unload(AssetID assetId) noexcept
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
AssetPath SHAssetManager::GenerateLocalPath(AssetPath path) noexcept
|
||||
{
|
||||
if (!IsRecognised(path.extension().string().c_str()))
|
||||
{
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace SHADE
|
|||
* \brief Deallocate all memory used by resource data
|
||||
****************************************************************************/
|
||||
static void Unload() noexcept;
|
||||
static void Unload(AssetID assetId) noexcept;
|
||||
|
||||
/****************************************************************************
|
||||
* \brief Load all resources that are in the folder
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHCameraComponent.h"
|
||||
#include "ECS_Base/Managers/SHComponentManager.h"
|
||||
|
||||
|
||||
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(0.5f)
|
||||
, perspProj(true), dirtyView(true), dirtyProj(true)
|
||||
, viewMatrix(), projMatrix()
|
||||
, position()
|
||||
{
|
||||
ComponentFamily::GetID<SHCameraComponent>();
|
||||
}
|
||||
|
||||
SHCameraComponent::~SHCameraComponent()
|
||||
{
|
||||
}
|
||||
|
||||
void SHCameraComponent::SetYaw(float yaw) noexcept
|
||||
{
|
||||
this->yaw = yaw;
|
||||
dirtyView = true;
|
||||
}
|
||||
|
||||
void SHCameraComponent::SetPitch(float pitch) noexcept
|
||||
{
|
||||
this->pitch = pitch;
|
||||
dirtyView = true;
|
||||
}
|
||||
|
||||
void SHCameraComponent::SetRoll(float roll) noexcept
|
||||
{
|
||||
this->roll = roll;
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPositionX(float x) noexcept
|
||||
{
|
||||
position.x = x;
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPositionY(float y) noexcept
|
||||
{
|
||||
position.y = y;
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPositionZ(float z) noexcept
|
||||
{
|
||||
position.z = z;
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPosition(float x,float y, float z) noexcept
|
||||
{
|
||||
position.x = x;
|
||||
position.y = y;
|
||||
position.z = z;
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPosition(SHVec3& pos) noexcept
|
||||
{
|
||||
this->position = pos;
|
||||
dirtyView = true;
|
||||
}
|
||||
|
||||
void SHCameraComponent::SetWidth(float width) noexcept
|
||||
{
|
||||
this->width = width;
|
||||
dirtyProj = true;
|
||||
}
|
||||
|
||||
|
||||
void SHCameraComponent::SetHeight(float height) noexcept
|
||||
{
|
||||
this->height = height;
|
||||
dirtyProj = true;
|
||||
}
|
||||
|
||||
void SHCameraComponent::SetNear(float znear) noexcept
|
||||
{
|
||||
this->zNear = znear;
|
||||
dirtyProj = true;
|
||||
}
|
||||
|
||||
void SHCameraComponent::SetFar(float zFar) noexcept
|
||||
{
|
||||
this->zFar = zFar;
|
||||
dirtyProj = true;
|
||||
}
|
||||
|
||||
void SHCameraComponent::SetFOV(float fov) noexcept
|
||||
{
|
||||
this->fov = fov;
|
||||
dirtyProj = true;
|
||||
}
|
||||
|
||||
float SHCameraComponent::GetYaw() const noexcept
|
||||
{
|
||||
return yaw;
|
||||
}
|
||||
|
||||
float SHCameraComponent::GetPitch() const noexcept
|
||||
{
|
||||
return pitch;
|
||||
}
|
||||
float SHCameraComponent::GetRoll() const noexcept
|
||||
{
|
||||
return roll;
|
||||
}
|
||||
float SHCameraComponent::GetAspectRatio() const noexcept
|
||||
{
|
||||
return width/height;
|
||||
}
|
||||
|
||||
float SHCameraComponent::GetFOV() const noexcept
|
||||
{
|
||||
return fov;
|
||||
}
|
||||
|
||||
const SHMatrix& SHCameraComponent::GetViewMatrix() const noexcept
|
||||
{
|
||||
return viewMatrix;
|
||||
}
|
||||
|
||||
const SHMatrix& SHCameraComponent::GetProjMatrix() const noexcept
|
||||
{
|
||||
return projMatrix;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
#pragma once
|
||||
|
||||
#include "ECS_Base/Components/SHComponent.h"
|
||||
#include "Math/Vector/SHVec3.h"
|
||||
#include "Math/SHMatrix.h"
|
||||
#include "SH_API.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
||||
class SH_API SHCameraComponent final : public SHComponent
|
||||
{
|
||||
private:
|
||||
|
||||
float yaw;
|
||||
float pitch;
|
||||
float roll;
|
||||
|
||||
float width;
|
||||
float height;
|
||||
float zNear;
|
||||
float zFar;
|
||||
float fov;
|
||||
|
||||
bool dirtyView;
|
||||
bool dirtyProj;
|
||||
|
||||
|
||||
SHMatrix viewMatrix;
|
||||
SHMatrix projMatrix;
|
||||
SHVec3 position;
|
||||
|
||||
bool perspProj;
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
friend class SHCameraSystem;
|
||||
|
||||
SHCameraComponent();
|
||||
~SHCameraComponent();
|
||||
|
||||
|
||||
//Getters and setters.
|
||||
void SetYaw(float yaw) noexcept;
|
||||
void SetPitch(float pitch) noexcept;
|
||||
void SetRoll(float roll) noexcept;
|
||||
void SetPositionX(float x) noexcept;
|
||||
void SetPositionY(float y) noexcept;
|
||||
void SetPositionZ(float z) noexcept;
|
||||
void SetPosition(float x, float y, float z) noexcept;
|
||||
void SetPosition(SHVec3& pos) noexcept;
|
||||
|
||||
void SetWidth(float width) noexcept;
|
||||
void SetHeight(float height) noexcept;
|
||||
void SetNear(float znear) noexcept;
|
||||
void SetFar(float zfar) noexcept;
|
||||
void SetFOV(float fov) noexcept;
|
||||
|
||||
|
||||
|
||||
float GetYaw() const noexcept;
|
||||
float GetPitch() const noexcept;
|
||||
float GetRoll() const noexcept;
|
||||
|
||||
float GetAspectRatio() const noexcept;
|
||||
float GetFOV() const noexcept;
|
||||
|
||||
const SHMatrix& GetViewMatrix() const noexcept;
|
||||
const SHMatrix& GetProjMatrix() const noexcept;
|
||||
|
||||
|
||||
float movementSpeed;
|
||||
SHVec3 turnSpeed;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHCameraSystem.h"
|
||||
#include "Math/SHMathHelpers.h"
|
||||
#include "Input/SHInputManager.h"
|
||||
#include "Math/Vector/SHVec2.h"
|
||||
|
||||
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
||||
void SHCameraSystem::EditorCameraUpdate::Execute(double dt) noexcept
|
||||
{
|
||||
SHCameraSystem* system = static_cast<SHCameraSystem*>(GetSystem());
|
||||
auto& camera = system->editorCamera;
|
||||
SHVec3 view, right, UP;
|
||||
system->GetCameraAxis(camera, view, right, UP);
|
||||
|
||||
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::A))
|
||||
{
|
||||
camera.position -= right * dt * camera.movementSpeed;
|
||||
camera.dirtyView = true;
|
||||
}
|
||||
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::D))
|
||||
{
|
||||
camera.position += right * dt * camera.movementSpeed;
|
||||
camera.dirtyView = true;
|
||||
}
|
||||
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::W))
|
||||
{
|
||||
camera.position += view * dt * camera.movementSpeed;
|
||||
camera.dirtyView = true;
|
||||
}
|
||||
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::S))
|
||||
{
|
||||
camera.position -= view * dt * camera.movementSpeed;
|
||||
camera.dirtyView = true;
|
||||
}
|
||||
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::Q))
|
||||
{
|
||||
camera.position += UP * dt * camera.movementSpeed;
|
||||
camera.dirtyView = true;
|
||||
}
|
||||
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::E))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void SHCameraSystem::Init(void)
|
||||
{
|
||||
editorCamera.SetPosition(0.0f, 0.0f, 0.0f);
|
||||
editorCamera.SetPitch(0.0f);
|
||||
editorCamera.SetYaw(0.0f);
|
||||
editorCamera.SetRoll(0.0f);
|
||||
editorCamera.movementSpeed = 2.0f;
|
||||
|
||||
}
|
||||
|
||||
void SHCameraSystem::Exit(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SHCameraComponent* SHCameraSystem::GetEditorCamera(void) noexcept
|
||||
{
|
||||
return &editorCamera;
|
||||
}
|
||||
|
||||
void SHCameraSystem::UpdateCameraComponent(SHCameraComponent& camera) noexcept
|
||||
{
|
||||
if (camera.dirtyView)
|
||||
{
|
||||
|
||||
SHVec3 view, right, UP;
|
||||
GetCameraAxis(camera, view, right, UP);
|
||||
|
||||
camera.viewMatrix = SHMatrix::Identity;
|
||||
camera.viewMatrix(0, 0) = right[0];
|
||||
camera.viewMatrix(0, 1) = right[1];
|
||||
camera.viewMatrix(0, 2) = right[2];
|
||||
|
||||
camera.viewMatrix(1, 0) = UP[0];
|
||||
camera.viewMatrix(1, 1) = UP[1];
|
||||
camera.viewMatrix(1, 2) = UP[2];
|
||||
|
||||
camera.viewMatrix(2, 0) = view[0];
|
||||
camera.viewMatrix(2, 1) = view[1];
|
||||
camera.viewMatrix(2, 2) = view[2];
|
||||
|
||||
camera.viewMatrix(0, 3) = -right.Dot(camera.position);
|
||||
camera.viewMatrix(1, 3) = -UP.Dot(camera.position);
|
||||
camera.viewMatrix(2, 3) = -view.Dot(camera.position);
|
||||
|
||||
camera.dirtyView = false;
|
||||
}
|
||||
if (camera.dirtyProj == true)
|
||||
{
|
||||
if (camera.perspProj == true)
|
||||
{
|
||||
const float ASPECT_RATIO = (camera.GetAspectRatio());
|
||||
const float TAN_HALF_FOV = tan(SHMath::DegreesToRadians(camera.fov) * 0.5f);
|
||||
camera.projMatrix = SHMatrix::Identity;
|
||||
camera.projMatrix(0, 0) = 1.0f / (ASPECT_RATIO * TAN_HALF_FOV);
|
||||
camera.projMatrix(1, 1) = 1.0f / TAN_HALF_FOV;
|
||||
camera.projMatrix(2, 2) = camera.zFar / (camera.zFar - camera.zNear);
|
||||
camera.projMatrix(3, 3) = 0.0f;
|
||||
|
||||
camera.projMatrix(3, 2) = 1.0f;
|
||||
camera.projMatrix(2, 3) = -(camera.zFar * camera.zNear) / (camera.zFar - camera.zNear);
|
||||
|
||||
|
||||
camera.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;
|
||||
|
||||
//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<<", "<<target.y<<", "<<target.z << std::endl;
|
||||
target += camera.position;
|
||||
////SHVec3::RotateZ(target, SHMath::DegreesToRadians(camera.roll));
|
||||
|
||||
//target = SHVec3::Normalise(target);
|
||||
|
||||
SHVec3::RotateZ(up, camera.roll);
|
||||
up = SHVec3::Normalise(up);
|
||||
|
||||
|
||||
forward = target - camera.position; forward = SHVec3::Normalise(forward);
|
||||
right = SHVec3::Cross(forward, up); right = SHVec3::Normalise(right);
|
||||
upVec = SHVec3::Cross(forward, right);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
#pragma once
|
||||
|
||||
#include "ECS_Base/System/SHSystem.h"
|
||||
#include "SHCameraComponent.h"
|
||||
#include "ECS_Base/System/SHSystemRoutine.h"
|
||||
#include "SH_API.h"
|
||||
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SH_API SHCameraSystem final : public SHSystem
|
||||
{
|
||||
private:
|
||||
//A camera component that represents editor camera.
|
||||
//This is not tied to any entity. Hence this EID should not be used.
|
||||
SHCameraComponent editorCamera;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
SHCameraSystem(void) = default;
|
||||
virtual ~SHCameraSystem(void) = default;
|
||||
|
||||
void Init (void);
|
||||
void Exit (void);
|
||||
|
||||
class SH_API EditorCameraUpdate final : public SHSystemRoutine
|
||||
{
|
||||
public:
|
||||
|
||||
EditorCameraUpdate() : SHSystemRoutine("Editor Camera Update", true) { };
|
||||
virtual void Execute(double dt) noexcept override final;
|
||||
|
||||
};
|
||||
friend class EditorCameraUpdate;
|
||||
|
||||
SHCameraComponent* GetEditorCamera (void) noexcept;
|
||||
|
||||
protected:
|
||||
|
||||
void UpdateCameraComponent(SHCameraComponent& camera) noexcept;
|
||||
|
||||
void GetCameraAxis(SHCameraComponent const& camera, SHVec3& forward, SHVec3& right, SHVec3& up) const noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -48,6 +48,9 @@ namespace SHADE
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
//Whether or not this component is active.
|
||||
//Systems using this component should are responsible for checking the active state of the component before running their functionality.
|
||||
|
@ -59,7 +62,7 @@ namespace SHADE
|
|||
* \return uint32_t
|
||||
* The entityID that this component belongs to.
|
||||
***************************************************************************/
|
||||
uint32_t GetEID()const
|
||||
uint32_t GetEID()const noexcept
|
||||
{
|
||||
return this->entityID;
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -214,23 +214,50 @@ namespace SHADE
|
|||
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||
}
|
||||
|
||||
bool SHEditorUI::InputSlider(const std::string& label, double min, double max, double& value, bool* isHovered)
|
||||
bool SHEditorUI::InputSlider(const std::string& label, int min, int max, int& value, bool* isHovered /*= nullptr*/)
|
||||
{
|
||||
float val = static_cast<float>(value);
|
||||
ImGui::Text(label.c_str());
|
||||
if (isHovered)
|
||||
*isHovered = ImGui::IsItemHovered();
|
||||
ImGui::SameLine();
|
||||
const bool CHANGED = ImGui::SliderFloat("#", &val,
|
||||
static_cast<float>(min), static_cast<float>(max), "%.3f",
|
||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||
ImGui::Text(label.c_str());
|
||||
if (isHovered)
|
||||
*isHovered = ImGui::IsItemHovered();
|
||||
ImGui::SameLine();
|
||||
return ImGui::SliderInt("##", &value,
|
||||
static_cast<float>(min), static_cast<float>(max), "%d",
|
||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||
}
|
||||
|
||||
if (CHANGED)
|
||||
{
|
||||
value = val;
|
||||
}
|
||||
bool SHEditorUI::InputSlider(const std::string& label, unsigned int min, unsigned int max, unsigned int& value, bool* isHovered /*= nullptr*/)
|
||||
{
|
||||
int val = static_cast<int>(value);
|
||||
const bool CHANGED = InputSlider(label, min, max, val, isHovered);
|
||||
if (CHANGED)
|
||||
{
|
||||
value = static_cast<int>(val);
|
||||
}
|
||||
|
||||
return CHANGED;
|
||||
return CHANGED;
|
||||
}
|
||||
|
||||
bool SHEditorUI::InputSlider(const std::string& label, float min, float max, float& value, bool* isHovered)
|
||||
{
|
||||
ImGui::Text(label.c_str());
|
||||
if (isHovered)
|
||||
*isHovered = ImGui::IsItemHovered();
|
||||
ImGui::SameLine();
|
||||
return ImGui::SliderFloat("##", &value,
|
||||
static_cast<float>(min), static_cast<float>(max), "%.3f",
|
||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||
}
|
||||
|
||||
bool SHEditorUI::InputSlider(const std::string& label, double min, double max, double& value, bool* isHovered /*= nullptr*/)
|
||||
{
|
||||
float val = static_cast<float>(value);
|
||||
const bool CHANGED = InputSlider(label, min, max, val, isHovered);
|
||||
if (CHANGED)
|
||||
{
|
||||
value = static_cast<double>(val);
|
||||
}
|
||||
|
||||
return CHANGED;
|
||||
}
|
||||
|
||||
bool SHEditorUI::InputVec2(const std::string& label, SHVec2& value, bool* isHovered)
|
||||
|
|
|
@ -230,9 +230,45 @@ namespace SHADE
|
|||
/// <returns>True if the value was changed.</returns>
|
||||
static bool InputAngle(const std::string& label, double& value, bool* isHovered = nullptr);
|
||||
/// <summary>
|
||||
/// Creates an int slider field widget for double input.
|
||||
/// <br/>
|
||||
/// Wraps up ImGui::SliderInt().
|
||||
/// </summary>
|
||||
/// <param name="label">Label used to identify this widget.</param>
|
||||
/// <param name="min">Minimum value of the slider.</param>
|
||||
/// <param name="max">Maximum value of the slider.</param>
|
||||
/// <param name="value">Reference to the variable to store the result.</param>
|
||||
/// <param name="isHovered>If set, stores the hover state of this widget.</param>
|
||||
/// <returns>True if the value was changed.</returns>
|
||||
static bool InputSlider(const std::string& label, int min, int max, int& value, bool* isHovered = nullptr);
|
||||
/// <summary>
|
||||
/// Creates an unsigned int slider field widget for double input.
|
||||
/// <br/>
|
||||
/// Wraps up ImGui::SliderInt().
|
||||
/// </summary>
|
||||
/// <param name="label">Label used to identify this widget.</param>
|
||||
/// <param name="min">Minimum value of the slider.</param>
|
||||
/// <param name="max">Maximum value of the slider.</param>
|
||||
/// <param name="value">Reference to the variable to store the result.</param>
|
||||
/// <param name="isHovered>If set, stores the hover state of this widget.</param>
|
||||
/// <returns>True if the value was changed.</returns>
|
||||
static bool InputSlider(const std::string& label, unsigned int min, unsigned int max, unsigned int& value, bool* isHovered = nullptr);
|
||||
/// <summary>
|
||||
/// Creates a float slider field widget for double input.
|
||||
/// <br/>
|
||||
/// Wraps up ImGui::SliderFloat().
|
||||
/// </summary>
|
||||
/// <param name="label">Label used to identify this widget.</param>
|
||||
/// <param name="min">Minimum value of the slider.</param>
|
||||
/// <param name="max">Maximum value of the slider.</param>
|
||||
/// <param name="value">Reference to the variable to store the result.</param>
|
||||
/// <param name="isHovered>If set, stores the hover state of this widget.</param>
|
||||
/// <returns>True if the value was changed.</returns>
|
||||
static bool InputSlider(const std::string& label, float min, float max, float& value, bool* isHovered = nullptr);
|
||||
/// <summary>
|
||||
/// Creates a double slider field widget for double input.
|
||||
/// <br/>
|
||||
/// Wraps up ImGui::InputSliderFloat().
|
||||
/// Wraps up ImGui::SliderFloat().
|
||||
/// </summary>
|
||||
/// <param name="label">Label used to identify this widget.</param>
|
||||
/// <param name="min">Minimum value of the slider.</param>
|
||||
|
|
|
@ -16,9 +16,9 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* ImGui Wrapper Functions - Widgets */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* ImGui Wrapper Functions - Widgets */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
template<typename Enum>
|
||||
inline bool SHEditorUI::InputEnumCombo(const std::string& label, Enum& v, int maxVal, std::function<const char* (Enum)> toStrFn, bool* isHovered)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include "Tools/SHLogger.h"
|
||||
#include "SH_API.h"
|
||||
|
||||
namespace SHADE
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include "vk_mem_alloc.h"
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -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<SHVkCommandBuffer>;
|
||||
friend class SHResourceLibrary<SHVkCommandBuffer>;
|
||||
|
||||
static constexpr uint16_t PUSH_CONSTANT_SIZE = 512;
|
||||
private:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// Project Includes
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// Project Includes
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define SH_VK_FRAMEBUFFER_H
|
||||
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
#include <span>
|
||||
|
||||
namespace SHADE
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,7 +15,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include <vector>
|
||||
// Project Includes
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -15,7 +15,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
// STL Includes
|
||||
#include <vector>
|
||||
// Project Includes
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -97,14 +97,16 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
SHMatrix SHCamera::GetViewMatrix() const
|
||||
SHMatrix SHCamera::GetViewMatrix()
|
||||
{
|
||||
return viewMatrix;
|
||||
updateMatrices();
|
||||
return viewMatrix;
|
||||
}
|
||||
|
||||
SHMatrix SHCamera::GetProjectionMatrix() const
|
||||
SHMatrix SHCamera::GetProjectionMatrix()
|
||||
{
|
||||
return projMatrix;
|
||||
updateMatrices();
|
||||
return projMatrix;
|
||||
}
|
||||
SHMatrix SHCamera::GetViewProjectionMatrix()
|
||||
{
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Aug 21, 2022
|
||||
\brief
|
||||
\brief
|
||||
|
||||
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
@ -17,64 +17,66 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
/***********************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Object that manages the view and projection transformations for rendering
|
||||
a 3D scene.
|
||||
*/
|
||||
/***********************************************************************************/
|
||||
class SHCamera
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructor/Destructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* View Set Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
void SetLookAt(const SHVec3& pos, const SHVec3& target, const SHVec3& up);
|
||||
/***********************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Object that manages the view and projection transformations for rendering
|
||||
a 3D scene.
|
||||
*/
|
||||
/***********************************************************************************/
|
||||
class SHCamera
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructor/Destructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* View Set Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
void SetLookAt(const SHVec3& pos, const SHVec3& target, const SHVec3& up);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Projection Set Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
void SetPerspective(float fov, float width, float height, float zNear, float zFar);
|
||||
void SetOrthographic(float width, float height, float zNear, float zFar);
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Projection Set Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
void SetPerspective(float fov, float width, float height, float zNear, float zFar);
|
||||
void SetOrthographic(float width, float height, float zNear, float zFar);
|
||||
|
||||
//void SetPerspectiveMatrixExplicit (
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Getter Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
SHMatrix GetViewMatrix() const;
|
||||
SHMatrix GetProjectionMatrix() const;
|
||||
SHMatrix GetViewProjectionMatrix();
|
||||
SHMatrix GetInverseViewMatrix() const;
|
||||
SHMatrix GetInverseProjectionMatrix() const;
|
||||
SHMatrix GetInverseViewProjectionMatrix();
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Getter Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
SHMatrix GetViewMatrix();
|
||||
SHMatrix GetProjectionMatrix();
|
||||
SHMatrix GetViewProjectionMatrix();
|
||||
SHMatrix GetInverseViewMatrix() const;
|
||||
SHMatrix GetInverseProjectionMatrix() const;
|
||||
SHMatrix GetInverseViewProjectionMatrix();
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Mapping Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
SHVec3 ScreenToWorld(const SHVec3& vec) const;
|
||||
SHVec3 WorldToScreen(const SHVec3& vec) const;
|
||||
SHVec3 CameraToWorld(const SHVec3& vec) const;
|
||||
SHVec3 WorldToCamera(const SHVec3& vec) const;
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Mapping Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
SHVec3 ScreenToWorld(const SHVec3& vec) const;
|
||||
SHVec3 WorldToScreen(const SHVec3& vec) const;
|
||||
SHVec3 CameraToWorld(const SHVec3& vec) const;
|
||||
SHVec3 WorldToCamera(const SHVec3& vec) const;
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
SHMatrix viewMatrix;
|
||||
SHMatrix projMatrix;
|
||||
SHMatrix vpMatrix;
|
||||
SHMatrix inverseViewMatrix;
|
||||
SHMatrix inverseProjMatrix;
|
||||
SHMatrix inverseVpMatrix;
|
||||
bool isDirty = true;
|
||||
private:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
SHMatrix viewMatrix;
|
||||
SHMatrix projMatrix;
|
||||
SHMatrix vpMatrix;
|
||||
SHMatrix inverseViewMatrix;
|
||||
SHMatrix inverseProjMatrix;
|
||||
SHMatrix inverseVpMatrix;
|
||||
bool isDirty = true;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
void updateMatrices();
|
||||
static SHVec3 multiplyHomogenous(const SHMatrix& mat, const SHVec3& vec);
|
||||
};
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
void updateMatrices();
|
||||
static SHVec3 multiplyHomogenous(const SHMatrix& mat, const SHVec3& vec);
|
||||
};
|
||||
}
|
|
@ -16,6 +16,9 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Graphics/Instance/SHVkInstance.h"
|
||||
#include "Graphics/Windowing/Surface/SHVkSurface.h"
|
||||
#include "Graphics/Swapchain/SHVkSwapchain.h"
|
||||
#include "Camera/SHCameraSystem.h"
|
||||
#include "Editor/SHEditor.hpp"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
//#include "SHRenderer.h"
|
||||
#include "Graphics/Windowing/SHWindow.h"
|
||||
#include "Graphics/MiddleEnd/PerFrame/SHPerFrameData.h"
|
||||
|
@ -318,6 +321,23 @@ namespace SHADE
|
|||
|
||||
// Bind textures
|
||||
|
||||
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||
|
||||
#ifdef SHEDITOR
|
||||
|
||||
auto editorSystem = SHSystemManager::GetSystem<SHEditor>();
|
||||
if (editorSystem->editorState != SHEditor::State::PLAY)
|
||||
{
|
||||
worldRenderer->SetViewProjectionMatrix(SHMatrix::Transpose(cameraSystem->GetEditorCamera()->GetProjMatrix() * cameraSystem->GetEditorCamera()->GetViewMatrix()));
|
||||
}
|
||||
else
|
||||
{
|
||||
// main camera
|
||||
}
|
||||
|
||||
#else
|
||||
// main camera
|
||||
#endif
|
||||
|
||||
// For every viewport
|
||||
for (int vpIndex = 0; vpIndex < static_cast<int>(viewports.size()); ++vpIndex)
|
||||
|
@ -565,19 +585,19 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
/* Texture Registration Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Handle<SHTexture> SHGraphicsSystem::Add(const SHTextureAsset& texAsset)
|
||||
Handle<SHTexture> SHGraphicsSystem::AddTexture(const SHTextureAsset& texAsset)
|
||||
{
|
||||
auto sampler = samplerCache.GetSampler(device, SHVkSamplerParams { .maxLod = static_cast<float>(texAsset.mipOffsets.size()) });
|
||||
return texLibrary.Add(texAsset, sampler);
|
||||
}
|
||||
|
||||
SHADE::Handle<SHADE::SHTexture> SHGraphicsSystem::Add(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector<uint32_t> mipOffsets)
|
||||
SHADE::Handle<SHADE::SHTexture> SHGraphicsSystem::AddTexture(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector<uint32_t> mipOffsets)
|
||||
{
|
||||
auto sampler = samplerCache.GetSampler(device, SHVkSamplerParams{ .maxLod = static_cast<float>(mipOffsets.size()) });
|
||||
return texLibrary.Add(pixelCount, pixelData, width, height, format, mipOffsets, sampler);
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::Remove(Handle<SHTexture> tex)
|
||||
void SHGraphicsSystem::RemoveTexture(Handle<SHTexture> tex)
|
||||
{
|
||||
texLibrary.Remove(tex);
|
||||
}
|
||||
|
@ -704,6 +724,14 @@ namespace SHADE
|
|||
|
||||
worldCamera->SetPerspective(90.0f, static_cast<float>(resizeWidth), static_cast<float>(resizeHeight), 0.0f, 100.0f);
|
||||
|
||||
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||
#ifdef SHEDITOR
|
||||
cameraSystem->GetEditorCamera()->SetWidth(resizeWidth);
|
||||
cameraSystem->GetEditorCamera()->SetHeight(resizeHeight);
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
for (auto& semaHandle : graphSemaphores)
|
||||
semaHandle = device->CreateSemaphore();
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include <array>
|
||||
|
||||
// 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"
|
||||
|
@ -231,8 +231,8 @@ namespace SHADE
|
|||
|
||||
*/
|
||||
/*******************************************************************************/
|
||||
Handle<SHTexture> Add(const SHTextureAsset& texAsset);
|
||||
Handle<SHTexture> Add(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector<uint32_t> mipOffsets);
|
||||
Handle<SHTexture> AddTexture(const SHTextureAsset& texAsset);
|
||||
Handle<SHTexture> AddTexture(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector<uint32_t> mipOffsets);
|
||||
/*******************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -246,7 +246,7 @@ namespace SHADE
|
|||
|
||||
*/
|
||||
/*******************************************************************************/
|
||||
void Remove(Handle<SHTexture> tex);
|
||||
void RemoveTexture(Handle<SHTexture> tex);
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -313,7 +313,7 @@ namespace SHADE
|
|||
SHWindow* window = nullptr;
|
||||
|
||||
// Middle End Resources
|
||||
ResourceManager resourceManager;
|
||||
SHResourceHub resourceManager;
|
||||
SHMeshLibrary meshLibrary;
|
||||
SHTextureLibrary texLibrary;
|
||||
SHSamplerCache samplerCache;
|
||||
|
|
|
@ -15,7 +15,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
// STL Includes
|
||||
#include <unordered_map>
|
||||
// Project Includes
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "SHCommonTypes.h"
|
||||
|
||||
namespace SHADE
|
||||
|
|
|
@ -13,7 +13,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
// STL Includes
|
||||
#include <memory>
|
||||
// Project Includes
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Graphics/Shaders/BlockInterface/SHShaderBlockInterface.h"
|
||||
#include "SH_API.h"
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ of DigiPen Institute of Technology is prohibited.
|
|||
// STL Includes
|
||||
#include <vector>
|
||||
// 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<MeshAddJob> meshAddJobs;
|
||||
std::vector<Handle<SHMesh>> meshRemoveJobs;
|
||||
// Tracking
|
||||
ResourceLibrary<SHMesh> meshes{};
|
||||
SHResourceLibrary<SHMesh> meshes{};
|
||||
std::vector<Handle<SHMesh>> meshOrder;
|
||||
// CPU Storage
|
||||
std::vector<SHMesh::VertexPosition> vertPosStorage;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -77,7 +77,7 @@ namespace SHADE
|
|||
{
|
||||
if (camera)
|
||||
{
|
||||
cpuCameraData.viewProjectionMatrix = camera->GetViewProjectionMatrix();
|
||||
//cpuCameraData.viewProjectionMatrix = camera->GetViewProjectionMatrix();
|
||||
cameraBuffer->WriteToMemory(&cpuCameraData, sizeof(SHShaderCameraData), 0, cameraDataAlignedSize * frameIndex);
|
||||
|
||||
std::array<uint32_t, 1> dynamicOffsets{ frameIndex * cameraDataAlignedSize };
|
||||
|
@ -90,6 +90,12 @@ namespace SHADE
|
|||
{
|
||||
}
|
||||
|
||||
void SHRenderer::SetViewProjectionMatrix(SHMatrix const& vpMatrix) noexcept
|
||||
{
|
||||
//cpuCameraData.viewProjectionMatrix = camera->GetViewMatrix() * camera->GetProjectionMatrix();
|
||||
cpuCameraData.viewProjectionMatrix = vpMatrix;
|
||||
}
|
||||
|
||||
Handle<SHRenderGraph> SHRenderer::GetRenderGraph(void) const noexcept
|
||||
{
|
||||
return renderGraph;
|
||||
|
|
|
@ -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 <vector>
|
||||
|
@ -78,6 +78,7 @@ namespace SHADE
|
|||
void Draw(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept;
|
||||
void UpdateDataAndBind (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
||||
void UpdateCameraDataToBuffer (void) noexcept;
|
||||
void SetViewProjectionMatrix (SHMatrix const& vpMatrix) noexcept;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Setters and Getters */
|
||||
|
|
|
@ -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<SHRenderer> SHViewport::AddRenderer(ResourceManager& resourceManager, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHRenderGraph> renderGraph)
|
||||
Handle<SHRenderer> SHViewport::AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHRenderGraph> renderGraph)
|
||||
{
|
||||
// Create the renderer
|
||||
auto renderer = resourceManager.Create<SHRenderer>(device, numFrames, cmdPools, descriptorPool, cameraDescLayout, GetHandle(), renderGraph);
|
||||
|
|
|
@ -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<SHRenderer> AddRenderer(ResourceManager& resourceManager, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHRenderGraph> renderGraph);
|
||||
Handle<SHRenderer> AddRenderer(SHResourceHub& resourceManager, uint32_t numFrames, std::vector<Handle<SHVkCommandPool>>& cmdPools, Handle<SHVkDescriptorPool> descriptorPool, Handle<SHVkDescriptorSetLayout> cameraDescLayout, Handle<SHRenderGraph> renderGraph);
|
||||
void RemoveRenderer(Handle<SHRenderer> renderer);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
|
|
@ -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<SHADE::SHMaterialInstance> SHMaterialInstanceCache::CreateOrGet(ResourceManager& manager, Handle<SHMaterial> material)
|
||||
SHADE::Handle<SHADE::SHMaterialInstance> SHMaterialInstanceCache::CreateOrGet(SHResourceHub& manager, Handle<SHMaterial> material)
|
||||
{
|
||||
// Check if there is already an existing instance
|
||||
auto matInst = cache.find(material);
|
||||
|
|
|
@ -15,7 +15,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
// STL Includes
|
||||
#include <unordered_map>
|
||||
// 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<SHMaterialInstance> CreateOrGet(ResourceManager& manager, Handle<SHMaterial> material);
|
||||
Handle<SHMaterialInstance> CreateOrGet(SHResourceHub& manager, Handle<SHMaterial> material);
|
||||
/***********************************************************************************/
|
||||
/*!
|
||||
|
||||
|
|
|
@ -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<AddJob> addJobs;
|
||||
std::vector<Handle<SHTexture>> removeJobs;
|
||||
// Tracking
|
||||
ResourceManager resourceManager;
|
||||
SHResourceHub resourceManager;
|
||||
std::vector<Handle<SHTexture>> texOrder;
|
||||
// CPU Storage
|
||||
std::vector<std::tuple<Handle<SHVkImageView>, Handle<SHVkSampler>, vk::ImageLayout>> combinedImageSamplers;
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include "Graphics/SHVulkanDefines.h"
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -367,7 +367,7 @@ namespace SHADE
|
|||
, graphResources{}
|
||||
, resourceManager{nullptr}
|
||||
{
|
||||
resourceManager = std::make_shared<ResourceManager>();
|
||||
resourceManager = std::make_shared<SHResourceHub>();
|
||||
}
|
||||
|
||||
SHRenderGraph::SHRenderGraph(SHRenderGraph&& rhs) noexcept
|
||||
|
|
|
@ -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<std::string, Handle<SHRenderGraphResource>> graphResources;
|
||||
|
||||
//! Resource library for graph handles
|
||||
std::shared_ptr<ResourceManager> resourceManager;
|
||||
std::shared_ptr<SHResourceHub> resourceManager;
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
|
|
@ -104,7 +104,7 @@ namespace SHADE
|
|||
|
||||
*/
|
||||
/***************************************************************************/
|
||||
SHRenderGraphNode::SHRenderGraphNode(std::shared_ptr<ResourceManager> rm, Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::vector<SHAttachmentDescInitParams> attDescInitParams, std::vector<Handle<SHRenderGraphNode>> predecessors, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept
|
||||
SHRenderGraphNode::SHRenderGraphNode(std::shared_ptr<SHResourceHub> rm, Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::vector<SHAttachmentDescInitParams> attDescInitParams, std::vector<Handle<SHRenderGraphNode>> predecessors, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept
|
||||
: logicalDeviceHdl{ logicalDevice }
|
||||
, renderpass{}
|
||||
, framebuffers{}
|
||||
|
|
|
@ -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> resourceManager;
|
||||
std::shared_ptr<SHResourceHub> resourceManager;
|
||||
|
||||
//! For Vulkan object creation
|
||||
Handle<SHVkLogicalDevice> logicalDeviceHdl;
|
||||
|
@ -88,7 +88,7 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* CTORS AND DTORS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
SHRenderGraphNode(std::shared_ptr<ResourceManager> rm, Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::vector<SHAttachmentDescInitParams> attDescInitParams, std::vector<Handle<SHRenderGraphNode>> predecessors, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept;
|
||||
SHRenderGraphNode(std::shared_ptr<SHResourceHub> rm, Handle<SHVkLogicalDevice> const& logicalDevice, Handle<SHVkSwapchain> const& swapchain, std::vector<SHAttachmentDescInitParams> attDescInitParams, std::vector<Handle<SHRenderGraphNode>> predecessors, std::unordered_map<std::string, Handle<SHRenderGraphResource>> const* resources) noexcept;
|
||||
SHRenderGraphNode(SHRenderGraphNode&& rhs) noexcept;
|
||||
SHRenderGraphNode& operator= (SHRenderGraphNode&& rhs) noexcept;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <string>
|
||||
#include "SHAttachmentDescriptionType.h"
|
||||
#include <vector>
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include "SH_API.h"
|
||||
|
||||
|
|
|
@ -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<SHSuperBatch>(GetHandle());
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "SHAttachmentDescriptionType.h"
|
||||
#include <string>
|
||||
#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<SHVkCommandBuffer>& commandBuffer, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept;
|
||||
void AddExteriorDrawCalls(std::function<void(Handle<SHVkCommandBuffer>&)> const& newDrawCall) noexcept;
|
||||
|
||||
void Init(ResourceManager& resourceManager) noexcept;
|
||||
void Init(SHResourceHub& resourceManager) noexcept;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* GETTERS AND SETTERS */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <Resource/Handle.h>
|
||||
#include <Resource/SHHandle.h>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "SHVkAttachDescGen.h"
|
||||
#include "SHVkSubpassParams.h"
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
#include <span>
|
||||
|
||||
namespace SHADE
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define SH_VK_SUBPASS_PARAMS_H
|
||||
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
#include <span>
|
||||
|
||||
namespace SHADE
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "SHVulkanIncludes.h"
|
||||
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -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 <vector>
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include "Resource/ResourceLibrary.h"
|
||||
#include "Resource/SHResourceLibrary.h"
|
||||
#include "Graphics/Swapchain/SHSwapchainParams.h"
|
||||
|
||||
namespace SHADE
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define SH_VK_FENCE_H
|
||||
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define SH_VK_SEMAPHORE_H
|
||||
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include "Resource/Handle.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <windows.h>
|
||||
#include "Graphics/SHVulkanIncludes.h"
|
||||
#include "Resource/ResourceLibrary.h"
|
||||
#include "Resource/SHResourceLibrary.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -8,8 +8,9 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
class SHResourceLibraryBase;
|
||||
template<typename T>
|
||||
class ResourceLibrary;
|
||||
class SHResourceLibrary;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
|
@ -25,6 +26,20 @@ namespace SHADE
|
|||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Exception thrown when a generic Handle is being casted to the wrong type.
|
||||
/// </summary>
|
||||
class BadHandleCastException : std::runtime_error
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
BadHandleCastException()
|
||||
: std::runtime_error("Attempted to cast a generic Handle to the wrong type. ")
|
||||
{}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Base implementation of the Handle that is not templated to allow for holding
|
||||
/// generic non-type-specific Handles.
|
||||
|
@ -80,7 +95,7 @@ namespace SHADE
|
|||
/// Generic implementation of a Handle object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the handle.</typeparam>
|
||||
template<typename T>
|
||||
template<typename T = void>
|
||||
class Handle : public HandleBase
|
||||
{
|
||||
public:
|
||||
|
@ -88,6 +103,16 @@ namespace SHADE
|
|||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
Handle() = default;
|
||||
/// <summary>
|
||||
/// Converts a generic/void Handle to a specific type.
|
||||
/// Runtime type checking is enabled to ensure that Handles are only being casted
|
||||
/// to the correct type.
|
||||
/// </summary>
|
||||
/// <param name="genericHandle">Generic handle to convert.</param>
|
||||
/// <exception cref="std::bad_cast">
|
||||
/// Thrown if an invalid conversion is made.
|
||||
/// </exception>
|
||||
explicit Handle(const Handle<void>& genericHandle);
|
||||
~Handle() = default;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
@ -140,13 +165,48 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
ResourceLibrary<T>* library = nullptr;
|
||||
SHResourceLibrary<T>* library = nullptr;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Friend Declarations */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
friend class ResourceLibrary<T>;
|
||||
};
|
||||
friend class SHResourceLibrary<T>;
|
||||
friend class Handle<void>;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Template Specialization for Handle that represents a type-less Handle.
|
||||
/// </summary>
|
||||
template<>
|
||||
class Handle<void> : public HandleBase
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
Handle() = default;
|
||||
template<typename T>
|
||||
explicit Handle(const Handle<T>& handle);
|
||||
~Handle() = default;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Overloaded Operators */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
inline bool operator==(const Handle<T>& rhs) const noexcept;
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
SHResourceLibraryBase* library = nullptr;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Friend Declarations */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
friend class Handle;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Interface that needs to be implemented by classes that want to store a Handle to
|
||||
|
@ -155,7 +215,7 @@ namespace SHADE
|
|||
template<typename T>
|
||||
class ISelfHandle
|
||||
{
|
||||
public:
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
@ -183,7 +243,7 @@ namespace SHADE
|
|||
/// </summary>
|
||||
/// <param name="rscLib">Required to lock usage to ResourceLibrary only.</param>
|
||||
/// <param name="hdl">Handle to set.</param>
|
||||
void SetHandle(const ResourceLibrary<T>& rscLib, Handle<T> hdl);
|
||||
void SetHandle(const SHResourceLibrary<T>& rscLib, Handle<T> hdl);
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
@ -220,4 +280,4 @@ namespace std
|
|||
};
|
||||
}
|
||||
|
||||
#include "Handle.hpp"
|
||||
#include "SHHandle.hpp"
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
// Primary Header
|
||||
#include "Handle.h"
|
||||
#include "ResourceLibrary.h"
|
||||
#include "SHHandle.h"
|
||||
#include "SHResourceLibrary.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -20,7 +20,21 @@ namespace SHADE
|
|||
{
|
||||
return id.Raw != INVALID_ID.Raw;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Handle<T> - Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
Handle<T>::Handle(const Handle<void>& genericHandle)
|
||||
: library { reinterpret_cast<SHResourceLibrary<T>*>(genericHandle.library) }
|
||||
{
|
||||
id = genericHandle.id;
|
||||
|
||||
// Check if valid
|
||||
if (library != nullptr && library->GetType() != typeid(T))
|
||||
throw BadHandleCastException();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Handle<T> - Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -63,6 +77,28 @@ namespace SHADE
|
|||
return &library->Get(*this);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Handle<void> - Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
Handle<void>::Handle(const Handle<T>& handle)
|
||||
: library{ static_cast<SHResourceLibraryBase*>(handle.library) }
|
||||
{
|
||||
id = handle.id;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Handle<void> - Overloaded Operators */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
bool SHADE::Handle<void>::operator==(const Handle<T>& rhs) const noexcept
|
||||
{
|
||||
return id.Raw == rhs.id.Raw && library == static_cast<void*>(rhs.library);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* ISelfHandle<T> - Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
inline ISelfHandle<T>::ISelfHandle(const ISelfHandle& rhs)
|
||||
: handle { rhs.handle }
|
||||
|
@ -73,6 +109,9 @@ namespace SHADE
|
|||
: handle { rhs.handle }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* ISelfHandle<T> - Overloaded Operators */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
inline ISelfHandle<T>& ISelfHandle<T>::operator=(const ISelfHandle& rhs)
|
||||
{
|
||||
|
@ -96,7 +135,7 @@ namespace SHADE
|
|||
return handle;
|
||||
}
|
||||
template<typename T>
|
||||
inline void ISelfHandle<T>::SetHandle(const ResourceLibrary<T>&, Handle<T> hdl)
|
||||
inline void ISelfHandle<T>::SetHandle(const SHResourceLibrary<T>&, Handle<T> hdl)
|
||||
{
|
||||
handle = hdl;
|
||||
}
|
|
@ -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)
|
|
@ -6,24 +6,42 @@
|
|||
#include <queue>
|
||||
|
||||
// Project Headers
|
||||
#include "Handle.h"
|
||||
#include "SHHandle.h"
|
||||
#include "Resource/SparseSet.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for SHResourceLibrary that holds information about the library type.
|
||||
/// </summary>
|
||||
class SHResourceLibraryBase
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Getter Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
inline std::type_index GetType() { return libraryType; }
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
std::type_index libraryType = typeid(void);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Generic Resource Library for a specified type of Resource. This object will own
|
||||
/// any resources created using it.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of resources that this library stores.</typeparam>
|
||||
template<typename T>
|
||||
class ResourceLibrary
|
||||
class SHResourceLibrary : public SHResourceLibraryBase
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructor */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
ResourceLibrary();
|
||||
SHResourceLibrary();
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
|
@ -75,13 +93,13 @@ namespace SHADE
|
|||
/// <summary>
|
||||
/// Manages all resources in multiple ResourceLibraries.
|
||||
/// </summary>
|
||||
class ResourceManager final
|
||||
class SHResourceHub final
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
~ResourceManager();
|
||||
~SHResourceHub();
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
|
@ -136,10 +154,10 @@ namespace SHADE
|
|||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
ResourceLibrary<T>& getLibrary();
|
||||
SHResourceLibrary<T>& getLibrary();
|
||||
template<typename T>
|
||||
const ResourceLibrary<T>& getLibrary() const;
|
||||
const SHResourceLibrary<T>& getLibrary() const;
|
||||
};
|
||||
}
|
||||
|
||||
#include "ResourceLibrary.hpp"
|
||||
#include "SHResourceLibrary.hpp"
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
// Primary Header
|
||||
#include "ResourceLibrary.h"
|
||||
#include "SHResourceLibrary.h"
|
||||
// Standard Library
|
||||
#include <utility>
|
||||
|
||||
|
@ -10,13 +10,14 @@ namespace SHADE
|
|||
/* ResourceLibrary - Constructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template <typename T>
|
||||
ResourceLibrary<T>::ResourceLibrary()
|
||||
SHResourceLibrary<T>::SHResourceLibrary()
|
||||
{
|
||||
// Type Checking
|
||||
//static_assert(std::is_copy_assignable_v<T>, "Resource Library's resources must be copy assignable.");
|
||||
//static_assert(std::is_copy_constructible_v<T>, "Resource Library's resources must be copy constructible.");
|
||||
static_assert(std::is_move_assignable_v<T>, "Resource Library's resources must be move assignable.");
|
||||
static_assert(std::is_move_constructible_v<T>, "Resource Library's resources must be move constructible.");
|
||||
|
||||
// Keep track of the type for conversions
|
||||
libraryType = typeid(T);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -24,7 +25,7 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
template <typename T>
|
||||
template <typename ... Args>
|
||||
Handle<T> ResourceLibrary<T>::Create(Args&&... args)
|
||||
Handle<T> SHResourceLibrary<T>::Create(Args&&... args)
|
||||
{
|
||||
// Create the handle
|
||||
Handle<T> handle;
|
||||
|
@ -55,7 +56,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
void ResourceLibrary<T>::Free(Handle<T> handle)
|
||||
void SHResourceLibrary<T>::Free(Handle<T> handle)
|
||||
{
|
||||
assertHandleValid(handle);
|
||||
|
||||
|
@ -63,7 +64,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
T& ResourceLibrary<T>::Get(Handle<T> handle)
|
||||
T& SHResourceLibrary<T>::Get(Handle<T> handle)
|
||||
{
|
||||
assertHandleValid(handle);
|
||||
|
||||
|
@ -71,7 +72,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
const T& ResourceLibrary<T>::Get(Handle<T> handle) const
|
||||
const T& SHResourceLibrary<T>::Get(Handle<T> handle) const
|
||||
{
|
||||
assertHandleValid(handle);
|
||||
|
||||
|
@ -82,14 +83,14 @@ namespace SHADE
|
|||
/* ResourceLibrary - Helper Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template <typename T>
|
||||
void ResourceLibrary<T>::assertHandleValid(Handle<T> handle) const
|
||||
void SHResourceLibrary<T>::assertHandleValid(Handle<T> handle) const
|
||||
{
|
||||
if (!handle || handle.id.Data.Version != versionCounts[handle.id.Data.Index])
|
||||
throw std::invalid_argument("Invalid handle provided!");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline uint32_t ResourceLibrary<T>::getAvailableFreeIndex()
|
||||
inline uint32_t SHResourceLibrary<T>::getAvailableFreeIndex()
|
||||
{
|
||||
// Get from the free list if present
|
||||
if (!freeList.empty())
|
||||
|
@ -107,25 +108,25 @@ namespace SHADE
|
|||
/* ResourceManager - Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template <typename T, typename ... Args>
|
||||
Handle<T> ResourceManager::Create(Args&&... args)
|
||||
Handle<T> SHResourceHub::Create(Args&&... args)
|
||||
{
|
||||
return getLibrary<T>().Create(std::forward<Args>(args) ...);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ResourceManager::Free(Handle<T> handle)
|
||||
void SHResourceHub::Free(Handle<T> handle)
|
||||
{
|
||||
getLibrary<T>().Free(handle);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& ResourceManager::Get(Handle<T> handle)
|
||||
T& SHResourceHub::Get(Handle<T> handle)
|
||||
{
|
||||
return getLibrary<T>().Get(handle);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& ResourceManager::Get(Handle<T> handle) const
|
||||
const T& SHResourceHub::Get(Handle<T> handle) const
|
||||
{
|
||||
return getLibrary<T>().Get(handle);
|
||||
}
|
||||
|
@ -134,18 +135,18 @@ namespace SHADE
|
|||
/* ResourceManager - Helper Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
template <typename T>
|
||||
ResourceLibrary<T>& ResourceManager::getLibrary()
|
||||
SHResourceLibrary<T>& SHResourceHub::getLibrary()
|
||||
{
|
||||
// Attempt to retrieve the library
|
||||
const std::type_index RSC_TYPE = typeid(T);
|
||||
if (resourceLibs.contains(RSC_TYPE))
|
||||
{
|
||||
return *static_cast<ResourceLibrary<T>*>(resourceLibs.at(RSC_TYPE));
|
||||
return *static_cast<SHResourceLibrary<T>*>(resourceLibs.at(RSC_TYPE));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Construct library if doesn't exist
|
||||
ResourceLibrary<T>* lib = new ResourceLibrary<T>();
|
||||
SHResourceLibrary<T>* lib = new SHResourceLibrary<T>();
|
||||
resourceLibs.emplace(RSC_TYPE, static_cast<void*>(lib));
|
||||
|
||||
// Construct deleter to properly delete objects with void*
|
||||
|
@ -156,8 +157,8 @@ namespace SHADE
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
const ResourceLibrary<T>& ResourceManager::getLibrary() const
|
||||
const SHResourceLibrary<T>& SHResourceHub::getLibrary() const
|
||||
{
|
||||
return const_cast<ResourceManager*>(this).getLibrary<T>();
|
||||
return const_cast<SHResourceHub*>(this).getLibrary<T>();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHResourceManager.cpp
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 21, 2022
|
||||
\brief Contains the definition of the functions of the SHResourceManager 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.
|
||||
*//*************************************************************************************/
|
||||
#include "SHpch.h"
|
||||
// Primary Include
|
||||
#include "SHResourceManager.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Static Data Member Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHResourceHub SHResourceManager::resourceHub;
|
||||
std::unordered_map<std::type_index, std::unordered_map<AssetID, Handle<void>>> SHResourceManager::handlesMap;
|
||||
std::unordered_map<std::type_index, SHADE::SHResourceManager::HandleAssetMap> SHResourceManager::assetIdMap;
|
||||
std::unordered_map<std::type_index, std::function<void(AssetID)>> SHResourceManager::typedFreeFuncMap;
|
||||
std::vector<AssetID> SHResourceManager::loadedAssetData;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Function Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void SHResourceManager::Unload(AssetID assetId)
|
||||
{
|
||||
// Search each library for the asset ID and try to free it
|
||||
Handle handle;
|
||||
for (auto& typedHandleMap : handlesMap)
|
||||
{
|
||||
if (typedHandleMap.second.contains(assetId))
|
||||
{
|
||||
// Save handle for later
|
||||
handle = typedHandleMap.second[assetId];
|
||||
// Dispose
|
||||
typedFreeFuncMap[typedHandleMap.first](assetId);
|
||||
typedHandleMap.second.erase(assetId);
|
||||
}
|
||||
}
|
||||
|
||||
// No handles were found
|
||||
if (!handle)
|
||||
return;
|
||||
|
||||
for (auto& typedAssetIdsMap : assetIdMap)
|
||||
{
|
||||
if (typedAssetIdsMap.second.contains(handle))
|
||||
{
|
||||
// Dispose
|
||||
typedAssetIdsMap.second.erase(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SHResourceManager::FinaliseChanges()
|
||||
{
|
||||
SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
|
||||
if (gfxSystem == nullptr)
|
||||
throw std::runtime_error("[SHResourceManager] Attempted to load graphics resource without a SHGraphicsSystem installed.");
|
||||
gfxSystem->BuildMeshBuffers();
|
||||
gfxSystem->BuildTextures();
|
||||
|
||||
// Free CPU Resources
|
||||
for (auto assetId : loadedAssetData)
|
||||
{
|
||||
SHAssetManager::Unload(assetId);
|
||||
}
|
||||
loadedAssetData.clear();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Query Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
std::optional<AssetID> SHResourceManager::GetAssetID(Handle<void> handle)
|
||||
{
|
||||
const Handle GENERIC_HANDLE = Handle(handle);
|
||||
|
||||
// Search each library for the asset ID and try to free it
|
||||
for (auto& typedAssetIdsMap : assetIdMap)
|
||||
{
|
||||
if (typedAssetIdsMap.second.contains(GENERIC_HANDLE))
|
||||
{
|
||||
return typedAssetIdsMap.second[GENERIC_HANDLE];
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHResourceManager.h
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 21, 2022
|
||||
\brief Contains the definition of the SHResourceManager 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 <unordered_map>
|
||||
// Project Includes
|
||||
#include "SH_API.h"
|
||||
#include "SHResourceLibrary.h"
|
||||
#include "Assets/SHAssetMacros.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Static class responsible for loading and caching runtime resources from their
|
||||
/// serialised Asset IDs.
|
||||
/// </summary>
|
||||
class SH_API SHResourceManager
|
||||
{
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Loading Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Loads or retrieves an existing loaded object of the specified type with the
|
||||
/// specified asset ID.
|
||||
/// Note that for specific types, the retrieved Handle may not be valid until after
|
||||
/// FinaliseChanges() is called.
|
||||
/// </summary>
|
||||
/// <typeparam name="ResourceType">
|
||||
/// Type of resource to load.
|
||||
/// </typeparam>
|
||||
/// <param name="assetId">Asset ID of the resource to load.</param>
|
||||
/// <returns>Handle to a loaded runtime asset.</returns>
|
||||
template<typename ResourceType>
|
||||
static Handle<ResourceType> LoadOrGet(AssetID assetId);
|
||||
/// <summary>
|
||||
/// Unloads an existing loaded asset. Attempting to unload an invalid Handle will
|
||||
/// simply do nothing except emit a warning.
|
||||
/// Faster than the untemplated version.
|
||||
/// </summary>
|
||||
/// <typeparam name="ResourceType">Type of resource to unload.</typeparam>
|
||||
/// <param name="assetId">Handle to the resource to unload.</param>
|
||||
template<typename ResourceType>
|
||||
static void Unload(Handle<ResourceType> assetId);
|
||||
/// <summary>
|
||||
/// Unloads an existing loaded asset. Attempting to unload an invalid Handle will
|
||||
/// simply do nothing except emit a warning.
|
||||
/// Compared to the templated version, this function is slower as it requires
|
||||
/// searching through the storage of all resource types.
|
||||
/// </summary>
|
||||
/// <param name="assetId">Handle to the resource to unload.</param>
|
||||
static void Unload(AssetID assetId);
|
||||
/// <summary>
|
||||
/// Needs to be called to finalise all changes to loads.
|
||||
/// </summary>
|
||||
static void FinaliseChanges();
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Query Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Retrieves the AssetID associated with a specified Handle.
|
||||
/// Faster than the untemplated version.
|
||||
/// </summary>
|
||||
/// <typeparam name="ResourceType">Type of resource to get the ID of.</typeparam>
|
||||
/// <param name="handle">Handle to get the AssetID of.</param>
|
||||
/// <return>
|
||||
/// AssetID for the specified Handle. If the Handle is invalid, there will be no
|
||||
/// value.
|
||||
/// </return>
|
||||
template<typename T>
|
||||
static std::optional<AssetID> GetAssetID(Handle<T> handle);
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="handle">Handle to get the AssetID of.</param>
|
||||
/// <return>
|
||||
/// AssetID for the specified Handle. If the Handle is invalid, there will be no
|
||||
/// value.
|
||||
/// </return>
|
||||
static std::optional<AssetID> GetAssetID(Handle<void> handle);
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
using AssetHandleMap = std::unordered_map<AssetID, Handle<void>>;
|
||||
using HandleAssetMap = std::unordered_map<Handle<void>, AssetID>;
|
||||
using AssetHandleMapRef = std::reference_wrapper<AssetHandleMap>;
|
||||
using HandleAssetMapRef = std::reference_wrapper<HandleAssetMap>;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
// Handles
|
||||
static SHResourceHub resourceHub;
|
||||
static std::unordered_map<std::type_index, AssetHandleMap> handlesMap;
|
||||
static std::unordered_map<std::type_index, HandleAssetMap> assetIdMap;
|
||||
static std::unordered_map<std::type_index, std::function<void(AssetID)>> typedFreeFuncMap;
|
||||
// Pointers to temp CPU resources
|
||||
static std::vector<AssetID> loadedAssetData;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Retrieves or creates the AssetHandleMap for the specific type if it doesn't exist
|
||||
/// </summary>
|
||||
/// <typeparam name="ResourceType">
|
||||
/// The type of AssetHandleMap to retrieve.
|
||||
/// </typeparam>
|
||||
/// <returns>Reference to the AssetHandleMap of the specified type.</returns>
|
||||
template<typename ResourceType>
|
||||
static std::pair<AssetHandleMapRef, HandleAssetMapRef> getAssetHandleMap();
|
||||
};
|
||||
}
|
||||
|
||||
#include "SHResourceManager.hpp"
|
|
@ -0,0 +1,172 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHResourceManager.hpp
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 21, 2022
|
||||
\brief Contains the definition of the function templates of the
|
||||
SHResourceManager 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
|
||||
// Primary Include
|
||||
#include "SHResourceManager.h"
|
||||
// Project Includes
|
||||
#include "Assets/SHAssetManager.h"
|
||||
#include "Assets/Asset Types/SHAssetIncludes.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "Tools/SHLog.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Loading Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
template<typename ResourceType>
|
||||
Handle<ResourceType> SHResourceManager::LoadOrGet(AssetID assetId)
|
||||
{
|
||||
// Check if it is an unsupported type
|
||||
if (!std::is_same_v<ResourceType, SHMesh> && !std::is_same_v<ResourceType, SHTexture>)
|
||||
{
|
||||
static_assert(true, "Unsupported Resource Type specified for SHResourceManager.");
|
||||
}
|
||||
|
||||
/* Attempt to get existing loaded asset */
|
||||
auto [typedHandleMap, typedAssetIdMap] = getAssetHandleMap<ResourceType>();
|
||||
if (typedHandleMap.get().contains(assetId))
|
||||
return Handle<ResourceType>(typedHandleMap.get()[assetId]);
|
||||
|
||||
/* Otherwise, we need to load it! */
|
||||
// Meshes
|
||||
if constexpr (std::is_same_v<ResourceType, SHMesh>)
|
||||
{
|
||||
// Get system
|
||||
SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
|
||||
if (gfxSystem == nullptr)
|
||||
throw std::runtime_error("[SHResourceManager] Attempted to load graphics resource without a SHGraphicsSystem installed.");
|
||||
|
||||
// Load
|
||||
const SHMeshAsset* assetData = SHAssetManager::GetData<SHMeshAsset>(assetId);
|
||||
if (assetData == nullptr)
|
||||
{
|
||||
SHLog::Warning("[SHResourceManager] Attempted to load an asset with an invalid Asset ID.");
|
||||
return {};
|
||||
}
|
||||
loadedAssetData.emplace_back(assetId);
|
||||
|
||||
Handle<SHMesh> meshHandle = gfxSystem->AddMesh
|
||||
(
|
||||
assetData->vertexPosition.size(),
|
||||
assetData->vertexPosition.data(),
|
||||
assetData->texCoords.data(),
|
||||
assetData->vertexTangent.data(),
|
||||
assetData->vertexNormal.data(),
|
||||
assetData->indices.size(),
|
||||
assetData->indices.data()
|
||||
);
|
||||
Handle genericHandle = Handle(meshHandle);
|
||||
typedHandleMap.get().emplace(assetId, genericHandle);
|
||||
typedAssetIdMap.get().emplace(genericHandle, assetId);
|
||||
return meshHandle;
|
||||
}
|
||||
// Textures
|
||||
else if constexpr (std::is_same_v<ResourceType, SHTexture>)
|
||||
{
|
||||
// Get system
|
||||
SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
|
||||
if (gfxSystem == nullptr)
|
||||
throw std::runtime_error("[SHResourceManager] Attempted to load graphics resource without a SHGraphicsSystem installed.");
|
||||
|
||||
// Load
|
||||
const SHTextureAsset* assetData = SHAssetManager::GetData<SHTextureAsset>(assetId);
|
||||
if (assetData == nullptr)
|
||||
{
|
||||
SHLog::Warning("[SHResourceManager] Attempted to load an asset with an invalid Asset ID.");
|
||||
return {};
|
||||
}
|
||||
loadedAssetData.emplace_back(assetId);
|
||||
|
||||
Handle<SHTexture> texHandle = gfxSystem->AddTexture
|
||||
(
|
||||
assetData->numBytes,
|
||||
assetData->pixelData,
|
||||
assetData->width,
|
||||
assetData->height,
|
||||
assetData->format,
|
||||
assetData->mipOffsets
|
||||
);
|
||||
typedHandleMap.get().emplace(assetId, Handle(texHandle));
|
||||
return texHandle;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ResourceType>
|
||||
void SHResourceManager::Unload(Handle<ResourceType> assetId)
|
||||
{
|
||||
// Check if it is an unsupported type
|
||||
if (!std::is_same_v<ResourceType, SHMesh> && !std::is_same_v<ResourceType, SHTexture>)
|
||||
{
|
||||
static_assert(true, "Unsupported Resource Type specified for SHResourceManager.");
|
||||
}
|
||||
|
||||
/* Attempt to get existing loaded asset */
|
||||
auto [typedHandleMap, typedAssetIdMap] = getAssetHandleMap<ResourceType>();
|
||||
if (typedHandleMap.get().contains(assetId))
|
||||
{
|
||||
// Dispose
|
||||
Handle handle = typedHandleMap.get()[assetId];
|
||||
Handle<ResourceType> typedHandle = static_cast<Handle<ResourceType>>(handle);
|
||||
typedHandle.Free();
|
||||
typedAssetIdMap.get().erase(handle);
|
||||
typedHandleMap.get().erase(assetId);
|
||||
}
|
||||
else
|
||||
{
|
||||
// There's nothing to remove
|
||||
SHLog::Warning("[SHResourceManager] Attempted to unload an invalid resource. Ignoring.");
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Query Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
std::optional<AssetID> SHResourceManager::GetAssetID(Handle<T> handle)
|
||||
{
|
||||
const Handle GENERIC_HANDLE = Handle(handle);
|
||||
auto [typedHandleMap, typedAssetIdMap] = getAssetHandleMap<T>();
|
||||
if (typedAssetIdMap.get().contains(GENERIC_HANDLE))
|
||||
{
|
||||
return typedAssetIdMap.GetId()[GENERIC_HANDLE];
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
template<typename ResourceType>
|
||||
std::pair<SHResourceManager::AssetHandleMapRef, SHResourceManager::HandleAssetMapRef> SHResourceManager::getAssetHandleMap()
|
||||
{
|
||||
const std::type_index TYPE = typeid(ResourceType);
|
||||
|
||||
if (!handlesMap.contains(TYPE))
|
||||
{
|
||||
handlesMap.emplace(TYPE, AssetHandleMap{});
|
||||
assetIdMap.emplace(TYPE, HandleAssetMap{});
|
||||
typedFreeFuncMap.emplace
|
||||
(
|
||||
TYPE,
|
||||
[TYPE](AssetID assetId)
|
||||
{
|
||||
static_cast<Handle<ResourceType>>(SHResourceManager::handlesMap[TYPE][assetId]).Free();
|
||||
}
|
||||
);
|
||||
}
|
||||
return std::make_pair(std::ref(handlesMap[TYPE]), std::ref(assetIdMap[TYPE]));
|
||||
}
|
||||
}
|
|
@ -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<char> 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<CsScriptSerialiseFuncPtr>
|
||||
csScriptsSerialiseYaml = dotNet.GetFunctionPtr<CsScriptSerialiseYamlFuncPtr>
|
||||
(
|
||||
DEFAULT_CSHARP_LIB_NAME,
|
||||
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
||||
"SerialiseScripts"
|
||||
);
|
||||
csScriptsSerialiseYaml = dotNet.GetFunctionPtr<CsScriptSerialiseYamlFuncPtr>
|
||||
csScriptsDeserialiseYaml = dotNet.GetFunctionPtr<CsScriptDeserialiseYamlFuncPtr>
|
||||
(
|
||||
DEFAULT_CSHARP_LIB_NAME,
|
||||
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
||||
"SerialiseScriptsYaml"
|
||||
"DeserialiseScripts"
|
||||
);
|
||||
csScriptDeserialise = dotNet.GetFunctionPtr<CsScriptDeserialiseFuncPtr>
|
||||
(
|
||||
DEFAULT_CSHARP_LIB_NAME,
|
||||
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
||||
"DeserialiseScript"
|
||||
);
|
||||
csScriptDeserialiseYaml = dotNet.GetFunctionPtr<CsScriptSerialiseYamlFuncPtr>
|
||||
(
|
||||
DEFAULT_CSHARP_LIB_NAME,
|
||||
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
||||
"SerialiseScriptsYaml"
|
||||
);*/
|
||||
csEditorRenderScripts = dotNet.GetFunctionPtr<CsScriptEditorFuncPtr>
|
||||
(
|
||||
DEFAULT_CSHARP_LIB_NAME,
|
||||
|
|
|
@ -13,7 +13,8 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
// STL Includes
|
||||
#include <filesystem>
|
||||
|
||||
// External Dependencies
|
||||
#include <yaml-cpp/yaml.h>
|
||||
// Project Headers
|
||||
#include "SH_API.h"
|
||||
#include "SHDotNetRuntime.h"
|
||||
|
@ -141,23 +142,26 @@ namespace SHADE
|
|||
/* Script Serialisation Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="entity"> The Entity to Serialise.</param>
|
||||
/// <returns>
|
||||
/// String that represents the set of scripts attached to the specified Entity.
|
||||
/// </returns>
|
||||
std::string SerialiseScripts(EntityID entity) const;
|
||||
/// <param name="entity">The Entity to Serialise.</param>
|
||||
/// <param name="scriptsNode">
|
||||
/// YAML Node that will store the serialised scripts.
|
||||
/// </param>
|
||||
/// <return>True if successfully serialised.</return>
|
||||
bool SerialiseScripts(EntityID entity, YAML::Node& scriptsNode) const;
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="entity">The Entity to deserialise a Script on to.</param>
|
||||
/// <param name="yaml">
|
||||
/// The YAML string that represents the Script to load into the Entity.
|
||||
/// <param name="scriptsNode">
|
||||
/// YAML Node that contains the serialised script data.
|
||||
/// </param>
|
||||
void DeserialiseScript(EntityID entity, const std::string& yaml) const;
|
||||
/// <return>True if successfully deserialised.</return>
|
||||
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 */
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
@ -77,6 +79,10 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Deserialise scripts
|
||||
if (node[ScriptsNode])
|
||||
SHSystemManager::GetSystem<SHScriptEngine>()->DeserialiseScripts(eid, node[ScriptsNode]);
|
||||
}
|
||||
|
||||
void SHSerialization::DeserializeSceneFromFile(std::filesystem::path const& path)
|
||||
|
@ -157,7 +163,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();
|
||||
|
@ -179,6 +185,11 @@ namespace SHADE
|
|||
components[rttr::type::get<SHRigidBodyComponent>().get_name().data()] = SHSerializationHelper::SerializeComponentToNode(rigidbody);
|
||||
}
|
||||
node[ComponentsNode] = components;
|
||||
|
||||
YAML::Node scripts;
|
||||
SHSystemManager::GetSystem<SHScriptEngine>()->SerialiseScripts(eid, scripts);
|
||||
node[ScriptsNode] = scripts;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -30,6 +30,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Editor/Command/SHCommandManager.h"
|
||||
#include "Editor/Command/SHCommand.hpp"
|
||||
#include "TooltipAttribute.hxx"
|
||||
#include "RangeAttribute.hxx"
|
||||
|
||||
// Using Directives
|
||||
using namespace System;
|
||||
|
@ -61,6 +62,43 @@ using namespace System::Collections::Generic;
|
|||
} \
|
||||
} \
|
||||
/// <summary>
|
||||
/// Alternative to RENDER_FIELD that checks for RangeAttribute and switches to a slider
|
||||
/// instead.
|
||||
/// </summary>
|
||||
/// <param name="MANAGED_TYPE">The managed type of the object to edit.</param>
|
||||
/// <param name="NATIVE_TYPE">The native type of the object to edit.</param>
|
||||
/// <param name="FUNC">The SHEditorUI:: function to use for editing.</param>
|
||||
#define RENDER_FIELD_RANGE(MANAGED_TYPE, NATIVE_TYPE, FUNC) \
|
||||
(field->FieldType == MANAGED_TYPE::typeid) \
|
||||
{ \
|
||||
NATIVE_TYPE val = safe_cast<NATIVE_TYPE>(field->GetValue(object)); \
|
||||
NATIVE_TYPE oldVal = val; \
|
||||
\
|
||||
RangeAttribute^ rangeAttrib = hasAttribute<RangeAttribute^>(field); \
|
||||
const std::string FIELD_NAME = Convert::ToNative(field->Name); \
|
||||
bool changed = false; \
|
||||
if (rangeAttrib) \
|
||||
{ \
|
||||
changed = SHEditorUI::InputSlider \
|
||||
( \
|
||||
FIELD_NAME, \
|
||||
static_cast<NATIVE_TYPE>(rangeAttrib->Min), \
|
||||
static_cast<NATIVE_TYPE>(rangeAttrib->Max), \
|
||||
val, &isHovered \
|
||||
); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
changed = SHEditorUI::FUNC(FIELD_NAME, val, &isHovered); \
|
||||
} \
|
||||
\
|
||||
if (changed) \
|
||||
{ \
|
||||
field->SetValue(object, val); \
|
||||
registerUndoAction(object, field, val, oldVal); \
|
||||
} \
|
||||
} \
|
||||
/// <summary>
|
||||
/// Macro expansion that is used in renderFieldInInspector() to check the type of a field
|
||||
/// named "field" against the specified type and if it matches, retrieves the value of
|
||||
/// that field from an object named "object" and pass it into the specified SHEditorUI::
|
||||
|
@ -77,6 +115,7 @@ using namespace System::Collections::Generic;
|
|||
{ \
|
||||
NATIVE_TYPE val = Convert::ToNative(safe_cast<MANAGED_TYPE>(field->GetValue(object))); \
|
||||
NATIVE_TYPE oldVal = val; \
|
||||
\
|
||||
if (SHEditorUI::FUNC(Convert::ToNative(field->Name), val, &isHovered)) \
|
||||
{ \
|
||||
field->SetValue(object, Convert::ToCLI(val)); \
|
||||
|
@ -199,16 +238,16 @@ namespace SHADE
|
|||
{
|
||||
bool isHovered = false;
|
||||
|
||||
if RENDER_FIELD (Int16, int, InputInt)
|
||||
else if RENDER_FIELD (Int32, int, InputInt)
|
||||
else if RENDER_FIELD (Int64, int, InputInt)
|
||||
else if RENDER_FIELD (UInt16, unsigned int, InputUnsignedInt)
|
||||
else if RENDER_FIELD (UInt32, unsigned int, InputUnsignedInt)
|
||||
else if RENDER_FIELD (UInt64, unsigned int, InputUnsignedInt)
|
||||
else if RENDER_FIELD (Byte, int, InputInt)
|
||||
if RENDER_FIELD_RANGE (Int16, int, InputInt)
|
||||
else if RENDER_FIELD_RANGE (Int32, int, InputInt)
|
||||
else if RENDER_FIELD_RANGE (Int64, int, InputInt)
|
||||
else if RENDER_FIELD_RANGE (UInt16, unsigned int, InputUnsignedInt)
|
||||
else if RENDER_FIELD_RANGE (UInt32, unsigned int, InputUnsignedInt)
|
||||
else if RENDER_FIELD_RANGE (UInt64, unsigned int, InputUnsignedInt)
|
||||
else if RENDER_FIELD_RANGE (Byte, int, InputInt)
|
||||
else if RENDER_FIELD (bool, bool, InputCheckbox)
|
||||
else if RENDER_FIELD (float, float, InputFloat)
|
||||
else if RENDER_FIELD (double, double, InputDouble)
|
||||
else if RENDER_FIELD_RANGE (float, float, InputFloat)
|
||||
else if RENDER_FIELD_RANGE (double, double, InputDouble)
|
||||
else if (field->FieldType->IsSubclassOf(Enum::typeid))
|
||||
{
|
||||
// Get all the names of the enums
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/************************************************************************************//*!
|
||||
\file RangeAttribute.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 18, 2022
|
||||
\brief Contains the definition of the functions of the managed Range Attribute
|
||||
class.
|
||||
|
||||
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.
|
||||
*//*************************************************************************************/
|
||||
#include "SHpch.h"
|
||||
#include "RangeAttribute.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
float RangeAttribute::Min::get()
|
||||
{
|
||||
return minVal;
|
||||
}
|
||||
float RangeAttribute::Max::get()
|
||||
{
|
||||
return maxVal;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
RangeAttribute::RangeAttribute(float min, float max)
|
||||
: minVal { min }
|
||||
, maxVal { max }
|
||||
{}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/************************************************************************************//*!
|
||||
\file RangeAttribute.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 18, 2022
|
||||
\brief Contains the definition of the managed Range Attribute class with
|
||||
the declaration of functions for working with it.
|
||||
|
||||
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
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple attribute to constrain the range of values for a field on the editor.
|
||||
/// </summary>
|
||||
[System::AttributeUsage(System::AttributeTargets::Field)]
|
||||
public ref class RangeAttribute : public System::Attribute
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Minimum value for the Ranged field.
|
||||
/// </summary>
|
||||
property float Min
|
||||
{
|
||||
float get();
|
||||
}
|
||||
/// <summary>
|
||||
/// Maximum value for the Ranged field.
|
||||
/// </summary>
|
||||
property float Max
|
||||
{
|
||||
float get();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor for a Tooltip attribute that fills in the description.
|
||||
/// </summary>
|
||||
/// <param name="description">Text to be shown when a field is hovered.</param>
|
||||
RangeAttribute(float min, float max);
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
float minVal;
|
||||
float maxVal;
|
||||
};
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple attribute to mark that a field in a Script should be serialised.
|
||||
/// Simple attribute to provide a field in a script with a tooltip.
|
||||
/// </summary>
|
||||
[System::AttributeUsage(System::AttributeTargets::Field)]
|
||||
public ref class TooltipAttribute : public System::Attribute
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/************************************************************************************//*!
|
||||
\file Time.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 19, 2022
|
||||
\brief This file is present so that the properties in Time.hxx would be compiled
|
||||
into the DLL.
|
||||
|
||||
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 "Time.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
double Time::DeltaTime::get()
|
||||
{
|
||||
return SHFrameRateController::GetRawDeltaTime();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/************************************************************************************//*!
|
||||
\file Time.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 19, 2022
|
||||
\brief Contains the definition of the Time static class and the definition of
|
||||
its properties.
|
||||
|
||||
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
|
||||
|
||||
#include "FRC/SHFramerateController.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Static class that contains the functions for working with time.
|
||||
/// </summary>
|
||||
public ref class Time abstract sealed
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Time taken to process the previous frame.
|
||||
/// Note, is affected by TimeScale. Use UnscaledDeltaTime if you wish to retrieve
|
||||
/// real world time. This is also affected by MaxDeltaTime clamping that
|
||||
/// UnscaledDeltaTime is subject to.
|
||||
/// </summary>
|
||||
static property double DeltaTime
|
||||
{
|
||||
double get();
|
||||
}
|
||||
};
|
||||
}
|
|
@ -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<YAML::Node*>(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<Script^>^ 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<YAML::Node*>(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<std::string>());
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// <br/> <br/>
|
||||
/// This function should only be called from native unmanaged code.
|
||||
/// </summary>
|
||||
/// <param name="entity">The Entity to Serialise.</param>
|
||||
/// <param name="buffer">
|
||||
/// StringBuilder handle that maps to a native char array that will contain the
|
||||
/// serialised string.
|
||||
/// </param>
|
||||
/// <param name="bufferSize">
|
||||
/// The size of the char array.
|
||||
/// <param name="yamlNode">
|
||||
/// Pointer to a YAML::Node that will be populated with all of the serialised
|
||||
/// scripts and their associated fields.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// True if serialisation is successful. False if the buffer is too small for
|
||||
/// the serialised output.
|
||||
/// </returns>
|
||||
static bool SerialiseScripts(Entity entity, System::Text::StringBuilder^ buffer, int bufferSize);
|
||||
static bool SerialiseScripts(Entity entity, System::IntPtr yamlNode);
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// <br/> <br/>
|
||||
/// This function should only be called from native unmanaged code.
|
||||
/// </summary>
|
||||
|
@ -265,10 +262,10 @@ namespace SHADE
|
|||
/// The Entity to attach the deserialised Scripts to.
|
||||
/// </param>
|
||||
/// <param name="yaml">
|
||||
/// JSON string that describes the Script to serialise.
|
||||
/// Pointer to the YAML::Node that contains serialized script data.
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
static bool DeserialiseScript(Entity entity, System::String^ yaml);
|
||||
static bool DeserialiseScripts(Entity entity, System::IntPtr yamlNode);
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
|
|
@ -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<FieldInfo^>^ 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<System::Int16> (fieldInfo, object, yaml) ||
|
||||
fieldInsertYaml<System::Int32> (fieldInfo, object, yaml) ||
|
||||
fieldInsertYaml<System::Int64> (fieldInfo, object, yaml) ||
|
||||
fieldInsertYaml<System::UInt16>(fieldInfo, object, yaml) ||
|
||||
fieldInsertYaml<System::UInt32>(fieldInfo, object, yaml) ||
|
||||
fieldInsertYaml<System::UInt64>(fieldInfo, object, yaml) ||
|
||||
fieldInsertYaml<System::Byte> (fieldInfo, object, yaml) ||
|
||||
fieldInsertYaml<bool> (fieldInfo, object, yaml) ||
|
||||
fieldInsertYaml<float> (fieldInfo, object, yaml) ||
|
||||
fieldInsertYaml<double> (fieldInfo, object, yaml))
|
||||
// Field YAML Node
|
||||
YAML::Node fieldNode;
|
||||
|
||||
// Retrieve string for the YAML
|
||||
const bool PRIMITIVE_SERIALIZED = fieldInsertYaml<System::Int16>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<System::Int32>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<System::Int64>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<System::UInt16>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<System::UInt32>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<System::UInt64>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<System::Byte>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<bool>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<float>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<double>(fieldInfo, object, fieldNode);
|
||||
|
||||
// Serialization of more complex types
|
||||
if (!PRIMITIVE_SERIALIZED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (fieldInfo->FieldType->IsSubclassOf(System::Enum::typeid))
|
||||
{
|
||||
yaml << safe_cast<int>(fieldInfo->GetValue(object));
|
||||
}
|
||||
else if (fieldInfo->FieldType == System::String::typeid)
|
||||
{
|
||||
System::String^ str = safe_cast<System::String^>(fieldInfo->GetValue(object));
|
||||
yaml << Convert::ToNative(str);
|
||||
}
|
||||
else if (fieldInfo->FieldType == Vector2::typeid)
|
||||
{
|
||||
Vector2 vec = safe_cast<Vector2>(fieldInfo->GetValue(object));
|
||||
yaml << YAML::BeginSeq << YAML::Flow << vec.x << vec.y << YAML::EndSeq;
|
||||
}
|
||||
else if (fieldInfo->FieldType == Vector3::typeid)
|
||||
{
|
||||
Vector3 vec = safe_cast<Vector3>(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<int>(fieldInfo->GetValue(object)));
|
||||
}
|
||||
else if (fieldInfo->FieldType == System::String::typeid)
|
||||
{
|
||||
System::String^ str = safe_cast<System::String^>(fieldInfo->GetValue(object));
|
||||
fieldNode = Convert::ToNative(str);
|
||||
}
|
||||
else if (fieldInfo->FieldType == Vector2::typeid)
|
||||
{
|
||||
Vector2 vec = safe_cast<Vector2>(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<Vector3>(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)
|
||||
|
|
|
@ -23,11 +23,12 @@ namespace SHADE
|
|||
/* Serialization Helper Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
template<typename FieldType>
|
||||
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<FieldType>(fieldInfo->GetValue(object));
|
||||
const FieldType VALUE = safe_cast<FieldType>(fieldInfo->GetValue(object));
|
||||
fieldNode = static_cast<FieldType>(VALUE);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -37,7 +38,7 @@ namespace SHADE
|
|||
template<typename FieldType>
|
||||
bool ReflectionUtilities::fieldAssignYaml(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& node)
|
||||
{
|
||||
return fieldAssignYaml<FieldType, FieldType>(fieldInfo, object, node);
|
||||
return fieldAssignYaml<FieldType, ToNativeType_T<FieldType>>(fieldInfo, object, node);
|
||||
}
|
||||
|
||||
template<typename FieldType, typename CastType>
|
||||
|
|
|
@ -52,24 +52,24 @@ namespace SHADE
|
|||
/// attribute will be serialised.
|
||||
/// </summary>
|
||||
/// <param name="object">The object to serialise.</param>
|
||||
static void Serialise(System::Object^ object, YAML::Emitter& yaml);
|
||||
static void Serialise(System::Object^ object, YAML::Node& yamlNode);
|
||||
/// <summary>
|
||||
/// Deserialises a YAML node that contains a map of Scripts and copies the
|
||||
/// deserialised data into the specified object if there are matching fields.
|
||||
/// </summary>
|
||||
/// <param name="yamlNode">
|
||||
/// 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.
|
||||
/// </param>
|
||||
/// <param name="object">The object to copy deserialised data into.</param>
|
||||
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<typename FieldType>
|
||||
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<typename FieldType>
|
||||
static bool fieldAssignYaml(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& node);
|
||||
|
|
|
@ -91,4 +91,68 @@ namespace SHADE
|
|||
/// <returns>Managed copy of a native std::string.</returns>
|
||||
static System::String^ ToCLI(const std::string& str);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Type Transformer for managed types to native types.
|
||||
/// </summary>
|
||||
/// <typeparam name="ManagedType">
|
||||
/// Managed type to get the native type for.
|
||||
/// </typeparam>
|
||||
template<typename ManagedType>
|
||||
struct ToNativeType
|
||||
{
|
||||
public:
|
||||
using Value = void;
|
||||
};
|
||||
template<> struct ToNativeType<System::Int16> { using Value = int16_t; };
|
||||
template<> struct ToNativeType<System::Int32> { using Value = int32_t; };
|
||||
template<> struct ToNativeType<System::Int64> { using Value = int64_t; };
|
||||
template<> struct ToNativeType<System::UInt16> { using Value = uint16_t; };
|
||||
template<> struct ToNativeType<System::UInt32> { using Value = uint32_t; };
|
||||
template<> struct ToNativeType<System::UInt64> { using Value = uint64_t; };
|
||||
template<> struct ToNativeType<System::Byte> { using Value = int8_t; };
|
||||
template<> struct ToNativeType<bool> { using Value = bool; };
|
||||
template<> struct ToNativeType<double> { using Value = double; };
|
||||
template<> struct ToNativeType<float> { using Value = float; };
|
||||
|
||||
/// <summary>
|
||||
/// Alias for ToNativeType::Value
|
||||
/// </summary>
|
||||
/// <typeparam name="ManagedType">
|
||||
/// Managed type to get the native type for.
|
||||
/// </typeparam>
|
||||
template<typename ManagedType>
|
||||
using ToNativeType_T = typename ToNativeType<ManagedType>::Value;
|
||||
|
||||
/// <summary>
|
||||
/// Type Transformer for native types to managed types.
|
||||
/// </summary>
|
||||
/// <typeparam name="ManagedType">
|
||||
/// Managed type to get the native type for.
|
||||
/// </typeparam>
|
||||
template<typename NativeType>
|
||||
struct ToManagedType
|
||||
{
|
||||
public:
|
||||
using Value = void;
|
||||
};
|
||||
template<> struct ToManagedType<int8_t> { using Value = System::Byte; };
|
||||
template<> struct ToManagedType<int16_t> { using Value = System::Int16; };
|
||||
template<> struct ToManagedType<int32_t> { using Value = System::Int32; };
|
||||
template<> struct ToManagedType<int64_t> { using Value = System::Int64; };
|
||||
template<> struct ToManagedType<uint16_t> { using Value = System::UInt16; };
|
||||
template<> struct ToManagedType<uint32_t> { using Value = System::UInt32; };
|
||||
template<> struct ToManagedType<uint64_t> { using Value = System::UInt64; };
|
||||
template<> struct ToManagedType<bool> { using Value = bool; };
|
||||
template<> struct ToManagedType<double> { using Value = double; };
|
||||
template<> struct ToManagedType<float> { using Value = float; };
|
||||
|
||||
/// <summary>
|
||||
/// Alias for ToManagedType::Value
|
||||
/// </summary>
|
||||
/// <typeparam name="ManagedType">
|
||||
/// Managed type to get the native type for.
|
||||
/// </typeparam>
|
||||
template<typename NativeType>
|
||||
using ToManagedType_T = typename ToManagedType<NativeType>::Value;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,11 @@ public class RaccoonShowcase : Script
|
|||
{
|
||||
[SerializeField]
|
||||
[Tooltip("Speed of the rotation in radians per second.")]
|
||||
[Range(-1.0f, 2.0f)]
|
||||
private double RotateSpeed = 1.0;
|
||||
//[SerializeField]
|
||||
//[Range(-5, 20)]
|
||||
//private int test = 5;
|
||||
[SerializeField]
|
||||
[Tooltip("Speed of the scaling in radians per second around each axis.")]
|
||||
private Vector3 ScaleSpeed = new Vector3(1.0, 1.0, 0.0);
|
||||
|
|
Loading…
Reference in New Issue