本文整理汇总了C++中PathNode::getParentNode方法的典型用法代码示例。如果您正苦于以下问题:C++ PathNode::getParentNode方法的具体用法?C++ PathNode::getParentNode怎么用?C++ PathNode::getParentNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathNode
的用法示例。
在下文中一共展示了PathNode::getParentNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void PathFinder::update(double aDelta)
{
//Make sure we are in the seaching path state.
while(isSearchingPath() == true)
{
//Next make sure there is at least 1 path node in the open list.
//If there isn't it's possible that the destination can not be reached.
if(m_OpenList.size() == 0)
{
m_State = StateError;
return;
}
//Get the first path node from the Open List, because Open List is sorted,
//we know this is the Path Node with the lowest F score.
PathNode* currentNode = m_OpenList.front();
//Next add it to the closed list.
m_ClosedList.push_back(currentNode);
//Lastly remove it from the Open List
m_OpenList.erase(m_OpenList.begin());
//Next get the current node's tile's index from the level.
int currentNodeTileIndex = m_Level->getTileIndexForTile(currentNode->getTile());
if(currentNodeTileIndex == m_DestinationTileIndex)
{
//If the current node's tile index is the same as the destination tile, the we
//have reached out destination tile and now know the shortest path.
do
{
//If the parent node doesn't equal NULL, and the current node to the final path list.
if(currentNode->getParentNode() != NULL)
{
m_FinalPath.insert(m_FinalPath.begin(), currentNode);
}
//Set the node's tile isPath flag to true
currentNode->getTile()->setIsPath(true);
//Set the current node to the parent node.
currentNode = currentNode->getParentNode();
}
while(currentNode != NULL);
//Set the state to the PathFound
m_State = StatePathFound;
return;
}
//Now, if we got here, it means we haven't reached the destination, we need to
// get the current node's adjacent tiles and calculate their path scores.
std::vector<Tile*> adjacentTiles;
addAdjacentTile(adjacentTiles, currentNode->getTile(), -1, 0); //Left
addAdjacentTile(adjacentTiles, currentNode->getTile(), 1, 0); //Right
addAdjacentTile(adjacentTiles, currentNode->getTile(), 0, -1); //Up
addAdjacentTile(adjacentTiles, currentNode->getTile(), 0, 1); //Down
//Cycle through the adjacent tiles
for(int i = 0; i < adjacentTiles.size(); i++)
{
Tile* adjacentTile = adjacentTiles.at(i);
//Next we need to check if the adjacent tile is already in the close list,
//if it is, then we can ignore this tile.
if(isTileInClosedList(adjacentTile) == true)
{
continue;
}
//Then we need to check if the adjacent tile is already in the Open List
if(isTileInOpenList(adjacentTile) == true)
{
//If we got here, then the tile is in the Open list alreadu and we have to determine
//if the existing tile's score is lower or the adjacent tile.
PathNode* existingNode = getPathNodeFromOpenList(adjacentTile);
//Check to see if the adjacent node has a higher G Score
//(since the h scores will be identical)
//than the existing node's G score.
if(existingNode->getScoreG() > currentNode->getScoreG() +1)
{
//Update the existing node's parent.
existingNode->setParentNode(currentNode);
//Set the lower G score
existingNode->setScoreG(currentNode->getScoreG() +1);
//Sort the OpenList
sortOpenList();
}
}
else
{
//If we got here then the tile doesn't exist in the Open or Closed list.
//Let's make a new PathNode object and calculate it's tile score.
PathNode* adjacentNode = new PathNode(adjacentTile);
//.........这里部分代码省略.........