Пример #1
0
struct Node *CreateNode(struct Seg *ts, const bbox_t bbox)
{
	struct Node *tn;
	struct Seg *rights = NULL;
	struct Seg *lefts = NULL;

	tn = GetMemory( sizeof( struct Node));				/* Create a node*/
 
	DivideSegs(ts,&rights,&lefts,bbox);						/* Divide node in two*/

	num_nodes++;

	tn->x = node_x;											/* store node line info*/
	tn->y = node_y;
	tn->dx = node_dx;
	tn->dy = node_dy;

	FindLimits(lefts,tn->leftbox);				/* Find limits of vertices	*/

	if(IsItConvex(lefts))	  								/* Check lefthand side*/
		{
	        if (verbosity > 1) Verbose("L");
		tn->nextl = CreateNode(lefts,tn->leftbox);	/* still segs remaining*/
		tn->chleft = 0;
	        if (verbosity > 1) Verbose("\b");
		}
	else
		{
		tn->nextl = NULL;
		tn->chleft = CreateSSector(lefts) | 0x8000;
		}

	FindLimits(rights, tn->rightbox);										/* Find limits of vertices*/
	
	if(IsItConvex(rights))									/* Check righthand side*/
		{
	        if (verbosity > 1) Verbose("R");
		tn->nextr = CreateNode(rights, tn->rightbox);	/* still segs remaining*/
		tn->chright = 0;
	        if (verbosity > 1) Verbose("\b");
		}
	else
		{
		tn->nextr = NULL;
		tn->chright =  CreateSSector(rights) | 0x8000;
		}

	return tn;
}
Пример #2
0
static glbsp_ret_e HandleLevel(void)
{
  superblock_t *seg_list;
  bbox_t seg_bbox;

  node_t *root_node;
  subsec_t *root_sub;

  glbsp_ret_e ret;

  if (cur_comms->cancelled)
    return GLBSP_E_Cancelled;

  DisplaySetBarLimit(1, 1000);
  DisplaySetBar(1, 0);

  cur_comms->build_pos = 0;

  LoadLevel();

  InitBlockmap();

  // create initial segs
  seg_list = CreateSegs();

  FindLimits(seg_list, &seg_bbox);

  // recursively create nodes
  ret = BuildNodes(seg_list, &root_node, &root_sub, 0, &seg_bbox);
  FreeSuper(seg_list);

  if (ret == GLBSP_E_OK)
  {
    ClockwiseBspTree(root_node);

    PrintVerbose("Built %d NODES, %d SSECTORS, %d SEGS, %d VERTEXES\n",
        num_nodes, num_subsecs, num_segs, num_normal_vert + num_gl_vert);

    if (root_node)
      PrintVerbose("Heights of left and right subtrees = (%d,%d)\n",
          ComputeBspHeight(root_node->r.node),
          ComputeBspHeight(root_node->l.node));

    SaveLevel(root_node);
  }

  FreeLevel();
  FreeQuickAllocCuts();
  FreeQuickAllocSupers();

  return ret;
}