当前位置: 首页>>代码示例>>C++>>正文


C++ NodesList::add方法代码示例

本文整理汇总了C++中NodesList::add方法的典型用法代码示例。如果您正苦于以下问题:C++ NodesList::add方法的具体用法?C++ NodesList::add怎么用?C++ NodesList::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NodesList的用法示例。


在下文中一共展示了NodesList::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: findPath

bool CCPathFinderNetwork::findPath(CCCollideable *objectToPath, Path &pathResult, const PathNode *fromNode, const PathNode *toNode)
{
    if( fromNode != NULL && toNode != NULL )
    {
        NodesList<const PathNode, 50> previousNodes;
        previousNodes.add( fromNode );

        pathTargetNode = toNode;
        path.distance = 0.0f;
        pathingFrom = fromNode;
        if( followPath( objectToPath, path, 0, 0.0f, previousNodes, fromNode, toNode ) )
        {
            pathResult = path;
            return true;
        }
    }
    return false;
}
开发者ID:Shushman,项目名称:multi,代码行数:18,代码来源:CCPathFinderNetwork.cpp

示例2: followPath

bool CCPathFinderNetwork::followPath(CCCollideable *objectToPath,
                                     Path &path, const int currentDirection,
                                     const float currentDistance,
                                     NodesList<const PathNode, 50> &previousNodes,
                                     const PathNode *fromNode, const PathNode *toNode)
{
	// Node found
	if( fromNode == toNode )
	{
		path.endDirection = currentDirection;
		path.distance = currentDistance;
		return true;
	}

	const int nextDirection = currentDirection+1;
	if( nextDirection >= 50 )
	{
		// Give up
		return false;
	}

	pathFromNode = fromNode;
    const CCList<PathNode::PathConnection> &connections = fromNode->connections;
	int *values = new int[connections.length];
	for( int i=0; i<connections.length; ++i )
	{
		values[i] = i;
	}
	qsort( values, connections.length, sizeof( int ), compare );

	for( int i=0; i<connections.length; ++i )
	{
		const PathNode::PathConnection *nextConnection = connections.list[values[i]];

        const PathNode *targetNode = nextConnection->node;

		// Previously followed?
		if( previousNodes.find( targetNode ) != -1 )
		{
			continue;
		}


        CCCollideable *collidedWith = CCOctreeMovementCollisionCheck( objectToPath, fromNode->point, targetNode->point );
        if( collidedWith != NULL )
        {
            continue;
        }

		const float pathDistance = currentDistance + nextConnection->distance;
		if( previousNodes.add( targetNode ) == false )
		{
			delete[] values;
			return false;
		}

		if( followPath( objectToPath, path, nextDirection, pathDistance, previousNodes, targetNode, toNode ) )
		{
			path.directions[currentDirection] = values[i];
			delete[] values;
			return true;
		}
	}

	delete[] values;
	return false;
}
开发者ID:Shushman,项目名称:multi,代码行数:67,代码来源:CCPathFinderNetwork.cpp


注:本文中的NodesList::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。