// Token: 0x060022E7 RID: 8935 RVA: 0x001963F4 File Offset: 0x001945F4 private void QueueGraphUpdatesInternal() { bool flag = false; while (this.graphUpdateQueue.Count > 0) { GraphUpdateObject graphUpdateObject = this.graphUpdateQueue.Dequeue(); if (graphUpdateObject.requiresFloodFill) { flag = true; } foreach (object obj in this.astar.data.GetUpdateableGraphs()) { IUpdatableGraph updatableGraph = (IUpdatableGraph)obj; NavGraph graph = updatableGraph as NavGraph; if (graphUpdateObject.nnConstraint == null || graphUpdateObject.nnConstraint.SuitableGraph(this.astar.data.GetGraphIndex(graph), graph)) { GraphUpdateProcessor.GUOSingle item = default(GraphUpdateProcessor.GUOSingle); item.order = GraphUpdateProcessor.GraphUpdateOrder.GraphUpdate; item.obj = graphUpdateObject; item.graph = updatableGraph; this.graphUpdateQueueRegular.Enqueue(item); } } } if (flag) { GraphUpdateProcessor.GUOSingle item2 = default(GraphUpdateProcessor.GUOSingle); item2.order = GraphUpdateProcessor.GraphUpdateOrder.FloodFill; this.graphUpdateQueueRegular.Enqueue(item2); } GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate); this.anyGraphUpdateInProgress = true; }
/** Triggers an event for all active graph modifiers */ public static void TriggerEvent(GraphModifier.EventType type) { List<GraphModifier> mods = GetActiveModifiers(); switch (type){ case EventType.PreScan: for (int i=0;i<mods.Count;i++) mods[i].OnPreScan(); break; case EventType.PostScan: for (int i=0;i<mods.Count;i++) mods[i].OnPostScan(); break; case EventType.LatePostScan: lastLateScanEvent = Time.frameCount; for (int i=0;i<mods.Count;i++) mods[i].OnLatePostScan(); break; case EventType.PreUpdate: for (int i=0;i<mods.Count;i++) mods[i].OnGraphsPreUpdate(); break; case EventType.PostUpdate: for (int i=0;i<mods.Count;i++) mods[i].OnGraphsPostUpdate(); break; case EventType.PostCacheLoad: lastPostCacheEvent = Time.frameCount; for (int i=0;i<mods.Count;i++) mods[i].OnPostCacheLoad (); break; } }
/// <summary>Schedules graph updates internally</summary> void QueueGraphUpdatesInternal() { while (graphUpdateQueue.Count > 0) { GraphUpdateObject ob = graphUpdateQueue.Dequeue(); if (ob.internalStage != GraphUpdateObject.STAGE_PENDING) { Debug.LogError("Expected remaining graph updates to be pending"); continue; } ob.internalStage = 0; 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; ob.internalStage += 1; graphUpdateQueueRegular.Enqueue(guo); } } } GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate); anyGraphUpdateInProgress = true; }
private void RemoveFromLinkedList() { if (root == this) { root = next; if (root != null) { root.prev = null; } } else { if (prev != null) { prev.next = next; } if (next != null) { next.prev = prev; } } prev = null; next = null; }
/// <summary> /// Deserializes graphs from the specified byte array additively. /// An error will be logged if deserialization fails. /// This function will add loaded graphs to the current ones. /// </summary> public void DeserializeGraphsAdditive(byte[] bytes) { var graphLock = AssertSafe(); try { if (bytes != null) { var sr = new AstarSerializer(this, active.gameObject); if (sr.OpenDeserialize(bytes)) { DeserializeGraphsPartAdditive(sr); sr.CloseDeserialize(); } else { Debug.Log("Invalid data file (cannot read zip).\nThe data is either corrupt or it was saved using a 3.0.x or earlier version of the system"); } } else { throw new System.ArgumentNullException(nameof(bytes)); } active.VerifyIntegrity(); } catch (System.Exception e) { Debug.LogError("Caught exception while deserializing data.\n" + e); graphs = new NavGraph[0]; } UpdateShortcuts(); GraphModifier.TriggerEvent(GraphModifier.EventType.PostGraphLoad); graphLock.Release(); }
/** Triggers an event for all active graph modifiers */ public static void TriggerEvent (GraphModifier.EventType type) { if (!Application.isPlaying) { FindAllModifiers (); } GraphModifier c = root; switch (type){ case EventType.PreScan: while (c != null) { c.OnPreScan(); c = c.next; } break; case EventType.PostScan: while (c != null) { c.OnPostScan(); c = c.next; } break; case EventType.LatePostScan: while (c != null) { c.OnLatePostScan(); c = c.next; } break; case EventType.PreUpdate: while (c != null) { c.OnGraphsPreUpdate(); c = c.next; } break; case EventType.PostUpdate: while (c != null) { c.OnGraphsPostUpdate(); c = c.next; } break; case EventType.PostCacheLoad: while (c != null) { c.OnPostCacheLoad(); c = c.next; } break; } }
public static void TriggerEvent(EventType type) { if (!Application.isPlaying) { FindAllModifiers(); } GraphModifier root = GraphModifier.root; switch (type) { case EventType.PostScan: while (root != null) { root.OnPostScan(); root = root.next; } return; case EventType.PreScan: while (root != null) { root.OnPreScan(); root = root.next; } return; case EventType.LatePostScan: while (root != null) { root.OnLatePostScan(); root = root.next; } return; case EventType.PreUpdate: while (root != null) { root.OnGraphsPreUpdate(); root = root.next; } return; case EventType.PostUpdate: while (root != null) { root.OnGraphsPostUpdate(); root = root.next; } break; case EventType.PostCacheLoad: while (root != null) { root.OnPostCacheLoad(); root = root.next; } break; } }
void IWorkItemContext.PreUpdate() { if (!preUpdateEventSent && !astar.isScanning) { preUpdateEventSent = true; GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate); } }
/** Adds this modifier to list of active modifiers. */ protected virtual void OnEnable () { OnDisable(); if (root == null) { root = this; } else { this.next = root; root.prev = this; root = this; } }
/** Removes this modifier from list of active modifiers */ protected virtual void OnDisable () { if (root == this) { root = this.next; if (root != null) root.prev = null; } else { if (prev != null) prev.next = next; if (next != null) next.prev = prev; } prev = null; next = null; }
/** Load from data from #file_cachedStartup */ public void LoadFromCache () { AstarPath.active.BlockUntilPathQueueBlocked(); if (file_cachedStartup != null) { var bytes = file_cachedStartup.bytes; DeserializeGraphs(bytes); GraphModifier.TriggerEvent(GraphModifier.EventType.PostCacheLoad); } else { Debug.LogError("Can't load from cache since the cache is empty"); } }
public void LoadFromCache() { AstarPath.active.BlockUntilPathQueueBlocked(); if (this.data_cachedStartup != null && this.data_cachedStartup.Length > 0) { this.DeserializeGraphs(this.data_cachedStartup); GraphModifier.TriggerEvent(GraphModifier.EventType.PostCacheLoad); } else { Debug.LogError("Can't load from cache since the cache is empty"); } }
void AddToLinkedList() { if (root == null) { root = this; } else { next = root; root.prev = this; root = this; } }
protected virtual void OnEnable() { this.OnDisable(); if (root == null) { root = this; } else { this.next = root; root.prev = this; root = this; } }
protected virtual void OnEnable() { this.OnDisable(); if (GraphModifier.root == null) { GraphModifier.root = this; } else { this.next = GraphModifier.root; GraphModifier.root.prev = this; GraphModifier.root = this; } }
public void LoadFromCache() { if (data_cachedStartup != null && data_cachedStartup.Length > 0) { //AstarSerializer serializer = new AstarSerializer (active); //DeserializeGraphs (serializer,data_cachedStartup); DeserializeGraphs(data_cachedStartup); GraphModifier.TriggerEvent(GraphModifier.EventType.PostCacheLoad); } else { Debug.LogError("Can't load from cache since the cache is empty"); } }
public void LoadFromCache() { PathProcessor.GraphUpdateLock graphUpdateLock = this.AssertSafe(false); if (this.file_cachedStartup != null) { byte[] bytes = this.file_cachedStartup.bytes; this.DeserializeGraphs(bytes); GraphModifier.TriggerEvent(GraphModifier.EventType.PostCacheLoad); } else { Debug.LogError("Can't load from cache since the cache is empty"); } graphUpdateLock.Release(); }
protected static List <T> GetModifiersOfType <T>() where T : GraphModifier { GraphModifier graphModifier = GraphModifier.root; List <T> list = new List <T>(); while (graphModifier != null) { T t = graphModifier as T; if (t != null) { list.Add(t); } graphModifier = graphModifier.next; } return(list); }
internal static void SerializeReferences(GraphSerializationContext ctx) { List<NodeLink2> modifiersOfType = GraphModifier.GetModifiersOfType<NodeLink2>(); ctx.writer.Write(modifiersOfType.Count); foreach (NodeLink2 nodeLink in modifiersOfType) { ctx.writer.Write(nodeLink.uniqueID); ctx.SerializeNodeReference(nodeLink.startNode); ctx.SerializeNodeReference(nodeLink.endNode); ctx.SerializeNodeReference(nodeLink.connectedNode1); ctx.SerializeNodeReference(nodeLink.connectedNode2); ctx.SerializeVector3(nodeLink.clamped1); ctx.SerializeVector3(nodeLink.clamped2); ctx.writer.Write(nodeLink.postScanCalled); } }
protected static List <T> GetModifiersOfType <T>() where T : GraphModifier { GraphModifier root = GraphModifier.root; List <T> list = new List <T>(); while (root != null) { T item = root as T; if (item != null) { list.Add(item); } root = root.next; } return(list); }
private void QueueGraphUpdatesInternal() { bool flag = false; while (this.graphUpdateQueue.Count > 0) { GraphUpdateObject graphUpdateObject = this.graphUpdateQueue.Dequeue(); if (graphUpdateObject.requiresFloodFill) { flag = true; } IEnumerator enumerator = this.astar.astarData.GetUpdateableGraphs().GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; IUpdatableGraph updatableGraph = (IUpdatableGraph)obj; NavGraph graph = updatableGraph as NavGraph; if (graphUpdateObject.nnConstraint == null || graphUpdateObject.nnConstraint.SuitableGraph(this.astar.astarData.GetGraphIndex(graph), graph)) { GraphUpdateProcessor.GUOSingle item = default(GraphUpdateProcessor.GUOSingle); item.order = GraphUpdateProcessor.GraphUpdateOrder.GraphUpdate; item.obj = graphUpdateObject; item.graph = updatableGraph; this.graphUpdateQueueRegular.Enqueue(item); } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } } if (flag) { GraphUpdateProcessor.GUOSingle item2 = default(GraphUpdateProcessor.GUOSingle); item2.order = GraphUpdateProcessor.GraphUpdateOrder.FloodFill; this.graphUpdateQueueRegular.Enqueue(item2); } GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate); this.anyGraphUpdateInProgress = true; }
/** Load from data from #file_cachedStartup */ public void LoadFromCache() { var graphLock = AssertSafe(); if (file_cachedStartup != null) { var bytes = file_cachedStartup.bytes; DeserializeGraphs(bytes); GraphModifier.TriggerEvent(GraphModifier.EventType.PostCacheLoad); } else { Debug.LogError("Can't load from cache since the cache is empty"); } graphLock.Release(); }
/** Schedules graph updates internally */ void QueueGraphUpdatesInternal() { bool anyRequiresFloodFill = false; while (graphUpdateQueue.Count > 0) { GraphUpdateObject ob = graphUpdateQueue.Dequeue(); if (ob.requiresFloodFill) { anyRequiresFloodFill = true; } 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 { order = GraphUpdateOrder.GraphUpdate, obj = ob, graph = g }; graphUpdateQueueRegular.Enqueue(guo); } } } if (anyRequiresFloodFill) { var guo = new GUOSingle { order = GraphUpdateOrder.FloodFill }; graphUpdateQueueRegular.Enqueue(guo); } GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate); anyGraphUpdateInProgress = true; }
/// <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> private bool ProcessGraphUpdates(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); } GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdate); if (OnGraphsUpdated != null) { OnGraphsUpdated(); } 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> private void QueueGraphUpdatesInternal() { 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); } } } GraphModifier.TriggerEvent(GraphModifier.EventType.PreUpdate); anyGraphUpdateInProgress = true; }
// Token: 0x060022E8 RID: 8936 RVA: 0x0019650C File Offset: 0x0019470C private bool ProcessGraphUpdates(bool force) { if (force) { this.asyncGraphUpdatesComplete.WaitOne(); } else if (!this.asyncGraphUpdatesComplete.WaitOne(0)) { return(false); } this.ProcessPostUpdates(); if (!this.ProcessRegularUpdates(force)) { return(false); } GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdate); if (this.OnGraphsUpdated != null) { this.OnGraphsUpdated(); } this.anyGraphUpdateInProgress = false; return(true); }
/** Removes this modifier from list of active modifiers */ protected virtual void OnDisable() { if (root == this) { root = this.next; if (root != null) { root.prev = null; } } else { if (prev != null) { prev.next = next; } if (next != null) { next.prev = prev; } } prev = null; next = null; }
private void RemoveFromLinkedList() { if (root == this) { root = this.next; if (root != null) { root.prev = null; } } else { if (this.prev != null) { this.prev.next = this.next; } if (this.next != null) { this.next.prev = this.prev; } } this.prev = null; this.next = null; }
protected virtual void OnDisable() { if (GraphModifier.root == this) { GraphModifier.root = this.next; if (GraphModifier.root != null) { GraphModifier.root.prev = null; } } else { if (this.prev != null) { this.prev.next = this.next; } if (this.next != null) { this.next.prev = this.prev; } } this.prev = null; this.next = null; }
/** 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; 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); }
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); }
public static void TriggerEvent(GraphModifier.EventType type) { if (!Application.isPlaying) { GraphModifier.FindAllModifiers(); } GraphModifier graphModifier = GraphModifier.root; switch (type) { case GraphModifier.EventType.PostScan: while (graphModifier != null) { graphModifier.OnPostScan(); graphModifier = graphModifier.next; } return; case GraphModifier.EventType.PreScan: while (graphModifier != null) { graphModifier.OnPreScan(); graphModifier = graphModifier.next; } return; case (GraphModifier.EventType) 3: case (GraphModifier.EventType) 5: case (GraphModifier.EventType) 6: case (GraphModifier.EventType) 7: IL_3F: if (type == GraphModifier.EventType.PostUpdate) { while (graphModifier != null) { graphModifier.OnGraphsPostUpdate(); graphModifier = graphModifier.next; } return; } if (type != GraphModifier.EventType.PostCacheLoad) { return; } while (graphModifier != null) { graphModifier.OnPostCacheLoad(); graphModifier = graphModifier.next; } return; case GraphModifier.EventType.LatePostScan: while (graphModifier != null) { graphModifier.OnLatePostScan(); graphModifier = graphModifier.next; } return; case GraphModifier.EventType.PreUpdate: while (graphModifier != null) { graphModifier.OnGraphsPreUpdate(); graphModifier = graphModifier.next; } return; } goto IL_3F; }
/// <summary>Triggers an event for all active graph modifiers</summary> public static void TriggerEvent(GraphModifier.EventType type) { if (!Application.isPlaying) { FindAllModifiers(); } try { GraphModifier c = root; switch (type) { case EventType.PreScan: while (c != null) { c.OnPreScan(); c = c.next; } break; case EventType.PostScan: while (c != null) { c.OnPostScan(); c = c.next; } break; case EventType.LatePostScan: while (c != null) { c.OnLatePostScan(); c = c.next; } break; case EventType.PreUpdate: while (c != null) { c.OnGraphsPreUpdate(); c = c.next; } break; case EventType.PostUpdate: while (c != null) { c.OnGraphsPostUpdate(); c = c.next; } break; case EventType.PostUpdateBeforeAreaRecalculation: while (c != null) { c.OnGraphsPostUpdateBeforeAreaRecalculation(); c = c.next; } break; case EventType.PostCacheLoad: while (c != null) { c.OnPostCacheLoad(); c = c.next; } break; case EventType.PostGraphLoad: while (c != null) { c.OnPostGraphLoad(); c = c.next; } break; } } catch (System.Exception e) { Debug.LogException(e); } }
public static void TriggerEvent(GraphModifier.EventType type) { if (!Application.isPlaying) { GraphModifier.FindAllModifiers(); } GraphModifier graphModifier = GraphModifier.root; switch (type) { case GraphModifier.EventType.PostScan: while (graphModifier != null) { graphModifier.OnPostScan(); graphModifier = graphModifier.next; } break; case GraphModifier.EventType.PreScan: while (graphModifier != null) { graphModifier.OnPreScan(); graphModifier = graphModifier.next; } break; default: if (type != GraphModifier.EventType.PostUpdate) { if (type == GraphModifier.EventType.PostCacheLoad) { while (graphModifier != null) { graphModifier.OnPostCacheLoad(); graphModifier = graphModifier.next; } } } else { while (graphModifier != null) { graphModifier.OnGraphsPostUpdate(); graphModifier = graphModifier.next; } } break; case GraphModifier.EventType.LatePostScan: while (graphModifier != null) { graphModifier.OnLatePostScan(); graphModifier = graphModifier.next; } break; case GraphModifier.EventType.PreUpdate: while (graphModifier != null) { graphModifier.OnGraphsPreUpdate(); graphModifier = graphModifier.next; } break; } }