/ 结束点在关闭结点,说明已找到,完成

webrtc安装

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Jls.Lib.AStar
  6. {
  7.     public class AStarClassic
  8.     {
  9.         public const int OBLIQUE = 14;
  10.         public const int STEP = 10;
  11.         public int[][] MapData { get; private set; }
  12.         public List<AStarNode> CloseList;
  13.         public List<AStarNode> OpenList;
  14.  
  15.         private List<List<AStarNode>> _nodes = new List<List<AStarNode>>();
  16.  
  17.         private int maxMapX;
  18.         private int maxMapY;
  19.  
  20.         public int CurrentSerialNumber = 0;
  21.  
  22.         public AStarClassic(int[][] mapData)
  23.         {
  24.             MapData = mapData;
  25.             maxMapX = mapData[0].Length - 1;
  26.             maxMapY = mapData.Length - 1;
  27.             var length = mapData.Length * mapData[0].Length;
  28.             OpenList = new List<AStarNode>(length);
  29.             CloseList = new List<AStarNode>(length);
  30.             for (var i = 0; i < mapData.Length; i++)
  31.             {
  32.                 var row = new List<AStarNode>();
  33.                 for (var j = 0; j < mapData[0].Length; j++)
  34.                 {
  35.                     var node = new AStarNode(j, i);
  36.                     node.Walkable = mapData[i][j] == 1;
  37.                     row.Add(node);
  38.                 }
  39.                 _nodes.Add(row);
  40.             }
  41.  
  42.         }
  43.  
  44.         /// <summary>
  45.         /// 寻路
  46.         /// </summary>
  47.         /// <param name="startNode"></param>
  48.         /// <param name="endNode"></param>
  49.         /// <param name="isIgnoreCorner"></param>
  50.         /// <returns></returns>
  51.         public AStarNode FindPath(AStarNode startNode, AStarNode endNode, bool isIgnoreCorner)
  52.         {
  53.             startNode = GetPoint(startNode.X, startNode.Y);
  54.             endNode = GetPoint(endNode.X, endNode.Y);
  55.             //if (!endNode.Walkable)
  56.             //{
  57.             // endNode = GetWalkableEndNode(startNode, endNode);
  58.             //}
  59.             OpenList.Add(startNode);
  60.             startNode.IsClose = true;
  61.             while (OpenList.Count != 0)
  62.             {
  63.                 var currentPoint = GetLowestFScore();
  64.  
  65.                 AddCloseList(currentPoint);
  66.                 currentPoint.IsClose = true;
  67.                 RemoveOpenList(currentPoint);
  68.  
  69.                 if (endNode.IsClose )
  70.                 {
  71.                     break;
  72.                 }
  73.  
  74.                 var adjacentPoints = getArounds(currentPoint, isIgnoreCorner);
  75.  
  76.                 foreach (AStarNode aPoint in adjacentPoints)
  77.                 {
  78.                     if (aPoint.IsClose )
  79.                     {
  80.                         continue;
  81.                     }
  82.                     if (! aPoint.IsOpen )
  83.                     {
  84.                         aPoint.CalcG(currentPoint);
  85.                         aPoint.CalcH(endNode);
  86.                         aPoint.CalcF();
  87.                         aPoint.Parent = currentPoint;
  88.                         aPoint.IsOpen = true;
  89.                         AddOpenList(aPoint);
  90.                     }
  91.                     else
  92.                     {
  93.                         //var aPointInOpen = OpenList.GetNode(aPoint);
  94.                         var aPointInOpen = aPoint;
  95.                         aPointInOpen.Count++;//
  96.  
  97.                         var newG = aPointInOpen.CalcNewG(currentPoint);
  98.  
  99.                         if (newG < aPointInOpen.G)
  100.                         {
  101.                             aPointInOpen.G = newG;
  102.                             aPointInOpen.CalcF();
  103.                             aPointInOpen.Parent = currentPoint;
  104.                         }
  105.                     }
  106.                 }
  107.             }
  108.  
  109.             return GetEndPointInCloseList(endNode);
  110.  
  111.         }
  112.  
  113.         /// <summary>
  114.         /// 如果结束结点不可用,查找结束节点离开始节点最近的可用节点
  115.         /// </summary>
  116.         /// <param name="startNode"> </param>
  117.         /// <param name="endNode"></param>
  118.         /// <returns></returns>
  119.         private AStarNode GetWalkableEndNode(AStarNode startNode, AStarNode endNode)
  120.         {
  121.             if (endNode.Walkable) return endNode;
  122.  
  123.             //1.找出周围有可用点的方形圈
  124.             var aroundCount = 1;
  125.             var foudedNodes = new List<AStarNode>();
  126.             while (true)
  127.             {
  128.                 //上下两行
  129.                 for (var i = -aroundCount; i <= aroundCount; i++)
  130.                 {
  131.                     var node = GetPoint(endNode.X + i, endNode.Y - aroundCount);
  132.                     if (node != null && node.Walkable)
  133.                     {
  134.                         foudedNodes.Add(node);
  135.                     }
  136.                     node = GetPoint(endNode.X + i, endNode.Y + aroundCount);
  137.                     if (node != null && node.Walkable)
  138.                     {
  139.                         foudedNodes.Add(node);
  140.                     }
  141.                 }
  142.  
  143.                 //左右两列
  144.                 for (var i = -aroundCount + 1; i < aroundCount; i++)
  145.                 {
  146.                     var node = GetPoint(endNode.X - aroundCount, endNode.Y + i);
  147.                     if (node != null && node.Walkable)
  148.                     {
  149.                         foudedNodes.Add(node);
  150.                     }
  151.                     node = GetPoint(endNode.X + aroundCount, endNode.Y + i);
  152.                     if (node != null && node.Walkable)
  153.                     {
  154.                         foudedNodes.Add(node);
  155.                     }
  156.                 }
  157.  
  158.                 if (foudedNodes.Count > 0)
  159.                 {
  160.                     break;
  161.                 }
  162.                 else
  163.                 {
  164.                     aroundCount += 1;
  165.  
  166.                 }
  167.             }
  168.             //2.没找到,说明没有可用点
  169.             if (foudedNodes.Count == 0) return null;
  170.  
  171.             //找出该圈中离开始点最近的点
  172.             var foundIncex = 0;
  173.             var shortDistance = GetDistance(startNode, foudedNodes[0]);
  174.             for (var i = 0; i < foudedNodes.Count; i++)
  175.             {
  176.                 var node = foudedNodes[i];
  177.                 var distance = GetDistance(startNode, node);
  178.                 if (distance < shortDistance)
  179.                 {
  180.                     shortDistance = distance;
  181.                     foundIncex = i;
  182.                 }
  183.  
  184.             }
  185.             return foudedNodes[foundIncex];
  186.         }
  187.  
  188.         /// <summary>
  189.         /// 计算两点直线距离
  190.         /// </summary>
  191.         /// <param name="startNode"></param>
  192.         /// <param name="endNode"></param>
  193.         /// <returns></returns>
  194.         private double GetDistance(AStarNode startNode, AStarNode endNode)
  195.         {
  196.             return Math.Sqrt((endNode.X - startNode.X) * (endNode.X - startNode.X) +
  197.                             (endNode.Y - startNode.Y) * (endNode.Y - startNode.Y));
  198.         }
  199.  
  200.         private AStarNode GetPoint(int x, int y)
  201.         {
  202.             return !ValidPoint(x, y) ? null : _nodes[y][x];
  203.         }
  204.  
  205.         /// <summary>
  206.         /// 查找开放节点中最低H值的节点
  207.         /// </summary>
  208.         /// <returns></returns>
  209.         private AStarNode GetLowestFScore()
  210.         {
  211.             return OpenList.OrderBy(t => t.F).FirstOrDefault();
  212.         }
  213.  
  214.         /// <summary>
  215.         /// 节点加入关闭列表
  216.         /// </summary>
  217.         /// <param name="aNode"></param>
  218.         private void AddCloseList(AStarNode aNode)
  219.         {
  220.             CloseList.Add(aNode);
  221.         }
  222.  
  223.         /// <summary>
  224.         /// 从开放节点中移去节点
  225.         /// </summary>
  226.         /// <param name="aNode"></param>
  227.         private void RemoveOpenList(AStarNode aNode)
  228.         {
  229.             OpenList.Remove(aNode);
  230.         }
  231.  
  232.         /// <summary>
  233.         /// 结束点在关闭结点,说明已找到,完成
  234.         /// </summary>
  235.         /// <param name="endNode"></param>
  236.         /// <returns></returns>
  237.         private bool IsEndInCloseList(AStarNode endNode)
  238.         {
  239.             //return CloseList.Exists(endNode);
  240.             return CloseList.Contains(endNode);
  241.  
  242.         }
  243.  
  244.         /// <summary>
  245.         /// 获取当前点的周边有效点
  246.         /// </summary>
  247.         /// <param name="currentNode"></param>
  248.         /// <param name="isIgnoreCorner">能否穿墙角</param>
  249.         /// <returns></returns>
  250.         private List<AStarNode> getArounds(AStarNode currentNode, bool isIgnoreCorner)
  251.         {
  252.             var arounds = new List<AStarNode>();
  253.  
  254.             for (int x = currentNode.X - 1; x <= currentNode.X + 1; x++)
  255.                 for (int y = currentNode.Y - 1; y <= currentNode.Y + 1; y++)
  256.                 {
  257.                     if (!(x == currentNode.X && y == currentNode.Y))
  258.                     {
  259.                         if (x < 0 || x > maxMapX || y < 0 || y > maxMapY) continue;
  260.                         var aPoint = _nodes[y][x];
  261.                         if (CanReachTo(currentNode, aPoint, isIgnoreCorner))
  262.                         {
  263.                             arounds.Add(aPoint);
  264.                         }
  265.                     }
  266.                 }
  267.             return arounds;
  268.  
  269.         }
  270.  
  271.         /// <summary>
  272.         /// 判断斜线方向能否到达
  273.         /// </summary>
  274.         /// <param name="currentNode"></param>
  275.         /// <param name="aNode"></param>
  276.         /// <param name="isIgnoreCorner">是否允许穿墙</param>
  277.         /// <returns></returns>
  278.         private bool CanReachTo(AStarNode currentNode, AStarNode aNode, bool isIgnoreCorner)
  279.         {
  280.             if (!ValidPoint(aNode.X, aNode.Y)) return false;
  281.             if (!aNode.Walkable) return false;
  282.             if (Math.Abs(aNode.X - currentNode.X) + Math.Abs(aNode.Y - currentNode.Y) == 1) return true; //横竖方向
  283.             //如果是斜方向移动, 判断是否 "拌脚"
  284.             var leftPoint = GetPoint(currentNode.X, aNode.Y);
  285.             var rightPoint = GetPoint(aNode.X, currentNode.Y);
  286.             if (leftPoint.Walkable && rightPoint.Walkable) //无墙角
  287.             {
  288.                 return true;
  289.             }
  290.             else if (leftPoint.Walkable || leftPoint.Walkable) //有一个
  291.             {
  292.                 return isIgnoreCorner; //有墙角
  293.             }
  294.             else
  295.             {
  296.                 return false;
  297.             }
  298.  
  299.         }
  300.  
  301.         /// <summary>
  302.         /// 是不是有效的点
  303.         /// </summary>
  304.         /// <param name="node"></param>
  305.         /// <returns></returns>
  306.         private bool ValidPoint(int x, int y)
  307.         {
  308.             if (x < 0 || x > maxMapX || y < 0 || y > maxMapY) return false;
  309.             return true;
  310.         }
  311.  
  312.         /// <summary>
  313.         /// 关闭列表中是否存在该点
  314.         /// </summary>
  315.         /// <param name="aNode"></param>
  316.         /// <returns></returns>
  317.         private bool IsInCloseList(AStarNode aNode)
  318.         {
  319.             //return CloseList.Exists(aNode);
  320.             //return CloseList.Contains(aNode);
  321.             return CloseList.IndexOf(aNode) != -1;
  322.  
  323.         }
  324.  
  325.         /// <summary>
  326.         /// 开放列表中是否存在该点
  327.         /// </summary>
  328.         /// <param name="aNode"></param>
  329.         /// <returns></returns>
  330.         private bool IsInOpenList(AStarNode aNode)
  331.         {
  332.             //return OpenList.Exists(aNode);
  333.             return OpenList.Contains(aNode);
  334.         }
  335.  
  336.         /// <summary>
  337.         /// 加入开放列表
  338.         /// </summary>
  339.         /// <param name="aNode"></param>
  340.         private void AddOpenList(AStarNode aNode)
  341.         {
  342.             aNode.SerialNumber = CurrentSerialNumber++;
  343.  
  344.             OpenList.Add(aNode);
  345.         }
  346.  
  347.         /// <summary>
  348.         /// 如果endPoint在关闭列表中,则返回它,否则返回null
  349.         /// </summary>
  350.         /// <param name="endNode"></param>
  351.         /// <returns></returns>
  352.         private AStarNode GetEndPointInCloseList(AStarNode endNode)
  353.         {
  354.             if (CloseList.IndexOf(endNode) != -1)
  355.             {
  356.                 return CloseList[CloseList.IndexOf(endNode)];
  357.             }
  358.             else
  359.             {
  360.                 return null;
  361.             }
  362.         }
  363.     }
  364.  
  365.  
  366.  
  367.  
  368. }

 

从老的机器拷贝两个目录 d:\depot_tools;d:\webrtc

在path 中加入d:\depot_tools;

dos中运行gclient,自动下载git;

 

 

1.https://sites.google.com/a/chromium.org/dev/developers/how-tos/install-depot-tools

下载安装depot_tools

2.depot_tools目录加入Path

3.运行gclient,自动下载很多工具,并下载git,当下载安装完时,运行gclient,显示gclient的用法帮助。

 

4.原来的all.sln生成,出现60+错误。

 

5.下载安装SDK7.1 win7_GRMSDKX_EN_DVD,带X的是64位的。报错,把原来已经安装的visual studio 2010 Redistributable x86/x64都卸载了,就可以安装了,再安装补丁VC-Compiler-KB2519277.exe

 

6.安装Directx SDK 安装DirectXSDK时提示Error Code s1023,Microsoft Visual C++ 2010 x86/x64 Redistributable 的版本大于10.0.30319 就会提示失败!将这个卸载掉就可以安装成功!!(中间有可能需重启),安装完后,再装VC-Compiler-KB2519277.exe

 

7.gclient config http://webrtc.googlecode.com/svn/trunk

 

gclient sync --force 运行最后, 会去下载win8 SDK.

 

中间中断,运行

set GYP_GENERATORS=msvs

call python trunk/webrtc/build/gyp_webrtc -G msvs_version=2012

会继续下载,如下:(下载不需要vpn,速度快些。)

posted @ 2014-04-09 15:31  tp3cd  阅读(251)  评论(0编辑  收藏  举报