Sign in to follow this  

Make linear the hierarchy

This topic is 1518 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Edited by Alundra

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Edited by Alundra

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

This topic is 1518 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this