.x file: How to use loops to traverse the tree structure

Started by
0 comments, last by Alberth 8 years, 8 months ago

I probably cannot get the number of children within that structure.

I mean the hierarchy because it isn't a member variable in the D3DXFRAME structure.

I sometimes would want to iterate a lot of frames, Is it an absolute thing to do it by recursion,

because I am getting stack overflows. I got about 50000 custom frames, so the C++ program cannot hold

that many frames on the stack by recursion, which is quite unsatisfactory.

Any ideas I can work around this?

Thanks

Jack

Advertisement
Don't know XNA nor directX, but the general strategy to avoid recursion is to have a 'notdone' list, a list of nodes you still have to visit.

while (!notdone.is_empty()) {
    node = notdone.pop(); // Get one of the nodes.
    // Do something with 'node'
    for (Node child : node.childs) { // Add childs to the 'notdone' list.
        notdone.append(child);
    }
}

This topic is closed to new replies.

Advertisement