public void GenerateObstacleInfo(CellManager cellMgr)
 {
     //标记所有格子为阻挡
     for (int row = 0; row < cellMgr.GetMaxRow(); row++)
     {
         for (int col = 0; col < cellMgr.GetMaxCol(); col++)
         {
             cellMgr.SetCellStatus(row, col, BlockType.STATIC_BLOCK);
         }
     }
     //打开可行走区
     foreach (TiledData data in walk_area_list_)
     {
         List <Vector3> pts = data.GetPoints();
         MapDataUtil.MarkObstacleArea(pts, cellMgr, BlockType.NOT_BLOCK);
     }
     //标记阻挡区
     foreach (TiledData data in obstacle_area_list_)
     {
         List <Vector3> pts = data.GetPoints();
         MapDataUtil.MarkObstacleArea(pts, cellMgr, BlockType.STATIC_BLOCK);
     }
     //标记阻挡线
     foreach (TiledData data in obstacle_line_list_)
     {
         List <Vector3> pts = data.GetPoints();
         MarkObstacleLine(pts, cellMgr, BlockType.STATIC_BLOCK);
     }
 }
        internal static void MarkObstacleArea(List <Vector3> pts, CellManager cellMgr, byte obstacle)
        {
            List <CellPos> cells = cellMgr.GetCellsInPolygon(pts);

            foreach (CellPos cell in cells)
            {
                cellMgr.SetCellStatus(cell.row, cell.col, obstacle);
            }
        }
        private void MarkObstacleLine(List <Vector3> pts, CellManager cellMgr, byte obstacle)
        {
            List <CellPos> pos_list = cellMgr.GetCellsCrossByPolyline(pts);

            foreach (CellPos pos in pos_list)
            {
                cellMgr.SetCellStatus(pos.row, pos.col, obstacle);
            }
        }
示例#4
0
        public void Init(CellManager cellMgr)
        {
            m_CellMgr = cellMgr;
            m_Map     = cellMgr.cells_arr_;
            m_MaxRows = cellMgr.GetMaxRow();
            m_MaxCols = cellMgr.GetMaxCol();

            m_PreprocessData = null;
        }
示例#5
0
        public void PreprocessMap(CellManager cellMgr, string filename)
        {
            m_Width     = cellMgr.GetMaxCol();
            m_Height    = cellMgr.GetMaxRow();
            byte[,] map = cellMgr.cells_arr_;

            using (FileStream fs = new FileStream(filename, FileMode.Create)) {
                // init
                fs.WriteByte((byte)(m_Width & 0x0ff));
                fs.WriteByte((byte)((m_Width & 0x0ff00) >> 8));
                fs.WriteByte((byte)(m_Height & 0x0ff));
                fs.WriteByte((byte)((m_Height & 0x0ff00) >> 8));

                int size = map.Length;
                m_Tree    = new TreeNode[size];
                m_PreTree = new PreTreeNode[size];

                for (int i = 0; i < size; ++i)
                {
                    m_PreTree[i].Wall    = BlockType.GetBlockType(map[i / m_Width, i % m_Width]) == 0;
                    m_Tree[i].OpToParent = (byte)OperationEnum.NO_OP;
                    m_PreTree[i].Visited = false;
                    m_PreTree[i].CostF   = float.MaxValue;
                    m_Tree[i].CostI      = (byte)255;
                }

                // Create Trees (multiple roots are possible)
                for (int i = 0; i < size; ++i)
                {
                    if (m_PreTree[i].Wall && !m_PreTree[i].Visited)
                    {
                        CreateTree(i);
                    }
                }

                // Compact
                for (int i = 0; i < size; ++i)
                {
                    // Round up to ensure that only the root node gets a cost of 0.
                    double scaledCostF = Math.Min(254.0, Math.Ceiling(m_PreTree[i].CostF / 5.0));
                    int    scaledCostI = (int)scaledCostF;
                    m_Tree[i].CostI = (byte)scaledCostI;
                }
                for (int i = 0; i < size; ++i)
                {
                    fs.WriteByte(m_Tree[i].CostI);
                    fs.WriteByte(m_Tree[i].OpToParent);
                }
                fs.Close();
            }
            m_PreTree = null;
            m_Tree    = null;
        }
示例#6
0
 public void GenerateObstacleInfoWithNavmesh(CellManager cellMgr)
 {
     //标记所有格子为阻挡
     for (int row = 0; row < cellMgr.GetMaxRow(); row++)
     {
         for (int col = 0; col < cellMgr.GetMaxCol(); col++)
         {
             cellMgr.SetCellStatus(row, col, BlockType.STATIC_BLOCK);
         }
     }
     //打开可行走区
     foreach (TriangleNode node in navmesh_triangle_list)
     {
         List <Vector3> pts = new List <Vector3>(node.Points);
         MapDataUtil.MarkObstacleArea(pts, cellMgr, BlockType.NOT_BLOCK);
     }
 }
示例#7
0
        private void FindNeighbors(JpsPathNode node)
        {
            int x = node.cell.row;
            int y = node.cell.col;

            m_Neighbors.Clear();

            JpsPathNode parent = node.prev;

            if (null != parent)
            {
                int px = parent.cell.row;
                int py = parent.cell.col;

                int dx = (x == px ? 0 : (x - px) / Math.Abs(x - px));
                int dy = (y == py ? 0 : (y - py) / Math.Abs(y - py));

                if (dx != 0 && dy != 0)
                {
                    if (IsWalkable(x, y + dy))
                    {
                        m_Neighbors.Add(new CellPos(x, y + dy));
                    }
                    if (IsWalkable(x + dx, y))
                    {
                        m_Neighbors.Add(new CellPos(x + dx, y));
                    }
                    if (IsWalkable(x, y + dy) || IsWalkable(x + dx, y))
                    {
                        m_Neighbors.Add(new CellPos(x + dx, y + dy));
                    }
                    if (!IsWalkable(x - dx, y) && IsWalkable(x, y + dy))
                    {
                        m_Neighbors.Add(new CellPos(x - dx, y + dy));
                    }
                    if (!IsWalkable(x, y - dy) && IsWalkable(x + dx, y))
                    {
                        m_Neighbors.Add(new CellPos(x + dx, y - dy));
                    }
                }
                else
                {
                    if (dx == 0)
                    {
                        if (IsWalkable(x, y + dy))
                        {
                            if (IsWalkable(x, y + dy))
                            {
                                m_Neighbors.Add(new CellPos(x, y + dy));
                            }
                            if (!IsWalkable(x + 1, y))
                            {
                                m_Neighbors.Add(new CellPos(x + 1, y + dy));
                            }
                            if (!IsWalkable(x - 1, y))
                            {
                                m_Neighbors.Add(new CellPos(x - 1, y + dy));
                            }
                        }
                    }
                    else
                    {
                        if (IsWalkable(x + dx, y))
                        {
                            if (IsWalkable(x + dx, y))
                            {
                                m_Neighbors.Add(new CellPos(x + dx, y));
                            }
                            if (!IsWalkable(x, y + 1))
                            {
                                m_Neighbors.Add(new CellPos(x + dx, y + 1));
                            }
                            if (!IsWalkable(x, y - 1))
                            {
                                m_Neighbors.Add(new CellPos(x + dx, y - 1));
                            }
                        }
                    }
                }
            }
            else
            {
                m_Neighbors = CellManager.GetCellAdjacent(node.cell, m_MinCell.row, m_MinCell.col, m_MaxCell.row, m_MaxCell.col);
            }
        }