示例#1
0
bool JPSPlus::GetPath(void *data, xyLocJPS& s, xyLocJPS& g, std::vector<xyLocJPS> &path)
{
	JPSPlus* Search = (JPSPlus*)data;

	if (path.size() > 0)
	{
		path.push_back(g);
		return true;
	}

	{
		// Initialize map
		int startRow = s.y;
		int startCol = s.x;
		m_goalRow = g.y;
		m_goalCol = g.x;

		path.clear();

		m_goalNode = &m_mapNodes[m_goalRow][m_goalCol];
		m_currentIteration++;

		m_openList.reset();
		m_openList.reserve(3000);

		// Push the starting node onto the Open list
		PathfindingNode* startNode = &m_mapNodes[startRow][startCol];
		startNode->m_parent = NULL;
		startNode->m_givenCost = 0;
		startNode->m_finalCost = 0;
		startNode->m_listStatus = PathfindingNode::OnOpen;
		startNode->m_iteration = m_currentIteration;
		m_openList.add(&m_mapNodes[startRow][startCol]);
	}

	PathStatus status = SearchLoop();

	if (status == PathFound)
	{
		FinalizePath(path);
		if (path.size() > 0)
		{
			path.pop_back();
			return false;
		}
		return true;
	}
	else
	{
		// No path
		return true;
	}
}
示例#2
0
bool Search::Find(bool firstLoop)
{
	if (firstLoop)
	{
		SetDefaults();
		if (!_caseSensitive)
		{
			for (unsigned int i=0;i<_criteria.size();i++)
			{
				Uncapitalize(_criteria[i]._query);
			}
		}
		if (!SI.Init(_beginPath)){
			SearchException se(L"Could not find path: ");
			se.AppendBasicLog(SI.GetPath());
		};
	}else
	{_cycleTimer=clock();}
	SearchLoop();
	return 0;
}