Пример #1
0
        internal override ExploreCell GetDestinationCell()
        {
            ExploreCell dest_cell = base.GetDestinationCell();

            if (dest_cell != null)
            {
                return(dest_cell);
            }

            ExploreCell current_explore_cell = GetCurrentExploreCell();

            if (current_explore_cell == null)
            {
                return(current_explore_cell);
            }

            if (!current_explore_cell.Explored)
            {
                return(current_explore_cell);
            }

            HashSet <ExploreCell> unexplored_cells = GetUnexploredCells(current_explore_cell);

            ExploreCellSelector selector = CreateExploreCellSelector();

            using (new ReadLock(DataLock))
                Algorihms.VisitBreadth(current_explore_cell, MovementFlag.None, -1, unexplored_cells, selector);

            if (selector.dest_cell != null)
            {
                return(selector.dest_cell);
            }

            return(null);
        }
Пример #2
0
        protected override ExploreCell GetDestinationCell(ExploreCell curr_explore_cell)
        {
            if (curr_explore_cell == null)
            {
                curr_explore_cell = GetCurrentExploreCell();
            }

            if (curr_explore_cell == null)
            {
                return(curr_explore_cell);
            }

            if (!curr_explore_cell.Explored)
            {
                return(curr_explore_cell);
            }

            HashSet <ExploreCell> unexplored_cells = GetUnexploredCells(curr_explore_cell);

            if (unexplored_cells.Count > 0)
            {
                ExploreCellSelector selector = CreateExploreCellSelector();

                using (new ReadLock(DataLock))
                    Algorihms.VisitBreadth(curr_explore_cell, MovementFlag.None, -1, unexplored_cells, selector);

                if (selector.dest_cell != null)
                {
                    return(selector.dest_cell);
                }
            }

            return(null);
        }
Пример #3
0
            private float GetExploredNeighboursPct(ExploreCell cell, int max_depth)
            {
                HashSet <ExploreCell> cells_group = new HashSet <ExploreCell>();

                Algorihms.Visit(cell, ref cells_group, MovementFlag.None, true, 0, max_depth);

                //treat missing cells as explored thus explore edges to possibly load new navmesh data
                int max_cells_num = (int)Math.Pow(9, max_depth);
                int missing_cells = Math.Max(0, max_cells_num - cells_group.Count);

                return((float)(cells_group.Count(x => ((ExploreCell)x).Explored) + missing_cells) / (float)max_cells_num);
            }
Пример #4
0
        private void UpdateExplorePath()
        {
            if (Navmesh == null)
            {
                return;
            }

            List <Vec3> new_explore_path = new List <Vec3>();

            using (new ReadLock(DataLock))
            {
                ExploreCell start_cell = null;

                Vec3 current_pos_copy = Navmesh.Navigator.CurrentPos;

                if (!current_pos_copy.IsEmpty)
                {
                    List <ExploreCell> containing_cells = m_ExploreCells.FindAll(c => c.Contains2D(current_pos_copy) && c.Neighbours.Count > 0);

                    float min_dist = float.MaxValue;

                    foreach (ExploreCell e_cell in containing_cells)
                    {
                        foreach (Cell cell in e_cell.Cells)
                        {
                            float dist = cell.AABB.Distance2D(current_pos_copy);
                            if (dist < min_dist)
                            {
                                start_cell = e_cell;
                                min_dist   = dist;
                            }
                        }
                    }
                }

                if (start_cell == null)
                {
                    return;
                }

                Algorihms.FindExplorePath2Opt(start_cell, m_ExploreCells, m_ExploreCellsDistancer, ref new_explore_path);
            }

            using (new WriteLock(ExplorePathDataLock))
            {
                ExplorePath             = new_explore_path;
                m_ExplorePathCalculated = true;
            }

            RequestExplorationUpdate();
        }