SP3-12 Hierarchical Active States #41
|
@ -53,7 +53,7 @@ namespace SHADE
|
||||||
for (const auto* child : node->GetChildren())
|
for (const auto* child : node->GetChildren())
|
||||||
{
|
{
|
||||||
// Active states of entities should sync with scene nodes
|
// Active states of entities should sync with scene nodes
|
||||||
const bool IS_NODE_ACTIVE = child->isActive;
|
const bool IS_NODE_ACTIVE = child->IsActive();
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
const bool IS_ENTITY_ACTIVE = SHEntityManager::GetEntityByID(child->GetEntityID())->GetActive();
|
const bool IS_ENTITY_ACTIVE = SHEntityManager::GetEntityByID(child->GetEntityID())->GetActive();
|
||||||
|
|
|
@ -25,14 +25,14 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
SHSceneNode::SHSceneNode(EntityID eid, SHSceneNode* parent) noexcept
|
SHSceneNode::SHSceneNode(EntityID eid, SHSceneNode* parent) noexcept
|
||||||
: isActive { true }
|
: active { true }
|
||||||
, entityID { eid }
|
, entityID { eid }
|
||||||
, parent { parent }
|
, parent { parent }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
SHSceneNode::SHSceneNode(const SHSceneNode& rhs) noexcept
|
SHSceneNode::SHSceneNode(const SHSceneNode& rhs) noexcept
|
||||||
: isActive { rhs.isActive }
|
: active { rhs.active }
|
||||||
, entityID { rhs.entityID }
|
, entityID { rhs.entityID }
|
||||||
, parent { rhs.parent }
|
, parent { rhs.parent }
|
||||||
{
|
{
|
||||||
|
@ -40,7 +40,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
SHSceneNode::SHSceneNode(SHSceneNode&& rhs) noexcept
|
SHSceneNode::SHSceneNode(SHSceneNode&& rhs) noexcept
|
||||||
: isActive { rhs.isActive }
|
: active { rhs.active }
|
||||||
, entityID { rhs.entityID }
|
, entityID { rhs.entityID }
|
||||||
, parent { rhs.parent }
|
, parent { rhs.parent }
|
||||||
{
|
{
|
||||||
|
@ -52,9 +52,9 @@ namespace SHADE
|
||||||
if (this == &rhs)
|
if (this == &rhs)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
isActive = rhs.isActive;
|
active = rhs.active;
|
||||||
entityID = rhs.entityID;
|
entityID = rhs.entityID;
|
||||||
parent = rhs.parent;
|
parent = rhs.parent;
|
||||||
|
|
||||||
children.clear();
|
children.clear();
|
||||||
std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children));
|
std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children));
|
||||||
|
@ -64,9 +64,9 @@ namespace SHADE
|
||||||
|
|
||||||
SHSceneNode& SHSceneNode::operator=(SHSceneNode&& rhs) noexcept
|
SHSceneNode& SHSceneNode::operator=(SHSceneNode&& rhs) noexcept
|
||||||
{
|
{
|
||||||
isActive = rhs.isActive;
|
active = rhs.active;
|
||||||
entityID = rhs.entityID;
|
entityID = rhs.entityID;
|
||||||
parent = rhs.parent;
|
parent = rhs.parent;
|
||||||
|
|
||||||
children.clear();
|
children.clear();
|
||||||
std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children));
|
std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children));
|
||||||
|
@ -104,6 +104,11 @@ namespace SHADE
|
||||||
/* Getter Function Definitions */
|
/* Getter Function Definitions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
bool SHSceneNode::IsActive() const noexcept
|
||||||
|
{
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
|
||||||
EntityID SHSceneNode::GetEntityID() const noexcept
|
EntityID SHSceneNode::GetEntityID() const noexcept
|
||||||
{
|
{
|
||||||
return entityID;
|
return entityID;
|
||||||
|
@ -154,7 +159,7 @@ namespace SHADE
|
||||||
if (root != nullptr)
|
if (root != nullptr)
|
||||||
return root;
|
return root;
|
||||||
|
|
||||||
SHLOG_WARNING("Scene has no root object!")
|
SHLOG_ERROR("Scene has no root object!")
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +176,7 @@ namespace SHADE
|
||||||
const auto NODE_ITER = entityNodeMap.find(entityID);
|
const auto NODE_ITER = entityNodeMap.find(entityID);
|
||||||
if (NODE_ITER == entityNodeMap.end())
|
if (NODE_ITER == entityNodeMap.end())
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Entity {} cannot be found in the scene! Unable to Get Scene node!", entityID)
|
SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to Get Scene node!", entityID)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
@ -192,7 +197,7 @@ namespace SHADE
|
||||||
const auto NODE_ITER = entityNodeMap.find(entityID);
|
const auto NODE_ITER = entityNodeMap.find(entityID);
|
||||||
if (NODE_ITER == entityNodeMap.end())
|
if (NODE_ITER == entityNodeMap.end())
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Entity {} cannot be found in the scene! Unable to get Parent node!", entityID)
|
SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to get Parent node!", entityID)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
@ -213,7 +218,7 @@ namespace SHADE
|
||||||
const auto NODE_ITER = entityNodeMap.find(entityID);
|
const auto NODE_ITER = entityNodeMap.find(entityID);
|
||||||
if (NODE_ITER == entityNodeMap.end())
|
if (NODE_ITER == entityNodeMap.end())
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Entity {} cannot be found in the scene!", entityID)
|
SHLOG_ERROR("Entity {} cannot be found in the scene!", entityID)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +253,7 @@ namespace SHADE
|
||||||
const auto NODE_ITER = entityNodeMap.find(entityID);
|
const auto NODE_ITER = entityNodeMap.find(entityID);
|
||||||
if (NODE_ITER == entityNodeMap.end())
|
if (NODE_ITER == entityNodeMap.end())
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Entity {} cannot be found in the scene!", entityID)
|
SHLOG_ERROR("Entity {} cannot be found in the scene!", entityID)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
@ -269,7 +274,7 @@ namespace SHADE
|
||||||
const auto NODE_ITER = entityNodeMap.find(entityID);
|
const auto NODE_ITER = entityNodeMap.find(entityID);
|
||||||
if (NODE_ITER == entityNodeMap.end())
|
if (NODE_ITER == entityNodeMap.end())
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Entity {} cannot be found in the scene!", entityID)
|
SHLOG_ERROR("Entity {} cannot be found in the scene!", entityID)
|
||||||
return root->GetChildren();
|
return root->GetChildren();
|
||||||
}
|
}
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
@ -277,6 +282,27 @@ namespace SHADE
|
||||||
return NODE_ITER->second->GetChildren();
|
return NODE_ITER->second->GetChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SHSceneGraph::IsActiveInHierarchy(EntityID entityID) const noexcept
|
||||||
|
{
|
||||||
|
////////////////////////////////////////
|
||||||
|
// Error handling
|
||||||
|
if (!SHEntityManager::IsValidEID(entityID))
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Entity {} is invalid!", entityID)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto NODE_ITER = entityNodeMap.find(entityID);
|
||||||
|
if (NODE_ITER == entityNodeMap.end())
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Entity {} cannot be found in the scene!", entityID)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
|
return NODE_ITER->second->IsActive();
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Setter Function Definitions */
|
/* Setter Function Definitions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
@ -289,7 +315,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle self assignment
|
// Handle self assignment
|
||||||
if (parentNode == parent)
|
if (parent && parentNode->entityID == parent->entityID)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (parent)
|
if (parent)
|
||||||
|
@ -300,6 +326,16 @@ namespace SHADE
|
||||||
parent->AddChild(this);
|
parent->AddChild(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHSceneNode::SetActive(bool newActiveState) noexcept
|
||||||
|
{
|
||||||
|
active = newActiveState;
|
||||||
|
|
||||||
|
for (auto* child : children)
|
||||||
|
{
|
||||||
|
SetActive(newActiveState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SHSceneGraph::SetParent(EntityID entityID, SHSceneNode* parent) const noexcept
|
void SHSceneGraph::SetParent(EntityID entityID, SHSceneNode* parent) const noexcept
|
||||||
{
|
{
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
@ -318,6 +354,9 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|
||||||
|
if (parent == nullptr)
|
||||||
|
parent = root;
|
||||||
|
|
||||||
NODE_ITER->second->SetParent(parent);
|
NODE_ITER->second->SetParent(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,14 +379,14 @@ namespace SHADE
|
||||||
auto NODE_ITER = entityNodeMap.find(entityID);
|
auto NODE_ITER = entityNodeMap.find(entityID);
|
||||||
if (NODE_ITER == entityNodeMap.end())
|
if (NODE_ITER == entityNodeMap.end())
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Entity {} cannot be found in the scene! Unable to set parent!", entityID)
|
SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to set parent!", entityID)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto PARENT_ITER = entityNodeMap.find(parent);
|
auto PARENT_ITER = entityNodeMap.find(parent);
|
||||||
if (PARENT_ITER == entityNodeMap.end())
|
if (PARENT_ITER == entityNodeMap.end())
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Entity {} cannot be found in the scene! Unable to parent to Entity {}", parent, entityID)
|
SHLOG_ERROR("Entity {} cannot be found in the scene! Unable to parent to Entity {}", parent, entityID)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
@ -476,7 +515,7 @@ namespace SHADE
|
||||||
auto NODE_ITER = entityNodeMap.find(entityID);
|
auto NODE_ITER = entityNodeMap.find(entityID);
|
||||||
if (NODE_ITER == entityNodeMap.end())
|
if (NODE_ITER == entityNodeMap.end())
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Entity {} does not exist in the scene!", entityID)
|
SHLOG_ERROR("Entity {} does not exist in the scene!", entityID)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,12 +38,6 @@ namespace SHADE
|
||||||
friend class SHSceneGraph;
|
friend class SHSceneGraph;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
/* Data Members */
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
bool isActive;
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Constructors & Destructor */
|
/* Constructors & Destructor */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -60,6 +54,7 @@ namespace SHADE
|
||||||
/* Getter Functions */
|
/* Getter Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
[[nodiscard]] bool IsActive () const noexcept;
|
||||||
[[nodiscard]] EntityID GetEntityID () const noexcept;
|
[[nodiscard]] EntityID GetEntityID () const noexcept;
|
||||||
[[nodiscard]] SHSceneNode* GetParent () const noexcept;
|
[[nodiscard]] SHSceneNode* GetParent () const noexcept;
|
||||||
[[nodiscard]] const std::vector<SHSceneNode*>& GetChildren () const noexcept;
|
[[nodiscard]] const std::vector<SHSceneNode*>& GetChildren () const noexcept;
|
||||||
|
@ -70,7 +65,8 @@ namespace SHADE
|
||||||
/* Setter Functions */
|
/* Setter Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void SetParent (SHSceneNode* parentNode) noexcept;
|
void SetParent (SHSceneNode* parentNode) noexcept;
|
||||||
|
void SetActive (bool newActiveState) noexcept;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Function Members */
|
/* Function Members */
|
||||||
|
@ -88,6 +84,7 @@ namespace SHADE
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
bool active;
|
||||||
EntityID entityID;
|
EntityID entityID;
|
||||||
SHSceneNode* parent;
|
SHSceneNode* parent;
|
||||||
std::vector<SHSceneNode*> children;
|
std::vector<SHSceneNode*> children;
|
||||||
|
@ -121,12 +118,14 @@ namespace SHADE
|
||||||
/* Getter Functions */
|
/* Getter Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
[[nodiscard]] const SHSceneNode* GetRoot () const noexcept;
|
[[nodiscard]] const SHSceneNode* GetRoot () const noexcept;
|
||||||
[[nodiscard]] SHSceneNode* GetNode (EntityID entityID) const noexcept;
|
[[nodiscard]] SHSceneNode* GetNode (EntityID entityID) const noexcept;
|
||||||
[[nodiscard]] SHSceneNode* GetParent (EntityID entityID) const noexcept;
|
[[nodiscard]] SHSceneNode* GetParent (EntityID entityID) const noexcept;
|
||||||
[[nodiscard]] SHSceneNode* GetChild (EntityID entityID, SHSceneNode* childNode) const noexcept;
|
[[nodiscard]] SHSceneNode* GetChild (EntityID entityID, SHSceneNode* childNode) const noexcept;
|
||||||
[[nodiscard]] SHSceneNode* GetChild (EntityID entityID, EntityID childEntityID) const noexcept;
|
[[nodiscard]] SHSceneNode* GetChild (EntityID entityID, EntityID childEntityID) const noexcept;
|
||||||
[[nodiscard]] const std::vector<SHSceneNode*>& GetChildren (EntityID entityID) const noexcept;
|
[[nodiscard]] const std::vector<SHSceneNode*>& GetChildren (EntityID entityID) const noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]] bool IsActiveInHierarchy (EntityID entityID) const noexcept;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Setter Functions */
|
/* Setter Functions */
|
||||||
|
|
Loading…
Reference in New Issue