本文整理汇总了C++中PathNode类的典型用法代码示例。如果您正苦于以下问题:C++ PathNode类的具体用法?C++ PathNode怎么用?C++ PathNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PathNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printf
void OpenQueue::Update( PathNode* pNode )
{
#ifdef DEBUG_PATH_DEEP
printf( "Open Update: " );
graph->PrintStateInfo( pNode->state );
printf( " total=%.1f\n", pNode->totalCost );
#endif
MPASSERT( pNode->inOpen );
// If the node now cost less than the one before it,
// move it to the front of the list.
if ( pNode->prev != sentinel && pNode->totalCost < pNode->prev->totalCost ) {
pNode->Unlink();
sentinel->next->AddBefore( pNode );
}
// If the node is too high, move to the right.
if ( pNode->totalCost > pNode->next->totalCost ) {
PathNode* it = pNode->next;
pNode->Unlink();
while ( pNode->totalCost > it->totalCost )
it = it->next;
it->AddBefore( pNode );
#ifdef DEBUG
sentinel->CheckList();
#endif
}
}
示例2: MPASSERT
void OpenQueue::Push( PathNode* pNode )
{
MPASSERT( pNode->inOpen == 0 );
MPASSERT( pNode->inClosed == 0 );
#ifdef DEBUG_PATH_DEEP
printf( "Open Push: " );
graph->PrintStateInfo( pNode->state );
printf( " total=%.1f\n", pNode->totalCost );
#endif
// Add sorted. Lowest to highest cost path. Note that the sentinel has
// a value of FLT_MAX, so it should always be sorted in.
MPASSERT( pNode->totalCost < FLT_MAX );
PathNode* iter = sentinel->next;
while ( true )
{
if ( pNode->totalCost < iter->totalCost ) {
iter->AddBefore( pNode );
pNode->inOpen = 1;
break;
}
iter = iter->next;
}
MPASSERT( pNode->inOpen ); // make sure this was actually added.
#ifdef DEBUG
sentinel->CheckList();
#endif
}
示例3: resetStartNode
void Follower::resetStartNode()
{
mStartNode->setPosition(mPosition);
//find closest existing node and use the same links as it has
PathNode* close;
gCurrentLevel->getPaths()->getNodeNearPosition(close, mPosition);
mStartNode->setLinks(close->getLinks());
}
示例4: findGlobalNode
PathNode* PathGraph::findGlobalNode(int globalNodeID) {
for (int i = 0; i < pathNodes.size(); ++i) {
PathNode* pathNode = pathNodes.get(i);
if (pathNode->getGlobalGraphNodeID() == globalNodeID)
return pathNode;
}
return NULL;
}
示例5: BuildPath
void Pathfinder::BuildPath(PathNode * lastNode) {
m_finalPath.clear();
m_edgesPath.clear();
//iterate over all node parents to get the full path
PathNode * node = lastNode;
USVec2D edgeDir;
USVec2D edgePos;
float edgeLength;
while (node->GetParent()) {
m_finalPath.push_back(node);
for (std::vector<Polygon::Edge>::iterator itr = node->GetPolygon()->m_edges.begin();
itr != node->GetPolygon()->m_edges.end(); ++itr) {
if (itr->m_neighbour == node->GetParent()->GetPolygon()) {
edgeDir = node->GetPolygon()->m_vertices[itr->m_verticesID[1]]
- node->GetPolygon()->m_vertices[itr->m_verticesID[0]];
edgeLength = edgeDir.Length();
edgePos = node->GetPolygon()->m_vertices[itr->m_verticesID[0]]
+ (edgeDir.NormVector() * (edgeLength / 2));
m_edgesPath.push_back(edgePos);
}
}
node = node->GetParent();
}
node = node;
}
示例6: ClearGraphPathInfo
void NavigationHandle::ClearGraphPathInfo()
{
for(unsigned int i = 0; i < Graph->count(); i++)
{
PathNode* node = dynamic_cast<PathNode*>(Graph->objectAtIndex(i));
node->ClearPathInfo();
}
Path->removeAllObjects();
PathIndex = 0;
}
示例7: PathNode
std::vector<PathNode*> Pathfinding::FindPath(PathNode* start, PathNode* goal)
{
std::vector<PathNode*> retPath;
PathNode* currentNode = new PathNode(*start);
currentNode->combineNode(currentNode, start);
while (!ArrivedAtEnd(currentNode, goal))
{
PathNode tempChildNode(*currentNode);
//Get adjacent walkable tiles
//Move the child node one node to the right to get the node to the right of currentNode
tempChildNode.xPos++;
AddChild(tempChildNode, currentNode, goal, Direction::DIRECTION::EAST);
//Move the child node to the left to get the node to the left of currentNode
tempChildNode.xPos -= 2;
AddChild(tempChildNode, currentNode, goal, Direction::DIRECTION::WEST);
//Move the child node up one row to get the node above currentNode
tempChildNode.xPos++;
tempChildNode.zPos++;
AddChild(tempChildNode, currentNode, goal, Direction::DIRECTION::NORTH);
//Finally, move the child node to the bottom, to get the node one below currentNode
tempChildNode.zPos -= 2;
AddChild(tempChildNode, currentNode, goal, Direction::DIRECTION::SOUTH);
mClosedSet.insert(currentNode);
mOpenList.sort(PathNode::FCostSort());
if (mOpenList.size() > 0)
{
currentNode = mOpenList.back();
mOpenList.remove(currentNode);
}
else
{
break;
}
}
//Populate and create the path vector
while (currentNode->parent != NULL && currentNode != start)
{
retPath.push_back(currentNode);
currentNode = currentNode->getParent();
}
std::reverse(retPath.begin(), retPath.end());
mOpenList.clear();
mClosedSet.clear();
return retPath;
}
示例8: Hash
PathNode* MicroPather::NewPathNode( void* state, float costFromStart, float estToEnd, PathNode* parent )
{
// Try to find an existing node for this state.
unsigned key = Hash( state ); //(HASH_SIZE-1) & ( (unsigned)state + (((unsigned)state)>>8) + (((unsigned)state)>>16) + (((unsigned)state)>>24) );
if ( !hashTable[key] ) {
// There isn't even a hashtable yet - create and initialize the PathNode.
hashTable[key] = AllocatePathNode();
hashTable[key]->Init( frame, state, costFromStart, estToEnd, parent );
return hashTable[key];
}
PathNode* root = hashTable[key];
PathNode* up = 0;
while ( root ) {
up = root;
if ( root->state == state ) {
root->Reuse( frame, costFromStart, estToEnd, parent );
assert( root->state == state );
return root;
}
#ifdef USE_BINARY_HASH
else if ( state > root->state ) {
root = root->right;
}
#endif
else {
#ifdef USE_BINARY_HASH
assert( state < root->state );
#endif
root = root->left;
}
}
assert( up );
PathNode* pNode = AllocatePathNode();
pNode->Init( frame, state, costFromStart, estToEnd, parent );
#ifdef USE_BINARY_HASH
if ( state > up->state ) {
assert( up->right == 0 );
up->right = pNode;
}
else {
assert( up->left == 0 );
up->left = pNode;
}
#else
up->left = pNode;
#endif
return pNode;
}
示例9: pathIndexChanged
void GopathBrowser::pathIndexChanged(const QModelIndex & index)
{
PathNode *node = m_model->nodeFromIndex(index);
if (node) {
QFileInfo info = node->fileInfo();
QModelIndex newIndex = index;
if (info.isDir()) {
newIndex = index;
} else {
newIndex = index.parent();
}
this->setStartIndex(newIndex);
}
}
示例10: PathNode
PathNode* PathNode::create(TilePoint pos)
{
PathNode* node = new PathNode();
if(node && node->init(pos))
{
node->autorelease();
return node;
}
else
{
CC_SAFE_DELETE(node);
return NULL;
}
}
示例11: openPathIndex
void GopathBrowser::openPathIndex(const QModelIndex &index)
{
PathNode *node = m_model->nodeFromIndex(index);
if (!node) {
return;
}
if (node->isDir()) {
this->setStartIndex(index);
} else if (node->isFile()) {
if (m_syncProject->isChecked()) {
this->setStartIndex(index.parent());
}
m_liteApp->fileManager()->openEditor(node->path(),true);
}
}
示例12: startPathChanged
void GopathBrowser::setStartIndex(const QModelIndex &index)
{
QModelIndex oldIndex = m_model->startIndex();
if (oldIndex != index) {
m_model->setStartIndex(index);
m_pathTree->update(oldIndex);
m_pathTree->update(index);
emit startPathChanged(m_model->filePath(index));
PathNode *node = m_model->nodeFromIndex(index);
if (node) {
m_startPathLabel->setText(QString("<p><a href file://%1>%2</p>").arg(node->path()).arg(node->text()));
m_startPathLabel->setToolTip(node->path());
}
}
}
示例13: getPath
bool KBlocksAIPlannerExtend::getPath(int index, AIPlanner_PieceInfo_Sequence *pseq)
{
if ((mPathList == 0) || (index >= (int)mPathList->size())) {
return false;
}
PathNode *node = (*mPathList)[index];
while (node != 0) {
KBlocksPiece piece = node->getContent();
pseq->push_back(piece);
node = node->getParent();
}
return true;
}
示例14: CalculateGhostEffect
float CalculateGhostEffect(const PathNode& in_node, const std::vector<const Pawn* const> in_ghosts)
{
float score = 0;
for(auto ghost : in_ghosts)
{
score += (ghost->GetPosition() - in_node.GetPosition()).MagnitudeSqr() / 1.0f;
if (ghost->GetClosestNode() == in_node.GetId())
score += 1000;
//When blue boost our want to go towards the ghost
if (ghost->GetState() == 2)
score = -score;
}
return score;
}
示例15: InsertOpenList
CCArray* NavigationHandle::InsertOpenList(cocos2d::CCArray* openList, PathNode* node)
{
for(unsigned int i = 0; i < openList->count(); i++)
{
PathNode* kNode = dynamic_cast<PathNode*>(openList->objectAtIndex(i));
if(node->fScore() <= kNode->fScore())
{
openList->insertObject(node, i);
return openList;
}
}
openList->addObject(node);
return openList;
}