Check to see if scenenode exists

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!
Post Reply
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Check to see if scenenode exists

Post by Seven »

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:

Re: Check to see if scenenode exists

Post by CuteAlien »

Not seeing the error on a quick view - what goes wrong?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Soganatsu-Julien
Posts: 29
Joined: Fri Sep 21, 2012 10:18 pm

Re: Check to see if scenenode exists

Post by Soganatsu-Julien »

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

Re: Check to see if scenenode exists

Post by hendu »

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

Re: Check to see if scenenode exists

Post by Seven »

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.
Post Reply