Skip to content

Commit

Permalink
SceneNode: add removeAndDestroyChild(SceneNode*)
Browse files Browse the repository at this point in the history
to avoid name based lookup with anonymous storage
  • Loading branch information
paroj committed Aug 29, 2017
1 parent b0b451b commit 8a3f414
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Components/Terrain/src/OgreTerrainQuadTreeNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace Ogre

if (mLocalNode)
{
mTerrain->_getRootSceneNode()->removeAndDestroyChild(mLocalNode->getName());
mTerrain->_getRootSceneNode()->removeAndDestroyChild(mLocalNode);
mLocalNode = 0;
}

Expand Down
15 changes: 5 additions & 10 deletions OgreMain/include/OgreSceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,13 @@ namespace Ogre {
*/
void removeAndDestroyChild(const String& name);

/** This method removes and destroys the child and all of its children.
@remarks
Unlike removeChild, which removes a single named child from this
node but does not destroy it, this method destroys the child
and all of it's children.
@par
Use this if you wish to recursively destroy a node as well as
detaching it from it's parent. Note that any objects attached to
the nodes will be detached but will not themselves be destroyed.
*/
/// @overload
void removeAndDestroyChild(unsigned short index);

/// @overload
void removeAndDestroyChild(SceneNode* child);


/** Removes and destroys all children of this node.
@remarks
Use this to destroy all child nodes of this node and remove
Expand Down
15 changes: 7 additions & 8 deletions OgreMain/src/OgreNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,6 @@ namespace Ogre {
return 0;
}
//-----------------------------------------------------------------------
struct NodeNameExists {
const String& name;
bool operator()(const Node* mo) {
return mo->getName() == name;
}
};
Node* Node::removeChild(Node* child)
{
if (child)
Expand All @@ -421,8 +415,7 @@ namespace Ogre {
// ensure it's our child
if (i != mChildren.end() && i->second == child)
#else
NodeNameExists pred = {child->getName()};
ChildNodeMap::iterator i = std::find_if(mChildren.begin(), mChildren.end(), pred);
ChildNodeMap::iterator i = std::find(mChildren.begin(), mChildren.end(), child);
if(i != mChildren.end() && *i == child)
#endif
{
Expand Down Expand Up @@ -774,6 +767,12 @@ namespace Ogre {
needUpdate();
}
//-----------------------------------------------------------------------
struct NodeNameExists {
const String& name;
bool operator()(const Node* mo) {
return mo->getName() == name;
}
};
Node* Node::getChild(const String& name) const
{
#if OGRE_NODE_STORAGE_LEGACY
Expand Down
9 changes: 9 additions & 0 deletions OgreMain/src/OgreSceneNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,15 @@ namespace Ogre {
pChild->getCreator()->destroySceneNode(pChild);
}
//-----------------------------------------------------------------------
void SceneNode::removeAndDestroyChild(SceneNode* child)
{
#if OGRE_NODE_STORAGE_LEGACY
removeAndDestroyChild(child->getName());
#else
removeAndDestroyChild(std::find(mChildren.begin(), mChildren.end(), child) - mChildren.begin());
#endif
}
//-----------------------------------------------------------------------
void SceneNode::removeAndDestroyAllChildren(void)
{
// do not store iterators (invalidated by
Expand Down

0 comments on commit 8a3f414

Please sign in to comment.