Merge pull request #46 from SHADE-DP/SP3-16-Math

SP3-16 Transform System integration into Application

UPDATES

Added missing instantiation of transform system into application
BUGFIXES

Fixed an error with the Transform System being an abstract class.
Fixed warning coming from Scene Graph when adding new nodes.
Changed editor pause to true for the Transform System
This commit is contained in:
XiaoQiDigipen 2022-09-23 00:32:55 +08:00 committed by GitHub
commit 7f527c30f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 17 deletions

View File

@ -22,6 +22,7 @@
#include "ECS_Base/Managers/SHEntityManager.h"
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Scene/SHSceneManager.h"
#include "Math/Transform/SHTransformSystem.h"
#include "Scenes/SBTestScene.h"
@ -45,8 +46,10 @@ namespace Sandbox
window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
// Create Systems
SHADE::SHSystemManager::CreateSystem<SHADE::SHGraphicsSystem>();
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>());
// Create Routines
@ -54,6 +57,12 @@ namespace Sandbox
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHScriptEngine, SHADE::SHScriptEngine::UpdateRoutine>();
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHScriptEngine, SHADE::SHScriptEngine::LateUpdateRoutine>();
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::BeginRoutine>();
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::RenderRoutine>();

View File

@ -8,6 +8,7 @@
#include "Scene/SHSceneManager.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
#include "Scripting/SHScriptEngine.h"
#include "Math/Transform/SHTransformComponent.h"
using namespace SHADE;
@ -38,11 +39,15 @@ namespace Sandbox
auto matInst = graphicsSystem->AddMaterialInstance();
// Create entity and add mesh
testObj = SHADE::SHEntityManager::CreateEntity<SHADE::SHRenderable>();
testObj = SHADE::SHEntityManager::CreateEntity<SHADE::SHRenderable, SHADE::SHTransformComponent>();
auto& renderable = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHRenderable>(testObj);
renderable.Mesh = CUBE_MESH;
renderable.SetMaterial(matInst);
renderable.TransformMatrix.Translate(0.0f, 0.0f, 2.0f);
// Create transform
auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
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>());
scriptEngine->AddScript(*SHADE::SHEntityManager::GetEntityByID(testObj), "TestScript");
}

View File

@ -25,14 +25,12 @@ namespace SHADE
/* Static Data Member Definitions */
/*-----------------------------------------------------------------------------------*/
//SHTransformSystem::TransformUpdateRoutine SHTransformSystem::UpdateRoutine;
/*-----------------------------------------------------------------------------------*/
/* Constructors & Destructor Definitions */
/*-----------------------------------------------------------------------------------*/
SHTransformSystem::TransformUpdateRoutine::TransformUpdateRoutine()
: SHSystemRoutine { "Transform Update", false }
: SHSystemRoutine { "Transform Update", true }
{}
@ -47,6 +45,16 @@ namespace SHADE
UpdateEntity(SCENE_GRAPH.GetRoot());
}
void SHTransformSystem::Init()
{
}
void SHTransformSystem::Exit()
{
}
/*-----------------------------------------------------------------------------------*/
/* Private Function Member Definitions */
/*-----------------------------------------------------------------------------------*/
@ -66,11 +74,9 @@ namespace SHADE
SHASSERT(IS_NODE_ACTIVE == IS_ENTITY_ACTIVE, "Entity and Node active states are not synced!")
#endif
// Anything below is inactive
if (!IS_NODE_ACTIVE)
{
UpdateEntity(child);
continue;
}
break;
const bool HAS_TRANSFORM = SHComponentManager::HasComponent<SHTransformComponent>(child->GetEntityID());
if (!HAS_TRANSFORM)
@ -96,7 +102,7 @@ namespace SHADE
if (parent)
{
localToWorld = parent->GetTRS();
worldToLocal = SHMatrix::Inverse(tf.local.trs);
worldToLocal = SHMatrix::Inverse(localToWorld);
}
while (!tf.updateQueue.empty())
@ -140,6 +146,10 @@ namespace SHADE
tf.world.scale = tf.local.scale * (parent ? parent->GetLocalScale() : SHVec3::One);
tf.world.ComputeTRS();
// Transpose TRS to column major
tf.local.trs.Transpose();
tf.world.trs.Transpose();
}
} // namespace SHADE

View File

@ -21,7 +21,7 @@ namespace SHADE
/* Type Definitions */
/*-----------------------------------------------------------------------------------*/
class SH_API SHTransformSystem : public SHSystem
class SH_API SHTransformSystem final : public SHSystem
{
public:
/*---------------------------------------------------------------------------------*/
@ -29,7 +29,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
SHTransformSystem () = default;
~SHTransformSystem () = default;
~SHTransformSystem () override = default;
SHTransformSystem (const SHTransformSystem&) = delete;
SHTransformSystem (SHTransformSystem&&) = delete;
@ -45,7 +45,7 @@ namespace SHADE
/* System Routines */
/*---------------------------------------------------------------------------------*/
class TransformUpdateRoutine : public SHSystemRoutine
class SH_API TransformUpdateRoutine final: public SHSystemRoutine
{
public:
/*-------------------------------------------------------------------------------*/
@ -72,7 +72,12 @@ namespace SHADE
void Execute(double dt) noexcept override;
};
//static TransformUpdateRoutine UpdateRoutine;
/*---------------------------------------------------------------------------------*/
/* Function Members */
/*---------------------------------------------------------------------------------*/
void Init () override;
void Exit () override;
private:
/*---------------------------------------------------------------------------------*/

View File

@ -497,9 +497,16 @@ namespace SHADE
SHSceneNode* newNode = AllocateNode(entityID);
if (parent == nullptr)
{
// Specific handling for root to avoid a warning when removing a non-existent child
parent = root;
newNode->SetParent(parent);
newNode->parent = root;
root->children.emplace_back(newNode);
}
else
{
newNode->SetParent(parent);
}
return newNode;
}