Changeset - r6510:68b182bc0b88
[Not reviewed]
master
0 4 0
KUDr - 17 years ago 2007-04-20 19:13:35
kudr@openttd.org
(svn r9693) -Codechange [YAPF]: GetBestNode() now returns pointer to node instead of reference
4 files changed with 14 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/yapf/yapf_base.hpp
Show inline comments
 
@@ -114,13 +114,14 @@ public:
 

	
 
		Yapf().PfSetStartupNodes();
 

	
 
		while (true) {
 
			m_num_steps++;
 
			Node *n = m_nodes.GetBestOpenNode();
 
			if (n == NULL) break;
 
			if (n == NULL)
 
				break;
 

	
 
			// if the best open node was worse than the best path found, we can finish
 
			if (m_pBestDestNode != NULL && m_pBestDestNode->GetCost() < n->GetCostEstimate())
 
				break;
 

	
 
			Yapf().PfFollowNode(*n);
 
@@ -157,15 +158,15 @@ public:
 
		return bDestFound;
 
	}
 

	
 
	/** If path was found return the best node that has reached the destination. Otherwise
 
	 *  return the best visited node (which was nearest to the destination).
 
	 */
 
	FORCEINLINE Node& GetBestNode()
 
	FORCEINLINE Node* GetBestNode()
 
	{
 
		return (m_pBestDestNode != NULL) ? *m_pBestDestNode : *m_pBestIntermediateNode;
 
		return (m_pBestDestNode != NULL) ? m_pBestDestNode : m_pBestIntermediateNode;
 
	}
 

	
 
	/** Calls NodeList::CreateNewNode() - allocates new node that can be filled and used
 
	 *  as argument for AddStartupNode() or AddNewNode()
 
	 */
 
	FORCEINLINE Node& CreateNewNode()
src/yapf/yapf_rail.cpp
Show inline comments
 
@@ -58,17 +58,17 @@ public:
 
		// find the best path
 
		bool bFound = Yapf().FindPath(v);
 
		if (!bFound) return false;
 

	
 
		// some path found
 
		// get found depot tile
 
		Node& n = Yapf().GetBestNode();
 
		*depot_tile = n.GetLastTile();
 
		Node *n = Yapf().GetBestNode();
 
		*depot_tile = n->GetLastTile();
 

	
 
		// walk through the path back to the origin
 
		Node* pNode = &n;
 
		Node *pNode = n;
 
		while (pNode->m_parent != NULL) {
 
			pNode = pNode->m_parent;
 
		}
 

	
 
		// if the origin node is our front vehicle tile/Trackdir then we didn't reverse
 
		// but we can also look at the cost (== 0 -> not reversed, == reverse_penalty -> reversed)
 
@@ -125,13 +125,13 @@ public:
 
			// treat the path as found if stopped on the first two way signal(s)
 
			*path_not_found = !(path_found || Yapf().m_stopped_on_first_two_way_signal);
 
		}
 

	
 
		// if path not found - return INVALID_TRACKDIR
 
		Trackdir next_trackdir = INVALID_TRACKDIR;
 
		Node* pNode = &Yapf().GetBestNode();
 
		Node *pNode = Yapf().GetBestNode();
 
		if (pNode != NULL) {
 
			// path was found or at least suggested
 
			// walk through the path back to the origin
 
			Node* pPrev = NULL;
 
			while (pNode->m_parent != NULL) {
 
				pPrev = pNode;
 
@@ -162,13 +162,13 @@ public:
 
		bool bFound = Yapf().FindPath(v);
 

	
 
		if (!bFound) return false;
 

	
 
		// path was found
 
		// walk through the path back to the origin
 
		Node* pNode = &Yapf().GetBestNode();
 
		Node *pNode = Yapf().GetBestNode();
 
		while (pNode->m_parent != NULL) {
 
			pNode = pNode->m_parent;
 
		}
 

	
 
		// check if it was reversed origin
 
		Node& best_org_node = *pNode;
src/yapf/yapf_road.cpp
Show inline comments
 
@@ -284,13 +284,13 @@ public:
 

	
 
		// find the best path
 
		Yapf().FindPath(v);
 

	
 
		// if path not found - return INVALID_TRACKDIR
 
		Trackdir next_trackdir = INVALID_TRACKDIR;
 
		Node* pNode = &Yapf().GetBestNode();
 
		Node *pNode = Yapf().GetBestNode();
 
		if (pNode != NULL) {
 
			// path was found or at least suggested
 
			// walk through the path back to its origin
 
			while (pNode->m_parent != NULL) {
 
				pNode = pNode->m_parent;
 
			}
 
@@ -326,13 +326,13 @@ public:
 

	
 
		// find the best path
 
		Yapf().FindPath(v);
 

	
 
		// if path not found - return distance = UINT_MAX
 
		uint dist = UINT_MAX;
 
		Node* pNode = &Yapf().GetBestNode();
 
		Node *pNode = Yapf().GetBestNode();
 
		if (pNode != NULL) {
 
			// path was found or at least suggested
 
			// get the path cost estimate
 
			dist = pNode->GetCostEstimate();
 
		}
 

	
 
@@ -368,14 +368,14 @@ public:
 
		// find the best path
 
		bool bFound = Yapf().FindPath(v);
 
		if (!bFound) return false;
 

	
 
		// some path found
 
		// get found depot tile
 
		Node& n = Yapf().GetBestNode();
 
		TileIndex depot_tile = n.m_segment_last_tile;
 
		Node *n = Yapf().GetBestNode();
 
		TileIndex depot_tile = n->m_segment_last_tile;
 
		assert(IsTileDepotType(depot_tile, TRANSPORT_ROAD));
 
		Depot* ret = GetDepotByTile(depot_tile);
 
		return ret;
 
	}
 
};
 

	
src/yapf/yapf_ship.cpp
Show inline comments
 
@@ -64,13 +64,13 @@ public:
 
		bool bFound = pf.FindPath(v);
 

	
 
		Trackdir next_trackdir = INVALID_TRACKDIR; // this would mean "path not found"
 
		if (bFound) {
 
			// path was found
 
			// walk through the path back to the origin
 
			Node* pNode = &pf.GetBestNode();
 
			Node* pNode = pf.GetBestNode();
 
			Node* pPrevNode = NULL;
 
			while (pNode->m_parent != NULL) {
 
				pPrevNode = pNode;
 
				pNode = pNode->m_parent;
 
			}
 
			// return trackdir from the best next node (direct child of origin)
0 comments (0 inline, 0 general)