Ejemplo n.º 1
0
nodeTree* makeTrace(nodeTree *root, int prev)
{
	if (root == NULL) return NULL;
	nodeTree* traceRoot = new nodeTree;

	traceRoot->key = prev + root->key;
	traceRoot->pLeft = makeTrace(root->pLeft, traceRoot->key);
	traceRoot->pRight = makeTrace(root->pRight, traceRoot->key);

	return traceRoot;
}
Ejemplo n.º 2
0
void Ship::destroy(Brick* brick, std::vector<Brick*>* selection, std::vector<Joint**>* front, vec3 impulse, vec3 pos, int axis, int tick)
{
	makeTrace(*front, *selection);

	for (int i = 0; i < selection->size(); ++i)
	{
		selection->at(i)->tick = tick;
	}


	//break front

	vec3 minFulcrum = vec3(0,0,0);
	float minCapacity = FLT_MAX;

	for (int i = 0; i < front->size(); ++i)
	{
		Connection* a = (*(*front)[i])->connection;
		Connection* b = (*(*(*front)[i])->twin)->connection;

 		if ((*(*front)[i])->capacity < minCapacity && axis != Y)
		{
			Joint* opposite = a->joints[axis][0].tableEntry == (*front)[i] ? a->joints[axis] + 1 : a->joints[axis];
			minFulcrum.y = opposite->data->y;
			if (axis == X)
				minFulcrum.x = opposite->data->fulcrum;
			else if (axis == Z)
				minFulcrum.z = opposite->data->fulcrum;

			minCapacity = (*(*front)[i])->capacity;
		}

		if (a != a->brick->connections + a->brick->numConnections - 1)
		{
			*a = a->brick->connections[--a->brick->numConnections];

			for (int d = X; d <= Z; ++d)
			{
				for (int i = 0; i < 2; ++i)
				{
					a->joints[d][i].connection = a;
					*a->joints[d][i].tableEntry = a->joints[d] + i;
				}
			}
		}
		else
		{
			--a->brick->numConnections;
		}


		if (b != b->brick->connections + b->brick->numConnections - 1)
		{
			*b = b->brick->connections[--b->brick->numConnections];

			for (int d = X; d <= Z; ++d)
			{
				for (int i = 0; i < 2; ++i)
				{
					b->joints[d][i].connection = b;
					*b->joints[d][i].tableEntry = b->joints[d] + i;
				}
			}
		}
		else
		{
			--b->brick->numConnections;
		}
			
	}


	//
	for (int i = 0; i < g_numBricks; ++i)
	{
		for (int j = 0; j < g_bricks[i].numConnections; ++j)
		{
			Connection* connection = g_bricks[i].connections +j;

			for (int d = 0; d < 2; ++d)
			{
				for (int k = 0; k < 2; ++k)
				{
					assert(connection->joints[d][k].connection == connection);
					assert(connection->joints[d][k].data == (*connection->joints[d][k].twin)->data);
				}
			}
		}
	}
	//

	vec3 angularMomentum = vec3(0, 0, 0);


	vec3 fulcrum = transformVec3(minFulcrum, m_body->getTransform());
	vec3 r(0, 0, 0);
	r.y = pos.y - fulcrum.y;
	if (axis == X)
		r.x = pos.x - fulcrum.x;
	else if (axis == Z)
		r.z = pos.z - fulcrum.z;
	angularMomentum = cross(r, impulse);


	//BodyDescription descr;
	//descr.transform = m_body->getTransform();
	//descr.type = BodyType::Dynamic;
	//descr.linearMomentum = impulse + m_body->getLinearMomentum();
	//descr.angularMomentum = angularMomentum + m_body->getAngularMomentum();

	//////
	//descr.linearMomentum = vec3(0, 0, 0);
	//descr.angularMomentum = vec3(0, 0, 0);

	//Ship* newShip = createShip(m_world, m_entities, descr, vec3(0,0,1));
	
	int id = m_impulses.size();
	
	Impulse newImpulse;
	newImpulse.brick = brick;
	newImpulse.impulse = impulse;
	newImpulse.pos = pos;
	newImpulse.angular = angularMomentum;

	m_impulses.push_back(newImpulse);

	// seperate selection
	for (int i = 0; i < selection->size(); ++i)
	{
		Brick* brick = selection->at(i);

		// free blocks
		for (int i = 0; i < brick->numBlocking; ++i)
		{
			if ((*brick->blocking[i])->connection->brick->tick != tick)
			{
				(*brick->blocking[i])->data->blocked--;
				brick->blocking[i] = brick->blocking[--brick->numBlocking];
			}
		}
		//m_body->removeCollider(brick->collider);
		//brick->ship = newShip;
		//newShip->m_body->addCollider(brick->collider);

	

	}
	
	//

	//newShip->calcBase();
	//calcBase();

	//assert(checkShip(newShip->m_base, g_tick++, newShip));
	//assert(checkShip(m_base, g_tick++, this));

	checkForInvalidBlock(m_base, tick , g_tick++);
}
Ejemplo n.º 3
0
void Hades()
{
	nodeTree *traceRoot = NULL;

	traceRoot = makeTrace(myTree->root, 0);
	traceRoot->key = processTraceKey(traceRoot);

	if (traceRoot->key % 13 == 0)
	{
		isJack = 1;
		queue *front = new queue;
		queue *rear = front;
		rear->next = NULL;
		bool same = 0;
		Tracing(myTree->root, traceRoot, rear, traceRoot->key, same);
		if (same == 0)
		{
			while (front != NULL)
			{
				queue *del = front;
				front = front->next;
				delete del;
			}
			int key = traceRoot->key;
			front = new queue;
			rear = new queue;
			front->next = rear;
			rear->next = NULL;
			rear->key = myTree->root->key;

			nodeTree *root = myTree->root;
			while (traceRoot->pLeft != NULL || traceRoot->pRight != NULL)
			{
				if (traceRoot->pLeft != NULL)
					if (traceRoot->pLeft->key == key)
					{
						traceRoot = traceRoot->pLeft;
						root = root->pLeft;
						rear->next = new queue;
						rear = rear->next;
						rear->next=NULL;
						rear->key = root->key;
						continue;
					}

				if (traceRoot->pRight != NULL)
					if (traceRoot->pRight->key == key)
					{
						traceRoot = traceRoot->pRight;
						root = root->pRight;
						rear->next = new queue;
						rear = rear->next;
						rear->next=NULL;
						rear->key = root->key;
						continue;
					}
			}
		}

		while (front->next != NULL)
		{
			queue *del = front;
			if (front->next->key == 888)
			{
				isBlackBeard = 0;
				isAVL = 0;
			}
			//num = front->next->ptr->key;
			delNode(front->next->key);
			front = front->next;
			delete del;
		}
		delete front;
	}
	else
	{
		deleteMyTree(myTree->root);
	}

	deleteMyTree(traceRoot);
}