Пример #1
0
 public bool ProcessWorkItems(bool force)
 {
     if (this.workItemsInProgressRightNow)
     {
         throw new Exception("Processing work items recursively. Please do not wait for other work items to be completed inside work items. If you think this is not caused by any of your scripts, this might be a bug.");
     }
     this.workItemsInProgressRightNow = true;
     while (this.workItems.Count > 0)
     {
         if (!this.workItemsInProgress)
         {
             this.workItemsInProgress     = true;
             this.queuedWorkItemFloodFill = false;
         }
         AstarWorkItem value = this.workItems[0];
         if (value.init != null)
         {
             value.init();
             value.init = null;
         }
         if (value.initWithContext != null)
         {
             value.initWithContext(this);
             value.initWithContext = null;
         }
         this.workItems[0] = value;
         bool flag;
         try
         {
             if (value.update != null)
             {
                 flag = value.update(force);
             }
             else
             {
                 flag = (value.updateWithContext == null || value.updateWithContext(this, force));
             }
         }
         catch
         {
             this.workItems.Dequeue();
             this.workItemsInProgressRightNow = false;
             throw;
         }
         if (!flag)
         {
             if (force)
             {
                 Debug.LogError("Misbehaving WorkItem. 'force'=true but the work item did not complete.\nIf force=true is passed to a WorkItem it should always return true.");
             }
             this.workItemsInProgressRightNow = false;
             return(false);
         }
         this.workItems.Dequeue();
     }
     this.EnsureValidFloodFill();
     this.workItemsInProgressRightNow = false;
     this.workItemsInProgress         = false;
     return(true);
 }
Пример #2
0
        /** Process graph updating work items.
         * Process all queued work items, e.g graph updates and the likes.
         *
         * \returns
         * - false if there are still items to be processed.
         * - true if the last work items was processed and pathfinding threads are ready to be resumed.
         *
         * \see AddWorkItem
         * \see threadSafeUpdateState
         * \see Update
         */
        public bool ProcessWorkItems(bool force)
        {
            if (workItemsInProgressRightNow)
            {
                throw new System.Exception("Processing work items recursively. Please do not wait for other work items to be completed inside work items. " +
                                           "If you think this is not caused by any of your scripts, this might be a bug.");
            }

            workItemsInProgressRightNow = true;
            while (workItems.Count > 0)
            {
                // Working on a new batch
                if (!workItemsInProgress)
                {
                    workItemsInProgress     = true;
                    queuedWorkItemFloodFill = false;
                }

                // Peek at first item in the queue
                AstarWorkItem itm = workItems[0];

                // Call init the first time the item is seen
                if (itm.init != null)
                {
                    itm.init();
                    itm.init = null;
                }

                if (itm.initWithContext != null)
                {
                    itm.initWithContext(this);
                    itm.initWithContext = null;
                }

                // Make sure the item in the queue is up to date
                workItems[0] = itm;

                bool status;
                try {
                    if (itm.update != null)
                    {
                        status = itm.update(force);
                    }
                    else if (itm.updateWithContext != null)
                    {
                        status = itm.updateWithContext(this, force);
                    }
                    else
                    {
                        status = true;
                    }
                } catch {
                    workItems.Dequeue();
                    workItemsInProgressRightNow = false;
                    throw;
                }

                if (!status)
                {
                    if (force)
                    {
                        Debug.LogError("Misbehaving WorkItem. 'force'=true but the work item did not complete.\nIf force=true is passed to a WorkItem it should always return true.");
                    }

                    // Still work items to process
                    workItemsInProgressRightNow = false;
                    return(false);
                }
                else
                {
                    workItems.Dequeue();
                }
            }

            EnsureValidFloodFill();

            workItemsInProgressRightNow = false;
            workItemsInProgress         = false;
            return(true);
        }
Пример #3
0
 /** Add a work item to be processed when pathfinding is paused.
  *
  * \see ProcessWorkItems
  */
 public void AddWorkItem(AstarWorkItem itm)
 {
     workItems.Enqueue(itm);
 }
Пример #4
0
        bool ProcessWorkItems(bool force, bool sendEvents)
        {
            if (workItemsInProgressRightNow)
            {
                throw new System.Exception("Processing work items recursively. Please do not wait for other work items to be completed inside work items. " +
                                           "If you think this is not caused by any of your scripts, this might be a bug.");
            }

            // Make sure the physics engine data is up to date.
            // Graph updates may use physics methods and it is very confusing if they
            // do not always pick up the latest changes made to the scene.
            UnityEngine.Physics.SyncTransforms();
            UnityEngine.Physics2D.SyncTransforms();

            workItemsInProgressRightNow = true;
            astar.data.LockGraphStructure(true);
            while (workItems.Count > 0)
            {
                // Working on a new batch
                if (!workItemsInProgress)
                {
                    workItemsInProgress = true;
                }

                // Peek at first item in the queue
                AstarWorkItem itm = workItems[0];
                bool          status;

                try {
                    // Call init the first time the item is seen
                    if (itm.init != null)
                    {
                        itm.init();
                        itm.init = null;
                    }

                    if (itm.initWithContext != null)
                    {
                        itm.initWithContext(this);
                        itm.initWithContext = null;
                    }

                    // Make sure the item in the queue is up to date
                    workItems[0] = itm;

                    if (itm.update != null)
                    {
                        status = itm.update(force);
                    }
                    else if (itm.updateWithContext != null)
                    {
                        status = itm.updateWithContext(this, force);
                    }
                    else
                    {
                        status = true;
                    }
                } catch {
                    workItems.Dequeue();
                    workItemsInProgressRightNow = false;
                    astar.data.UnlockGraphStructure();
                    throw;
                }

                if (!status)
                {
                    if (force)
                    {
                        Debug.LogError("Misbehaving WorkItem. 'force'=true but the work item did not complete.\nIf force=true is passed to a WorkItem it should always return true.");
                    }

                    // Still work items to process
                    workItemsInProgressRightNow = false;
                    astar.data.UnlockGraphStructure();
                    return(false);
                }
                else
                {
                    workItems.Dequeue();
                }
            }

            if (sendEvents)
            {
                Profiler.BeginSample("PostUpdate");
                if (anyGraphsDirty)
                {
                    GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdateBeforeAreaRecalculation);
                }
                Profiler.EndSample();

                EnsureValidFloodFill();

                Profiler.BeginSample("PostUpdate");
                if (anyGraphsDirty)
                {
                    GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdate);
                    if (OnGraphsUpdated != null)
                    {
                        OnGraphsUpdated();
                    }
                }
                Profiler.EndSample();
            }

            // Reset flags at the end
            anyGraphsDirty     = false;
            preUpdateEventSent = false;

            workItemsInProgressRightNow = false;
            workItemsInProgress         = false;
            astar.data.UnlockGraphStructure();
            return(true);
        }
Пример #5
0
        /// <summary>
        /// Process graph updating work items.
        /// Process all queued work items, e.g graph updates and the likes.
        ///
        /// Returns:
        /// - false if there are still items to be processed.
        /// - true if the last work items was processed and pathfinding threads are ready to be resumed.
        ///
        /// See: AddWorkItem
        /// See: threadSafeUpdateState
        /// See: Update
        /// </summary>
        public bool ProcessWorkItems(bool force)
        {
            if (workItemsInProgressRightNow)
            {
                throw new System.Exception("Processing work items recursively. Please do not wait for other work items to be completed inside work items. " +
                                           "If you think this is not caused by any of your scripts, this might be a bug.");
            }

            UnityEngine.Physics2D.SyncTransforms();
            workItemsInProgressRightNow = true;
            astar.data.LockGraphStructure(true);
            while (workItems.Count > 0)
            {
                // Working on a new batch
                if (!workItemsInProgress)
                {
                    workItemsInProgress     = true;
                    queuedWorkItemFloodFill = false;
                }

                // Peek at first item in the queue
                AstarWorkItem itm = workItems[0];
                bool          status;

                try {
                    // Call init the first time the item is seen
                    if (itm.init != null)
                    {
                        itm.init();
                        itm.init = null;
                    }

                    if (itm.initWithContext != null)
                    {
                        itm.initWithContext(this);
                        itm.initWithContext = null;
                    }

                    // Make sure the item in the queue is up to date
                    workItems[0] = itm;

                    if (itm.update != null)
                    {
                        status = itm.update(force);
                    }
                    else if (itm.updateWithContext != null)
                    {
                        status = itm.updateWithContext(this, force);
                    }
                    else
                    {
                        status = true;
                    }
                } catch {
                    workItems.Dequeue();
                    workItemsInProgressRightNow = false;
                    astar.data.UnlockGraphStructure();
                    throw;
                }

                if (!status)
                {
                    if (force)
                    {
                        Debug.LogError("Misbehaving WorkItem. 'force'=true but the work item did not complete.\nIf force=true is passed to a WorkItem it should always return true.");
                    }

                    // Still work items to process
                    workItemsInProgressRightNow = false;
                    astar.data.UnlockGraphStructure();
                    return(false);
                }
                else
                {
                    workItems.Dequeue();
                }
            }

            EnsureValidFloodFill();

            Profiler.BeginSample("PostUpdate");
            if (anyGraphsDirty)
            {
                GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdate);
            }
            Profiler.EndSample();

            anyGraphsDirty = false;
            workItemsInProgressRightNow = false;
            workItemsInProgress         = false;
            astar.data.UnlockGraphStructure();
            return(true);
        }
Пример #6
0
 // Token: 0x06002343 RID: 9027 RVA: 0x0019439F File Offset: 0x0019259F
 public void AddWorkItem(AstarWorkItem item)
 {
     this.workItems.Enqueue(item);
 }