libtcoddocumentation

12.1. Creating a BSP tree

Creating the root node

First, you have to create the root node of the tree. This node encompasses the whole rectangular region.

TCODBsp::TCODBsp(int x,int y,int w, int h)

TCOD_bsp_t *TCOD_bsp_new_with_size(int x,int y,int w, int h)

bsp_new_with_size(x,y,w, h)

TCODBsp::TCODBsp(int x, int y, int w, int h)

ParameterDescription
x,y,w,hTop left corner position and size of the rectangular region covered by the BSP tree.
Example:

TCODBsp *myBSP = new TCODBsp(0,0,50,50);

TCOD_bsp_t *my_bsp=TCOD_bsp_new_with_size(0,0,50,50);

my_bsp=libtcod.bsp_new_with_size(0,0,50,50)


Deleting a part of the tree

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

void TCODBsp::removeSons()

void TCOD_bsp_remove_sons(TCOD_bsp_t *node)

bsp_remove_sons(node)

TCODBsp::removeSons()

ParameterDescription
nodeIn the C version, the node reference.
Example:

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);

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);

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)


deleting the tree

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

void TCODBsp::~TCODBsp()

void TCOD_bsp_delete(TCOD_bsp_t *node)

bsp_delete(node)

void TCODBsp::Dispose()

ParameterDescription
nodeIn the C version, the node reference.
Example:

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;

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);

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)