Beispiel #1
0
        private void UpdateExploration()
        {
            Vec3 current_pos = m_Navigator.CurrentPos;

            if (current_pos.IsZero())
            {
                return;
            }

            if (!IsDataAvailable)
            {
                m_Navmesh.Log("[Nav] Exploration data unavailable!");
                return;
            }

            if (IsExplored())
            {
                m_Navmesh.Log("[Nav] Exploration finished!");
                m_Navigator.ClearDestination(DestType.Explore);
                return;
            }

            using (new ReadLock(DataLock, true))
            {
                if (m_Navigator.GetDestinationType() < DestType.Explore)
                {
                    m_DestCell = GetDestinationCell();
                    m_Navigator.SetDestination(GetDestinationCellPosition(), DestType.Explore, ExploreDestPrecision);
                    //m_Navmesh.Log("[Nav] Explore dest changed.");
                }

                {
                    // mark cells as explored when passing by close enough
                    ExploreCell current_explore_cell = m_ExploreCells.FirstOrDefault(x => !x.Explored && x.Position.Distance2D(current_pos) < ExploreDestPrecision);

                    if (current_explore_cell != null)
                    {
                        OnCellExplored(current_explore_cell);
                    }
                }

                OnUpdateExploration();
            }
        }
Beispiel #2
0
        private void UpdateExploration()
        {
            Vec3 current_pos = m_Navigator.CurrentPos;

            if (current_pos.IsZero())
            {
                return;
            }

            if (!IsDataAvailable)
            {
                m_Navmesh.Log("[Nav] Exploration data unavailable!");
                return;
            }

            if (IsExplored())
            {
                m_Navmesh.Log("[Nav] Exploration finished!");
                m_Navigator.ClearDestination(DestType.Explore);
                return;
            }

            if (m_DestCell != null)
            {
                bool mark_dest_cell_as_explored = false;
                // perform connection check only when reevaluation is forced (usually due to navigation data change)
                bool is_dest_cell_connected = (!m_ForceReevaluation && !m_ValidateDestCell) || m_Navmesh.AreConnected(GetDestinationCellPosition(), current_pos, MovementFlag.Walk, ExploreDestPrecision, 0, out var unused1, out var unused2);

                // delay exploration of currently unconnected explore cells, unless they are already delayed (mark them as explored in that case)
                if (!is_dest_cell_connected)
                {
                    if (!m_DestCell.Delayed)
                    {
                        m_DestCell.Delayed  = true;
                        m_ForceReevaluation = true; // this is a change to find another un-delayed explore cell
                    }
                    else
                    {
                        // looks like there are no better cells to visit, and there is no way to reach this one... so sorry but we have to mark it as explored
                        mark_dest_cell_as_explored = true;
                    }
                }

                m_ValidateDestCell = false;

                // mark destination cell as explored when external function says so or destination cell is no longer connected (mostly due to nav blocker)
                mark_dest_cell_as_explored |= AlternativeExploredCondition?.Invoke(m_DestCell, current_pos) ?? false;

                if (mark_dest_cell_as_explored)
                {
                    OnCellExplored(m_DestCell);
                }
            }

            using (new ReadLock(DataLock, true))
            {
                if (m_Navigator.GetDestinationType() < DestType.Explore || (m_DestCell?.Explored ?? false) || m_ForceReevaluation)
                {
                    SelectNewDestinationCell();
                    //m_Navmesh.Log("[Nav] Explore dest changed.");
                }

                // mark cells as explored when passing by close enough
                ExploreCell current_explore_cell = m_ExploreCells.FirstOrDefault(x => !x.Explored && x.Position.Distance2D(current_pos) < ExploreDestPrecision);

                if (current_explore_cell != null)
                {
                    OnCellExplored(current_explore_cell);
                }

                OnUpdateExploration();
            }
        }
Beispiel #3
0
        private void UpdateExploration(bool forceReevaluation, bool ignore_explored)
        {
            Vec3 current_pos = m_Navigator.CurrentPos;

            if (current_pos.IsZero())
            {
                return;
            }

            if (!IsDataAvailable)
            {
                m_Navmesh.Log("[Nav] Exploration data unavailable!");
                return;
            }

            if (!ignore_explored && IsExplored())
            {
                m_Navmesh.Log("[Nav] Exploration finished!");
                m_Navigator.ClearDestination(DestType.Explore);
                return;
            }

            if (m_DestCell != null)
            {
                bool validate_dest_cell         = Interlocked.CompareExchange(ref m_ValidateDestCell, 0, 1) == 1;
                bool mark_dest_cell_as_explored = false;
                // perform connection check only when reevaluation is forced (usually due to navigation data change)
                bool is_dest_cell_connected = (!forceReevaluation && !validate_dest_cell) || m_Navmesh.AreConnected(GetDestinationCellPosition(), current_pos, MovementFlag.Walk, 0, 0, out var unused1, out var unused2);

                // delay exploration of currently unconnected explore cells, unless they are already delayed (mark them as explored in that case)
                if (!is_dest_cell_connected)
                {
                    if (!m_DestCell.Delayed)
                    {
                        m_DestCell.Delayed = true;
                        forceReevaluation  = true; // this is a change to find another un-delayed explore cell
                    }
                    else
                    {
                        // looks like there are no better cells to visit, and there is no way to reach this one... so sorry but we have to mark it as explored
                        mark_dest_cell_as_explored = true;
                    }
                }

                // mark destination cell as explored when external function says so or destination cell is no longer connected (mostly due to nav blocker)
                mark_dest_cell_as_explored |= AlternativeExploredCondition?.Invoke(m_DestCell, current_pos) ?? false;

                if (mark_dest_cell_as_explored)
                {
                    Trace.WriteLine($"Explore cell GID {m_DestCell.GlobalId} considered explored by external logic.");
                    OnCellExplored(m_DestCell);
                }
            }

            using (new ReadLock(DataLock, true))
            {
                if ((Enabled && m_Navigator.GetDestinationType() < DestType.Explore) || (m_DestCell?.Explored ?? false) || forceReevaluation)
                {
                    SelectNewDestinationCell(null);
                    //m_Navmesh.Log("[Nav] Explore dest changed.");
                }

                ExploreCell travel_through_explore_cell = m_ExploreCells.FirstOrDefault(x => x.Contains2D(current_pos));

                if (travel_through_explore_cell != null && !travel_through_explore_cell.Explored)
                {
                    bool mark_explored = false;
                    if (AlternativeExploredCondition?.Invoke(travel_through_explore_cell, current_pos) ?? false)
                    {
                        Trace.WriteLine($"Explore cell GID {travel_through_explore_cell.GlobalId} considered explored by external logic.");
                        mark_explored = true;
                    }

                    // mark cells as explored when passing by close enough
                    if (travel_through_explore_cell.Position.Distance2D(current_pos) < ExploreDestPrecision)
                    {
                        Trace.WriteLine($"Explore cell GID {travel_through_explore_cell.GlobalId} considered explored because of passing by.");
                        mark_explored = true;
                    }

                    if (mark_explored)
                    {
                        OnCellExplored(travel_through_explore_cell);
                    }
                }

                OnUpdateExploration(travel_through_explore_cell);
            }
        }