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