示例#1
0
void PathGraph::setPartTags ( void )
{
	static PathNodeStack unprocessed;

	int nodeCount = getNodeCount();

	for(int i = 0; i < nodeCount; i++)
	{
		PathNode * node = getNode(i);

		node->setPartId(-1);

		// ignore nodes without edges unless they're the only node in the cell

		int edgeCount = getEdgeCount(node->getIndex());

		if(edgeCount > 0)
		{
			unprocessed.push(node);
		}
		else
		{
			PathNodeType type = node->getType();

			if((nodeCount == 1) && (type == PNT_CellPortal))
			{
				unprocessed.push(node);
			}
		}
	}

	static PathNodeStack processing;

	int currentTag = 0;

	while(!unprocessed.empty())
	{
		PathNode * currentNode = unprocessed.top();
		unprocessed.pop();

		if(currentNode->getPartId() != -1) continue;

		processing.push(currentNode);

		while(!processing.empty())
		{
			PathNode * node = processing.top();
			processing.pop();

			if(node->getPartId() != -1) continue;

			node->setPartId(currentTag);

			int edgeCount = getEdgeCount(node->getIndex());

			for(int i = 0; i < edgeCount; i++)
			{
				int neighborIndex = getEdge(node->getIndex(),i)->getIndexB();

				PathNode * neighborNode = getNode(neighborIndex);

				processing.push(neighborNode);
			}
		}

		currentTag++;
	}

	m_partCount = currentTag;
}