Merge branch 'main' into SP3-1-Rendering
# Conflicts: # SHADE_Application/src/Application/SBApplication.cpp # SHADE_Application/src/Scenes/SBTestScene.cpp
This commit is contained in:
commit
04cdb25ddd
|
@ -22,6 +22,8 @@
|
||||||
#include "ECS_Base/Managers/SHEntityManager.h"
|
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||||
#include "Scene/SHSceneManager.h"
|
#include "Scene/SHSceneManager.h"
|
||||||
|
#include "Math/Transform/SHTransformSystem.h"
|
||||||
|
|
||||||
#include "Scenes/SBTestScene.h"
|
#include "Scenes/SBTestScene.h"
|
||||||
#include "Math/Transform/SHTransformComponent.h"
|
#include "Math/Transform/SHTransformComponent.h"
|
||||||
|
|
||||||
|
@ -45,8 +47,10 @@ namespace Sandbox
|
||||||
window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
|
window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
|
||||||
|
|
||||||
// Create Systems
|
// Create Systems
|
||||||
SHADE::SHSystemManager::CreateSystem<SHADE::SHGraphicsSystem>();
|
|
||||||
SHADE::SHSystemManager::CreateSystem<SHADE::SHScriptEngine>();
|
SHADE::SHSystemManager::CreateSystem<SHADE::SHScriptEngine>();
|
||||||
|
// TODO(Diren): Create Physics System here
|
||||||
|
SHADE::SHSystemManager::CreateSystem<SHADE::SHTransformSystem>();
|
||||||
|
SHADE::SHSystemManager::CreateSystem<SHADE::SHGraphicsSystem>();
|
||||||
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
|
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
|
||||||
|
|
||||||
// Create Routines
|
// Create Routines
|
||||||
|
@ -54,6 +58,12 @@ namespace Sandbox
|
||||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHScriptEngine, SHADE::SHScriptEngine::UpdateRoutine>();
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHScriptEngine, SHADE::SHScriptEngine::UpdateRoutine>();
|
||||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHScriptEngine, SHADE::SHScriptEngine::LateUpdateRoutine>();
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHScriptEngine, SHADE::SHScriptEngine::LateUpdateRoutine>();
|
||||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHScriptEngine, SHADE::SHScriptEngine::FrameCleanUpRoutine>();
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHScriptEngine, SHADE::SHScriptEngine::FrameCleanUpRoutine>();
|
||||||
|
|
||||||
|
// TODO(Diren): Register Physics System & Routines here
|
||||||
|
|
||||||
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHTransformSystem, SHADE::SHTransformSystem::TransformUpdateRoutine>();
|
||||||
|
SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHTransformComponent>();
|
||||||
|
|
||||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::BatcherDispatcherRoutine>();
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::BatcherDispatcherRoutine>();
|
||||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::BeginRoutine>();
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::BeginRoutine>();
|
||||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::RenderRoutine>();
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::RenderRoutine>();
|
||||||
|
|
|
@ -39,16 +39,17 @@ namespace Sandbox
|
||||||
auto matInst = graphicsSystem->AddMaterialInstance();
|
auto matInst = graphicsSystem->AddMaterialInstance();
|
||||||
|
|
||||||
// Create entity and add mesh
|
// Create entity and add mesh
|
||||||
testObj = SHADE::SHEntityManager::CreateEntity<SHADE::SHRenderable, SHTransformComponent>();
|
testObj = SHADE::SHEntityManager::CreateEntity<SHADE::SHRenderable, SHADE::SHTransformComponent>();
|
||||||
//SHComponentManager::AddComponent<SHTransformComponent>(testObj);
|
|
||||||
auto& renderable = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHRenderable>(testObj);
|
auto& renderable = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHRenderable>(testObj);
|
||||||
auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
|
auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
|
||||||
|
|
||||||
renderable.Mesh = CUBE_MESH;
|
renderable.Mesh = CUBE_MESH;
|
||||||
renderable.SetMaterial(matInst);
|
renderable.SetMaterial(matInst);
|
||||||
renderable.TransformMatrix.Translate(0.0f, 0.0f, 2.0f);
|
// Create transform
|
||||||
|
auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
|
||||||
// Add script
|
transform.SetLocalPosition(SHVec3{ 0.0f, 0.0f, 2.0f });
|
||||||
|
|
||||||
|
renderable.TransformMatrix = SHMatrix::Translate(0.0f, 0.0f, 2.0f);
|
||||||
SHADE::SHScriptEngine* scriptEngine = static_cast<SHADE::SHScriptEngine*>(SHADE::SHSystemManager::GetSystem<SHADE::SHScriptEngine>());
|
SHADE::SHScriptEngine* scriptEngine = static_cast<SHADE::SHScriptEngine*>(SHADE::SHSystemManager::GetSystem<SHADE::SHScriptEngine>());
|
||||||
scriptEngine->AddScript(*SHADE::SHEntityManager::GetEntityByID(testObj), "TestScript");
|
scriptEngine->AddScript(*SHADE::SHEntityManager::GetEntityByID(testObj), "TestScript");
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,14 +25,12 @@ namespace SHADE
|
||||||
/* Static Data Member Definitions */
|
/* Static Data Member Definitions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
//SHTransformSystem::TransformUpdateRoutine SHTransformSystem::UpdateRoutine;
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Constructors & Destructor Definitions */
|
/* Constructors & Destructor Definitions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
SHTransformSystem::TransformUpdateRoutine::TransformUpdateRoutine()
|
SHTransformSystem::TransformUpdateRoutine::TransformUpdateRoutine()
|
||||||
: SHSystemRoutine { "Transform Update", false }
|
: SHSystemRoutine { "Transform Update", true }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,6 +45,16 @@ namespace SHADE
|
||||||
UpdateEntity(SCENE_GRAPH.GetRoot());
|
UpdateEntity(SCENE_GRAPH.GetRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHTransformSystem::Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHTransformSystem::Exit()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Private Function Member Definitions */
|
/* Private Function Member Definitions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
@ -58,19 +66,8 @@ namespace SHADE
|
||||||
|
|
||||||
for (const auto* child : node->GetChildren())
|
for (const auto* child : node->GetChildren())
|
||||||
{
|
{
|
||||||
// Active states of entities should sync with scene nodes
|
|
||||||
const bool IS_NODE_ACTIVE = child->IsActive();
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
const bool IS_ENTITY_ACTIVE = SHEntityManager::GetEntityByID(child->GetEntityID())->GetActive();
|
|
||||||
SHASSERT(IS_NODE_ACTIVE == IS_ENTITY_ACTIVE, "Entity and Node active states are not synced!")
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!IS_NODE_ACTIVE)
|
|
||||||
{
|
|
||||||
UpdateEntity(child);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool HAS_TRANSFORM = SHComponentManager::HasComponent<SHTransformComponent>(child->GetEntityID());
|
const bool HAS_TRANSFORM = SHComponentManager::HasComponent<SHTransformComponent>(child->GetEntityID());
|
||||||
if (!HAS_TRANSFORM)
|
if (!HAS_TRANSFORM)
|
||||||
|
@ -78,8 +75,13 @@ namespace SHADE
|
||||||
|
|
||||||
auto* childTransform = SHComponentManager::GetComponent<SHTransformComponent>(child->GetEntityID());
|
auto* childTransform = SHComponentManager::GetComponent<SHTransformComponent>(child->GetEntityID());
|
||||||
|
|
||||||
if (childTransform->dirty || HAS_PARENT_CHANGED)
|
// Only update if node in hierarchy and component are both active
|
||||||
UpdateTransform(*childTransform, NODE_TRANSFORM);
|
const bool IS_NODE_ACTIVE = child->IsActive();
|
||||||
|
if (IS_NODE_ACTIVE && childTransform->isActive)
|
||||||
|
{
|
||||||
|
if (childTransform->dirty || HAS_PARENT_CHANGED)
|
||||||
|
UpdateTransform(*childTransform, NODE_TRANSFORM);
|
||||||
|
}
|
||||||
|
|
||||||
UpdateEntity(child);
|
UpdateEntity(child);
|
||||||
|
|
||||||
|
@ -96,7 +98,7 @@ namespace SHADE
|
||||||
if (parent)
|
if (parent)
|
||||||
{
|
{
|
||||||
localToWorld = parent->GetTRS();
|
localToWorld = parent->GetTRS();
|
||||||
worldToLocal = SHMatrix::Inverse(tf.local.trs);
|
worldToLocal = SHMatrix::Inverse(localToWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!tf.updateQueue.empty())
|
while (!tf.updateQueue.empty())
|
||||||
|
@ -140,6 +142,10 @@ namespace SHADE
|
||||||
tf.world.scale = tf.local.scale * (parent ? parent->GetLocalScale() : SHVec3::One);
|
tf.world.scale = tf.local.scale * (parent ? parent->GetLocalScale() : SHVec3::One);
|
||||||
|
|
||||||
tf.world.ComputeTRS();
|
tf.world.ComputeTRS();
|
||||||
|
|
||||||
|
// Transpose TRS to column major
|
||||||
|
tf.local.trs.Transpose();
|
||||||
|
tf.world.trs.Transpose();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace SHADE
|
} // namespace SHADE
|
|
@ -21,7 +21,7 @@ namespace SHADE
|
||||||
/* Type Definitions */
|
/* Type Definitions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class SH_API SHTransformSystem : public SHSystem
|
class SH_API SHTransformSystem final : public SHSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -29,7 +29,7 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
SHTransformSystem () = default;
|
SHTransformSystem () = default;
|
||||||
~SHTransformSystem () = default;
|
~SHTransformSystem () override = default;
|
||||||
|
|
||||||
SHTransformSystem (const SHTransformSystem&) = delete;
|
SHTransformSystem (const SHTransformSystem&) = delete;
|
||||||
SHTransformSystem (SHTransformSystem&&) = delete;
|
SHTransformSystem (SHTransformSystem&&) = delete;
|
||||||
|
@ -45,7 +45,7 @@ namespace SHADE
|
||||||
/* System Routines */
|
/* System Routines */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class TransformUpdateRoutine : public SHSystemRoutine
|
class SH_API TransformUpdateRoutine final: public SHSystemRoutine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*-------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------*/
|
||||||
|
@ -72,7 +72,12 @@ namespace SHADE
|
||||||
void Execute(double dt) noexcept override;
|
void Execute(double dt) noexcept override;
|
||||||
};
|
};
|
||||||
|
|
||||||
//static TransformUpdateRoutine UpdateRoutine;
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Function Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void Init () override;
|
||||||
|
void Exit () override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -497,9 +497,16 @@ namespace SHADE
|
||||||
SHSceneNode* newNode = AllocateNode(entityID);
|
SHSceneNode* newNode = AllocateNode(entityID);
|
||||||
|
|
||||||
if (parent == nullptr)
|
if (parent == nullptr)
|
||||||
|
{
|
||||||
|
// Specific handling for root to avoid a warning when removing a non-existent child
|
||||||
parent = root;
|
parent = root;
|
||||||
|
newNode->parent = root;
|
||||||
newNode->SetParent(parent);
|
root->children.emplace_back(newNode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newNode->SetParent(parent);
|
||||||
|
}
|
||||||
|
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue