< index
< 14. BSP toolkit
< 14.5 Traversing the tree

=====================================
14.6 Destroying a tree
=====================================

You can delete a part of the tree, releasing resources for all sub nodes with :

C++ : void TCODBsp::removeSons()
C   : void TCOD_bsp_remove_sons(TCOD_bsp_t *node)
Py  : bsp_remove_sons(node)

ParameterDescription
nodeIn the C version, the node reference.

Example :

C++ : TCODBsp *myBSP = new TCODBsp(0,0,50,50);
      // create a tree
      myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f); 
      // clear it (keep only the root)
      myBSP->removeSons();
      // and rebuild another random tree
      myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f); 
C   : TCOD_bsp_t *my_bsp=TCOD_bsp_new_with_size(0,0,50,50);
      TCOD_bsp_split_recursive(my_bsp,NULL,4,5,5,1.5f,1.5f);
      TCOD_bsp_remove_sons(my_bsp);
      TCOD_bsp_split_recursive(my_bsp,NULL,4,5,5,1.5f,1.5f);
Py  : my_bsp=libtcod.bsp_new_with_size(0,0,50,50)
      libtcod.bsp_split_recursive(my_bsp,0,4,5,5,1.5,1.5)
      libtcod.bsp_remove_sons(my_bsp)
      libtcod.bsp_split_recursive(my_bsp,0,4,5,5,1.5,1.5)


You can also completely delete the tree, including the root node to release every resource used :

C++ : void TCODBsp::~TCODBsp()
C   : void TCOD_bsp_delete(TCOD_bsp_t *node)
Py  : bsp_delete(node)

ParameterDescription
nodeIn the C version, the node reference.

Example :

C++ : TCODBsp *myBSP = new TCODBsp(0,0,50,50);
      // create a tree
      myBSP->splitRecursive(NULL,4,5,5,1.5f,1.5f); 
      // use the tree ...
      // delete the tree
      delete myBSP; 
C   : TCOD_bsp_t *my_bsp=TCOD_bsp_new_with_size(0,0,50,50);
      TCOD_bsp_split_recursive(my_bsp,NULL,4,5,5,1.5f,1.5f);
      /* use the tree ... */
      TCOD_bsp_delete(my_bsp);
Py  : my_bsp=libtcod.bsp_new_with_size(0,0,50,50)
      libtcod.bsp_split_recursive(my_bsp,0,4,5,5,1.5,1.5)
      # use the tree ...
      libtcod.bsp_delete(my_bsp)

insert a comment