Ejemplo n.º 1
0
void MakeTree(int FStart,int FEnd,int MStart,int MEnd,node &T)
{
	T.d = FList[FStart];
	bool Found = false;
	for(int i = MStart;i<= MEnd && !Found;i++)
	{
		if( FList[FStart] == MList[i])
		{
			Found = true;
			if( i != MStart)
			{
				node *p = new node();
				T.rChild = p;
				MakeTree(FStart+1,FStart+i-MStart,MStart,i-1,*(T.rChild));
			}
			if( i != MEnd)
			{
				node *p = new node();
				T.lChild = p;
				MakeTree(FStart+i-MStart+1,FEnd,i+1,MEnd,*(T.lChild));
			}
		}
	}
	if(!Found)
	{
		cout<<"\n error"<<endl;
	}
}
Ejemplo n.º 2
0
/* Build tree bottom-up */
static Node MakeTree(int iDepth) {
        if (iDepth<=0) {
                return leaf_Node();
        } else {
                return make_Node(MakeTree(iDepth-1),
                                 MakeTree(iDepth-1));
        }
}
int main(int argc, char argv[]) {

	Node *root;

	int T;
	int N;

	scanf("%d ", &T);
	for (int test_case = 1; test_case <= T; test_case++) {
		scanf("%d ", &N);

		root = GetNode();
		MakeTree(root, N);

		printf("# Preorder\n");
		PreorderTraversal(root->left);
		putchar('\n');

		printf("# Inorder\n");
		InorderTraversal(root->left);
		putchar('\n');

		printf("# Postorder\n");
		PostorderTraversal(root->left);
		putchar('\n');

		if (root != NULL) {
			DeleteNode(root);
			//DeleteAllNode();
		}
	}

	return 0;
}
Ejemplo n.º 4
0
    static void TimeConstruction(int depth) {
        long    tStart, tFinish;
        int     iNumIters = NumIters(depth);
        Node    tempTree;

        printf("Creating %d trees of depth %d\n", iNumIters, depth);

        tStart = currentTime();
        for (int i = 0; i < iNumIters; ++i) {
#			ifndef GC
            tempTree = new Node0();
#			else
            tempTree = new GC_NEW(Node0) Node0();
#			endif
            Populate(depth, tempTree);
#		        ifndef GC
            delete tempTree;
#			endif
            tempTree = 0;
        }
        tFinish = currentTime();
        printf("\tTop down construction took %d msec\n", elapsedTime(tFinish - tStart));

        tStart = currentTime();
        for (int i = 0; i < iNumIters; ++i) {
            tempTree = MakeTree(depth);
#			ifndef GC
            delete tempTree;
#			endif
            tempTree = 0;
        }
        tFinish = currentTime();
        printf("\tBottom up construction took %d msec\n", elapsedTime(tFinish - tStart));
    }
Ejemplo n.º 5
0
/******************************************************** 
 *! @brief 関数
	-
@param[out]     -
@param[in]      -
@par            -
@return         -
@note      
*********************************************************/
PRIVATE EVALUATE_TREE_T* CreateEvaluateTree( PLAYER_T CurrentPlayer )
{
	EVALUATE_TREE_T		*pEvaluateTreeTop;	
	EVALUATE_TABLE_T	*pReversiTableTop;
	SIZE_T				AllocateAreaSize;
	unsigned int		Depth;
	
	/* Create Evaluate Table of Top Node */
	pReversiTableTop = (EVALUATE_TABLE_T*)malloc( sizeof(EVALUATE_TABLE_T) );
	AllocateAreaSize = sizeof( pReversiTableTop->aEvaluatReversiTable );
	CopyCurrentReversiTable( pReversiTableTop->aEvaluatReversiTable, AllocateAreaSize );
	
	/* Create Evaluate Tree Top Node */
	pEvaluateTreeTop = (EVALUATE_TREE_T*)malloc( sizeof(EVALUATE_TREE_T) );
	pEvaluateTreeTop->Depth					= 0;
	pEvaluateTreeTop->NodeID				= 0;
	pEvaluateTreeTop->DiscInfo.h			= 0;
	pEvaluateTreeTop->DiscInfo.v			= 0;
	pEvaluateTreeTop->DiscInfo.CurrentPlayer= TOGGLE_PLAYER( CurrentPlayer );	/* Currentは1手前の相手ターンの盤面 */
	pEvaluateTreeTop->NumNextIndex			= 0;
	pEvaluateTreeTop->pEvaluatReversiTable	= pReversiTableTop;
	pEvaluateTreeTop->Score					= CalcScore( pEvaluateTreeTop->DiscInfo.CurrentPlayer,
														 pEvaluateTreeTop->pEvaluatReversiTable->aEvaluatReversiTable );
	pEvaluateTreeTop->pNextNode				= NULL;
	pEvaluateTreeTop->pNextDepthNode		= NULL;
	
	/* Create Tree */
	MakeTree( pEvaluateTreeTop );
	
	return pEvaluateTreeTop;
}
Ejemplo n.º 6
0
/**
 * Creates a tree tile
 * Ground type and density is preserved.
 *
 * @pre the tile must be suitable for trees.
 *
 * @param tile where to plant the trees.
 * @param treetype The type of the tree
 * @param count the number of trees (minus 1)
 * @param growth the growth status
 */
static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, uint growth)
{
	assert(treetype != TREE_INVALID);
	assert(CanPlantTreesOnTile(tile, true));

	TreeGround ground;
	uint density = 3;

	switch (GetTileType(tile)) {
		case MP_WATER:
			ground = TREE_GROUND_SHORE;
			break;

		case MP_CLEAR:
			switch (GetClearGround(tile)) {
				case CLEAR_GRASS:  ground = TREE_GROUND_GRASS;       break;
				case CLEAR_ROUGH:  ground = TREE_GROUND_ROUGH;       break;
				case CLEAR_SNOW:   ground = GetRawClearGround(tile) == CLEAR_ROUGH ? TREE_GROUND_ROUGH_SNOW : TREE_GROUND_SNOW_DESERT; break;
				default:           ground = TREE_GROUND_SNOW_DESERT; break;
			}
			if (GetClearGround(tile) != CLEAR_ROUGH) density = GetClearDensity(tile);
			break;

		default: NOT_REACHED();
	}

	MakeTree(tile, treetype, count, growth, ground, density);
}
Ejemplo n.º 7
0
void * FbMasterInfoBase::Execute(wxEvtHandler * owner, FbThread * thread, const FbFilterObj &filter)
{
	if (thread->IsClosed()) return NULL;

	FbCommonDatabase database;
	database.JoinThread(thread);
	FbGenreFunction func_genre;
	FbAggregateFunction func_aggregate;
	database.CreateFunction(wxT("AGGREGATE"), 1, func_aggregate);
	database.CreateFunction(wxT("GENRE"), 1, func_genre);
	database.AttachConfig();
	if (thread->IsClosed()) return NULL;

	wxString sql;
	switch (GetMode()) {
		case FB2_MODE_LIST: sql = GetListSQL(database); break;
		case FB2_MODE_TREE: sql = GetTreeSQL(database); break;
	}
	sql = FormatSQL(sql, GetWhere(database), filter);

	FbSQLite3Statement stmt = database.PrepareStatement(sql);
	Bind(stmt);
	FbSQLite3ResultSet result = stmt.ExecuteQuery();
	if (!result.IsOk()) return NULL;

	switch (GetMode()) {
		case FB2_MODE_LIST: MakeList(owner, thread, result); break;
		case FB2_MODE_TREE: MakeTree(owner, thread, result); break;
	}
	return NULL;
}
Ejemplo n.º 8
0
        // Build tree bottom-up
        static Node MakeTree(int iDepth) {
                if (iDepth<=0) {
#		     ifndef GC
                        return new Node0();
#		     else
                        return new (GC_NEW(Node0)) Node0();
#		     endif
                } else {
#		     ifndef GC
                        return new Node0(MakeTree(iDepth-1),
                                         MakeTree(iDepth-1));
#		     else
                        return new (GC_NEW(Node0)) Node0(MakeTree(iDepth-1),
                                         		 MakeTree(iDepth-1));
#		     endif
                }
        }
int main()
{
    int kase,i,n;
    Tsize=1;root=0;
    while(scanf("%d",&n)==1){
     MakeTree(n);}
     PostOrder(root);
    // getchar();getchar();
    return 0;
}
Ejemplo n.º 10
0
void MakeTree(STreeNode &p,int i)
{
	if( i< length)
	{
		p.node =  CNodeList[i];
		p.lChild = NULL;
		p.rChild = NULL;
		if(i*2+1<length)
		{
			STreeNode *r = new STreeNode();
			p.rChild = r;
			MakeTree(*(p.rChild),i*2+1);
		}
		if(i*2+2 < length)
		{
			STreeNode *l = new STreeNode();
			p.lChild = l;
			MakeTree(*(p.lChild),i*2+2);
		}
	}
}
Ejemplo n.º 11
0
void main()
{
	cout<<"Please enter the tree node list"<<endl;
	cin>> CNodeList;
	STreeNode Head ;
	STreeNode *p = NULL;
	length = strlen(CNodeList);
	MakeTree(Head,0);
	ShowTree(&Head);
	cout<<endl;
	cout<<"叶节点个数为 "<<count/2<<endl;
}
Ejemplo n.º 12
0
 hrf::ScoreAverager::IScorerVector TreeCreator::MakeTrees(int n) {
     
     assert(n >= 0);
     
     std::vector<std::unique_ptr<hrf::IScorer>>* raw_result = new std::vector<std::unique_ptr<hrf::IScorer>>;
     raw_result->reserve(n);
     
     for (int i=0; i<n; ++i) {
         raw_result->push_back(MakeTree());
     }
     
     return std::unique_ptr<const std::vector<std::unique_ptr<hrf::IScorer>>>(raw_result);
 }
Ejemplo n.º 13
0
// Build tree bottom-up
static Node MakeTree(int iDepth) {
	Node result;
        if (iDepth<=0) {
#	    ifndef GC
		result = calloc(1, sizeof(Node0));
#	    else
		result = GC_NEW(Node0); HOLE();
#	    endif
	    /* result is implicitly initialized in both cases. */
	    return result;
        } else {
	    Node left = MakeTree(iDepth-1);
	    Node right = MakeTree(iDepth-1);
#	    ifndef GC
		result = malloc(sizeof(Node0));
#	    else
		result = GC_NEW(Node0); HOLE();
#	    endif
	    init_Node(result, left, right);
	    return result;
        }
}
Ejemplo n.º 14
0
void Tree::MakeTree(Tree * node, const SuperCategoryParameter::TreeScheme * node_param){
	if( node_param->children_size() == 0 ){
		CHECK_NE(node_param->label(),-1);
		node->SetLabel(node_param->label());
	}
	else {
		CHECK_EQ(node->label,-1);
		for(int i = 0; i < node_param->children_size(); ++i) {
			shared_ptr<Tree> child(new Tree());
			node->InsertChild(child);
			MakeTree(child.get(), &node_param->children(i));
		}
	}
}
Ejemplo n.º 15
0
void main()
{
	node Head;
	cout<<"请输入前序序列"<<endl;
	cin>>FList;
	cout<<"请输入中序序列"<<endl;
	cin>>MList;

	MakeTree(0,strlen(FList)-1,0,strlen(MList)-1,Head);
	cout<<"后序序列为"<<endl;
	BackOrder(&Head);
	cout<<"数有 "<<leaf(&Head)<<" 个叶子"<<endl;
	cout<<"数高 "<<Height(&Head,0)<<endl;
}
Ejemplo n.º 16
0
main() {
        Node    root;
        Node    longLivedTree;
        Node    tempTree;
        double *array;
        int     i;
        int     d;

        printf ("Garbage Collector Test\n");
        printf (" Live storage will peak at %d bytes.\n\n",
                2 * sizeof(struct Node0) * TreeSize(kLongLivedTreeDepth) +
                sizeof(double) * kArraySize);
        printf (" Stretching memory with a binary tree of depth %d\n",
                kStretchTreeDepth);
        PrintDiagnostics();
        
        /* Stretch the memory space quickly */
        tempTree = MakeTree(kStretchTreeDepth);
        free_Node(tempTree);
        tempTree = 0;

        /* Create a long lived object */
        printf (" Creating a long-lived binary tree of depth %d\n",
                kLongLivedTreeDepth);
        longLivedTree = leaf_Node();
        Populate(kLongLivedTreeDepth, longLivedTree);

        /* Create long-lived array, filling half of it */
        printf (" Creating a long-lived array of %d doubles\n",
                kArraySize);
        array = (double *) malloc(kArraySize*sizeof(double));
        for (i = 0; i < kArraySize/2; ++i) {
                array[i] = 1.0/i; /* sic */
        }
        PrintDiagnostics();

        for (d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2) {
                TimeConstruction(d);
        }

        if (longLivedTree == 0 || array[1000] != 1.0/1000)
                printf ("Failed\n");
                /* Fake reference to LongLivedTree */
                /* and array */
                /* to keep them from being optimized away */

        PrintDiagnostics();
}
int main()
{    int i,j,temp;
    int *pscore;
    char namebuf[31],c;
    MakeTree();
    pscore = searchscore("Li Ming");
    for(i=0;i<nCourse;++i)
    {    for(j=0;j<nStudent;++j)
        {    scanf("%d",&temp);
            getchar();
            gets(namebuf);
            *(searchscore(namebuf)) += temp;
        }
        rank = 1;
        nowscore = *pscore;
        PostOrder(root);
        printf("%d\n",rank);
    }
    return 0;
}
Ejemplo n.º 18
0
 void TreeCreator::MakeTreesParallelHelper(bkp::JobQueue<std::unique_ptr<MakeTreesJob>>& job_queue)
 {
     bool got_job;
     std::unique_ptr<MakeTreesJob> job;
     auto tied_result = std::tie(got_job, job);
     
     while (!job_queue.IsComplete()) {
         tied_result = job_queue.TryPopFront();
         if (got_job) {
             
             auto iter = job->begin_;
             auto end = job->end_;
             while (iter != end) {
                 *iter = MakeTree();
                 ++iter;
             }
             
         }
     }
 }
Ejemplo n.º 19
0
static void TimeConstruction(int depth) {
        long    tStart, tFinish;
        int     iNumIters = NumIters(depth);
        Node    tempTree;
        int     i;

        printf ("Creating %d trees of depth %d\n", iNumIters, depth);
                
        for (i = 0; i < iNumIters; ++i) {
                tempTree = leaf_Node();
                Populate(depth, tempTree);
                free_Node(tempTree);
                tempTree = 0;
        }
        for (i = 0; i < iNumIters; ++i) {
                tempTree = MakeTree(depth);
                free_Node(tempTree);
                tempTree = 0;
        }
}
Ejemplo n.º 20
0
        static void TimeConstruction(int depth) {
                long    tStart, tFinish;
                int     iNumIters = NumIters(depth);
                Node    tempTree;

                cout << "Creating " << iNumIters
                     << " trees of depth " << depth << endl;
                
                tStart = currentTime();
                for (int i = 0; i < iNumIters; ++i) {
#			ifndef GC
                          tempTree = new Node0();
#			else
                          tempTree = new (GC_NEW(Node0)) Node0();
#			endif
                        Populate(depth, tempTree);
#		        ifndef GC
                          delete tempTree;
#			endif
                        tempTree = 0;
                }
                tFinish = currentTime();
                cout << "\tTop down construction took "
                     << elapsedTime(tFinish - tStart) << " msec" << endl;
                     
                tStart = currentTime();
                for (int i = 0; i < iNumIters; ++i) {
                        tempTree = MakeTree(depth);
#			ifndef GC
                          delete tempTree;
#			endif
                        tempTree = 0;
                }
                tFinish = currentTime();
                cout << "\tBottom up construction took "
                     << elapsedTime(tFinish - tStart) << " msec" << endl;

        }
Ejemplo n.º 21
0
int PCS_Model::SaveToPOF(std::string filename, AsyncProgress* progress)
{
	PCS_Model::BSP_MAX_DEPTH = 0;
	PCS_Model::BSP_NODE_POLYS = 1;
	PCS_Model::BSP_TREE_TIME = 0;
	PCS_Model::BSP_COMPILE_ERROR = false;
	POF poffile;
	unsigned int i,j,k,l;
	progress->setTarget(6 + light_arrays.size() + ai_paths.size() + insignia.size() + shield_mesh.size() + 
					thrusters.size() + docking.size() + turrets.size() + weapons.size() + special.size() +
					eyes.size() + model_info.size() + subobjects.size() + textures.size());
	char cstringtemp[256];


	// Update Progress
	progress->incrementWithMessage("Writing Header Pt1");

	// --------- convert cross sections --------- 
	std::vector<cross_section> sections;
	sections.resize(header.cross_sections.size());

	for (i = 0; i < header.cross_sections.size(); i++)
	{
		sections[i].depth = header.cross_sections[i].depth;
		sections[i].radius = header.cross_sections[i].radius;
	}
	poffile.HDR2_Set_CrossSections(header.cross_sections.size(), sections);

	// Update Progress
	progress->incrementWithMessage("Writing Header Pt2");

	// --------- ACEN --------- 
	poffile.ACEN_Set_acen(POFTranslate(autocentering));

	
	// Update Progress
	progress->incrementWithMessage("Writing Acen");
	// --------- TXTR --------- 

	
	// Update Progress
	progress->incrementWithMessage("Writing Textures");
	for (i = 0; i < textures.size(); i++)
		poffile.TXTR_AddTexture(textures[i]);

	
	// --------- Sub object Consversion ---------

	wxLongLong time = wxGetLocalTimeMillis();
	bool bsp_compiled = false;
	header.max_radius = 0.0f;
	for (i = 0; i < subobjects.size(); i++)
	{
		// Update Progress
		//if (subobjects[i].name == "debris08")
		//	sprintf(cstringtemp, "Submodel %d: %s SENTINAL!", i, subobjects[i].name.c_str());
		//else
			sprintf(cstringtemp, "Submodel %d: %s", i, subobjects[i].name.c_str());
		progress->incrementWithMessage(cstringtemp);
	
		//memset((char *)&obj, 0, sizeof(OBJ2)); this is NO LONGER ALLOWED - obj2 now contains an class w/ vtable
		boost::scoped_ptr<OBJ2> obj(new OBJ2);
		obj->submodel_number = i;
		if (!PMFObj_to_POFObj2(i, *obj, bsp_compiled, header.max_radius))
		{
			return 2; // error occured in bsp splitting!
		}
		poffile.OBJ2_Add(*obj); // takes over object management - including pointers
	}
	time = wxGetLocalTimeMillis() - time;

	// we succeeded in compiling - let's cache the result
	can_bsp_cache = true;
	bsp_cache.resize(subobjects.size());
	for (i = 0; i < subobjects.size(); i++)
		poffile.OBJ2_Get_BSPData(i, bsp_cache[i].bsp_data);


	// --------- ---------------------- ---------
	

	int idx = GetModelInfoCount();
	char cstrtmp[256];
	wxString strtmp = PCS2_VERSION;
	sprintf(cstrtmp, "PMFSaveToPOF: Compiled on %s with %s\nmax BSP depth was %d\nmost polys in a single node was %d\nTotal Compile time was %ldms, tree generation time was %ldms", std::string(strtmp.mb_str()).c_str(), std::string(PCS2_COMP_VERSION.mb_str()).c_str(), PCS_Model::BSP_MAX_DEPTH,PCS_Model::BSP_NODE_POLYS, time.ToLong(), PCS_Model::BSP_TREE_TIME.ToLong());
	
	bool found = false;
	for (i = 0; i < model_info.size() && !found; i++)
	{
		if (strstr(model_info[i].c_str(), "PMFSaveToPOF") != NULL)
		{
			found = true;
			if (bsp_compiled) // update the string
				model_info[i] = cstrtmp;
		}
	}

	if (!found)
		AddModelInfo(cstrtmp);

	j = 0;
	for (i = 0; i < model_info.size(); i++)
		j += model_info[i].length() + 1;
	
	boost::scoped_ptr<char> pinf(new char[j]);
	memset(pinf.get(), 0, j);
	j = 0;

	for (i = 0; i < model_info.size(); i++)
	{
		// Update Progress
		sprintf(cstringtemp, "Writing String %d", i); 
		progress->incrementWithMessage(cstringtemp);

		strncpy(pinf.get()+j, model_info[i].c_str(), model_info[i].length());
		j+= model_info[i].length() + 1;
	}
	poffile.PINF_Set(pinf.get(), j);

	if (found)
		model_info.resize(idx); // back down to size

	// ---------  EYE --------- 

	for (i = 0; i < eyes.size(); i++)
	{
		// Update Progress
		sprintf(cstringtemp, "Writing Eye %d", i);
		progress->incrementWithMessage(cstringtemp);
		poffile.EYE_Add_Eye(eyes[i].sobj_number, 
							POFTranslate(eyes[i].sobj_offset), 
							POFTranslate(eyes[i].normal));
	}


	// --------- SPCL --------- 	

	for (i = 0; i < special.size(); i++)
	{
		// Update Progress
		sprintf(cstringtemp, "Writing Special %d", i);
		progress->incrementWithMessage(cstringtemp);
		poffile.SPCL_AddSpecial(special[i].name, special[i].properties, 
									POFTranslate(special[i].point), special[i].radius);
	}

	k = l = 0;
	// --------- weapons (GPNT/MPNT) --------- 
	for (i = 0; i < weapons.size(); i++)
	{
		// Update Progress
		sprintf(cstringtemp, "Writing Weapon %d", i);
		progress->incrementWithMessage(cstringtemp);
		if (weapons[i].type == GUN)
		{
			poffile.GPNT_AddSlot();

			for (j = 0; j < weapons[i].muzzles.size(); j++)
			{
				poffile.GPNT_AddPoint(k, POFTranslate(weapons[i].muzzles[j].point),
										 POFTranslate(weapons[i].muzzles[j].norm));
			}
			k++;
		}
		else
		{	poffile.MPNT_AddSlot();

			for (j = 0; j < weapons[i].muzzles.size(); j++)
			{
				poffile.MPNT_AddPoint(l, POFTranslate(weapons[i].muzzles[j].point),
										 POFTranslate(weapons[i].muzzles[j].norm));
			}
			l++;
		}
	}

	// --------- turrets TGUN/TMIS --------- 
	k = l = 0;

	for (i = 0; i < turrets.size(); i++)
	{
		// Update Progress
		sprintf(cstringtemp, "Writing Turret %d", i);
		progress->incrementWithMessage(cstringtemp);
		if (turrets[i].type == GUN)
		{
			poffile.TGUN_Add_Bank(turrets[i].sobj_parent, 
								  turrets[i].sobj_par_phys, 
								  POFTranslate(turrets[i].turret_normal));
			for (j = 0; j < turrets[i].fire_points.size(); j++)
			{
				poffile.TGUN_Add_FirePoint(k, POFTranslate(turrets[i].fire_points[j]));
			}
			k++;
		}
		else
		{
			poffile.TMIS_Add_Bank(turrets[i].sobj_parent, 
								  turrets[i].sobj_par_phys, 
								  POFTranslate(turrets[i].turret_normal));
			for (j = 0; j < turrets[i].fire_points.size(); j++)
			{
				poffile.TMIS_Add_FirePoint(l, POFTranslate(turrets[i].fire_points[j]));
			}
			l++;
		}
	}

	// --------- docking --------- 
	for (i = 0; i < docking.size(); i++)
	{
		// Update Progress
		sprintf(cstringtemp, "Writing Docking %d", i);
		progress->incrementWithMessage(cstringtemp);
		poffile.DOCK_Add_Dock(docking[i].properties);

		for (j = 0; j < docking[i].dockpoints.size(); j++)
		{
			poffile.DOCK_Add_Point(i, POFTranslate(docking[i].dockpoints[j].point), 
									  POFTranslate(docking[i].dockpoints[j].norm));
		}

		for (j = 0; j < docking[i].paths.size(); j++)
		{
			poffile.DOCK_Add_SplinePath(i, docking[i].paths[j]);
		}
	}

	// --------- thrusters --------- 
	for (i = 0; i < thrusters.size(); i++)
	{
		// Update Progress
		sprintf(cstringtemp, "Writing Thruster %d", i);
		progress->incrementWithMessage(cstringtemp);
		poffile.FUEL_Add_Thruster(thrusters[i].properties);

		for (j = 0; j < thrusters[i].points.size(); j++)
		{
			poffile.FUEL_Add_GlowPoint(i, thrusters[i].points[j].radius,
										  POFTranslate(thrusters[i].points[j].pos),
										  POFTranslate(thrusters[i].points[j].norm));
		}
	}

	// --------- shield_mesh --------- 
	int fcs[3], nbs[3];
	std::vector<vector3d> points(shield_mesh.size()*3);
	vector3d shldtvect;

	// make points list
	l = 0;
	for (i = 0; i < shield_mesh.size(); i++)
	{
		for (j = 0; j < 3; j++)
		{
			bool found_corner = false;
			for (auto& p : points)
			{
				if (p == POFTranslate(shield_mesh[i].corners[j]))
				{
					found_corner = true;
					break;
				}
			}
			if (!found_corner)
			{
				if (l >= points.size())
					points.resize(points.size()*2);
				points[l] = POFTranslate(shield_mesh[i].corners[j]);
				l++;
			}
		}
	}
	points.resize(l);

	// translate shield mesh
	for (i = 0; i < shield_mesh.size(); i++)
	{
		// Update Progress
		sprintf(cstringtemp, "Writing Shield Tri %d", i);
		progress->incrementWithMessage(cstringtemp);
		// adds points to list if need, determine fcs[]
		for (j = 0; j < 3; j++)
		{
			shldtvect = POFTranslate(shield_mesh[i].corners[j]);
			fcs[j] = FindInList(points, shldtvect);
		}

		// determine neighbors (nbs[])
		j=0;
		for (k = 0; k < shield_mesh.size() && j < 3; k++)
		{
			if (Neighbor(shield_mesh[i], shield_mesh[k]) && i != k)
			{
				nbs[j] = k;
				j++;
			}
		}
		// add
		poffile.SHLD_Add_Face(POFTranslate(shield_mesh[i].face_normal), fcs, nbs);
	}

	// add points
	// Update Progress
	progress->incrementWithMessage("Writing Shield Points");
	for (i = 0; i < points.size(); i++)
		poffile.SHLD_Add_Vertex(points[i]);

	
	progress->incrementWithMessage("Writing Shield Collision Tree");
	// --------------- generate shield collision tree ----------------
	if (poffile.SHLD_Count_Faces() > 0)
	{
		std::vector<pcs_polygon> shldmesh(poffile.SHLD_Count_Faces());

		// make a pcs_polygon mesh from the shields
		for (i = 0; i < shldmesh.size(); i++)
		{
			shldmesh[i].verts.resize(3);

			poffile.SHLD_Get_Face(i, shldmesh[i].norm, fcs, nbs);

			for (j = 0; j < 3; j++)
			{
				 poffile.SHLD_Get_Vertex(fcs[j], shldmesh[i].verts[j].point);
				 shldmesh[i].verts[j].norm = shldmesh[i].norm;
			}
			
			shldmesh[i].centeroid = PolygonCenter(shldmesh[i]);
		}

		// make the tree
		vector3d smin, smax;
		std::unique_ptr<bsp_tree_node> shld_root = MakeTree(shldmesh, smax, smin);

		// pack the tree
		int sldc_size = CalcSLDCTreeSize(shld_root.get());
		std::vector<char> sldc;
		sldc.resize(sldc_size);
		
		PackTreeInSLDC(shld_root.get(), 0, &sldc.front(), sldc_size);

		poffile.SLDC_SetTree(std::move(sldc)); // POFHandler will steal our copy of the buffer
	}

	// --------- insignia --------- 

	vector3d uv, vv;
	float *u = (float *)&uv, *v = (float *)&vv;
	for (i = 0; i < insignia.size(); i++)
	{
		// Update Progress
		sprintf(cstringtemp, "Writing Insignia %d", i);
		progress->incrementWithMessage(cstringtemp);
		poffile.INSG_Add_insignia(insignia[i].lod, POFTranslate(insignia[i].offset));

		for (j = 0; j < insignia[i].faces.size(); j++)
		{
			for (k = 0; k < 3; k++)
			{
				while ((l = poffile.INST_Find_Vert(i, POFTranslate(insignia[i].faces[j].verts[k]))) == (unsigned)-1)
				{
					poffile.INSG_Add_Insig_Vertex(i, POFTranslate(insignia[i].faces[j].verts[k]));
				} 
				fcs[k] = l;
				u[k] = insignia[i].faces[j].u[k];
				v[k] = insignia[i].faces[j].v[k];
			}
			poffile.INSG_Add_Insig_Face(i, fcs, uv, vv);
		}
	}

	// --------- ai_paths --------- 
	for (i = 0; i < ai_paths.size(); i++)
	{
		// Update Progress
		sprintf(cstringtemp, "Writing Path %d", i);
		progress->incrementWithMessage(cstringtemp);
		poffile.PATH_Add_Path(ai_paths[i].name, ai_paths[i].parent);

		for (j = 0; j < ai_paths[i].verts.size(); j++)
		{
			poffile.PATH_Add_Vert(i, POFTranslate(ai_paths[i].verts[j].pos), 
									 ai_paths[i].verts[j].radius);
		}
	}

	// --------- light arrays --------- 
	pcs_glow_array *gla;
	for (i = 0; i < light_arrays.size(); i++)
	{
		// Update Progress
		sprintf(cstringtemp, "Writing Glow %d", i);
		progress->incrementWithMessage(cstringtemp);
		gla = &light_arrays[i];
		poffile.GLOW_Add_LightGroup(gla->disp_time, gla->on_time, gla->off_time,
								    gla->obj_parent, gla->LOD, gla->type, gla->properties);
		for (j = 0; j < gla->lights.size(); j++)
		{
			poffile.GLOW_Add_GlowPoint(i, gla->lights[j].radius,
										  POFTranslate(gla->lights[j].pos),
										  POFTranslate(gla->lights[j].norm));
		}
	}

	// --------- HDR2 --------- 
	
	// let's make new BBoxes based on the subobjects
	vector3d minbox, maxbox, tmpmin, tmpmax;
	poffile.OBJ2_Get_BoundingMax(0, maxbox);
	poffile.OBJ2_Get_BoundingMin(0, minbox);

	for (i = 1; i < poffile.OBJ2_Count(); i++)
	{
		vector3d sobj_offset(POFTranslate(OffsetFromParent(i)));
		poffile.OBJ2_Get_BoundingMax(i, tmpmax);
		poffile.OBJ2_Get_BoundingMin(i, tmpmin);
		ExpandBoundingBoxes(maxbox, minbox, tmpmax + sobj_offset);
		ExpandBoundingBoxes(maxbox, minbox, tmpmin + sobj_offset);

	}

	for (i = 0; i < poffile.SHLD_Count_Vertices(); i++)
	{
		poffile.SHLD_Get_Vertex(i, tmpmax);
		ExpandBoundingBoxes(maxbox, minbox, tmpmax);
	}

	// update our bounding boxes
	//axis doesn't matter on the bounding boxes - it's all negative/positive values! i'm a faqing moron
	poffile.HDR2_Set_MinBound(header.min_bounding_overridden ? header.min_bounding_override : minbox);
	poffile.HDR2_Set_MaxBound(header.max_bounding_overridden ? header.max_bounding_override : maxbox);
	this->header.max_bounding = minbox;
	this->header.min_bounding = maxbox;

	poffile.HDR2_Set_MaxRadius(header.max_radius_overridden ? header.max_radius_override : header.max_radius);
	poffile.HDR2_Set_Details(header.detail_levels.size(), header.detail_levels);
	poffile.HDR2_Set_Debris(header.debris_pieces.size(), header.debris_pieces);
	poffile.HDR2_Set_Mass(header.mass);
	poffile.HDR2_Set_MassCenter(POFTranslate(header.mass_center));
	poffile.HDR2_Set_MomentInertia(header.MOI);
	poffile.HDR2_Set_SOBJCount(GetSOBJCount());

	std::ofstream out(filename.c_str(), std::ios::out | std::ios::binary);

	if (!poffile.SavePOF(out))
		return 1;

	return 0;
}
Ejemplo n.º 22
0
Archivo: maketree.c Proyecto: 8l/csolve
QuadTree MakeTree(int size, int center_x, int center_y, int lo_proc,
		  int hi_proc, QuadTree parent, ChildType ct, int level) 
{
  int intersect=0;
  QuadTree retval;

#ifdef FUTURES
  retval = (QuadTree) ALLOC(lo_proc,sizeof(*retval));
#else
  retval = (QuadTree) mymalloc(sizeof(*retval));
#endif
  retval->parent = parent;
  retval->childtype = ct;

  intersect = CheckIntersect(center_x,center_y,size);
  size = size/2;
  if ((intersect==0) && (size<512))
      {
      retval->color = white;
      retval->nw = NULL;
      retval->ne = NULL;
      retval->sw = NULL;
      retval->se = NULL;
    }
  else if (intersect==2) 
    {
      retval->color=black;
      retval->nw = NULL;
      retval->ne = NULL;
      retval->sw = NULL;
      retval->se = NULL;
    }
  else 
    {
      if (!level)
	{
	  retval->color = black;
	  retval->nw = NULL;
	  retval->ne = NULL;
	  retval->sw = NULL;
	  retval->se = NULL;
	}
      else 
	{
	  int mid1,mid2;
#ifdef FUTURES 
     future_cell_int fc_sw,fc_se,fc_ne;
#endif

	  mid1 = (lo_proc+hi_proc)/2;
	  mid2 = (lo_proc+hi_proc+1)/2;

#ifndef FUTURES
	  retval->sw = MakeTree(size,center_x-size,center_y-size,
				(mid2+hi_proc+1)/2,hi_proc,retval,
				southwest,level-1);
	  retval->se = MakeTree(size,center_x+size,center_y-size,
				mid2,(mid2+hi_proc)/2,retval,
				southeast,level-1);
	  retval->ne = MakeTree(size,center_x+size,center_y+size,
				(lo_proc+mid1+1)/2,mid1,retval,
				northeast,level-1);
	  retval->nw = MakeTree(size,center_x-size,center_y+size,
				lo_proc,(lo_proc+mid1)/2,retval,
				northwest,level-1);
#else
	  FUTURE(size,center_x-size,center_y-size,
				(mid2+hi_proc+1)/2,hi_proc,retval,
				southwest,level-1,MakeTree,&fc_sw);
	  FUTURE(size,center_x+size,center_y-size,
				mid2,(mid2+hi_proc)/2,retval,
				southeast,level-1,MakeTree,&fc_se);
	  FUTURE(size,center_x+size,center_y+size,
				(lo_proc+mid1+1)/2,mid1,retval,
				northeast,level-1,MakeTree,&fc_ne);
	  retval->nw = MakeTree(size,center_x-size,center_y+size,
				lo_proc,(lo_proc+mid1)/2,retval,
				northwest,level-1);
     TOUCH(&fc_sw);
     retval->sw = (QuadTree) fc_sw.value;
     TOUCH(&fc_se);
     retval->se = (QuadTree) fc_se.value;
     TOUCH(&fc_ne);
     retval->ne = (QuadTree) fc_ne.value;
#endif
	  retval->color = grey;
	}
    }
  return retval;
}
Ejemplo n.º 23
0
/******************************************************** 
 *! @brief 関数
	-
@param[out]     -
@param[in]      -
@par            -
@return         -
@note      
*********************************************************/
PRIVATE void MakeTree( EVALUATE_TREE_T *pCurrentNode )
{
	int					h, v;
	DISC_INFO_T			DiscInfo;
	ERROR_CHECK			Result;
	EVALUATE_TREE_T		*pNextDepthNode;
	EVALUATE_TREE_T		*pNextNode;
	
	if ( pCurrentNode->Depth <= DEPTH_MAX ) {
#ifdef DEBUG_MAKE_NODE
		printf("\nDepth = %d, NodeID = %d, CurrentPlayer = %d, Pos = [%d, %d], Score = %d"
				,pCurrentNode->Depth ,pCurrentNode->NodeID ,pCurrentNode->DiscInfo.CurrentPlayer ,pCurrentNode->DiscInfo.h
				,pCurrentNode->DiscInfo.v/COEF_LINE ,pCurrentNode->Score );
		PrintReversiTable( pCurrentNode->pEvaluatReversiTable->aEvaluatReversiTable );
#endif
		/* 有効な位置を探す */
		for ( v=REALV(1); v < VERTICAL_NUM; v=v+REALV(1) ) {
			for ( h=REALH(1); h < HORIZON_NUM; h=h+REALH(1) ) {
				DiscInfo.h = h;
				DiscInfo.v = v;
				DiscInfo.CurrentPlayer = TOGGLE_PLAYER( pCurrentNode->DiscInfo.CurrentPlayer );
				Result = CheckInputPos( &DiscInfo, pCurrentNode->pEvaluatReversiTable->aEvaluatReversiTable, FALSE );
				
				/* 有効な位置を見つけたら新しいノードを生成する */
				if ( Result == SUCCESS ) {
					
					if ( pCurrentNode->NumNextIndex == 0 ) { /* 1つでも有効な位置が見つかったら次の深さのノードを生成する */
						
						/* Tableへのポインタは生成し終わったら消滅して欲しいのでスコープは必要最低限に限定する */
						EVALUATE_TABLE_T	*pNextDepthTable;
						
						/* Create Evaluate Table of Next Depth Node */
						pNextDepthTable = (EVALUATE_TABLE_T*)malloc( sizeof(EVALUATE_TABLE_T) );
						memcpy( pNextDepthTable, pCurrentNode->pEvaluatReversiTable, sizeof(EVALUATE_TABLE_T) );	/* CurrentノードのTableをコピーする */
						ReversingDisc( DiscInfo, pNextDepthTable->aEvaluatReversiTable );							/* コピーしたTableで石をひっくり返す */
					
						/* Create Evaluate Tree Next Depth Node */
						pCurrentNode->pNextDepthNode			= (EVALUATE_TREE_T*)malloc( sizeof(EVALUATE_TREE_T) );
						pNextDepthNode							= pCurrentNode->pNextDepthNode;	/* 確保した領域にポインタを繋ぐ */
						pNextDepthNode->Depth					= pCurrentNode->Depth + 1;
						pNextDepthNode->NodeID					= pCurrentNode->NumNextIndex;
						pNextDepthNode->DiscInfo.h				= DiscInfo.h;
						pNextDepthNode->DiscInfo.v				= DiscInfo.v;
						pNextDepthNode->DiscInfo.CurrentPlayer	= DiscInfo.CurrentPlayer;
						pNextDepthNode->pEvaluatReversiTable	= pNextDepthTable;
						pNextDepthNode->Score					= CalcScore( pNextDepthNode->DiscInfo.CurrentPlayer,
																			 pNextDepthNode->pEvaluatReversiTable->aEvaluatReversiTable );
						pNextDepthNode->pNextNode				= NULL;
						pNextDepthNode->pNextDepthNode			= NULL;
						
						/* Create Evaluate Tree Next Next Depth Node */
						MakeTree( pNextDepthNode );
						
						/* 探索深度限界判定 */
						if ( pNextDepthNode != NULL ) {
							/* NextDepthがまだ探索深度限界に達していない */
							pNextNode = pNextDepthNode->pNextNode;		/* 以後、新しい選択肢が見つかったらNextNodeに新規Nodeを追加していく */
						} else {
							/* NextDepthが探索深度限界に達していた */
							return;	/* 深度限界なので他の選択肢を探る必要なし */
						}
						
					} else {	/* 次の選択肢が見つかったらノードを生成する */
						
						/* Tableへのポインタは生成し終わったら消滅して欲しいのでスコープは必要最低限に限定する */
						EVALUATE_TABLE_T	*pNextTable;

						/* Create Evaluate Table of Next Node */
						pNextTable = (EVALUATE_TABLE_T*)malloc( sizeof(EVALUATE_TABLE_T) );
						memcpy( pNextTable, pCurrentNode->pEvaluatReversiTable, sizeof(EVALUATE_TABLE_T) );	/* CurrentノードのTableをコピーする */
						ReversingDisc( DiscInfo, pNextTable->aEvaluatReversiTable );						/* コピーしたTableで石をひっくり返す */
					
						/* Create Evaluate Tree Next Node */
						pNextNode								= (EVALUATE_TREE_T*)malloc( sizeof(EVALUATE_TREE_T) );
						pNextNode->Depth						= pCurrentNode->pNextDepthNode->Depth;
						pNextNode->NodeID						= pCurrentNode->NumNextIndex;
						pNextNode->DiscInfo.h					= DiscInfo.h;
						pNextNode->DiscInfo.v					= DiscInfo.v;
						pNextNode->DiscInfo.CurrentPlayer		= DiscInfo.CurrentPlayer;
						pNextNode->pEvaluatReversiTable			= pNextTable;
						pNextNode->Score						= CalcScore( pNextNode->DiscInfo.CurrentPlayer,
																			 pNextNode->pEvaluatReversiTable->aEvaluatReversiTable );
						pNextNode->pNextNode					= NULL;
						pNextNode->pNextDepthNode				= NULL;
						
						/* Create Evaluate Tree Next Depth Next Node */
						MakeTree( pNextNode );
						
						/* pNextNodeに今回生成したNodeのNextNodeアドレスを入れておく
						 * 新しい選択肢が見つかったらpNextNodeに追加していく		*/
						pNextNode = pNextNode->pNextNode;
					}
					
					pCurrentNode->NumNextIndex++;		/* 有効な選択肢が見つかったら次の深さのノード数をインクリメントする */
				}
			}
		}
		
	} else {
		/* 評価木の深度が限界に達したので、確保した領域を解放してTree生成終了 */
		FREE( pCurrentNode->pEvaluatReversiTable );
		FREE( pCurrentNode );
		return;
	}
#ifdef DEBUG_MAKE_NODE
	printf("\n [Depth = %d] NumNextIndex = %d" ,pCurrentNode->Depth ,pCurrentNode->NumNextIndex );
#endif
	
	return;
}
Ejemplo n.º 24
0
LRESULT CSideBar::OnFocusGraph(WPARAM wParam, LPARAM lParam)
{
   /*
   if (m_linelayer_chooser) {
      if (lParam == 9) {
         m_linelayer_chooser->DestroyWindow();
         delete m_linelayer_chooser;
         m_linelayer_chooser = NULL;
      }
      else {
         m_linelayer_chooser->PostMessage(WM_DMP_FOCUS_GRAPH, wParam, lParam);
      }
   }
   */

   // Replacement for m_linelayer_chooser is my tree ctrl:
   CTreeCtrl& tree = GetTreeCtrl();
   CListCtrl& list = GetListCtrl();
   if (::IsWindow(tree.m_hWnd)) {
      CGraphDoc *pDoc = (CGraphDoc *) wParam;
      if (lParam == CGraphDoc::CONTROLS_DESTROYALL && pDoc == m_treeDoc) {      // Lost graph
         m_topgraph = NULL;
         m_backgraph = NULL;
         tree.DeleteAllItems();
         list.DeleteAllItems();
         list.SetColumnWidth(0,0);
         m_treeDoc = NULL;
      }
      else if (lParam == CGraphDoc::CONTROLS_LOADALL && pDoc != m_treeDoc) {    // [Possible] change of window (sent on focus)
         m_treeDoc = pDoc;
         m_topgraph = NULL;
         m_backgraph = NULL;
         MakeTree();
      }
      else if (lParam == CGraphDoc::CONTROLS_LOADGRAPH && pDoc == m_treeDoc) {    // Force update if match current window
         m_topgraph = NULL;
         m_backgraph = NULL;
         MakeGraphTree();
         // also make drawing tree as this overrides layer visible status sometimes:
         MakeDrawingTree();
      }
      else if (lParam == CGraphDoc::CONTROLS_RELOADGRAPH && pDoc == m_treeDoc) {    // Force reload of graph tree if match current window
         m_topgraph = NULL;
         m_backgraph = NULL;
         ClearGraphTree();
         MakeGraphTree();
      }
      else if (lParam == CGraphDoc::CONTROLS_LOADDRAWING && pDoc == m_treeDoc) {    // Force update if match current window
         MakeDrawingTree();
      }
      else if (lParam == CGraphDoc::CONTROLS_LOADATTRIBUTES && pDoc == m_treeDoc) {    // Force update if match current window
         MakeAttributeList();
      }
      else if (lParam == CGraphDoc::CONTROLS_CHANGEATTRIBUTE && pDoc == m_treeDoc) {    // Force update if match current window
         SetAttributeChecks();
      }
      else if (lParam == CGraphDoc::CONTROLS_LOADCONVERT && pDoc == m_treeDoc) {
         m_topgraph = NULL;
         m_backgraph = NULL;
         MakeGraphTree();
         // conversions typically turn off drawing layers:
         SetDrawingTreeChecks();
      }
      if (m_treeDoc == NULL) {
         tree.EnableWindow(FALSE);
         // Stop some strange auto scroll property:
         SetTreeStyle(TVS_NOSCROLL, TRUE);
      }
      else {
         tree.EnableWindow(TRUE);
         // Stop some strange auto scroll property:
         SetTreeStyle(TVS_NOSCROLL, FALSE);
      }
   }

   return 0;
}
Ejemplo n.º 25
0
int main() {
        Node    root;
        Node    longLivedTree;
        Node    tempTree;
        long    tStart, tFinish;
        long    tElapsed;
  	int	i, d;
	double 	*array;

#ifdef GC
 // GC_full_freq = 30;
 // GC_free_space_divisor = 16;
 // GC_enable_incremental();
#endif
	printf("Garbage Collector Test\n");
 	printf(" Live storage will peak at %d bytes.\n\n",
               2 * sizeof(Node0) * TreeSize(kLongLivedTreeDepth) +
               sizeof(double) * kArraySize);
        printf(" Stretching memory with a binary tree of depth %d\n",
               kStretchTreeDepth);
        PrintDiagnostics();
#	ifdef PROFIL
	    init_profiling();
#	endif
       
        tStart = currentTime();
        
        // Stretch the memory space quickly
        tempTree = MakeTree(kStretchTreeDepth);
#	ifndef GC
          destroy_Node(tempTree);
#	endif
        tempTree = 0;

        // Create a long lived object
        printf(" Creating a long-lived binary tree of depth %d\n",
               kLongLivedTreeDepth);
#	ifndef GC
          longLivedTree = calloc(1, sizeof(Node0));
#	else 
          longLivedTree = GC_NEW(Node0);
#	endif
        Populate(kLongLivedTreeDepth, longLivedTree);
        ggggc_collectFull();
        // Create long-lived array, filling half of it
	printf(" Creating a long-lived array of %d doubles\n", kArraySize);
#	ifndef GC
          array = malloc(kArraySize * sizeof(double));
#	else
#	  ifndef NO_PTRFREE
            array = GC_MALLOC_ATOMIC(sizeof(double) * kArraySize);
#	  else
            array = GC_MALLOC(sizeof(double) * kArraySize);
#	  endif
#	endif
        ggggc_collectFull();
        for (i = 0; i < kArraySize/2; ++i) {
                array[i] = 1.0/i;
        }
        PrintDiagnostics();

        for (d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2) {
                TimeConstruction(d);
        }

        if (longLivedTree == 0 || array[1000] != 1.0/1000)
		fprintf(stderr, "Failed\n");
                                // fake reference to LongLivedTree
                                // and array
                                // to keep them from being optimized away

        tFinish = currentTime();
        tElapsed = elapsedTime(tFinish-tStart);
        PrintDiagnostics();
        printf("Completed in %d msec\n", tElapsed);
#	ifdef GC
	  printf("Completed %d collections\n", GC_gc_no);
	  printf("Heap size is %d\n", GC_get_heap_size());
#       endif
#	ifdef PROFIL
	  dump_profile();
#	endif
}
Ejemplo n.º 26
0
        void main() {
                Node    root;
                Node    longLivedTree;
                Node    tempTree;
                long    tStart, tFinish;
                long    tElapsed;

#ifdef GC
// GC_full_freq = 30;
GC_enable_incremental();
#endif
                cout << "Garbage Collector Test" << endl;
                cout << " Live storage will peak at "
                     << 2 * sizeof(Node0) * TreeSize(kLongLivedTreeDepth) +
                        sizeof(double) * kArraySize
                     << " bytes." << endl << endl;
                cout << " Stretching memory with a binary tree of depth "
                     << kStretchTreeDepth << endl;
                PrintDiagnostics();
               
                tStart = currentTime();
                
                // Stretch the memory space quickly
                tempTree = MakeTree(kStretchTreeDepth);
#		ifndef GC
                  delete tempTree;
#		endif
                tempTree = 0;

                // Create a long lived object
                cout << " Creating a long-lived binary tree of depth "
                     << kLongLivedTreeDepth << endl;
#		ifndef GC
                  longLivedTree = new Node0();
#		else 
                  longLivedTree = new (GC_NEW(Node0)) Node0();
#		endif
                Populate(kLongLivedTreeDepth, longLivedTree);

                // Create long-lived array, filling half of it
                cout << " Creating a long-lived array of "
                     << kArraySize << " doubles" << endl;
#		ifndef GC
                  double *array = new double[kArraySize];
#		else
                  double *array = (double *)
				GC_MALLOC_ATOMIC(sizeof(double) * kArraySize);
#		endif
                for (int i = 0; i < kArraySize/2; ++i) {
                        array[i] = 1.0/i;
                }
                PrintDiagnostics();

                for (int d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2)
{
                        TimeConstruction(d);
                }

                if (longLivedTree == 0 || array[1000] != 1.0/1000)
                        cout << "Failed" << endl;
                                        // fake reference to LongLivedTree
                                        // and array
                                        // to keep them from being optimized away

                tFinish = currentTime();
                tElapsed = elapsedTime(tFinish-tStart);
                PrintDiagnostics();
                cout << "Completed in " << tElapsed << " msec" << endl;
#		ifdef GC
		  cout << "Completed " << GC_gc_no << " collections" <<endl;
		  cout << "Heap size is " << GC_get_heap_size() << endl;
#		endif
        }
Ejemplo n.º 27
0
bool PCS_Model::PMFObj_to_POFObj2(int src_num, OBJ2 &dst, bool &bsp_compiled, float& model_radius)
{

	pcs_sobj &src = subobjects[src_num];

	dst.submodel_parent = src.parent_sobj;
	dst.offset = POFTranslate(src.offset);
	dst.geometric_center = POFTranslate(src.geometric_center);
	dst.submodel_name = APStoString(src.name);
	dst.properties = APStoString(src.properties);

	switch (src.movement_type)
	{
		case ROTATE:
			dst.movement_type = 1;
			break;
		default:
			dst.movement_type = -1;
	}
	switch (src.movement_axis)
	{
		case MV_X:
			dst.movement_axis = 0;
			break;
		case MV_Z:
			dst.movement_axis = 1;
			break;
		case MV_Y:
			dst.movement_axis = 2;
			break;
		default:
			dst.movement_axis = -1;
	}

	dst.reserved = 0;



	if(!can_bsp_cache || bsp_cache[src_num].changed)
	{

		// convert them to POF axis
		std::vector<pcs_polygon> clean_list = src.polygons;
		for (size_t i = 0; i < clean_list.size(); i++)
		{
			clean_list[i].norm = POFTranslate(clean_list[i].norm);
			for (size_t j = 0; j < clean_list[i].verts.size(); j++)
			{
				clean_list[i].verts[j].point = POFTranslate(clean_list[i].verts[j].point);
				clean_list[i].verts[j].norm = POFTranslate(clean_list[i].verts[j].norm);
			}
			clean_list[i].centeroid = PolygonCenter(clean_list[i]);
		}

		// BSP Compilation!
		// assemble points list
		std::vector<bsp_vert> points_list;
		std::vector<vector3d> pnts;
		std::unordered_map<vector3d, int> point_to_index;
		std::unordered_map<vector3d, int> normal_to_index;
		for (size_t i = 0; i < pnts.size(); i++) {
			point_to_index.insert(std::make_pair(pnts[i], i));
		}
		bsp_vert temp;
		points_list.reserve(clean_list.size());
		for (size_t i = 0; i < clean_list.size(); i++)
		{
			for (size_t j = 0; j < clean_list[i].verts.size(); j++)
			{
				auto point = point_to_index.find(clean_list[i].verts[j].point);
				if (point == point_to_index.end()) {
					point_to_index.insert(std::make_pair(clean_list[i].verts[j].point, points_list.size()));
					points_list.emplace_back();
					points_list.back().point = clean_list[i].verts[j].point;
					pnts.push_back(points_list.back().point);
				}
				auto normal = normal_to_index.find(clean_list[i].verts[j].norm);
				if (normal == normal_to_index.end()) {
					points_list[normal_to_index.size() / 128].norms.push_back(clean_list[i].verts[j].norm);
					normal_to_index.insert(std::make_pair(clean_list[i].verts[j].norm, normal_to_index.size()));
				}
			}
		}



		// create our defpoints
		BSP_DefPoints points;
		MakeDefPoints(points, points_list);
		vector3d AvgNormal;

		// create tree
		std::unique_ptr<bsp_tree_node> root = MakeTree(clean_list, dst.bounding_box_max_point, dst.bounding_box_min_point);

		// allocate buffer and write the defpoints
		dst.bsp_data.resize(points.head.size + CalculateTreeSize(root.get(), clean_list));

		if (points.Write(&dst.bsp_data.front()) != points.head.size)
			return false; // calculation error

		//std::ofstream bsp_debug("c:\\bsp.txt");
		//DebugPrintTree(root, bsp_debug);

		// pack the tree
		int error_flags = 0;
		PackTreeInBSP(root.get(), points.head.size, &dst.bsp_data.front(), clean_list, normal_to_index, point_to_index, points, dst.geometric_center, dst.bsp_data.size(), error_flags);
		
		// we got errors!
		if (error_flags != BSP_NOERRORS)
			return false;

		// update the bsp_compiled to be true
		bsp_compiled = true;

		// update the BSP cache with the new result
		if (can_bsp_cache)
		{
			// clear the saved - stale cache
			bsp_cache[src_num].decache();
			bsp_cache[src_num].bsp_data = dst.bsp_data;
			bsp_cache[src_num].changed = false;
		}


	}
	else // Used cached copy!
	{
		dst.bsp_data = bsp_cache[src_num].bsp_data;
	}
	dst.radius = 0.0f;
	dst.bounding_box_max_point = vector3d(FLT_MIN, FLT_MIN, FLT_MIN);
	dst.bounding_box_min_point = vector3d(FLT_MAX, FLT_MAX, FLT_MAX);

	vector3d global_offset(OffsetFromParent(src_num));
	for(unsigned int i = 0; i<src.polygons.size(); i++){
		for(unsigned int j = 0; j<src.polygons[i].verts.size(); j++){
			ExpandBoundingBoxes(dst.bounding_box_max_point, dst.bounding_box_min_point,  src.polygons[i].verts[j].point);
			float norm = Magnitude(src.polygons[i].verts[j].point);
			if (norm > dst.radius) {
				dst.radius = norm;
			}
			float global_norm = Magnitude(src.polygons[i].verts[j].point + global_offset);
			if (global_norm > model_radius) {
				model_radius = global_norm;
			}

		}
	}
	if (dst.radius == 0.0f) {
		dst.bounding_box_max_point = vector3d();
		dst.bounding_box_min_point = vector3d();
	}
	if (src.radius_overridden) {
		dst.radius = src.radius_override;
	}
	if (src.bounding_box_min_point_overridden) {
		dst.bounding_box_min_point = src.bounding_box_min_point_override;
	}
	if (src.bounding_box_max_point_overridden) {
		dst.bounding_box_max_point = src.bounding_box_max_point_override;
	}
	POFTranslateBoundingBoxes(dst.bounding_box_min_point, dst.bounding_box_max_point);
	return true;
}