Exemplo n.º 1
0
        private void dbg_GenerateGrids()
        {
            Random rng = new Random();

            const float connectionLength = 200;
            const float connectionWidth  = 45;

            for (int i = 0; i < 10; ++i)
            {
                var connectorPos = m_Navmesh.GetRandomPos(rng);

                connectorPos.Z = 0;

                GridCell gCell = new GridCell(connectorPos - new Vec3(1, 1, 0) * connectionLength * 0.5f, connectorPos + new Vec3(1, 1, 0) * connectionLength * 0.5f);

                // add cross connector
                gCell.Add(new Nav.Cell(connectorPos - new Vec3(connectionLength * 0.5f, connectionWidth * 0.5f, 0), connectorPos + new Vec3(connectionLength * 0.5f, connectionWidth * 0.5f, 0), MovementFlag.All));
                gCell.Add(new Nav.Cell(connectorPos - new Vec3(connectionWidth * 0.5f, connectionLength * 0.5f, 0), connectorPos + new Vec3(connectionWidth * 0.5f, connectionLength * 0.5f, 0), MovementFlag.All));

                m_Navmesh.Add(gCell, true);
            }
        }
Exemplo n.º 2
0
        public bool Add(GridCell g_cell, bool trigger_nav_data_change)
        {
            if (g_cell == null || g_cell.Cells.Count == 0)
            {
                return(false);
            }

            bool add_to_list = true;

            using (new WriteLock(DataLock))
            {
                // check if same grid is not already defined (merge then)
                GridCell base_grid_cell = m_GridCells.Find(x => x.AABB.Equals(g_cell.AABB));

                if (base_grid_cell != null)
                {
                    add_to_list = false;
                    base_grid_cell.Add(g_cell.Cells);

                    Log("[Nav] Grid cell {" + g_cell.GlobalId + "} with " + g_cell.Cells.Count + " cell(s) merged with grid cell {" + base_grid_cell.GlobalId + "}");
                }

                m_AllCells.AddRange(g_cell.Cells);

                foreach (GridCell grid_cell in m_GridCells)
                {
                    grid_cell.AddNeighbour(g_cell);
                }

                if (add_to_list)
                {
                    m_GridCells.Add(g_cell);

                    Log("[Nav] Grid cell {" + g_cell.GlobalId + "} with " + g_cell.Cells.Count + " cell(s) added");
                }
            }

            if (Explorator != null)
            {
                Explorator.OnGridCellAdded(g_cell, trigger_nav_data_change);
            }

            Navigator.RequestPathUpdate();

            return(true);
        }
Exemplo n.º 3
0
        public bool Add(GridCell g_cell, bool trigger_nav_data_change)
        {
            if (g_cell == null || g_cell.Cells.Count == 0)
            {
                return(false);
            }

            using (new WriteLock(DataLock))
            {
                // check if same grid is not already defined (merge then)
                GridCell base_grid_cell = m_GridCells.FirstOrDefault(x => x.AABB.Equals(g_cell.AABB));

                if (base_grid_cell != null)
                {
                    base_grid_cell.Add(g_cell.Cells);
                    Log("[Nav] Grid cell (" + g_cell.Id + " " + g_cell.Min + ") with " + g_cell.Cells.Count + " cell(s) merged with grid cell (" + base_grid_cell.Id + " " + base_grid_cell.Min + ")");

                    foreach (GridCell grid_cell in m_GridCells)
                    {
                        grid_cell.AddNeighbour(base_grid_cell);
                    }
                }
                else
                {
                    foreach (GridCell grid_cell in m_GridCells)
                    {
                        grid_cell.AddNeighbour(g_cell);
                    }

                    m_GridCells.Add(g_cell);
                    Log("[Nav] Grid cell (" + g_cell.Id + " " + g_cell.Min + ") with " + g_cell.Cells.Count + " cell(s) added");
                }

                m_AllCells.UnionWith(g_cell.Cells);
                UpdateCellsPatches(g_cell.Cells);

                NotifyOnGridCellAdded(g_cell);
            }

            NotifyOnNavDataChanged();

            return(true);
        }