Merge pull request #33 from SHADE-DP/SP3-5-ECS
SP3-5 ecs Added Scene Graph functionality to Entity, Scene graph set parent missing old parent check (diren handling) Scene graph functionality untested. Added SH_API to Scene Graph
This commit is contained in:
commit
624c8fa4d6
|
@ -47,32 +47,57 @@ namespace SHADE
|
||||||
|
|
||||||
void SHEntity::SetParent(SHEntity* newParent) noexcept
|
void SHEntity::SetParent(SHEntity* newParent) noexcept
|
||||||
{
|
{
|
||||||
(void)newParent;
|
SHSceneManager::GetCurrentSceneGraph().SetParent(GetEID(), newParent->GetEID());
|
||||||
//TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHEntity::SetParent(EntityID newParentID) noexcept
|
void SHEntity::SetParent(EntityID newParentID) noexcept
|
||||||
{
|
{
|
||||||
(void)newParentID;
|
SHSceneManager::GetCurrentSceneGraph().SetParent(GetEID(), newParentID);
|
||||||
//TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SHEntity* SHEntity::GetParent()const noexcept
|
SHEntity* SHEntity::GetParent()const noexcept
|
||||||
{
|
{
|
||||||
//TODO
|
SHSceneNode* parent = SHSceneManager::GetCurrentSceneGraph().GetParent(GetEID());
|
||||||
return nullptr;
|
if (parent != nullptr)
|
||||||
|
return SHEntityManager::GetEntityByID(parent->GetEntityID());
|
||||||
|
else
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityID SHEntity::GetParentEID()const noexcept
|
||||||
|
{
|
||||||
|
SHSceneNode* parent = SHSceneManager::GetCurrentSceneGraph().GetParent(GetEID());
|
||||||
|
if (parent != nullptr)
|
||||||
|
return parent->GetEntityID();
|
||||||
|
else
|
||||||
|
return MAX_EID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<SHEntity*>const& SHEntity::GetChildren()const noexcept
|
std::vector<SHEntity*>const& SHEntity::GetChildren()const noexcept
|
||||||
{
|
{
|
||||||
//TODO
|
std::vector<SHEntity*> childrenEntity;
|
||||||
return std::vector<SHEntity*>{};
|
|
||||||
|
auto& childrenNodes = SHSceneManager::GetCurrentSceneGraph().GetChildren(GetEID());
|
||||||
|
for (auto& childNode : childrenNodes)
|
||||||
|
{
|
||||||
|
childrenEntity.push_back(SHEntityManager::GetEntityByID(childNode->GetEntityID()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return childrenEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<EntityID>const& SHEntity::GetChildrenID()const noexcept
|
std::vector<EntityID>const& SHEntity::GetChildrenID()const noexcept
|
||||||
{
|
{
|
||||||
return std::vector<EntityID>{};
|
std::vector<EntityID> childrenEntity;
|
||||||
|
|
||||||
|
auto& childrenNodes = SHSceneManager::GetCurrentSceneGraph().GetChildren(GetEID());
|
||||||
|
for (auto& childNode : childrenNodes)
|
||||||
|
{
|
||||||
|
childrenEntity.push_back(childNode->GetEntityID());
|
||||||
|
}
|
||||||
|
|
||||||
|
return childrenEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,13 @@ namespace SHADE
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
SHEntity* GetParent()const noexcept;
|
SHEntity* GetParent()const noexcept;
|
||||||
|
|
||||||
|
/********************************************************************
|
||||||
|
* \brief
|
||||||
|
* Get the entity ID of the parent.
|
||||||
|
* \return
|
||||||
|
* return the entity ID of the parent
|
||||||
|
********************************************************************/
|
||||||
|
EntityID GetParentEID() const noexcept;
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* \brief
|
* \brief
|
||||||
|
|
|
@ -8,5 +8,6 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
EntityID eid;
|
EntityID eid;
|
||||||
std::vector<ComponentTypeID> componentTypeIDs;
|
std::vector<ComponentTypeID> componentTypeIDs;
|
||||||
|
EntityID parentEID;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,8 +103,16 @@ namespace SHADE
|
||||||
SHComponentManager::AddComponent(eID, id);
|
SHComponentManager::AddComponent(eID, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Link up with scene graph.
|
||||||
|
|
||||||
|
if (parentEID != MAX_EID)
|
||||||
|
SHSceneManager::GetCurrentSceneGraph().AddNode(eID, SHSceneManager::GetCurrentSceneGraph().GetNode(parentEID));
|
||||||
|
else
|
||||||
|
SHSceneManager::GetCurrentSceneGraph().AddNode(eID);
|
||||||
|
|
||||||
//set up event stuff
|
//set up event stuff
|
||||||
SHEntityCreationEvent event{ eID,componentTypeIDs };
|
SHEntityCreationEvent event{ eID,componentTypeIDs, parentEID };
|
||||||
SHEventManager::BroadcastEvent<SHEntityCreationEvent>(event, SH_ENTITY_CREATION_EVENT);
|
SHEventManager::BroadcastEvent<SHEntityCreationEvent>(event, SH_ENTITY_CREATION_EVENT);
|
||||||
|
|
||||||
//(SHComponentManager::AddComponent<ComponentTypes>(eID), ...);
|
//(SHComponentManager::AddComponent<ComponentTypes>(eID), ...);
|
||||||
|
@ -138,6 +146,14 @@ namespace SHADE
|
||||||
//Call all the children to Destroy themselves first before the parent is destroyed.
|
//Call all the children to Destroy themselves first before the parent is destroyed.
|
||||||
if (entityVec[eIndex])
|
if (entityVec[eIndex])
|
||||||
{
|
{
|
||||||
|
auto& children = SHSceneManager::GetCurrentSceneGraph().GetChildren(eID);
|
||||||
|
for (auto& child : children)
|
||||||
|
{
|
||||||
|
DestroyEntity(child->GetEntityID());
|
||||||
|
}
|
||||||
|
|
||||||
|
SHSceneManager::GetCurrentSceneGraph().RemoveNode(eID);
|
||||||
|
|
||||||
//auto& children = entityVec[eIndex]->GetChildrenID();
|
//auto& children = entityVec[eIndex]->GetChildrenID();
|
||||||
//while(!children.empty())
|
//while(!children.empty())
|
||||||
//{
|
//{
|
||||||
|
@ -159,6 +175,8 @@ namespace SHADE
|
||||||
entityVec[eIndex].reset(nullptr);
|
entityVec[eIndex].reset(nullptr);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SHEntityDestroyedEvent event{eID};
|
SHEntityDestroyedEvent event{eID};
|
||||||
SHEventManager::BroadcastEvent<SHEntityDestroyedEvent>(event, SH_ENTITY_DESTROYED_EVENT);
|
SHEventManager::BroadcastEvent<SHEntityDestroyedEvent>(event, SH_ENTITY_DESTROYED_EVENT);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "../SHECSMacros.h"
|
#include "../SHECSMacros.h"
|
||||||
#include "ECS_Base/Events/SHEntityCreationEvent.h"
|
#include "ECS_Base/Events/SHEntityCreationEvent.h"
|
||||||
#include "ECS_Base/Events/SHEntityDestroyedEvent.h"
|
#include "ECS_Base/Events/SHEntityDestroyedEvent.h"
|
||||||
|
#include "Scene/SHSceneManager.h"
|
||||||
#include "Events/SHEventManager.hpp"
|
#include "Events/SHEventManager.hpp"
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
|
|
||||||
|
@ -132,10 +133,19 @@ namespace SHADE
|
||||||
std::vector<ComponentTypeID> typeIDVec;
|
std::vector<ComponentTypeID> typeIDVec;
|
||||||
(typeIDVec.push_back(ComponentFamily::GetID<ComponentTypes>()), ...);
|
(typeIDVec.push_back(ComponentFamily::GetID<ComponentTypes>()), ...);
|
||||||
|
|
||||||
SHEntityCreationEvent event{ eID,typeIDVec };
|
|
||||||
|
//Link up with scene graph.
|
||||||
|
|
||||||
|
if (parentEID != MAX_EID)
|
||||||
|
SHSceneManager::GetCurrentSceneGraph().AddNode(eID, SHSceneManager::GetCurrentSceneGraph().GetNode(parentEID));
|
||||||
|
else
|
||||||
|
SHSceneManager::GetCurrentSceneGraph().AddNode(eID);
|
||||||
|
|
||||||
|
SHEntityCreationEvent event{ eID,typeIDVec,parentEID };
|
||||||
SHEventManager::BroadcastEvent<SHEntityCreationEvent>(event, SH_ENTITY_CREATION_EVENT);
|
SHEventManager::BroadcastEvent<SHEntityCreationEvent>(event, SH_ENTITY_CREATION_EVENT);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*if (entityHandle.IsValid(parentEID) == false)
|
/*if (entityHandle.IsValid(parentEID) == false)
|
||||||
{
|
{
|
||||||
entityVec[eIndex]->sceneNode.ConnectToRoot();
|
entityVec[eIndex]->sceneNode.ConnectToRoot();
|
||||||
|
@ -146,8 +156,6 @@ namespace SHADE
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
//Link up with scene graph.
|
|
||||||
|
|
||||||
|
|
||||||
return eID;
|
return eID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace SHADE
|
||||||
std::string const GetName() const noexcept;
|
std::string const GetName() const noexcept;
|
||||||
SHRoutineStats const& GetStats()const noexcept;
|
SHRoutineStats const& GetStats()const noexcept;
|
||||||
|
|
||||||
virtual void Execute(double dt) noexcept {};
|
virtual void Execute(double dt) noexcept { (void)dt; };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ namespace SHADE
|
||||||
SHLOG_INFO("Test for add and remove component")
|
SHLOG_INFO("Test for add and remove component")
|
||||||
|
|
||||||
EntityID id1 = SHEntityManager::CreateEntity();
|
EntityID id1 = SHEntityManager::CreateEntity();
|
||||||
EntityID id2 = SHEntityManager::CreateEntity();
|
SHEntityManager::CreateEntity();
|
||||||
EntityID id3 = SHEntityManager::CreateEntity();
|
SHEntityManager::CreateEntity();
|
||||||
|
|
||||||
|
|
||||||
SHComponentManager::AddComponent<SHComponent_A>(id1);
|
SHComponentManager::AddComponent<SHComponent_A>(id1);
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace SHADE
|
||||||
|
|
||||||
virtual void Execute(double dt) noexcept
|
virtual void Execute(double dt) noexcept
|
||||||
{
|
{
|
||||||
|
(void)dt;
|
||||||
std::cout << GetName() << " System Version: " << GetSystem()->GetSystemVersion() << std::endl;
|
std::cout << GetName() << " System Version: " << GetSystem()->GetSystemVersion() << std::endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#define SH_SCENE_H
|
#define SH_SCENE_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "SHSceneGraph.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -19,15 +20,19 @@ namespace SHADE
|
||||||
class SHScene
|
class SHScene
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
SHSceneGraph sceneGraph;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
SHScene() = default;
|
SHScene() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual ~SHScene() = default;
|
||||||
|
|
||||||
std::string sceneName;
|
std::string sceneName;
|
||||||
|
|
||||||
virtual ~SHScene() = default;
|
SHSceneGraph& GetSceneGraph() noexcept { return sceneGraph; }
|
||||||
|
|
||||||
virtual void Load() = 0;
|
virtual void Load() = 0;
|
||||||
virtual void Init() = 0;
|
virtual void Init() = 0;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
// Project Headers
|
// Project Headers
|
||||||
#include "ECS_Base/Entity/SHEntity.h"
|
#include "ECS_Base/Entity/SHEntity.h"
|
||||||
|
#include "SH_API.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -21,7 +22,7 @@ namespace SHADE
|
||||||
/* Type Definitions */
|
/* Type Definitions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class SHSceneNode
|
class SH_API SHSceneNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -75,7 +76,7 @@ namespace SHADE
|
||||||
std::vector<SHSceneNode*> children;
|
std::vector<SHSceneNode*> children;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SHSceneGraph
|
class SH_API SHSceneGraph
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -37,6 +37,12 @@ namespace SHADE
|
||||||
std::function<void()> SHSceneManager::newScene = []() {};
|
std::function<void()> SHSceneManager::newScene = []() {};
|
||||||
//void (*SHSceneManager::prevSceneCreate)() = []() {};
|
//void (*SHSceneManager::prevSceneCreate)() = []() {};
|
||||||
|
|
||||||
|
|
||||||
|
SHSceneGraph& SHSceneManager::GetCurrentSceneGraph() noexcept
|
||||||
|
{
|
||||||
|
return currentScene->GetSceneGraph();
|
||||||
|
}
|
||||||
|
|
||||||
void SHSceneManager::UpdateSceneManager() noexcept
|
void SHSceneManager::UpdateSceneManager() noexcept
|
||||||
{
|
{
|
||||||
if (sceneChanged == false)
|
if (sceneChanged == false)
|
||||||
|
|
|
@ -57,6 +57,15 @@ namespace SHADE
|
||||||
//boolean to check if the programme has been terminated.
|
//boolean to check if the programme has been terminated.
|
||||||
static bool quit;
|
static bool quit;
|
||||||
|
|
||||||
|
/********************************************************************
|
||||||
|
* \brief
|
||||||
|
* Get the scene graph of the current scene.
|
||||||
|
* \return
|
||||||
|
* A reference to the scene graph of the current active scene.
|
||||||
|
********************************************************************/
|
||||||
|
static SHSceneGraph& GetCurrentSceneGraph() noexcept;
|
||||||
|
|
||||||
|
|
||||||
/*!*************************************************************************
|
/*!*************************************************************************
|
||||||
* \brief
|
* \brief
|
||||||
* Initialize scene manager and loads a default scene
|
* Initialize scene manager and loads a default scene
|
||||||
|
|
Loading…
Reference in New Issue