示例#1
0
 void InsertValue(TreeNode* root, int& val)
 {
     if(root == NULL)
       return;
     InsertValue(root->left, val);
     root->val = val++;
     InsertValue(root->right, val);
 }
示例#2
0
void LoadAtmosphere() {
	if (!(gfstate & GFS_UIATMOSPHERE))
		return;
	atmosactive = true;
	char buf[512];
	int i = 0, tmp;
	LPCHANNEL lpChannel;
	FILE *file = fopen("channels.atm", "r");
	if (file) {
		while (!feof(file)) {
			fgets(buf, sizeof(buf), file);
			tmp = strlen(buf) - 1;
			if (buf[tmp] == 0x0A) 
				buf[tmp] = 0; 
			if (buf[0] && buf[0] != '#') {
				if (!i) {
					lpChannel = (LPCHANNEL)malloc(sizeof(CHANNEL));
					strncpy(lpChannel->channelname, buf, 64);
					lcase(lpChannel->channelname);
				} else {
					strncpy((char *)lpChannel + 64 + ((i - 1) * 128), buf, 128);
				}
				i++;
				if (i == 4) {
					i = 0;
					InsertValue(lpChannel->channelname, lpChannel, channels, TABLESIZE_CHANNELS);
				}
			}
		}
		fclose(file);
	}
}
示例#3
0
    void Decompress(char* source, char* dest) {
        assert(source != nullptr);
        assert(dest != nullptr);

        BinaryReader reader(source);
        BinaryWriter writer(dest);
        
        ReadHeader(reader);
        maxDictSize_ = 1 << indexBits_;
        AllocateDictionary();
        
        TrieNode* previousNode = nullptr;
        unsigned char firstChar;
        unsigned char lastChar;

        while(reader.IsEOF() == false) {
            int index = reader.ReadBits(IndexBits());
            if(index == maxDictSize_ -1) break;
            
            if(index >= dictSize_) {
                firstChar = WriteString(previousNode, writer);
                writer.WriteByte(lastChar);
            }
            else {
                firstChar = WriteString(nodes_[index], writer);
            }
            
            if(previousNode) {
                InsertValue(firstChar, previousNode);
            }

            lastChar = firstChar;
            previousNode = nodes_[index];
        }
    }
示例#4
0
文件: td3.c 项目: anliec/TP-Algo
int main(void) 
{
  char lecture[100];
  int val;
  BinaryHeap * heap;
  heap = Init(10);

  fscanf(stdin,"%99s",lecture);
  while (strcmp(lecture,"bye")!=0) {
    if (strcmp(lecture,"insert")==0) {
      fscanf(stdin,"%99s",lecture);
      val = strtol(lecture,NULL,10);
      InsertValue(heap,val);
    } else if (strcmp(lecture,"extract")==0) {
      if(ExtractMax(heap,&val))
      {
        printf("%d\r\n",val);
      }
    } else if (strcmp(lecture,"print")==0) {
      printTab(heap);
    }
    fscanf(stdin,"%99s",lecture);
  }
  Destroy(heap);
  return 0;
}
示例#5
0
 vector<TreeNode*> generateTrees(int n)
 {
     vector<TreeNode*> roots = generateTreesInternal(n);
     int val = 0;
     for(int i = 0; i < roots.size(); ++i)
     {
         val = 1;
     	InsertValue(roots[i], val);
     }
     return roots;
 }
示例#6
0
ERR AddForce(PhysicsObject* target, double x_force, double y_force, double x_pos, double y_pos)
{
    Force* force = (Force*)malloc(sizeof(Force));
    if(force == NULL)
    {
        fprintf(stderr, "Memory allocation failure");
        return 1;
    }
    force->x_force  = x_force;
    force->y_force  = y_force;
    force->x_pos    = x_pos;
    force->y_pos    = y_pos;
    return InsertValue(force, target->forces, 0);
}
示例#7
0
void ValuesTable::AddData(DatabaseQuery *q, bool &view_values_changed, bool &stats_updated) {

	DatabaseQuery::ValueData& vd = q->value_data;
	PeriodType pt = vd.period_type;
	if (pt != m_draw->GetPeriod() || q->draw_info != m_draw->GetDrawInfo()) {
		return;
	}

	for (std::vector<DatabaseQuery::ValueData::V>::iterator i = q->value_data.vv->begin();
			i != q->value_data.vv->end();
			i++)
		InsertValue(&(*i), view_values_changed, stats_updated);

}
int IsCyclicGraph(graph g)
{
    int no = g.size;
    int * visit;
    visit = (int*)calloc((no+1),sizeof(int));
    stack s;
    NODE top = CreateNode();
    s = CreateStack();
    top = InsertValue(top,1);
    visit[Value(top)] = 1;
    s = push(s, Value(top));
    while(s.top!=NULL)
    {
        top = CreateNode();
        top = InsertValue(top,Value(s.top));
        s = pop(s);
        top = g.list[Value(top)].top;
        while(top!=NULL)
        {
            NODE temp = CreateNode();
            temp = InsertValue(temp,Value(top));
            if(visit[Value(top)] != 1)
            {
                s = push(s,Value(temp));
                visit[Value(top)] = 1;
            }
            else
            {
                printf("Graph is Cyclic %d\n",Value(top));
                return -1;
            }
            top = top->next;
        }
    }
    printf("Graph is Acyclic\n");
    return 1;
}
示例#9
0
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    void Compress(char* source, char* dest, unsigned indexBits, bool freeze) {
        assert(source != nullptr);
        assert(dest != nullptr);

        indexBits_ = indexBits;
        freeze_ = freeze;
        maxDictSize_ = 1 << indexBits_;
        AllocateDictionary();
        
        BinaryReader reader(source);
        BinaryWriter writer(dest);

        WriteHeader(writer);
        TrieNode* previousNode = rootNode_;

        while(true) {
            bool stop = false;
            unsigned char value;
            TrieNode* currentNode = nullptr;

            if(reader.IsEOF() == false) {
                value = reader.ReadByte();
                currentNode = previousNode->GetNodeForValue(value);
            }
            else stop = true;

            if((currentNode == nullptr) || 
               (stop && (previousNode != rootNode_))) {
                TrieNode* lastNode = currentNode ? currentNode : previousNode;
                writer.WriteBits(lastNode->Index, IndexBits());
                
                if(stop == false) {
                    InsertValue(value, previousNode);
                    previousNode = rootNode_->GetNodeForValue(value);
                }
            }
            else previousNode = currentNode;

            if(stop) break;
        }

        writer.WriteBits(maxDictSize_ - 1, IndexBits());
    }
示例#10
0
文件: Shell.c 项目: authorNari/panda
static	ValueStruct	*
ExecShell(
	DBCOMM_CTRL		*ctrl,
	RecordStruct	*rec,
	LargeByteString	*src,
	ValueStruct		*args)
{
	int		c;
	ValueStruct	*val;
	DBG_Struct	*dbg;
	ValueStruct	*ret;
	LargeByteString	*lbs;

ENTER_FUNC;
	ret = NULL;
	dbg =  rec->opt.db->dbg;
	lbs = (LargeByteString *)dbg->process[PROCESS_UPDATE].conn;
	if	(  src  ==  NULL )	{
		Error("function \"%s\" is not found.",ctrl->func);
	}
	RewindLBS(src);
	while	(  ( c = LBS_FetchByte(src) )  >=  0  ) {
		if		(  c  !=  SQL_OP_ESC  ) {
			LBS_EmitChar(lbs,c);
		} else {
			c = LBS_FetchByte(src);
			switch	(c) {
			  case	SQL_OP_REF:
				val = (ValueStruct *)LBS_FetchPointer(src);
				InsertValue(dbg,lbs,val);
				break;
			  case	SQL_OP_EOL:
			  case	0:
				LBS_EmitChar(lbs,';');
				break;
			  default:
				break;
			}
		}
	}
LEAVE_FUNC;
	return	(ret);
}
示例#11
0
HRESULT CXFields::InsertField(int pos, BSTR key, short type)
{
	if(pos < 0 || pos >= (int)GetCount())
		return DISP_E_BADINDEX;

	if(!isVBType(type))
		return E_INVALIDARG;

	CXComPtr<CXField> pField;

	pField.CreateObject();

	pField->m_strName = key;
	pField->m_nType = type;

	InsertValue(pos, pField);

	return S_OK;
}
示例#12
0
int main()
{
    HashTable H = initHashTable(13);
    int Key = 5;
    Position Pos = Find(H, Key);
    Position newPos;

    assert(H->TheCells[Pos].Info == EMPTY);
    // test insert and find
    Insert(H, Key);
    assert(H->TheCells[Pos].Info == OCCUPY);
    InsertValue(H, Key, 90);
    newPos = Find(H, Key);
    assert(Pos == newPos);
    assert(H->TheCells[newPos].Info == OCCUPY);
    assert(H->TheCells[newPos].Value == 90);

    printf("pass!\n");
    return 0;
}
示例#13
0
void test ()
{	
	BinarySort * tree = Init(10);
	
	uint64_t* nombresPremiers1 = ( uint64_t* ) malloc( sizeof( uint64_t ) * 64 );
	nombresPremiers1[0] = 2;
	nombresPremiers1[1] = 3;
	nombresPremiers1[2] = 5;
	Decomposition *dec1 = (Decomposition*) malloc (sizeof(Decomposition));
	dec1 -> value = 30;
	dec1 -> tabSize = 3;
	dec1 -> primeNumbers = nombresPremiers1;
	
	uint64_t* nombresPremiers2 = ( uint64_t* ) malloc( sizeof( uint64_t ) * 64 );
	nombresPremiers2[0] = 2;
	nombresPremiers2[1] = 2;
	nombresPremiers2[2] = 7;
	Decomposition *dec2 = (Decomposition*) malloc (sizeof(Decomposition));
	dec2 -> value = 28;
	dec2 -> tabSize = 3;
	dec2 -> primeNumbers = nombresPremiers2;
	
	uint64_t* nombresPremiers5 = ( uint64_t* ) malloc( sizeof( uint64_t ) * 64 );
	nombresPremiers5[0] = 29;
	Decomposition *dec5 = (Decomposition*) malloc (sizeof(Decomposition));
	dec5 -> value = 29;
	dec5 -> tabSize = 1;
	dec5 -> primeNumbers = nombresPremiers5;
	
	uint64_t* nombresPremiers3 = ( uint64_t* ) malloc( sizeof( uint64_t ) * 64 );
	nombresPremiers3[0] = 3;
	nombresPremiers3[1] = 3;
	nombresPremiers3[2] = 11;
	Decomposition *dec3 = (Decomposition*) malloc (sizeof(Decomposition));
	dec3 -> value = 99;
	dec3 -> tabSize = 3;
	dec3 -> primeNumbers = nombresPremiers3;
	
	uint64_t* nombresPremiers4 = ( uint64_t* ) malloc( sizeof( uint64_t ) * 64 );
	nombresPremiers4[0] = 2;
	nombresPremiers4[1] = 2;
	Decomposition *dec4 = (Decomposition*) malloc (sizeof(Decomposition));
	dec4 -> value = 4;
	dec4 -> tabSize = 2;
	dec4 -> primeNumbers = nombresPremiers4;
	
	InsertValue(tree,dec1);
	InsertValue(tree,dec4);
	InsertValue(tree,dec2);
	InsertValue(tree,dec5);
	InsertValue(tree,dec3);
	printf("La valeur de filled apres les insert values est de : %d\r\n",tree->filled);
	
	int indiceTab=0;
	int compteurValeur=0;
	int j;
	while ( compteurValeur < tree->filled )
	{	if (tree->array[indiceTab] != NULL)
		{	printf( "indice : " );
			printf( "%d\r\n" , indiceTab );
			printf( "%ju\r\n" , tree->array[indiceTab]->value);
			for ( j = 0 ; j < tree -> array[indiceTab] -> tabSize ; j++ )
			{	
				printf( "%ju\r\n" , tree -> array[indiceTab] -> primeNumbers[j] );
			}
		 	compteurValeur++;
		}
	 	indiceTab++;
	}

	Destroy (tree);


	
}
int main()
{
	__pTrieHead = new TrieTreeNode();

	InsertValue(__pTrieHead, "truck");
	InsertValue(__pTrieHead, "trick");
	InsertValue(__pTrieHead, "trunck");
	InsertValue(__pTrieHead, "trash");
	InsertValue(__pTrieHead, "tank");

	/*FindWord(__pTrieHead, "tank");
	FindWord(__pTrieHead, "truck");
	FindWord(__pTrieHead, "trick");
	FindWord(__pTrieHead, "trunck");
	FindWord(__pTrieHead, "trash");

	FindWord(__pTrieHead, "trudt");*/

	FindWordByPrefix(__pTrieHead, "t");

	getch();
	FreeTrieTree(__pTrieHead);
	return 1;

/* Derived d;
	Base* b1 = &d;
	Base& b2 = d;
	Base b3;*/

	/*AccessVTable clAccessVTable;

	int* vptrBase = (int*)&clAccessVTable;
	getch();
	return 0;

	fn1();*/

	// Late binding for both:
	/*cout << "b1->f() = " << b1->f() << endl;
	cout << "b2.f() = " << b2.f() << endl;

	// Early binding (probably):
	cout << "b3.f() = " << b3.f() << endl;

	cout << "VPTR's Address " << (int*)(&d+0) << endl;
	cout << "virtual tables's Address " << (int*)*(int*)(&d+0) << endl; // Value of VPTR
	cout << "Value at first entry of VIRTUAL TABLE " << (int*)*(int*)*(int*)(&d+0) << endl;

	Fun pFun = (Fun)*(int*)*(int*)(&d+0);   // calling Virtual function
	pFun();
	d.fnDisplay();

	/*Derived* pDerivedPtr = new Derived[10];
	Derived* pTempDptr;
	pTempDptr = (pDerivedPtr+5);
	delete [] pTempDptr;

	int i=10;
	int & iRef = i;

	/*Temp *pTemp = new Temp;

	//Allocate memoty for 2Dimensional array and assign value to it...
	Temp** ppTemp = new Temp*[10];

	for ( i =0 ; i < 10 ; i++ )
		ppTemp[i] = new Temp;
	
	memset(ppTemp, 0 , 10 * sizeof (Temp));

	for ( i =0 ; i < 10 ; i++ )
	{
		delete ppTemp[i];
		ppTemp[i] = NULL;
	}
	delete []ppTemp;
	//Allocation of 2D arary on heap ends...



	//Difference between passing reference and pointers as function argument...
	{
		Temp t1;
		t1.iInt = 10;

		//call copy constructor...
		Temp t2 = t1;

		//call pointered copy constructor...
		Temp t3(&t2);
	}
	//Ends...
	
	*/
	//getch();
	char ch='\0';
	int option=0, iValue=0, iDirection=-1;
	do
	{
		printf("\n*****************************");
		printf("\n\tTREE OPERATIONS");
		printf("\n*****************************");
		printf("\n1.Insert Node Element");
		printf("\n2.Delete Node Element");
		printf("\n3.Search Node Element");
		printf("\n4.Find Node Element");
		printf("\n5.InOrder Traversal");
		printf("\n6.PreOrder Traversal");
		printf("\n7.PostOrder Traversal");
		printf("\n8.Is Mirror Image");
		printf("\n9.BFS Traversal");
		printf("\n10.DFS Traversal");
		printf("\n11.Create Mirror Image Tree");
		printf("\n12.Release Tree Nodes");
		printf("\n13.Terminate");
		printf("\n*****************************");
		printf("\nEnter Option : ");
		scanf("%d",&option);
		
		switch ( option )
		{
		case 1:
			{
				printf("\nEnter value:");
				scanf("%d", &iValue);
				InsertTreeNode(&__pRoot, iValue);
			}
			break;
		case 2:
			break;
		case 3:
			{
				clock_t StartTime, EndTime;
				float micro=0.0, seconds=0.0;
				printf("\nEnter value to search:");
				scanf("%d", &iValue);
				StartTime = clock();
				if (!SearchTreeNode(__pRoot, iValue))
					printf("\nNOT FOUND...!!!");
				EndTime= clock();
				micro = ((float)StartTime- (float)EndTime);
				printf("\nTime taken to perform search operation is [%f] microseconds", micro);
				printf("\nTime taken to perform search operation is [%f] seconds", seconds);
			}
			break;
		case 4:
			break;
		case 5:
			{
				TraverseTree_InOrder(__pRoot);
			}
			break;
		case 6:
			{
				TraverseTree_PreOrder(__pRoot);
			}
			break;
		case 7:
			{
				TraverseTree_PostOrder(__pRoot);
			}
			break;

		case 8:
			{
				if ( MirrorImage(__pRoot, NULL, NULL))
					printf("\nTree is Mirro Image.");
				else	
					printf("\nTree is not Mirror Image");
			}	
		break;
		case 9:
			{
				TraverseTree_PostOrder(__pRoot);
			}
		break;
		case 10:
			{
				TraverseTree_PostOrder(__pRoot);
			}
		break;
		case 11:
			{
				printf("\nEnter value:");
				scanf("%d", &iValue);
				printf("\nEnter direction [LEFT =1, RIGHT=1]:");
				scanf("%d", &iDirection);
				CreateMirrorImageTree(&__pRoot, iValue, iDirection);
			}
		break;
		case 12:
			{
				ReleaseTreeNodes(&__pRoot);
					//__pRoot = NULL;
			}
			break;
		}
	}
	while (option<13);
	ReleaseTreeNodes(&__pRoot);
	return 1;
} 
示例#15
0
//***************************************************************************************************
//	UpdateTile
//***************************************************************************************************
void eCTerrainTileList::UpdateTile(GEUInt a_iActiveListIndex, GEUInt a_iViewWorldPosX, GEUInt a_iViewWorldPosY)
{
	eSTerrainTileData* __restrict	pTile			= m_pActiveList[a_iActiveListIndex];
	unsigned int				iTileLodLevel		= pTile->asStruct.m_iLodLevel;
	unsigned int				iTilePosX			= pTile->asStruct.m_iPosX;
	unsigned int				iTilePosY			= pTile->asStruct.m_iPosY;
	unsigned int				eTileState			= pTile->asStruct.m_eState;

	//unsigned int				iTilePositionData	= pTile->asInt;
	//unsigned int				iTileLodLevel		= GET_LOD_LEVEL_FROM_INT_DATA(iTilePositionData); //pTile->m_iLodLevel;
	//unsigned int				iTilePosX			= GET_POS_X_FROM_INT_DATA(iTilePositionData); //pTile->m_iPosX;
	//unsigned int				iTilePosY			= GET_POS_Y_FROM_INT_DATA(iTilePositionData); //pTile->m_iPosY;
	//unsigned int				eTileState			= GET_STATE_FROM_INT_DATA(iTilePositionData);


	if (eTileState != TileState_Enabled)
	{
		SetFreeIndex(a_iActiveListIndex);
		return;
	}	

	if (iTileLodLevel > 0)
	{
		unsigned int	iDistanceFromTileSqr	= ComputeDistanceFromTileSqr(iTileLodLevel, iTilePosX, iTilePosY, a_iViewWorldPosX, a_iViewWorldPosY);
		unsigned int	iDistanceThresholdSqr	= GetDistanceThresholdSqr(iTileLodLevel); //pTile->m_iDistanceThreshold * pTile->m_iDistanceThreshold;

		if (iDistanceFromTileSqr <= iDistanceThresholdSqr)
		{
			// tile needs to be splitted

			unsigned int	iChildLodLevel			= iTileLodLevel - 1;
			unsigned int	iChildPosX 				= iTilePosX * 2;
			unsigned int	iChildPosY				= iTilePosY * 2;		

			unsigned int	iChild0TileIndex	= ComputeTileIndex(iChildLodLevel, iChildPosX, iChildPosY);
			unsigned int	iChild1TileIndex	= ComputeTileIndex(iChildLodLevel, iChildPosX + 1, iChildPosY);
			unsigned int	iChild2TileIndex	= ComputeTileIndex(iChildLodLevel, iChildPosX, iChildPosY + 1);
			unsigned int	iChild3TileIndex	= ComputeTileIndex(iChildLodLevel, iChildPosX + 1, iChildPosY + 1);

			//
			eSTerrainTileData*	pChild0Tile			= &m_pTiles[iChild0TileIndex];
			eSTerrainTileData*	pChild1Tile			= &m_pTiles[iChild1TileIndex];
			eSTerrainTileData*	pChild2Tile			= &m_pTiles[iChild2TileIndex];
			eSTerrainTileData*	pChild3Tile			= &m_pTiles[iChild3TileIndex];


			pTile->asStruct.m_eState		= TileState_ChildEnabled;

			pChild0Tile->asStruct.m_eState	= TileState_Enabled;
			pChild1Tile->asStruct.m_eState	= TileState_Enabled;
			pChild2Tile->asStruct.m_eState	= TileState_Enabled;
			pChild3Tile->asStruct.m_eState	= TileState_Enabled;


			SetFreeIndex(a_iActiveListIndex);

			//
			unsigned int iFreeIndex0 = InsertValue(pChild0Tile);
			unsigned int iFreeIndex1 = InsertValue(pChild1Tile);
			unsigned int iFreeIndex2 = InsertValue(pChild2Tile);
			unsigned int iFreeIndex3 = InsertValue(pChild3Tile);

			GE_UNUSED(iFreeIndex0);
			GE_ASSERT(iFreeIndex0 > a_iActiveListIndex);
			GE_UNUSED(iFreeIndex1);
			GE_ASSERT(iFreeIndex1 > a_iActiveListIndex);
			GE_UNUSED(iFreeIndex2);
			GE_ASSERT(iFreeIndex2 > a_iActiveListIndex);
			GE_UNUSED(iFreeIndex3);
			GE_ASSERT(iFreeIndex3 > a_iActiveListIndex);			
			return;
		}


		unsigned int	iChildLodLevel			= iTileLodLevel - 1;
		unsigned int	iChildPosX 				= iTilePosX * 2;
		unsigned int	iChildPosY				= iTilePosY * 2;

		unsigned int	iChild0TileIndex	= ComputeTileIndex(iChildLodLevel, iChildPosX, iChildPosY);
		unsigned int	iChild1TileIndex	= ComputeTileIndex(iChildLodLevel, iChildPosX + 1, iChildPosY);
		unsigned int	iChild2TileIndex	= ComputeTileIndex(iChildLodLevel, iChildPosX, iChildPosY + 1);
		unsigned int	iChild3TileIndex	= ComputeTileIndex(iChildLodLevel, iChildPosX + 1, iChildPosY + 1);

		//
		GE_ASSERT(m_pTiles[iChild0TileIndex].asStruct.m_eState == TileState_Disabled);
		GE_ASSERT(m_pTiles[iChild1TileIndex].asStruct.m_eState == TileState_Disabled);
		GE_ASSERT(m_pTiles[iChild2TileIndex].asStruct.m_eState == TileState_Disabled);
		GE_ASSERT(m_pTiles[iChild3TileIndex].asStruct.m_eState == TileState_Disabled);
	}


	if (iTileLodLevel < (m_iLodCount - 1))
	{
		unsigned int		iParentLodLevel		= iTileLodLevel + 1;
		unsigned int		iParentPosX			= iTilePosX / 2;
		unsigned int		iParentPosY			= iTilePosY / 2;
		unsigned int		iParentTileIndex	= ComputeTileIndex(iParentLodLevel, iParentPosX, iParentPosY);
		eSTerrainTileData*	pParentTile			= &m_pTiles[iParentTileIndex];

		unsigned int	iDistanceFromTileSqr			= ComputeDistanceFromTileSqr(iParentLodLevel, iParentPosX, iParentPosY, a_iViewWorldPosX, a_iViewWorldPosY);
		unsigned int	iParentDistanceThresholdSqr		= GetDistanceThresholdSqr(iParentLodLevel); //pParentTile->m_iDistanceThreshold * pParentTile->m_iDistanceThreshold;

		if (iDistanceFromTileSqr > iParentDistanceThresholdSqr) 
		{
			// tile need to be merged
			unsigned int	iSiblingPosX			= iParentPosX * 2;
			unsigned int	iSiblingPosY			= iParentPosY * 2;
			unsigned int	iSibling0TileIndex		= ComputeTileIndex(iTileLodLevel, iSiblingPosX, iSiblingPosY);
			unsigned int	iSibling1TileIndex		= ComputeTileIndex(iTileLodLevel, iSiblingPosX + 1, iSiblingPosY);
			unsigned int	iSibling2TileIndex		= ComputeTileIndex(iTileLodLevel, iSiblingPosX, iSiblingPosY + 1);
			unsigned int	iSibling3TileIndex		= ComputeTileIndex(iTileLodLevel, iSiblingPosX + 1, iSiblingPosY + 1);

			//
			eSTerrainTileData*	pSibling0Tile			= &m_pTiles[iSibling0TileIndex];
			eSTerrainTileData*	pSibling1Tile			= &m_pTiles[iSibling1TileIndex];
			eSTerrainTileData*	pSibling2Tile			= &m_pTiles[iSibling2TileIndex];
			eSTerrainTileData*	pSibling3Tile			= &m_pTiles[iSibling3TileIndex];

			pParentTile->asStruct.m_eState			= TileState_Enabled;

			pSibling0Tile->asStruct.m_eState		= TileState_Disabled;
			pSibling1Tile->asStruct.m_eState		= TileState_Disabled;
			pSibling2Tile->asStruct.m_eState		= TileState_Disabled;
			pSibling3Tile->asStruct.m_eState		= TileState_Disabled;

			SetFreeIndex(a_iActiveListIndex);

			unsigned int iNewIndex = InsertValue(pParentTile);
			GE_UNUSED(iNewIndex);
			GE_ASSERT(iNewIndex > a_iActiveListIndex);

			return;
		}

		GE_ASSERT(pParentTile->asStruct.m_eState == TileState_ChildEnabled);
	}

	// if we reach here, the tile will be drawn
	unsigned int iMaterialType = pTile->asStruct.m_iMaterialType;
	m_arrTileTypeCount[iMaterialType]++;


}
示例#16
0
 /** Set the integer value of a parameter in the trace
 * \param [in] name : the name of the parameter to set
 * \param [in] value : the int value to set the parameter to */
 void SetValue(const std::string &name, const int &value) {
     if(intTraceData.count(name) > 0)
         intTraceData[name] = value;
     else
         InsertValue(name,value);
 }
示例#17
0
 /** Set the double value of a parameter in the trace
 * \param [in] name : the name of the parameter to set
 * \param [in] value : the double value to set the parameter to */
 void SetValue(const std::string &name, const double &value) {
     if(doubleTraceData.count(name) > 0)
         doubleTraceData[name] = value;
     else
         InsertValue(name,value);
 }
示例#18
0
 void SetValue(std::string name, double value) {
     if (doubleTraceData.count(name) > 0) 
         doubleTraceData[name] = value;
     else
         InsertValue(name,value);
 }
ERR TestControllerLoop()
{
    while(flags & CONTINUE)
    {
        //AddForce(ship->physics_object, 0.0, 10.0, ship->physics_object->cog_x, ship->physics_object->cog_y);        

        SDL_Event event;
        while(SDL_PollEvent(&event) != 0)
        {
            if(event.type == SDL_QUIT)
                 flags ^= CONTINUE;
            else if(event.type == SDL_KEYDOWN && event.key.repeat == 0)
                switch(event.key.keysym.sym)
                {
                case SDLK_UP: 
                    flames->sprite->data[CURRENT_LOOP] ^= 1;
                    flags ^= ENGINE;
                    break;
                case SDLK_DOWN:
                    ship->y_speed = 0.0;
                    ship->x_speed = 0.0;
                    break;
                case SDLK_LEFT: ship->a_speed   = -5.0; break;
                case SDLK_RIGHT: ship->a_speed  = 5.0; break;
                case SDLK_r :
                    yoshi->center_x = 220;
                    yoshi->center_y = 120;
                    yoshi->x_speed = 0;
                    yoshi->y_speed = 0;
                    ship->center_x = 520;
                    ship->center_y = 120;
                    ship->x_speed = 0;
                    ship->y_speed = 0;
                case SDLK_SPACE:
                    tmp = CopyEntity(bolt);
                    tmp->center_x = ship->center_x;
                    tmp->center_y = ship->center_y;
                    tmp->angle = ship->angle;
                    tmp->x_speed = RotateOffsetX(0.0, -10.0, ship->angle);
                    tmp->y_speed = RotateOffsetY(0.0, -10.0, ship->angle);
                    InsertValue(tmp, bolts, 0);
                    break;
                }
            else if(event.type == SDL_KEYUP)
                switch(event.key.keysym.sym)
                {
                case SDLK_UP:
                    flames->sprite->data[CURRENT_LOOP] ^= 1;
                    flags ^= ENGINE;
                    break;
                case SDLK_DOWN: break;
                case SDLK_LEFT: ship->a_speed   = 0.0; break;
                case SDLK_RIGHT: ship->a_speed  = 0.0; break;
                case SDLK_SPACE: 
                    break;
                }
        }

        if(flags & UPDATE)
        {
            if(flags & ENGINE)
                AddForce(ship->physics_object, RotateOffsetX(0.0, -20.0, ship->angle), RotateOffsetY(0.0, -20.0, ship->angle),
                        ship->physics_object->cog_x, ship->physics_object->cog_y);

            if(CheckCollision(ship->collision_object, yoshi->collision_object) != 0)
            {
                printf("BOOM\n");
                //flags ^= CONTINUE;
                AddForce(ship->physics_object, yoshi->x_speed * yoshi->physics_object->mass, yoshi->y_speed * yoshi->physics_object->mass,
                        ship->physics_object->cog_x, ship->physics_object->cog_y);
                AddForce(yoshi->physics_object, ship->x_speed * ship->physics_object->mass, ship->y_speed * ship->physics_object->mass,
                        yoshi->physics_object->cog_x, yoshi->physics_object->cog_y);
            }
            Element* el = bolts->start;
            Entity* tmp = NULL;
            int i = 0;
            while(el != NULL)
            {
                tmp = (Entity*)el->value;
                //if(CheckCollision(ship->collision_object, tmp->collision_object) != 0)
                //{
                //    printf("BOOM\n");
                //    flags ^= CONTINUE;
                //}
                if(CheckCollision(yoshi->collision_object, tmp->collision_object) != 0)
                {
                    AddForce(yoshi->physics_object, RotateOffsetX(0.0, -10.0, tmp->angle), RotateOffsetY(0.0, -10.0, tmp->angle),
                            yoshi->physics_object->cog_x, yoshi->physics_object->cog_y);
                    yoshi->sprite->zoom -= 0.5;
                    if(yoshi->sprite->zoom < 0.5)
                        yoshi->sprite->zoom = 0.5;
                    FreeEntity(tmp);
                    FreeElement(bolts, i);
                }
                i++;
                el = el->next;
            }

            UpdateEntity(ship);

            flames->angle = ship->angle;
            flames->center_x = ship->center_x + RotateOffsetX(0.0, ship->sprite->h * ship->sprite->zoom, ship->angle);
            flames->center_y = ship->center_y + RotateOffsetY(0.0, ship->sprite->h * ship->sprite->zoom, ship->angle);
            UpdateEntity(flames);

            UpdateEntity(yoshi);
            yoshi->sprite->zoom      += 0.01;
            yoshi->physics_object->mass = yoshi->sprite->zoom * 100;
            if(yoshi->physics_object->mass < 1)
                yoshi->physics_object->mass = 1;
            yoshi->collision_object->radius = 32*yoshi->sprite->zoom;
            if(yoshi->collision_object->radius < 1)
                yoshi->collision_object->radius = 1;

            for(i = 0; i < bolts->size; i++)
            {
                Entity* tmp = (Entity*)GetValue(bolts, i);
                if(tmp->center_x < -15 || tmp->center_y < -15 || tmp->center_x > 1000 || tmp->center_y > 500)
                {
                    FreeEntity(tmp);
                    FreeElement(bolts, i);
                }
                else
                    UpdateEntity(tmp);
            }
        }

        if(flags & DRAW)
        {
            ClearPMap(visual_debug);
            DrawEntity(ship);
            DrawEntityDebugInfo(visual_debug, ship);
            DrawEntity(flames);
            DrawEntity(yoshi);
            DrawEntityDebugInfo(visual_debug, yoshi);
            int i;
            for(i = 0; i < bolts->size; i++)
            {
                Entity* tmp = (Entity*)GetValue(bolts, i);
                DrawEntity(tmp);
                DrawEntityDebugInfo(visual_debug, tmp);
            }
            DrawPixelMap(visual_debug);
            Render();
        }
    }
    return ExitTestController();
}
示例#20
0
 void SetValue(std::string name, int value) {
     if (intTraceData.count(name) > 0)
         intTraceData[name] = value;
     else
         InsertValue(name,value);
 }