Make linear the hierarchy

Started by
5 comments, last by ankhd 10 years, 6 months ago

Hi all,

To update and save the hierarchy without recursive functions you have to make the array linear :

- Parent

- Child

- Child

- Parent

...
...

SceneManager has an array m_ActorArray.

Each actor has a function AddChild and RemoveChild and an array of Children.

How make the array linear efficiently ?

Thanks for the help

Advertisement
You need to learn how to ask questions, by giving enough context so we can understand what you are trying to do, why, what you have tried before, what difficulties you have encountered...

Presumably they want to write a file out that once loaded in can be used to reconstruct the tree.

You can do it with XML and probably other ways (JSON, etc.). Using a library is going to be easier than rolling your own.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

My current array is not linear, that means a child can be at the end of the array and the parent in the middle.

When I save the scene, at the end I save the hierarchy by index :

for each object

uint32 NumChildren

for each child

uint32 ChildIndex;

When I load the scene after added all object in the array I use this hierarchy to set children to the good parent.

Using a linear array I could just store the object, numChildren and add in the array each child and add them as child in the object.

But I don't got an efficient way who is elegant to have that working.

Linear array means better cache and means less size of the scene save since no hierarchy needed just NumChildren after each object.

Thanks for the help

Then sort the array. The code to do that doesn't need to be efficient, or elegant, it just needs to work. It's not a frequent operation, so worrying about it's runtime cost is pretty pointless imho.


Linear array means better cache

Assuming you're talking about memory cache performance, this isn't an issue if you're doing an I/O operation like saving a scene; the I/O will completely overwhelm things performance-wise.


and means less size of the scene save since no hierarchy needed just NumChildren after each object.
Can you just serialize this in a single pass? Each time you serialize an object, write the number of children right after it, and then serialize the children (yes, you may need to write a 0 for child nodes, but is that a big deal?). It should make both your saving and loading code simpler.

Hi.

What are you using this for.???? it may shed some more light on what help you need.

This topic is closed to new replies.

Advertisement