Added Event for Scene Graph Change Parent
This commit is contained in:
parent
6172ff35b6
commit
5a0b34ceea
|
@ -5,8 +5,9 @@ typedef uint32_t SHEventIdentifier;
|
|||
typedef uint32_t SHEventHandle;
|
||||
|
||||
//Add your event identifiers here:
|
||||
constexpr SHEventIdentifier SH_EXAMPLE_EVENT{0};
|
||||
constexpr SHEventIdentifier SH_ENTITY_DESTROYED_EVENT{ 1 };
|
||||
constexpr SHEventIdentifier SH_ENTITY_CREATION_EVENT{ 2 };
|
||||
constexpr SHEventIdentifier SH_COMPONENT_ADDED_EVENT{ 3 };
|
||||
constexpr SHEventIdentifier SH_COMPONENT_REMOVED_EVENT{ 4 };
|
||||
constexpr SHEventIdentifier SH_EXAMPLE_EVENT { 0 };
|
||||
constexpr SHEventIdentifier SH_ENTITY_DESTROYED_EVENT { 1 };
|
||||
constexpr SHEventIdentifier SH_ENTITY_CREATION_EVENT { 2 };
|
||||
constexpr SHEventIdentifier SH_COMPONENT_ADDED_EVENT { 3 };
|
||||
constexpr SHEventIdentifier SH_COMPONENT_REMOVED_EVENT { 4 };
|
||||
constexpr SHEventIdentifier SH_SCENEGRAPH_CHANGE_PARENT_EVENT { 5 };
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
// Project Headers
|
||||
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||
#include "Events/SHEventManager.hpp"
|
||||
#include "Tools/SHLogger.h"
|
||||
#include "Tools/SHException.h"
|
||||
|
||||
|
@ -364,10 +365,18 @@ namespace SHADE
|
|||
}
|
||||
////////////////////////////////////////
|
||||
|
||||
const SHSceneGraphChangeParentEvent EVENT_DATA
|
||||
{
|
||||
.oldParentID = NODE_ITER->second->GetParent()->GetEntityID(),
|
||||
.newParentID = parent->GetEntityID()
|
||||
};
|
||||
|
||||
if (parent == nullptr)
|
||||
parent = root;
|
||||
|
||||
NODE_ITER->second->SetParent(parent);
|
||||
|
||||
SHEventManager::BroadcastEvent<SHSceneGraphChangeParentEvent>(EVENT_DATA, SH_SCENEGRAPH_CHANGE_PARENT_EVENT);
|
||||
}
|
||||
|
||||
void SHSceneGraph::SetParent(EntityID entityID, EntityID parent) const noexcept
|
||||
|
@ -401,8 +410,16 @@ namespace SHADE
|
|||
}
|
||||
////////////////////////////////////////
|
||||
|
||||
const SHSceneGraphChangeParentEvent EVENT_DATA
|
||||
{
|
||||
.oldParentID = NODE_ITER->second->GetParent()->GetEntityID(),
|
||||
.newParentID = parent
|
||||
};
|
||||
|
||||
SHSceneNode* currentNode = NODE_ITER->second;
|
||||
currentNode->SetParent(PARENT_ITER->second);
|
||||
|
||||
SHEventManager::BroadcastEvent<SHSceneGraphChangeParentEvent>(EVENT_DATA, SH_SCENEGRAPH_CHANGE_PARENT_EVENT);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -563,7 +580,7 @@ namespace SHADE
|
|||
ReleaseNode(node);
|
||||
}
|
||||
|
||||
void SHSceneGraph::Traverse (const UnaryPredicate& predicate) const
|
||||
void SHSceneGraph::Traverse (const UnaryFunction& predicate) const
|
||||
{
|
||||
TraverseAndInvokePredicate(root, predicate);
|
||||
}
|
||||
|
@ -602,7 +619,7 @@ namespace SHADE
|
|||
delete node;
|
||||
}
|
||||
|
||||
void SHSceneGraph::TraverseAndInvokePredicate(const SHSceneNode* node, const UnaryPredicate& predicate)
|
||||
void SHSceneGraph::TraverseAndInvokePredicate(const SHSceneNode* node, const UnaryFunction& predicate)
|
||||
{
|
||||
for (auto* child : node->children)
|
||||
{
|
||||
|
|
|
@ -97,9 +97,8 @@ namespace SHADE
|
|||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
using EntityNodeMap = std::unordered_map<EntityID, SHSceneNode*>;
|
||||
|
||||
using UnaryPredicate = std::function<void(SHSceneNode*)>;
|
||||
using EntityNodeMap = std::unordered_map<EntityID, SHSceneNode*>;
|
||||
using UnaryFunction = std::function<void(SHSceneNode*)>;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -143,8 +142,7 @@ namespace SHADE
|
|||
bool RemoveNode (SHSceneNode* nodeToRemove) noexcept;
|
||||
void Reset () noexcept;
|
||||
|
||||
void Traverse (const UnaryPredicate& predicate) const;
|
||||
|
||||
void Traverse (const UnaryFunction& predicate) const;
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -160,8 +158,13 @@ namespace SHADE
|
|||
|
||||
SHSceneNode* AllocateNode (EntityID entityID);
|
||||
void ReleaseNode (SHSceneNode* node) noexcept;
|
||||
static void TraverseAndInvokePredicate (const SHSceneNode* node, const UnaryPredicate& predicate);
|
||||
static void TraverseAndInvokePredicate (const SHSceneNode* node, const UnaryFunction& predicate);
|
||||
};
|
||||
|
||||
struct SHSceneGraphChangeParentEvent
|
||||
{
|
||||
EntityID oldParentID;
|
||||
EntityID newParentID;
|
||||
};
|
||||
|
||||
} // namespace SHADE
|
Loading…
Reference in New Issue