/// <summary> /// Updates graphs. /// Will do some graph updates, possibly signal another thread to do them. /// Will only process graph updates added by QueueGraphUpdatesInternal /// /// Returns: True if all graph updates have been done and pathfinding (or other tasks) may resume. /// False if there are still graph updates being processed or waiting in the queue. /// </summary> /// <param name="force">If true, all graph updates will be processed before this function returns. The return value /// will be True.</param> bool ProcessGraphUpdates(IWorkItemContext context, bool force) { Assert.IsTrue(anyGraphUpdateInProgress); if (force) { asyncGraphUpdatesComplete.WaitOne(); } else { #if !UNITY_WEBGL if (!asyncGraphUpdatesComplete.WaitOne(0)) { return(false); } #endif } Assert.AreEqual(graphUpdateQueueAsync.Count, 0, "Queue should be empty at this stage"); ProcessPostUpdates(); if (!ProcessRegularUpdates(force)) { return(false); } Assert.AreEqual(graphUpdateQueueRegular.Count, 0, "QueueRegular should be empty at this stage"); Assert.AreEqual(graphUpdateQueueAsync.Count, 0, "QueueAsync should be empty at this stage"); Assert.AreEqual(graphUpdateQueuePost.Count, 0, "QueuePost should be empty at this stage"); anyGraphUpdateInProgress = false; return(true); }
/// <summary>Schedules graph updates internally</summary> void QueueGraphUpdatesInternal(IWorkItemContext context) { while (graphUpdateQueue.Count > 0) { GraphUpdateObject ob = graphUpdateQueue.Dequeue(); foreach (IUpdatableGraph g in astar.data.GetUpdateableGraphs()) { NavGraph gr = g as NavGraph; if (ob.nnConstraint == null || ob.nnConstraint.SuitableGraph(astar.data.GetGraphIndex(gr), gr)) { var guo = new GUOSingle(); guo.order = GraphUpdateOrder.GraphUpdate; guo.obj = ob; guo.graph = g; graphUpdateQueueRegular.Enqueue(guo); context.SetGraphDirty(gr); } } } context.PreUpdate(); anyGraphUpdateInProgress = true; }