Merge branch 'main' into SP3-6-c-scripting
This commit is contained in:
commit
2051d485eb
|
@ -53,7 +53,7 @@ namespace SHADE
|
|||
for (const auto* child : node->GetChildren())
|
||||
{
|
||||
// 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
|
||||
const bool IS_ENTITY_ACTIVE = SHEntityManager::GetEntityByID(child->GetEntityID())->GetActive();
|
||||
|
|
|
@ -25,14 +25,14 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
SHSceneNode::SHSceneNode(EntityID eid, SHSceneNode* parent) noexcept
|
||||
: isActive { true }
|
||||
: active { true }
|
||||
, entityID { eid }
|
||||
, parent { parent }
|
||||
{}
|
||||
|
||||
|
||||
SHSceneNode::SHSceneNode(const SHSceneNode& rhs) noexcept
|
||||
: isActive { rhs.isActive }
|
||||
: active { rhs.active }
|
||||
, entityID { rhs.entityID }
|
||||
, parent { rhs.parent }
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
SHSceneNode::SHSceneNode(SHSceneNode&& rhs) noexcept
|
||||
: isActive { rhs.isActive }
|
||||
: active { rhs.active }
|
||||
, entityID { rhs.entityID }
|
||||
, parent { rhs.parent }
|
||||
{
|
||||
|
@ -52,9 +52,9 @@ namespace SHADE
|
|||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
isActive = rhs.isActive;
|
||||
entityID = rhs.entityID;
|
||||
parent = rhs.parent;
|
||||
active = rhs.active;
|
||||
entityID = rhs.entityID;
|
||||
parent = rhs.parent;
|
||||
|
||||
children.clear();
|
||||
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
|
||||
{
|
||||
isActive = rhs.isActive;
|
||||
entityID = rhs.entityID;
|
||||
parent = rhs.parent;
|
||||
active = rhs.active;
|
||||
entityID = rhs.entityID;
|
||||
parent = rhs.parent;
|
||||
|
||||
children.clear();
|
||||
std::ranges::copy(rhs.children.begin(), rhs.children.end(), std::back_inserter(children));
|
||||
|
@ -104,6 +104,11 @@ namespace SHADE
|
|||
/* Getter Function Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
bool SHSceneNode::IsActive() const noexcept
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
EntityID SHSceneNode::GetEntityID() const noexcept
|
||||
{
|
||||
return entityID;
|
||||
|
@ -154,7 +159,7 @@ namespace SHADE
|
|||
if (root != nullptr)
|
||||
return root;
|
||||
|
||||
SHLOG_WARNING("Scene has no root object!")
|
||||
SHLOG_ERROR("Scene has no root object!")
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -171,7 +176,7 @@ namespace SHADE
|
|||
const auto NODE_ITER = entityNodeMap.find(entityID);
|
||||
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;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
|
@ -192,7 +197,7 @@ namespace SHADE
|
|||
const auto NODE_ITER = entityNodeMap.find(entityID);
|
||||
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;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
|
@ -213,7 +218,7 @@ namespace SHADE
|
|||
const auto NODE_ITER = entityNodeMap.find(entityID);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -248,7 +253,7 @@ namespace SHADE
|
|||
const auto NODE_ITER = entityNodeMap.find(entityID);
|
||||
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;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
|
@ -269,7 +274,7 @@ namespace SHADE
|
|||
const auto NODE_ITER = entityNodeMap.find(entityID);
|
||||
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();
|
||||
}
|
||||
////////////////////////////////////////
|
||||
|
@ -277,6 +282,27 @@ namespace SHADE
|
|||
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 */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -289,7 +315,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
// Handle self assignment
|
||||
if (parentNode == parent)
|
||||
if (parent && parentNode->entityID == parent->entityID)
|
||||
return;
|
||||
|
||||
if (parent)
|
||||
|
@ -300,6 +326,16 @@ namespace SHADE
|
|||
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
|
||||
{
|
||||
////////////////////////////////////////
|
||||
|
@ -318,6 +354,9 @@ namespace SHADE
|
|||
}
|
||||
////////////////////////////////////////
|
||||
|
||||
if (parent == nullptr)
|
||||
parent = root;
|
||||
|
||||
NODE_ITER->second->SetParent(parent);
|
||||
}
|
||||
|
||||
|
@ -340,14 +379,14 @@ namespace SHADE
|
|||
auto NODE_ITER = entityNodeMap.find(entityID);
|
||||
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;
|
||||
}
|
||||
|
||||
auto PARENT_ITER = entityNodeMap.find(parent);
|
||||
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;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
|
@ -476,7 +515,7 @@ namespace SHADE
|
|||
auto NODE_ITER = entityNodeMap.find(entityID);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,12 +38,6 @@ namespace SHADE
|
|||
friend class SHSceneGraph;
|
||||
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
bool isActive;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors & Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -60,6 +54,7 @@ namespace SHADE
|
|||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
[[nodiscard]] bool IsActive () const noexcept;
|
||||
[[nodiscard]] EntityID GetEntityID () const noexcept;
|
||||
[[nodiscard]] SHSceneNode* GetParent () const noexcept;
|
||||
[[nodiscard]] const std::vector<SHSceneNode*>& GetChildren () const noexcept;
|
||||
|
@ -70,7 +65,8 @@ namespace SHADE
|
|||
/* Setter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
void SetParent (SHSceneNode* parentNode) noexcept;
|
||||
void SetParent (SHSceneNode* parentNode) noexcept;
|
||||
void SetActive (bool newActiveState) noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Function Members */
|
||||
|
@ -88,6 +84,7 @@ namespace SHADE
|
|||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
bool active;
|
||||
EntityID entityID;
|
||||
SHSceneNode* parent;
|
||||
std::vector<SHSceneNode*> children;
|
||||
|
@ -121,12 +118,14 @@ namespace SHADE
|
|||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
[[nodiscard]] const SHSceneNode* GetRoot () const noexcept;
|
||||
[[nodiscard]] SHSceneNode* GetNode (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, EntityID childEntityID) const noexcept;
|
||||
[[nodiscard]] const std::vector<SHSceneNode*>& GetChildren (EntityID entityID) const noexcept;
|
||||
[[nodiscard]] const SHSceneNode* GetRoot () const noexcept;
|
||||
[[nodiscard]] SHSceneNode* GetNode (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, EntityID childEntityID) const noexcept;
|
||||
[[nodiscard]] const std::vector<SHSceneNode*>& GetChildren (EntityID entityID) const noexcept;
|
||||
|
||||
[[nodiscard]] bool IsActiveInHierarchy (EntityID entityID) const noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Setter Functions */
|
||||
|
|
Loading…
Reference in New Issue