| 570 | |
| 571 | |
| 572 | void MicroPather::GetNodeNeighbors( PathNode* node, MP_VECTOR< NodeCost >* pNodeCost ) |
| 573 | { |
| 574 | if ( node->numAdjacent == 0 ) { |
| 575 | // it has no neighbors. |
| 576 | pNodeCost->resize( 0 ); |
| 577 | } |
| 578 | else if ( node->cacheIndex < 0 ) |
| 579 | { |
| 580 | // Not in the cache. Either the first time or just didn't fit. We don't know |
| 581 | // the number of neighbors and need to call back to the client. |
| 582 | stateCostVec.resize( 0 ); |
| 583 | graph->AdjacentCost( &node->state, &stateCostVec ); |
| 584 | |
| 585 | #ifdef DEBUG |
| 586 | { |
| 587 | // If this assert fires, you have passed a state |
| 588 | // as its own neighbor state. This is impossible -- |
| 589 | // bad things will happen. |
| 590 | for ( unsigned i=0; i<stateCostVec.size(); ++i ) |
| 591 | MPASSERT( stateCostVec[i].state != node->state ); |
| 592 | } |
| 593 | #endif |
| 594 | |
| 595 | pNodeCost->resize( stateCostVec.size() ); |
| 596 | node->numAdjacent = stateCostVec.size(); |
| 597 | |
| 598 | if ( node->numAdjacent > 0 ) { |
| 599 | // Now convert to pathNodes. |
| 600 | // Note that the microsoft std library is actually pretty slow. |
| 601 | // Move things to temp vars to help. |
| 602 | const unsigned stateCostVecSize = stateCostVec.size(); |
| 603 | const StateCost* stateCostVecPtr = &stateCostVec[0]; |
| 604 | NodeCost* pNodeCostPtr = &(*pNodeCost)[0]; |
| 605 | |
| 606 | for( unsigned i=0; i<stateCostVecSize; ++i ) { |
| 607 | cPosition state = stateCostVecPtr[i].state; |
| 608 | pNodeCostPtr[i].cost = stateCostVecPtr[i].cost; |
| 609 | pNodeCostPtr[i].node = pathNodePool.GetPathNode( frame, state, FLT_MAX, FLT_MAX, 0 ); |
| 610 | } |
| 611 | |
| 612 | // Can this be cached? |
| 613 | int start = 0; |
| 614 | if ( pNodeCost->size() > 0 && pathNodePool.PushCache( pNodeCostPtr, pNodeCost->size(), &start ) ) { |
| 615 | node->cacheIndex = start; |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | else { |
| 620 | // In the cache! |
| 621 | pNodeCost->resize( node->numAdjacent ); |
| 622 | NodeCost* pNodeCostPtr = &(*pNodeCost)[0]; |
| 623 | pathNodePool.GetCache( node->cacheIndex, node->numAdjacent, pNodeCostPtr ); |
| 624 | |
| 625 | // A node is uninitialized (even if memory is allocated) if it is from a previous frame. |
| 626 | // Check for that, and Init() as necessary. |
| 627 | for( int i=0; i<node->numAdjacent; ++i ) { |
| 628 | PathNode* pNode = pNodeCostPtr[i].node; |
| 629 | if ( pNode->frame != frame ) { |
nothing calls this directly
no test coverage detected