Merge remote-tracking branch 'origin/main' into SP3-2-Physics

This commit is contained in:
Diren D Bharwani 2022-11-22 22:33:44 +08:00
commit 899736d54a
25 changed files with 473 additions and 45 deletions

View File

@ -1,4 +1,4 @@
Start in Fullscreen: false Start in Fullscreen: false
Starting Scene ID: 94283040 Starting Scene ID: 94246101
Window Size: {x: 1920, y: 1080} Window Size: {x: 1920, y: 1080}
Window Title: SHADE Engine Window Title: SHADE Engine

View File

@ -0,0 +1,84 @@
- EID: 0
Name: Canvas
IsActive: true
NumberOfChildren: 1
Components:
Canvas Component:
Canvas Width: 10
Canvas Height: 10
IsActive: true
Scripts: ~
- EID: 6
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 141771688
Material: 129340704
IsActive: true
Button Component:
Default Texture: 0
Hovered Texture: 0
Clicked Texture: 0
IsActive: true
Scripts: ~
- EID: 1
Name: Camera
IsActive: true
NumberOfChildren: 0
Components:
Camera Component:
Position: {x: 0, y: 3, z: 8}
Pitch: 0
Yaw: 0
Roll: 0
Width: 1920
Height: 1080
Near: 0.00999999978
Far: 10000
Perspective: true
IsActive: true
Light Component:
Position: {x: 0, y: 0, z: 0}
Type: Directional
Direction: {x: 1.79999995, y: 0, z: 1}
Color: {x: 0.951541841, y: 0.921719015, z: 0.553319454, w: 1}
Layer: 4294967295
Strength: 0
IsActive: true
Scripts: ~
- EID: 7
Name: BigBoi
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: -16.8647861, z: -14.039052}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975}
IsActive: true
Renderable Component:
Mesh: 149697411
Material: 126974645
IsActive: true
Scripts: ~
- EID: 8
Name: AmbientLight
IsActive: true
NumberOfChildren: 0
Components:
Light Component:
Position: {x: 0, y: 0, z: 0}
Type: Ambient
Direction: {x: 0, y: 0, z: 1}
Color: {x: 1, y: 1, z: 1, w: 1}
Layer: 4294967295
Strength: 0.25
IsActive: true
Scripts: ~

View File

@ -0,0 +1,3 @@
Name: UI Test
ID: 87707373
Type: 5

View File

@ -126,7 +126,9 @@ namespace Sandbox
//SHSystemManager::RegisterRoutine<SHCameraSystem, SHCameraSystem::EditorCameraUpdate>(); //SHSystemManager::RegisterRoutine<SHCameraSystem, SHCameraSystem::EditorCameraUpdate>();
SHSystemManager::RegisterRoutine<SHUISystem, SHUISystem::AddUIComponentRoutine>(); SHSystemManager::RegisterRoutine<SHUISystem, SHUISystem::AddUIComponentRoutine>();
SHSystemManager::RegisterRoutine<SHUISystem, SHUISystem::UpdateCanvasMatrixRoutine>();
SHSystemManager::RegisterRoutine<SHUISystem, SHUISystem::UpdateUIMatrixRoutine>(); SHSystemManager::RegisterRoutine<SHUISystem, SHUISystem::UpdateUIMatrixRoutine>();
SHSystemManager::RegisterRoutine<SHUISystem, SHUISystem::UpdateButtonsRoutine>();
SHSystemManager::RegisterRoutine<SHCameraSystem, SHCameraSystem::CameraSystemUpdate>(); SHSystemManager::RegisterRoutine<SHCameraSystem, SHCameraSystem::CameraSystemUpdate>();
#ifdef SHEDITOR #ifdef SHEDITOR

View File

@ -53,15 +53,16 @@ project "SHADE_CSharp"
function configElementCS(cfg) function configElementCS(cfg)
_p(2,'<Configurations>Debug;Release;Publish</Configurations>') _p(2,'<Configurations>Debug;Release;Publish</Configurations>')
end end
function docsElementCS(cfg) -- function docsElementCS(cfg)
_p(2,'<GenerateDocumentationFile>true</GenerateDocumentationFile>') -- _p(2,'<GenerateDocumentationFile>true</GenerateDocumentationFile>')
end -- end
function docsLocationElementCS(cfg) -- function docsLocationElementCS(cfg)
_p(2,'<DocumentationFile>$(OutDir)</DocumentationFile>') -- _p(2,'<DocumentationFile>$(OutDir)</DocumentationFile>')
end -- end
premake.override(premake.vstudio.cs2005.elements, "projectProperties", function (oldfn, cfg) premake.override(premake.vstudio.cs2005.elements, "projectProperties", function (oldfn, cfg)
return table.join(oldfn(cfg), { return table.join(oldfn(cfg), {
platformsElementCS, configElementCS, docsElementCS, docsLocationElementCS, -- platformsElementCS, configElementCS, docsElementCS, docsLocationElementCS,
platformsElementCS, configElementCS,
}) })
end) end)

View File

@ -52,7 +52,7 @@ namespace SHADE
std::ifstream file{ path.string(), std::ios::in | std::ios::binary }; std::ifstream file{ path.string(), std::ios::in | std::ios::binary };
if (!file.is_open()) if (!file.is_open())
{ {
SHLOG_ERROR("Unable to open SHMesh File: {}", path.string()); SHLOG_ERROR("[Model Loader] Unable to open SHModel File: {}", path.string());
return; return;
} }

View File

@ -26,7 +26,7 @@ namespace SHADE
if (!file.is_open()) if (!file.is_open())
{ {
SHLOG_ERROR("Unable to open text File: {}", path.string()); SHLOG_ERROR("[Text Loader] Unable to open text File: {}", path.string());
return nullptr; return nullptr;
} }
std::stringstream stream; std::stringstream stream;
@ -70,7 +70,7 @@ namespace SHADE
if (!file.is_open()) if (!file.is_open())
{ {
SHLOG_ERROR("Unable to open text File: {}", path.string()); SHLOG_ERROR("[Text Loader] Unable to open text File: {}", path.string());
return; return;
} }

View File

@ -22,7 +22,7 @@ namespace SHADE
std::ifstream file{ path.string(), std::ios::in | std::ios::binary }; std::ifstream file{ path.string(), std::ios::in | std::ios::binary };
if (!file.is_open()) if (!file.is_open())
{ {
SHLOG_ERROR("Error opening SHTexture file: {}", path.string()); SHLOG_ERROR("[Texture Loader] Error opening SHTexture file: {}", path.string());
} }
auto const intBytes{ sizeof(uint32_t) }; auto const intBytes{ sizeof(uint32_t) };
@ -61,7 +61,7 @@ namespace SHADE
std::ofstream file{ path, std::ios::out | std::ios::binary }; std::ofstream file{ path, std::ios::out | std::ios::binary };
if (!file.is_open()) if (!file.is_open())
{ {
SHLOG_ERROR("Unable to open file for writing texture file: {}", path.string()); SHLOG_ERROR("[Texture Loader] Unable to open file for writing texture file: {}", path.string());
} }
auto asset = *dynamic_cast<SHTextureAsset const*>(data); auto asset = *dynamic_cast<SHTextureAsset const*>(data);

View File

@ -220,7 +220,7 @@ namespace SHADE
break; break;
default: default:
SHLOG_ERROR("Asset type of {} not an internal asset type, cannot be created", name); SHLOG_ERROR("[Asset Manager] Asset type of {} not an internal asset type, cannot be created", name);
return 0; return 0;
} }
@ -272,14 +272,14 @@ namespace SHADE
return true; return true;
} }
SHLOG_ERROR("Asset data has not been written into, cannot be saved: {}", SHLOG_ERROR("[Asset Manager] Asset data has not been written into, cannot be saved: {}",
asset.path.filename().string()); asset.path.filename().string());
return false; return false;
} }
} }
SHLOG_WARNING("Asset id: {} not an internal asset type, save cannot be triggered", id); SHLOG_WARNING("[Asset Manager] Asset id: {} not an internal asset type, save cannot be triggered", id);
return false; return false;
} }
@ -297,10 +297,10 @@ namespace SHADE
{ {
return (DeleteLocalFile(asset.path) && DeleteLocalFile(asset.path.string() + META_EXTENSION.data())); return (DeleteLocalFile(asset.path) && DeleteLocalFile(asset.path.string() + META_EXTENSION.data()));
} }
SHLOG_WARNING("Asset id: {} not an internal asset type, file deletion not allowed", id); SHLOG_WARNING("[Asset Manager] Asset id: {} not an internal asset type, file deletion not allowed", id);
} }
SHLOG_WARNING("Asset id does not exist, nothing was deleted: {}", id); SHLOG_WARNING("[Asset Manager] Asset id does not exist, nothing was deleted: {}", id);
return false; return false;
} }
@ -334,7 +334,7 @@ namespace SHADE
std::filesystem::path const newPath{ GenerateLocalPath(path) }; std::filesystem::path const newPath{ GenerateLocalPath(path) };
if (newPath.empty()) if (newPath.empty())
{ {
SHLOG_WARNING("Unsupported file format for asset: {}", path.string()); SHLOG_WARNING("[Asset Manager] Unsupported file format for asset: {}", path.string());
return 0; return 0;
} }
@ -386,7 +386,7 @@ namespace SHADE
{ {
if (!std::filesystem::exists(path)) if (!std::filesystem::exists(path))
{ {
SHLOG_ERROR("Path provided does not point to a file: {}", path.string()); SHLOG_ERROR("[Asset Manager] Path provided does not point to a file: {}", path.string());
return; return;
} }
AssetPath newPath; AssetPath newPath;
@ -416,7 +416,7 @@ namespace SHADE
auto pathGen = SHTextureCompiler::CompileTextureAsset(path); auto pathGen = SHTextureCompiler::CompileTextureAsset(path);
if (!pathGen.has_value()) if (!pathGen.has_value())
{ {
SHLOG_ERROR("Texture Compilation Failed for: {}", path.string()); SHLOG_ERROR("[Asset Manager] Texture Compilation Failed for: {}", path.string());
return; return;
} }
newPath = pathGen.value(); newPath = pathGen.value();
@ -433,7 +433,7 @@ namespace SHADE
} }
else else
{ {
SHLOG_WARNING("File Type compilation not yet Implemented: {}", path.string()); SHLOG_WARNING("[Asset Manager] File Type compilation not yet Implemented: {}", path.string());
return; return;
} }
@ -520,7 +520,7 @@ namespace SHADE
SHAssetData* data = loaders[static_cast<size_t>(asset.type)]->Load(asset.path); SHAssetData* data = loaders[static_cast<size_t>(asset.type)]->Load(asset.path);
if (data == nullptr) if (data == nullptr)
{ {
SHLOG_ERROR("Unable to load asset into memory: {}\n", asset.path.string()); SHLOG_ERROR("[Asset Manager] Unable to load asset into memory: {}\n", asset.path.string());
} }
else else
{ {
@ -537,7 +537,7 @@ namespace SHADE
if (parentData == nullptr) if (parentData == nullptr)
{ {
SHLOG_ERROR("Unable to load asset into memory: {}\n", parent.path.string()); SHLOG_ERROR("[Asset Manager] Unable to load asset into memory: {}\n", parent.path.string());
} }
else else
{ {
@ -653,6 +653,34 @@ namespace SHADE
return newAsset.id; return newAsset.id;
} }
else if(ext == MATERIAL_EXTENSION)
{
SHAsset newAsset{
path.stem().string(),
GenerateAssetID(AssetType::MATERIAL),
AssetType::MATERIAL,
path,
false
};
assetCollection.emplace(newAsset.id, newAsset);
SHAssetMetaHandler::WriteMetaData(newAsset);
return newAsset.id;
}
else if (ext == PREFAB_EXTENSION)
{
SHAsset newAsset{
path.stem().string(),
GenerateAssetID(AssetType::PREFAB),
AssetType::PREFAB,
path,
false
};
assetCollection.emplace(newAsset.id, newAsset);
SHAssetMetaHandler::WriteMetaData(newAsset);
return newAsset.id;
}
else if (ext == FONT_EXTENSION) else if (ext == FONT_EXTENSION)
{ {
SHAsset newAsset{ SHAsset newAsset{

View File

@ -90,5 +90,22 @@ namespace SHADE
return SHMatrix::Identity; return SHMatrix::Identity;
} }
float SHCameraDirector::GetWidth() noexcept
{
SHCameraComponent* camComponent = GetMainCameraComponent();
if (camComponent)
return camComponent->GetWidth();
else
return 0.0f;
}
float SHCameraDirector::GetHeight() noexcept
{
SHCameraComponent* camComponent = GetMainCameraComponent();
if (camComponent)
return camComponent->GetHeight();
else
return 0.0f;
}
} }

View File

@ -30,6 +30,8 @@ namespace SHADE
void SetMainCamera(SHCameraComponent& cam) noexcept; void SetMainCamera(SHCameraComponent& cam) noexcept;
SHMatrix const& GetOrthoMatrix() noexcept; SHMatrix const& GetOrthoMatrix() noexcept;
SHMatrix const& GetPerspectiveMatrix() noexcept; SHMatrix const& GetPerspectiveMatrix() noexcept;
float GetWidth() noexcept;
float GetHeight() noexcept;
private: private:
SHMatrix viewMatrix; SHMatrix viewMatrix;

View File

@ -8,6 +8,8 @@
#include "Math/Transform/SHTransformComponent.h" #include "Math/Transform/SHTransformComponent.h"
#include <math.h> #include <math.h>
#include "Scene/SHSceneManager.h" #include "Scene/SHSceneManager.h"
#include "ECS_Base/Managers/SHSystemManager.h"
#include "Editor/SHEditor.h"
namespace SHADE namespace SHADE
{ {
@ -57,6 +59,8 @@ namespace SHADE
//std::cout << camera.yaw << std::endl; //std::cout << camera.yaw << std::endl;
camera.pitch -= mouseY * dt * camera.turnSpeed.x; camera.pitch -= mouseY * dt * camera.turnSpeed.x;
camera.yaw -= mouseX * dt * camera.turnSpeed.y; camera.yaw -= mouseX * dt * camera.turnSpeed.y;
camera.dirtyView = true; camera.dirtyView = true;
@ -150,6 +154,8 @@ namespace SHADE
void SHCameraSystem::UpdateCameraComponent(SHCameraComponent& camera) noexcept void SHCameraSystem::UpdateCameraComponent(SHCameraComponent& camera) noexcept
{ {
if (camera.isActive == false) if (camera.isActive == false)
return; return;
@ -436,4 +442,22 @@ namespace SHADE
SetCameraViewMatrix(camera, viewMtx); SetCameraViewMatrix(camera, viewMtx);
} }
SHVec2 SHCameraSystem::GetCameraWidthHeight(size_t index) noexcept
{
#ifdef SHEDITOR
auto editor = SHSystemManager::GetSystem<SHEditor>();
if (editor->editorState != SHEditor::State::PLAY)
{
return SHVec2{ GetEditorCamera()->GetWidth(), GetEditorCamera()->GetHeight() };
}
else
{
return SHVec2{ GetDirector(index)->GetWidth(),GetDirector(index)->GetHeight() };
}
#else
return SHVec2{ GetDirector(index)->GetWidth(),GetDirector(index)->GetHeight() };
#endif
}
} }

View File

@ -27,6 +27,7 @@ namespace SHADE
void UpdateCameraComponent(SHCameraComponent& camera) noexcept; void UpdateCameraComponent(SHCameraComponent& camera) noexcept;
void UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept; void UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept;
public: public:
@ -57,6 +58,8 @@ namespace SHADE
void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept; void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept;
void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept; void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept;
void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept; void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept;
SHVec2 GetCameraWidthHeight(size_t index) noexcept;
}; };

View File

@ -20,6 +20,7 @@
#include "Camera/SHCameraArmComponent.h" #include "Camera/SHCameraArmComponent.h"
#include "UI/SHUIComponent.h" #include "UI/SHUIComponent.h"
#include "UI/SHCanvasComponent.h" #include "UI/SHCanvasComponent.h"
#include "UI/SHButtonComponent.h"
#include "SHEditorComponentView.h" #include "SHEditorComponentView.h"
#include "AudioSystem/SHAudioListenerComponent.h" #include "AudioSystem/SHAudioListenerComponent.h"
#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
@ -149,6 +150,10 @@ namespace SHADE
{ {
DrawComponent(textRendererComponent); DrawComponent(textRendererComponent);
} }
if (auto buttonComponent = SHComponentManager::GetComponent_s<SHButtonComponent>(eid))
{
DrawComponent(buttonComponent);
}
ImGui::Separator(); ImGui::Separator();
// Render Scripts // Render Scripts
SHScriptEngine* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>()); SHScriptEngine* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
@ -161,6 +166,7 @@ namespace SHADE
DrawAddComponentButton<SHCameraArmComponent>(eid); DrawAddComponentButton<SHCameraArmComponent>(eid);
DrawAddComponentButton<SHLightComponent>(eid); DrawAddComponentButton<SHLightComponent>(eid);
DrawAddComponentButton<SHCanvasComponent>(eid); DrawAddComponentButton<SHCanvasComponent>(eid);
DrawAddComponentButton<SHButtonComponent>(eid);
// Components that require Transforms // Components that require Transforms

View File

@ -454,12 +454,12 @@ namespace SHADE
ImGui::BeginGroup(); ImGui::BeginGroup();
ImGui::PushID(label.data()); ImGui::PushID(label.data());
TextLabel(label); TextLabel(label);
const bool hasChange = ImGui::DragScalar("##dragScalar", data_type, &value, speed, &p_min, &p_max, displayFormat, flags); const bool hasChange = ImGui::InputScalar("##dragScalar", data_type, &value);
static bool startRecording = false; static bool startRecording = false;
if (hasChange) if (hasChange)
{ {
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<T>>(get(), value, set)), startRecording); SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<T>>(get(), value, set)), startRecording);
if (!startRecording) if (!startRecording && ImGui::IsMouseDown(ImGuiMouseButton_Left))
startRecording = true; startRecording = true;
} }
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
@ -477,7 +477,7 @@ namespace SHADE
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
} }
return hasChange; return false;
} }
static bool DragFloat(const std::string_view& label, std::function<float(void)> get, std::function<void(float const&)> set, std::string_view const& tooltip = {}, static bool DragFloat(const std::string_view& label, std::function<float(void)> get, std::function<void(float const&)> set, std::string_view const& tooltip = {},

View File

@ -313,7 +313,8 @@ namespace SHADE
auto uiComp = SHComponentManager::GetComponent_s<SHUIComponent>(rendId); auto uiComp = SHComponentManager::GetComponent_s<SHUIComponent>(rendId);
if (uiComp) if (uiComp)
{ {
transformData.emplace_back(uiComp->GetMatrix()); if(uiComp->isActive)
transformData.emplace_back(uiComp->GetMatrix());
} }
else else
transformData.emplace_back(transform->GetTRS()); transformData.emplace_back(transform->GetTRS());

View File

@ -55,7 +55,11 @@ namespace SHADE
void SHSuperBatch::Remove(const SHRenderable* renderable) noexcept void SHSuperBatch::Remove(const SHRenderable* renderable) noexcept
{ {
Handle<SHMaterial> baseMat = (renderable->HasMaterialChanged() ? renderable->GetPrevMaterial() : renderable->GetMaterial())->GetBaseMaterial(); Handle<SHMaterialInstance> matInst = renderable->HasMaterialChanged() ? renderable->GetPrevMaterial() : renderable->GetMaterial();
if (!matInst)
return;
Handle<SHMaterial> baseMat = matInst->GetBaseMaterial();
const Handle<SHVkPipeline> PIPELINE = baseMat->HasPipelineChanged() ? baseMat->GetPrevPipeline() : baseMat->GetPipeline(); const Handle<SHVkPipeline> PIPELINE = baseMat->HasPipelineChanged() ? baseMat->GetPrevPipeline() : baseMat->GetPipeline();
// Check if we have a Batch with the same pipeline yet // Check if we have a Batch with the same pipeline yet

View File

@ -968,7 +968,7 @@ namespace SHADE
for (auto& renderable : renderables) for (auto& renderable : renderables)
{ {
// Check if the material instance is now unused // Check if the material instance is now unused
renderable.CleanUpMaterials(); renderable.CleanUpMaterials();
if (!renderable.HasChanged()) if (!renderable.HasChanged())
continue; continue;

View File

@ -34,9 +34,10 @@ namespace SHADE
void SHRenderable::OnDestroy() void SHRenderable::OnDestroy()
{ {
// Remove from SuperBatch // Remove from SuperBatch
if (sharedMaterial) auto currMat = GetMaterial();
if (currMat)
{ {
Handle<SHSuperBatch> superBatch = sharedMaterial->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch(); Handle<SHSuperBatch> superBatch = currMat->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch();
superBatch->Remove(this); superBatch->Remove(this);
} }
@ -64,7 +65,6 @@ namespace SHADE
if (material) if (material)
{ {
oldMaterial = material; oldMaterial = material;
material.Free();
material = {}; material = {};
} }
else if (sharedMaterial) else if (sharedMaterial)
@ -150,6 +150,8 @@ namespace SHADE
{ {
matChanged = false; matChanged = false;
meshChanged = false; meshChanged = false;
if (oldMaterial)
oldMaterial.Free();
oldMaterial = {}; oldMaterial = {};
oldMesh = {}; oldMesh = {};
} }

View File

@ -12,9 +12,12 @@
#include "Assets/Asset Types/SHSceneAsset.h" #include "Assets/Asset Types/SHSceneAsset.h"
#include "Camera/SHCameraComponent.h" #include "Camera/SHCameraComponent.h"
#include "Camera/SHCameraArmComponent.h"
#include "Math/Transform/SHTransformComponent.h" #include "Math/Transform/SHTransformComponent.h"
#include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Physics/Interface/SHRigidBodyComponent.h" #include "Physics/Interface/SHRigidBodyComponent.h"
#include "UI/SHCanvasComponent.h"
#include "UI/SHButtonComponent.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"
#include "Scripting/SHScriptEngine.h" #include "Scripting/SHScriptEngine.h"
@ -207,10 +210,15 @@ namespace SHADE
AddComponentToComponentNode<SHTransformComponent>(components, eid); AddComponentToComponentNode<SHTransformComponent>(components, eid);
AddComponentToComponentNode<SHCameraComponent>(components, eid); AddComponentToComponentNode<SHCameraComponent>(components, eid);
AddComponentToComponentNode<SHCameraArmComponent>(components, eid);
AddConvComponentToComponentNode<SHRenderable>(components, eid); AddConvComponentToComponentNode<SHRenderable>(components, eid);
AddComponentToComponentNode<SHLightComponent>(components, eid); AddComponentToComponentNode<SHLightComponent>(components, eid);
AddComponentToComponentNode<SHRigidBodyComponent>(components, eid); AddComponentToComponentNode<SHRigidBodyComponent>(components, eid);
AddConvComponentToComponentNode<SHColliderComponent>(components, eid); AddConvComponentToComponentNode<SHColliderComponent>(components, eid);
AddComponentToComponentNode<SHCanvasComponent>(components, eid);
AddComponentToComponentNode<SHButtonComponent>(components, eid);
AddConvComponentToComponentNode<SHTextRenderableComponent>(components, eid); AddConvComponentToComponentNode<SHTextRenderableComponent>(components, eid);
node[ComponentsNode] = components; node[ComponentsNode] = components;
@ -259,10 +267,14 @@ namespace SHADE
AddComponentID<SHTransformComponent>(componentIDList, componentsNode); AddComponentID<SHTransformComponent>(componentIDList, componentsNode);
AddComponentID<SHCameraComponent>(componentIDList, componentsNode); AddComponentID<SHCameraComponent>(componentIDList, componentsNode);
AddComponentID<SHCameraArmComponent>(componentIDList, componentsNode);
AddComponentID<SHRenderable>(componentIDList, componentsNode); AddComponentID<SHRenderable>(componentIDList, componentsNode);
AddComponentID<SHRigidBodyComponent>(componentIDList, componentsNode); AddComponentID<SHRigidBodyComponent>(componentIDList, componentsNode);
AddComponentID<SHLightComponent>(componentIDList, componentsNode); AddComponentID<SHLightComponent>(componentIDList, componentsNode);
AddComponentID<SHColliderComponent>(componentIDList, componentsNode); AddComponentID<SHColliderComponent>(componentIDList, componentsNode);
AddComponentID<SHCanvasComponent>(componentIDList, componentsNode);
AddComponentID<SHButtonComponent>(componentIDList, componentsNode);
AddComponentID<SHTextRenderableComponent>(componentIDList, componentsNode); AddComponentID<SHTextRenderableComponent>(componentIDList, componentsNode);
return componentIDList; return componentIDList;
@ -337,9 +349,13 @@ namespace SHADE
return; return;
SHSerializationHelper::InitializeComponentFromNode<SHTransformComponent>(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode<SHTransformComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHCameraComponent>(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode<SHCameraComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHCameraArmComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHRigidBodyComponent>(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode<SHRigidBodyComponent>(componentsNode, eid);
SHSerializationHelper::ConvertNodeToComponent<SHRenderable>(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent<SHRenderable>(componentsNode, eid);
SHSerializationHelper::ConvertNodeToComponent<SHColliderComponent>(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent<SHColliderComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHCanvasComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHButtonComponent>(componentsNode, eid);
SHSerializationHelper::ConvertNodeToComponent<SHTextRenderableComponent>(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent<SHTextRenderableComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid);
} }

View File

@ -0,0 +1,58 @@
#include "SHpch.h"
#include "SHButtonComponent.h"
namespace SHADE
{
SHButtonComponent::SHButtonComponent()
:size(1.0f), offset(0.0f), isHovered(false), isClicked(false),
defaultTexture(0), hoveredTexture(0), clickedTexture(0)
{
}
AssetID SHButtonComponent::GetDefaultTexture() const noexcept
{
return defaultTexture;
}
AssetID SHButtonComponent::GetHoveredTexture() const noexcept
{
return hoveredTexture;
}
AssetID SHButtonComponent::GetClickedTexture() const noexcept
{
return clickedTexture;
}
void SHButtonComponent::SetDefaultTexture(AssetID texture) noexcept
{
defaultTexture = texture;
}
void SHButtonComponent::SetHoveredTexture(AssetID texture) noexcept
{
hoveredTexture = texture;
}
void SHButtonComponent::SetClickedTexture(AssetID texture) noexcept
{
clickedTexture = texture;
}
}
RTTR_REGISTRATION
{
using namespace SHADE;
using namespace rttr;
registration::class_<SHButtonComponent>("Button Component")
.property("Default Texture", &SHButtonComponent::GetDefaultTexture, &SHButtonComponent::SetDefaultTexture)
.property("Hovered Texture", &SHButtonComponent::GetHoveredTexture, &SHButtonComponent::SetHoveredTexture)
.property("Clicked Texture", &SHButtonComponent::GetClickedTexture, &SHButtonComponent::SetClickedTexture)
;
}

View File

@ -0,0 +1,48 @@
#pragma once
#include <rttr/registration>
#include "SH_API.h"
#include "ECS_Base/Components/SHComponent.h"
#include "Math/Vector/SHVec3.h"
#include "Math/Vector/SHVec2.h"
#include "Assets/SHAssetMacros.h"
namespace SHADE
{
class SH_API SHButtonComponent final: public SHComponent
{
public:
SHButtonComponent();
virtual ~SHButtonComponent() = default;
SHVec2 size;
SHVec2 offset;
AssetID GetClickedTexture() const noexcept;
AssetID GetDefaultTexture() const noexcept;
AssetID GetHoveredTexture() const noexcept;
void SetDefaultTexture(AssetID texture) noexcept;
void SetHoveredTexture(AssetID texture) noexcept;
void SetClickedTexture(AssetID texture) noexcept;
friend class SHUISystem;
private:
bool isHovered;
bool isClicked;
AssetID defaultTexture;
AssetID hoveredTexture;
AssetID clickedTexture;
RTTR_ENABLE()
};
}

View File

@ -3,6 +3,13 @@
#include "ECS_Base/Managers/SHComponentManager.h" #include "ECS_Base/Managers/SHComponentManager.h"
#include "ECS_Base/Managers/SHSystemManager.h" #include "ECS_Base/Managers/SHSystemManager.h"
#include "Math/Transform/SHTransformComponent.h" #include "Math/Transform/SHTransformComponent.h"
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Camera/SHCameraSystem.h"
#include "Editor/EditorWindow/SHEditorWindowManager.h"
#include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h"
#include "Editor/SHEditor.h"
#include "Resource/SHResourceManager.h"
#include "Input/SHInputManager.h"
namespace SHADE namespace SHADE
{ {
@ -12,6 +19,7 @@ namespace SHADE
SystemFamily::GetID<SHUISystem>(); SystemFamily::GetID<SHUISystem>();
SHComponentManager::CreateComponentSparseSet<SHCanvasComponent>(); SHComponentManager::CreateComponentSparseSet<SHCanvasComponent>();
SHComponentManager::CreateComponentSparseSet<SHUIComponent>(); SHComponentManager::CreateComponentSparseSet<SHUIComponent>();
SHComponentManager::CreateComponentSparseSet<SHButtonComponent>();
} }
void SHUISystem::Exit() void SHUISystem::Exit()
@ -95,7 +103,7 @@ namespace SHADE
{ {
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(comp.GetEID()); auto transform = SHComponentManager::GetComponent<SHTransformComponent>(comp.GetEID());
if (canvasComp != nullptr) if (canvasComp != nullptr)
comp.localToCanvasMatrix = canvasComp->GetMatrix() * transform->GetTRS(); comp.localToCanvasMatrix = canvasComp->GetMatrix()* transform->GetTRS();
else else
comp.localToCanvasMatrix = transform->GetTRS(); comp.localToCanvasMatrix = transform->GetTRS();
} }
@ -108,6 +116,109 @@ namespace SHADE
} }
} }
void SHUISystem::UpdateCanvasComponent(SHCanvasComponent& comp) noexcept
{
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
SHVec2 camSize = cameraSystem->GetCameraWidthHeight(0);
comp.canvasMatrix = SHMatrix::Identity;
comp.canvasMatrix(0, 0) = camSize.x * 0.5f / (comp.GetCanvasWidth() * 0.5f);
comp.canvasMatrix(1, 1) = camSize.y * 0.5f / (comp.GetCanvasHeight() * 0.5f);
}
void SHUISystem::UpdateCanvasMatrixRoutine::Execute(double dt) noexcept
{
SHUISystem* system = (SHUISystem*)GetSystem();
auto& dense = SHComponentManager::GetDense<SHCanvasComponent>();
for (auto& comp : dense)
{
if(SHSceneManager::CheckNodeAndComponentsActive<SHCanvasComponent>(comp.GetEID()))
system->UpdateCanvasComponent(comp);
}
}
void SHUISystem::UpdateButtonComponent(SHButtonComponent& comp) noexcept
{
if (!SHComponentManager::HasComponent<SHTransformComponent>(comp.GetEID()) || !SHComponentManager::HasComponent<SHUIComponent>(comp.GetEID()))
{
return;
}
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
auto uiComp = SHComponentManager::GetComponent<SHUIComponent>(comp.GetEID());
SHVec4 topExtent4 = uiComp->GetMatrix() * SHVec4(-comp.size.x * 0.5f, comp.size.y * 0.5f , 0.0f,1.0f);
SHVec4 btmExtent4 = uiComp->GetMatrix() * SHVec4(comp.size.x * 0.5f , -comp.size.y * 0.5f , 0.0f, 1.0f);
SHVec2 topExtent{ topExtent4.x,-topExtent4.y };
SHVec2 btmExtent{ btmExtent4.x,-btmExtent4.y };
SHVec2 windowSize;
SHVec2 mousePos;
#ifdef SHEDITOR
windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->windowSize;
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos;
#endif
SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0).x , cameraSystem->GetCameraWidthHeight(0).y };
topExtent += camSize * 0.5f;
btmExtent += camSize * 0.5f;
//Convert everything to using ratios
topExtent /= camSize;
btmExtent /= camSize;
mousePos /= windowSize;
//SHLOG_INFO("mousePos: {} , {}", mousePos.x, mousePos.y);
comp.isClicked = false;
if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x
&& mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y)
{
comp.isHovered = true;
if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
{
comp.isClicked = true;
}
//SHLOG_INFO("BUTTON HOVERED");
}
else
{
comp.isHovered = false;
//SHLOG_INFO("BUTTON NOT HOVERED")
}
if (SHComponentManager::HasComponent<SHRenderable>(comp.GetEID()))
{
//auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
//auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
//auto material = renderable->GetModifiableMaterial();
//material->SetProperty("texture", comp.GetDefaultTexture());
}
}
void SHUISystem::UpdateButtonsRoutine::Execute(double dt) noexcept
{
SHUISystem* system = (SHUISystem*)GetSystem();
auto& dense = SHComponentManager::GetDense<SHButtonComponent>();
for (auto& comp : dense)
{
if (SHSceneManager::CheckNodeAndComponentsActive<SHButtonComponent>(comp.GetEID()))
system->UpdateButtonComponent(comp);
}
}
}//end namespace }//end namespace

View File

@ -4,6 +4,7 @@
#include "ECS_Base/System/SHSystem.h" #include "ECS_Base/System/SHSystem.h"
#include "ECS_Base/System/SHSystemRoutine.h" #include "ECS_Base/System/SHSystemRoutine.h"
#include "SHUIComponent.h" #include "SHUIComponent.h"
#include "SHButtonComponent.h"
#include "SHCanvasComponent.h" #include "SHCanvasComponent.h"
#include "Scene/SHSceneGraph.h" #include "Scene/SHSceneGraph.h"
#include "Scene/SHSceneManager.h" #include "Scene/SHSceneManager.h"
@ -38,6 +39,23 @@ namespace SHADE
}; };
friend class UpdateUIMatrixRoutine; friend class UpdateUIMatrixRoutine;
class SH_API UpdateCanvasMatrixRoutine final: public SHSystemRoutine
{
public:
UpdateCanvasMatrixRoutine() :SHSystemRoutine("Update Canvas Matrix Routine", true) {};
virtual void Execute(double dt) noexcept override final;
};
friend class UpdateCanvasMatrixRoutine;
class SH_API UpdateButtonsRoutine final: public SHSystemRoutine
{
public:
UpdateButtonsRoutine() : SHSystemRoutine("Update Buttons Routine", true) {};
virtual void Execute(double dt) noexcept override final;
};
friend class UpdateButtonsRoutine;
void Init(); void Init();
void Exit(); void Exit();
@ -45,8 +63,8 @@ namespace SHADE
private: private:
void UpdateUIComponent(SHUIComponent& comp) noexcept; void UpdateUIComponent(SHUIComponent& comp) noexcept;
void UpdateButtonComponent(SHButtonComponent& comp) noexcept;
void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept;
}; };

View File

@ -119,14 +119,14 @@ project "SHADE_Managed"
links{"librttr_core.lib"} links{"librttr_core.lib"}
links{"fmodstudio_vc.lib", "fmod_vc.lib"} links{"fmodstudio_vc.lib", "fmod_vc.lib"}
require "vstudio" -- require "vstudio"
function docsElementCPP(cfg) -- function docsElementCPP(cfg)
_p(3,'<GenerateXMLDocumentationFiles>true</GenerateXMLDocumentationFiles>') -- _p(3,'<GenerateXMLDocumentationFiles>true</GenerateXMLDocumentationFiles>')
end -- end
premake.override(premake.vstudio.vc2010.elements, "clCompile", function (oldfn, cfg) -- premake.override(premake.vstudio.vc2010.elements, "clCompile", function (oldfn, cfg)
return table.join(oldfn(cfg), { -- return table.join(oldfn(cfg), {
docsElementCPP, -- docsElementCPP,
}) -- })
end) -- end)