本文整理汇总了C++中PathNode::getIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ PathNode::getIndex方法的具体用法?C++ PathNode::getIndex怎么用?C++ PathNode::getIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathNode
的用法示例。
在下文中一共展示了PathNode::getIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setPartTags
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;
}
示例2: search
void PathCmp::search (Eigen::Vector2f targetPos_) {
_level = LogicSystem::getInstance()->getLevel();
for (auto it = _openList.begin(); it != _openList.end(); ++ it) {
if (*it != nullptr)
delete *it;
}
_openList.clear();
for (auto it = _closedList.begin(); it != _closedList.end(); ++ it) {
if (*it != nullptr)
delete *it;
}
_closedList.clear();
_shortestPath.clear();
auto posCmp = getEntity()->GET_CMP(PositionComponent);
_srcIdx = _level->posToTileIndex(posCmp->getPosition());
_tarIdx = _level->posToTileIndex(targetPos_);
if (_srcIdx == _tarIdx)
return;
if (_level->isTileObstacle(_tarIdx.x(), _tarIdx.y()))
return;
PathNode* srcNode = new PathNode(_srcIdx);
calcCostH(srcNode);
_openList.push_back(srcNode);
do {
PathNode* curNode = _openList[0];
_closedList.push_back(curNode);
_openList.erase(_openList.begin());
if (curNode->getIndex() == _tarIdx) {
PathNode* walkNode = curNode;
_shortestPath.clear();
do {
Eigen::Vector2f pos;
pos.x() = _level->tileIndexXToPosX(walkNode->getIndex().x());
pos.y() = _level->tileIndexYToPosY(walkNode->getIndex().y());
_shortestPath.push_front(pos);
walkNode = walkNode->getParent();
} while (walkNode);
for (auto it = _openList.begin(); it != _openList.end(); ++ it) {
if (*it != nullptr)
delete *it;
}
_openList.clear();
for (auto it = _closedList.begin(); it != _closedList.end(); ++ it) {
if (*it != nullptr)
delete *it;
}
_closedList.clear();
break;
}
putAdjacentTiles(curNode);
for (auto it = _adjacentTiles.begin(); it != _adjacentTiles.end(); ++ it) {
bool isInClosedList = false;
for (int i = 0; i < _closedList.size(); ++ i)
if ((*it) == _closedList[i]->getIndex())
isInClosedList = true;
if (isInClosedList) continue;
auto node = new PathNode(*it);
int costGToAdd = calcCostG(node, curNode);
std::vector<PathNode *>::iterator opit = _openList.begin();
while (opit != _openList.end()) {
if ((*opit)->getIndex() == node->getIndex())
break;
++ opit;
}
// already on openlist
if (opit!= _openList.end()) {
delete node;
node = (*opit);
if (curNode->getCostG() + costGToAdd < node->getCostG())
node->setCostG(curNode->getCostG() + costGToAdd);
} else {
node->setParent(curNode);
node->setCostG(curNode->getCostG() + costGToAdd);
calcCostH(node);
addOpenList(node);
}
}
} while (_openList.size() > 0);
}