Пример #1
0
//much slower than the regular one
void RecursiveCalcPath(Path& thePath, Map* map, const IntVec2& start, const IntVec2& goal, bool ignoreEntities){
	PROFILE_SECTION();
	if (!thePath.m_initialized && map){
		thePath = Path(map, start, goal); //this adds a start node to open list
	}
	
	if (!thePath.IsOpenListEmpty() && !thePath.m_isComplete){
		thePath = ProcessOneStepOfPath(thePath, map, start, goal, ignoreEntities);

		RecursiveCalcPath(thePath, map, start, goal, ignoreEntities);

	}
	else{

		return;

	}


}
Пример #2
0
void RenderDebugPathMeshOnMap2D(OpenGLRenderer* renderer, MeshRenderer& pathMeshRenderer, Path& pathToRender, Map* map){
	UNUSED(renderer);
	//renderer->SetTextureViewTransparent();

	ModelViewMatrix& mapToWorldTransform = map->m_mapToWorldTransformMatrix;

	//set mesh renderer
	Vertex3Ds inPathVerts;
	inPathVerts.clear();

	Tile* pathingTile = NULL;
	
	//render start/goal/open tiles
	if (map && !pathToRender.IsOpenListEmpty()){

		//render start tile
		pathingTile = map->GetTileAtMapPosition(pathToRender.m_startPosition);
		GenerateVertexArrayTextureQuad(inPathVerts, pathingTile->m_renderBounds, AABB2::ZERO_TO_ONE, Rgba::SILVER, false);

		
		//render goal tile
		pathingTile = map->GetTileAtMapPosition(pathToRender.m_goalPosition);
		GenerateVertexArrayTextureQuad(inPathVerts, pathingTile->m_renderBounds, AABB2::ZERO_TO_ONE, Rgba::GOLD, false);

		if (pathToRender.m_activeNode){
			pathingTile = map->GetTileAtMapPosition(pathToRender.m_activeNode->m_position);
			GenerateVertexArrayTextureQuad(inPathVerts, pathingTile->m_renderBounds, AABB2::ZERO_TO_ONE, Rgba::MAGENTA, false);

			//OUTPUT_COLOR_STRING_TO_SCREEN(IntToString(pathToRender.m_activeNode->m_nodeCost.f), pathingTile->m_renderBounds.mins.x, pathingTile->m_renderBounds.maxs.y, Rgba::GOLD);
		}
	
		static Rgba openListColor = Rgba::BLUE;
		openListColor.a = 127;

		for (OpenListPathMapIterator it = pathToRender.m_openList.begin(); it != pathToRender.m_openList.end(); ++it){
			PathNode& pathnode = *(it->second);

			pathingTile = map->GetTileAtMapPosition(pathnode.m_position);

			GenerateVertexArrayTextureQuad(inPathVerts, pathingTile->m_renderBounds, AABB2::ZERO_TO_ONE, openListColor , false);

			//OUTPUT_COLOR_STRING_TO_SCREEN(IntToString(pathnode.m_nodeCost.f), pathingTile->m_renderBounds.mins.x, pathingTile->m_renderBounds.maxs.y, Rgba::GOLD);
		}

	}


	//create path mesh for all of closed list
	if (map && pathToRender.m_closedList.size() > 1 ){

		static Rgba closedListColor = Rgba::RED;
		closedListColor.a = 127;

		for (ClosedListIterator it = pathToRender.m_closedList.begin() + 1; it != pathToRender.m_closedList.end() - 1; ++it){
			PathNode& pathnode = (*it);

			pathingTile = map->GetTileAtMapPosition(pathnode.m_position);

			GenerateVertexArrayTextureQuad(inPathVerts, pathingTile->m_renderBounds, AABB2::ZERO_TO_ONE, closedListColor, false);
			
			//OUTPUT_COLOR_STRING_TO_SCREEN(IntToString(pathnode.m_nodeCost.f), pathingTile->m_renderBounds.mins.x, pathingTile->m_renderBounds.maxs.y, Rgba::GOLD);
			
		}//end of for

		if (pathToRender.m_isImpossible){
			return;
		}
	
		static Rgba pathColor = Rgba::GREEN;
		pathColor.a = 210;

		//Create path mesh for only path
		ClosedListIterator mypathIterator = pathToRender.m_closedList.end() - 1;
		PathNode& myPathGoalNode = (*mypathIterator);
		//start traversing from goal back to start
		PathNode* traversalPathNode = &myPathGoalNode;
		//traversalPathNode = traversalPathNode->m_parent;

		//create last closed node added
		pathingTile = map->GetTileAtMapPosition(traversalPathNode->m_position);
		GenerateVertexArrayTextureQuad(inPathVerts, pathingTile->m_renderBounds, AABB2::ZERO_TO_ONE, pathColor, false);

		if (traversalPathNode->m_parent != NULL)
			traversalPathNode = traversalPathNode->m_parent;

		//create path
		while (traversalPathNode->m_parent != NULL){
			   
			   pathingTile = map->GetTileAtMapPosition(traversalPathNode->m_position); //has an infinite loop in certain cases
			   GenerateVertexArrayTextureQuad(inPathVerts, pathingTile->m_renderBounds, AABB2::ZERO_TO_ONE, pathColor, false);
		
				//OUTPUT_COLOR_STRING_TO_SCREEN(IntToString(traversalPathNode->m_nodeCost.f), pathingTile->m_renderBounds.mins.x, pathingTile->m_renderBounds.maxs.y, Rgba::WHITE);
			
				traversalPathNode = traversalPathNode->m_parent;
		}//end of while

	
	

	}//end of outer if

	//copy all verts to mesh
	pathMeshRenderer.m_mesh->CopyMeshVertexData(inPathVerts);
	pathMeshRenderer.RenderMesh2D(&mapToWorldTransform);
	inPathVerts.clear();
	
}