本文整理汇总了C++中TileNode::getTotalCost方法的典型用法代码示例。如果您正苦于以下问题:C++ TileNode::getTotalCost方法的具体用法?C++ TileNode::getTotalCost怎么用?C++ TileNode::getTotalCost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TileNode
的用法示例。
在下文中一共展示了TileNode::getTotalCost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TileNode
std::vector<Vec2> TMXPathFinding::getPath(Vec2 startPos, Vec2 endPos, std::vector<int> walkableGIDs, std::vector<int> obstacleGIDs) {
open.clear();
close.clear();
// inizialize a goal node
goalNode = new TileNode();
goalNode->setLocX(endPos.x);
goalNode->setLocY(endPos.y);
// inizialize a start node
startNode = new TileNode();
startNode->setLocX(startPos.x);
startNode->setLocY(startPos.y);
startNode->setCostFromStart(0);
startNode->setParent(nullptr);
int cost = getDistance(startNode, goalNode);
startNode->setCostToGoal(cost);
startNode->setTotalCost();
open.emplace(startNode, startNode->getTotalCost());
while (open.size() != 0) {
// Fix a Cost to check the values
min = 32767; // std::numeric_limits<int>::max()
TileNode *minNode;
// Find minNode from open QUEUE
for (auto kv : open) {
extractNode = kv.first;
iCost = kv.second;
if (iCost < min) {
min = iCost; // Change min to the New Cost got from the open QUEUE
minNode = extractNode;
}
}
extractNode = minNode;
open.erase(minNode); // pop node from open
// if it's a goal, we're done
if (extractNode->getLocation() == goalNode->getLocation()) {
// 1- retrieve all extractNode's parents
// 2- save into Vec2 vector
// 3- reverse Vec2 vector
// 4- return Vec2 vector
std::vector<Vec2> points;
points.push_back(extractNode->getLocation());
int size = extractNode->getCostFromStart();
for (int i = 0; i < size; i++) {
points.push_back(Vec2(extractNode->getParent()->getLocation().x, extractNode->getParent()->getLocation().y));
extractNode = extractNode->getParent();
}
std::reverse(points.begin(), points.end());
return points;
}
else {
for (int i = 0; i < dir; i++) {
costToOpen = 0;
costToClose = 0;
inOpen = false;
inClose = false;
newNode = new TileNode();
newNode->setLocX(extractNode->getLocation().x);
newNode->setLocY(extractNode->getLocation().y);
switch (i) {
case 0: // left
newNode->setLocX(-1);
newNode->setLocY(0);
break;
case 1: // right
newNode->setLocX(1);
newNode->setLocY(0);
break;
case 2: // up
newNode->setLocX(0);
newNode->setLocY(1);
break;
case 3: // down
newNode->setLocX(0);
newNode->setLocY(-1);
break;
case 4: // top-left
newNode->setLocX(-1);
newNode->setLocY(1);
break;
case 5: // bottom-left
newNode->setLocX(-1);
newNode->setLocY(-1);
break;
case 6: // bottom-right
newNode->setLocX(1);
newNode->setLocY(-1);
break;
case 7: // top-right
newNode->setLocX(1);
newNode->setLocY(1);
//.........这里部分代码省略.........