You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Seven
Posts: 1034 Joined: Mon Nov 14, 2005 2:03 pm
Post
by Seven » Sat May 10, 2014 12:27 pm
My application needs to determine whether a scenenode still exists or not.
This is the code I am using, but of course, it does not perfrom as I want.
Anyone got ideas on this?
Code: Select all
bool CSO_Editor::nodeExistsRetro(ISceneNode* s, ISceneNode* node)
{
list<ISceneNode*>::ConstIterator i = s->getChildren().begin();
while (i != s->getChildren().end())
{
if ((*i) == node) return true;
if (nodeExistsRetro((*i), node)) return true;
i++;
}
return false;
}
bool CSO_Editor::nodeExists(ISceneNode* node)
{
list<ISceneNode*>::ConstIterator i = getSmgr()->getRootSceneNode()->getChildren().begin();
while (i != getSmgr()->getRootSceneNode()->getChildren().end())
{
if ((*i) == node) return true;
if (nodeExistsRetro((*i),node)) return true;
i++;
}
return false;
}
CuteAlien
Admin
Posts: 9734 Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:
Post
by CuteAlien » Mon May 12, 2014 11:00 am
Not seeing the error on a quick view - what goes wrong?
Soganatsu-Julien
Posts: 29 Joined: Fri Sep 21, 2012 10:18 pm
Post
by Soganatsu-Julien » Tue May 13, 2014 8:04 am
Same for me, not seeing error on a quick look ^^
you can try this method instead, remixed from the irrlicht sources and that not needs two methods to traverse the scene tree
Code: Select all
bool CSO_Editor::nodeExists(ISceneNode *toFind, ISceneNode* start=0)
{
if (start == 0)
start = getSmgr()->getRootSceneNode();
if (start == toFind)
return true;
const ISceneNodeList& list = start->getChildren();
ISceneNodeList::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{
bool exists = nodeExists(toFind, *it);
if (exists)
return exists;
}
return false;
}
hendu
Posts: 2600 Joined: Sat Dec 18, 2010 12:53 pm
Post
by hendu » Tue May 13, 2014 3:04 pm
Also, that is horribly inefficient when you can do it much faster. Instead of O(n) for all nodes, O(n) for direct parents.
while (node->parent) {
if (node->parent == root)
true
node = node->parent
}
false
Seven
Posts: 1034 Joined: Mon Nov 14, 2005 2:03 pm
Post
by Seven » Tue May 13, 2014 9:04 pm
got it. Thanks to all for the help. As always, I enjoy this forum where we can get actual help. Keep up the good work.