CCArray* Pathfinding::search ( const CCPoint& tStartTile, const CCPoint& tTargetTile ) { this->setOpenList ( CCArray::create ( ) ); this->setClosedList ( CCArray::create ( ) ); CCLOG ( "In search, within thread" ); // Add the first node to the open list PathfindingNode* pNode = PathfindingNode::create ( ); pNode->setTilePos ( tStartTile ); pNode->setParent ( KD_NULL ); pNode->setG ( 0 ); pNode->setH ( 0 ); pNode->setF ( pNode->getG ( ) + pNode->getH ( ) ); m_pOpenList->addObject ( pNode ); this->searchLowestCostNodeInOpenList ( tTargetTile ); // Retrieve path CCArray* pPathToPlayer = CCArray::create ( ); pNode = this->isOnList ( tTargetTile, m_pClosedList ); if ( pNode ) { CCLOG ( "Path found..." ); pPathToPlayer->addObject ( pNode ); if ( l_bPathfindingDebuggingTiles ) { // Debugging pathfinding GameMgr->getCoordinateFunctions ( )->debugTile ( pNode->getTilePos ( ) ); } PathfindingNode* pParentnode = pNode->getParent ( ); while ( pParentnode ) { CCLOG ( "%f %f", pNode->getTilePos ( ).x, pNode->getTilePos ( ).y ); pNode = pParentnode; pParentnode = pNode->getParent ( ); pPathToPlayer->addObject ( pNode ); if ( l_bPathfindingDebuggingTiles ) { // Debugging pathfinding GameMgr->getCoordinateFunctions ( )->debugTile ( pNode->getTilePos ( ) ); } } } else { CCLOG ( "No path found" ); } return pPathToPlayer; }