Added Scene graph functionality (un tested)
This commit is contained in:
parent
f21aa8836c
commit
44611115fe
|
@ -47,32 +47,57 @@ namespace SHADE
|
|||
|
||||
void SHEntity::SetParent(SHEntity* newParent) noexcept
|
||||
{
|
||||
(void)newParent;
|
||||
//TODO
|
||||
SHSceneManager::GetCurrentSceneGraph().SetParent(GetEID(), newParent->GetEID());
|
||||
}
|
||||
|
||||
void SHEntity::SetParent(EntityID newParentID) noexcept
|
||||
{
|
||||
(void)newParentID;
|
||||
//TODO
|
||||
SHSceneManager::GetCurrentSceneGraph().SetParent(GetEID(), newParentID);
|
||||
}
|
||||
|
||||
SHEntity* SHEntity::GetParent()const noexcept
|
||||
{
|
||||
//TODO
|
||||
SHSceneNode* parent = SHSceneManager::GetCurrentSceneGraph().GetParent(GetEID());
|
||||
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
|
||||
{
|
||||
//TODO
|
||||
return std::vector<SHEntity*>{};
|
||||
std::vector<SHEntity*> childrenEntity;
|
||||
|
||||
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
|
||||
{
|
||||
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;
|
||||
|
||||
/********************************************************************
|
||||
* \brief
|
||||
* Get the entity ID of the parent.
|
||||
* \return
|
||||
* return the entity ID of the parent
|
||||
********************************************************************/
|
||||
EntityID GetParentEID() const noexcept;
|
||||
|
||||
/**************************************************************************
|
||||
* \brief
|
||||
|
|
|
@ -8,5 +8,6 @@ namespace SHADE
|
|||
{
|
||||
EntityID eid;
|
||||
std::vector<ComponentTypeID> componentTypeIDs;
|
||||
EntityID parentEID;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -103,8 +103,16 @@ namespace SHADE
|
|||
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
|
||||
SHEntityCreationEvent event{ eID,componentTypeIDs };
|
||||
SHEntityCreationEvent event{ eID,componentTypeIDs, parentEID };
|
||||
SHEventManager::BroadcastEvent<SHEntityCreationEvent>(event, SH_ENTITY_CREATION_EVENT);
|
||||
|
||||
//(SHComponentManager::AddComponent<ComponentTypes>(eID), ...);
|
||||
|
@ -138,6 +146,14 @@ namespace SHADE
|
|||
//Call all the children to Destroy themselves first before the parent is destroyed.
|
||||
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();
|
||||
//while(!children.empty())
|
||||
//{
|
||||
|
@ -159,6 +175,8 @@ namespace SHADE
|
|||
entityVec[eIndex].reset(nullptr);
|
||||
|
||||
|
||||
|
||||
|
||||
SHEntityDestroyedEvent event{eID};
|
||||
SHEventManager::BroadcastEvent<SHEntityDestroyedEvent>(event, SH_ENTITY_DESTROYED_EVENT);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "ECS_Base/Events/SHEntityCreationEvent.h"
|
||||
#include "ECS_Base/Events/SHEntityDestroyedEvent.h"
|
||||
#include "Events/SHEventManager.h"
|
||||
#include "Scene/SHSceneManager.h"
|
||||
#include "SH_API.h"
|
||||
|
||||
namespace SHADE
|
||||
|
@ -132,10 +133,19 @@ namespace SHADE
|
|||
std::vector<ComponentTypeID> typeIDVec;
|
||||
(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);
|
||||
|
||||
|
||||
|
||||
/*if (entityHandle.IsValid(parentEID) == false)
|
||||
{
|
||||
entityVec[eIndex]->sceneNode.ConnectToRoot();
|
||||
|
@ -146,8 +156,6 @@ namespace SHADE
|
|||
}*/
|
||||
|
||||
|
||||
//Link up with scene graph.
|
||||
|
||||
|
||||
return eID;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#define SH_SCENE_H
|
||||
|
||||
#include <string>
|
||||
#include "SHSceneGraph.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -19,15 +20,19 @@ namespace SHADE
|
|||
class SHScene
|
||||
{
|
||||
private:
|
||||
SHSceneGraph sceneGraph;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
SHScene() = default;
|
||||
|
||||
public:
|
||||
virtual ~SHScene() = default;
|
||||
|
||||
std::string sceneName;
|
||||
|
||||
virtual ~SHScene() = default;
|
||||
SHSceneGraph& GetSceneGraph() noexcept { return sceneGraph; }
|
||||
|
||||
virtual void Load() = 0;
|
||||
virtual void Init() = 0;
|
||||
|
|
|
@ -37,6 +37,12 @@ namespace SHADE
|
|||
std::function<void()> SHSceneManager::newScene = []() {};
|
||||
//void (*SHSceneManager::prevSceneCreate)() = []() {};
|
||||
|
||||
|
||||
SHSceneGraph& SHSceneManager::GetCurrentSceneGraph() noexcept
|
||||
{
|
||||
return currentScene->GetSceneGraph();
|
||||
}
|
||||
|
||||
void SHSceneManager::UpdateSceneManager() noexcept
|
||||
{
|
||||
if (sceneChanged == false)
|
||||
|
|
|
@ -57,6 +57,15 @@ namespace SHADE
|
|||
//boolean to check if the programme has been terminated.
|
||||
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
|
||||
* Initialize scene manager and loads a default scene
|
||||
|
|
Loading…
Reference in New Issue