Hi!
Just want to share some problem i've been having with Scene Nodes and Parent hierarchy, as i wanted Nodes to have knowledge their parents, i have rearranged the code this way and use the boost:weak_ptr to solve a double deletion of the nodes, as weak_ptr wont delete the node if there are no references:
Display All
To avoid possible deadlock while adding the node i am not sure if Root node and Nodes Groups (Static, Actor,...) should point to themselves ?
For now im using this code and im not having troubles on deletion, but im also not sure if this would be a correct architecture for a scene graph...
Regards,
@B^)>
Just want to share some problem i've been having with Scene Nodes and Parent hierarchy, as i wanted Nodes to have knowledge their parents, i have rearranged the code this way and use the boost:weak_ptr to solve a double deletion of the nodes, as weak_ptr wont delete the node if there are no references:
Source Code
- class ISceneNode
- {
- ...
- virtual void SetParent(boost::weak_ptr<ISceneNode> parent)=0;
- virtual bool HasParent()=0;
- virtual shared_ptr<ISceneNode> getParent() const =0;
- ...
- }
- class SceneNode : public ISceneNode
- {
- boost::weak_ptr<ISceneNode> m_weakParentNode;
- ...
- virtual void SetParent(boost::weak_ptr<ISceneNode> parent){m_weakParentNode = parent;}
- virtual bool HasParent(){return (!m_weakParentNode.expired();}
- shared_ptr<ISceneNode> getParent() const {return m_weakParentNode.lock();}
- };
- bool SceneNode::VAddChild(shared_ptr<ISceneNode> kid)
- {
- bool ret = false;
- //Did the node ever had a parent or was it misleaded???
- //:(
- shared_ptr<ISceneNode> pRelativeParent(kid->HasParent()? kid->getParent() : m_weakParentNode.lock() );
- if(!pRelativeParent)
- {
- assert(pRelativeParent);
- return false;
- }
- if(pRelativeParent.get() == this)
- {
- //FORCE THAT IM REALLY THE PARENT
- kid->SetParent(m_weakParentNode);
- m_Children.push_back(kid);
- ret = true;
- }
- else
- {
- pRelativeParent->VAddChild(kid);
- }
- ...
- }
To avoid possible deadlock while adding the node i am not sure if Root node and Nodes Groups (Static, Actor,...) should point to themselves ?
For now im using this code and im not having troubles on deletion, but im also not sure if this would be a correct architecture for a scene graph...
Regards,
@B^)>