bh_system *system;
void *user;
+ u32 max_per_leaf;
struct bh_node
{
{
bh_node *node = &bh->nodes[ inode ];
+ if( node->count <= bh->max_per_leaf )
+ return;
+
v3f extent;
v3_sub( node->bbx[1], node->bbx[0], extent );
}
VG_STATIC bh_tree *bh_create( void *lin_alloc, bh_system *system,
- void *user, u32 item_count )
+ void *user, u32 item_count, u32 max_per_leaf )
{
+ assert( max_per_leaf > 0 );
+
+ if( item_count == 0 )
+ {
+ bh_tree *bh = vg_linear_alloc( lin_alloc, sizeof(bh_tree) );
+ bh->node_count = 0;
+ bh->system = system;
+ bh->user = user;
+ return bh;
+ }
+
u32 totsize = sizeof(bh_tree) + sizeof(bh_node)*(item_count*2-1);
bh_tree *bh = vg_linear_alloc( lin_alloc, totsize );
bh->system = system;
bh->user = user;
+ bh->max_per_leaf = max_per_leaf;
bh_node *root = &bh->nodes[0];
bh->node_count = 1;
VG_STATIC int bh_ray( bh_tree *bh, v3f co, v3f dir, ray_hit *hit )
{
+ if( bh->node_count < 2 )
+ return 0;
+
int count = 0;
u32 stack[100];
u32 depth = 2;
VG_STATIC int bh_select( bh_tree *bh, boxf box, u32 *buffer, int len )
{
+ if( bh->node_count < 2 )
+ return 0;
+
int count = 0;
u32 stack[100];
u32 depth = 2;