Merge pull request #38 from SHADE-DP/SP3-12-SceneGraph
This commit is contained in:
commit
67d673ff80
|
@ -507,6 +507,11 @@ namespace SHADE
|
|||
ReleaseNode(node);
|
||||
}
|
||||
|
||||
void SHSceneGraph::Traverse (const UnaryPredicate& predicate) const
|
||||
{
|
||||
TraverseAndInvokePredicate(root, predicate);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Private Function Member Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -541,4 +546,13 @@ namespace SHADE
|
|||
delete node;
|
||||
}
|
||||
|
||||
void SHSceneGraph::TraverseAndInvokePredicate(const SHSceneNode* node, const UnaryPredicate& predicate)
|
||||
{
|
||||
for (auto* child : node->children)
|
||||
{
|
||||
predicate(child);
|
||||
TraverseAndInvokePredicate(child, predicate);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace SHADE
|
|
@ -18,12 +18,25 @@
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
class SHSceneGraph;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
class SH_API SHSceneNode
|
||||
{
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Friends */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
friend class SHSceneGraph;
|
||||
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
|
@ -71,6 +84,10 @@ namespace SHADE
|
|||
void RemoveAllChildren () noexcept;
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
EntityID entityID;
|
||||
SHSceneNode* parent;
|
||||
std::vector<SHSceneNode*> children;
|
||||
|
@ -83,7 +100,10 @@ namespace SHADE
|
|||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
using EntityNodeMap = std::unordered_map<EntityID, SHSceneNode*>;
|
||||
using EntityNodeMap = std::unordered_map<EntityID, SHSceneNode*>;
|
||||
|
||||
using UnaryPredicate = void (*)(SHSceneNode*);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors & Destructor */
|
||||
|
@ -124,6 +144,9 @@ namespace SHADE
|
|||
bool RemoveNode (SHSceneNode* nodeToRemove) noexcept;
|
||||
void Reset () noexcept;
|
||||
|
||||
void Traverse (const UnaryPredicate& predicate) const;
|
||||
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
|
@ -136,8 +159,9 @@ namespace SHADE
|
|||
/* Function Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
SHSceneNode* AllocateNode (EntityID entityID);
|
||||
void ReleaseNode (SHSceneNode* node) noexcept;
|
||||
SHSceneNode* AllocateNode (EntityID entityID);
|
||||
void ReleaseNode (SHSceneNode* node) noexcept;
|
||||
static void TraverseAndInvokePredicate (const SHSceneNode* node, const UnaryPredicate& predicate);
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue