Пример #1
0
 private void DoVisualizePath(WrappedPathingResult pathingResult)
 {
     _visualizationPath?.Hide();
     _visualizationPath = new GamePath($"path({Owner.Name})", Owner.Region)
     {
         HasLavaEffect = false
     };
     foreach (var node in pathingResult.Points)
     {
         var model = GamePath.MarkerModel.Green;
         if ((node.Flags & dtPolyFlags.DOOR) != 0)
         {
             model = GamePath.MarkerModel.Red;
         }
         else if ((node.Flags & dtPolyFlags.SWIM) != 0)
         {
             model = GamePath.MarkerModel.Blue;
         }
         else if ((node.Flags & dtPolyFlags.JUMP) != 0)
         {
             model = GamePath.MarkerModel.Yellow;
         }
         _visualizationPath.Append(new GameLocation(Owner.Region, node.Position, 0), Owner.MaxSpeed, model);
     }
     Owner.DebugSend("Visualizing Path");
     _visualizationPath.Show();
 }
Пример #2
0
        private async Task ReplotPathAsync(Vector3 target)
        {
            // Try acquiring a pathing lock
            if (Interlocked.CompareExchange(ref isReplottingPath, REPLOTTING, IDLE) != IDLE)
            {
                // Computation is already in progress. ReplotPathAsync will be called again automatically by .PathTo every few ms
                return;
            }

            // we make a blocking call here because we are already in a worker thread and inside a lock
            try {
                var currentZone   = Owner.Zone;
                var currrentPos   = Owner.Position;
                var pathingResult = await PathingMgr.Instance.GetPathStraightAsync(currentZone, currrentPos, target).ConfigureAwait(false);

                lock (_pathNodes) {
                    _pathNodes.Clear();
                    if (pathingResult.Error != PathingError.NoPathFound && pathingResult.Error != PathingError.NavmeshUnavailable &&
                        pathingResult.Points != null)
                    {
                        DidFindPath = true;
                        var to = pathingResult.Points.Length - 1; /* remove target node only if no partial path */
                        if (pathingResult.Error == PathingError.PartialPathFound)
                        {
                            to = pathingResult.Points.Length;
                        }
                        for (int i = 1; i < to; i++) /* remove first node */
                        {
                            var pt = pathingResult.Points[i];
                            if (pt.Position.X < -500000)
                            {
                                log.Error("PathCalculator.ReplotPath returned weird node: " + pt + " (result=" + pathingResult.Error +
                                          "); this=" + this);
                            }
                            _pathNodes.Enqueue(pt);
                        }

                        if (Owner.DebugMode)
                        {
                            Owner.DebugSend("Found path to target with {0} nodes for {1} (VisualizePath={2})",
                                            pathingResult.Points.Length, Owner.Name, VisualizePath);
                        }

                        // Visualize the path?
                        if (VisualizePath)
                        {
                            DoVisualizePath(pathingResult);
                        }
                        else if (_visualizationPath != null)
                        {
                            _visualizationPath.Hide();
                            _visualizationPath = null;
                        }
                    }
                    else
                    {
                        //noPathFoundMetric.Mark();
                        DidFindPath = false;
                        if (Owner.DebugMode)
                        {
                            Owner.DebugSend("No path to destination found for {0}", Owner.Name);
                        }
                    }
                    _lastTarget = target;
                    ForceReplot = false;
                }
            }
            finally {
                if (Interlocked.Exchange(ref isReplottingPath, IDLE) != REPLOTTING)
                {
                    log.Warn("PathCalc semaphore was in IDLE state even though we were replotting. This should never happen");
                }
            }
        }