Archived

This topic is now archived and is closed to further replies.

loading and saving a bsp tree

This topic is 5649 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, do someone know how can i save and load a bsp tree from disk, i use to traverse the tree and save it giving an increased reference index , but for loading is a mess because it takes too time to reconstruct , so i would like to kno if someone has a better solution for this problem , thanks in advance

Share this post


Link to post
Share on other sites
Here''s how I''d do it:


  
void write_tree( node_t *node )
{
if( inner_node( node ) )
{
// a 1 indicates an inner node

write( 1 );
write_tree( node->left );
write_tree( node->right );
}
else
{
// a 0 indicates a leaf node

write( 0 );
write_node( node ); // write the data for this node

}
}


Then, to read it in:


  
node_t *read_tree()
{
node_t *node = new node_t;

int inner = read_byte();
if( inner )
{
node->left = read_tree();
node->right = read_tree();
}
else
{
read_node( node ); // read the data for this node

}

return node;
}


It uses an extra byte per node, but that''s not too much of an overhead, really.


codeka.com - Just click it.

Share this post


Link to post
Share on other sites
Thanks , i think you mean ''inner node'' a node which has childrn and leaf a node containing data , don''t you, well , i''m going to code it , thanks again

Share this post


Link to post
Share on other sites
Your using linked lists for the BSP tree. For infinite gains, including ease of saving and loading...use arrays..search for leaf BSP trees, you''ll also be able to generate PVS informations as well as use portals amongst others.

Share this post


Link to post
Share on other sites