Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/Assets/AstarPathfindingProject/Core/AstarPath.cs b/Assets/AstarPathfindingProject/Core/AstarPath.cs
- index d54e6cd..55acf19 100644
- --- a/Assets/AstarPathfindingProject/Core/AstarPath.cs
- +++ b/Assets/AstarPathfindingProject/Core/AstarPath.cs
- @@ -685,7 +685,6 @@ public class AstarPath : MonoBehaviour {
- /** Calls OnDrawGizmos on graph generators and also #OnDrawGizmosCallback */
- private void OnDrawGizmos () {
- - AstarProfiler.StartProfile ("OnDrawGizmos");
- if (active == null) {
- active = this;
- @@ -698,6 +697,11 @@ public class AstarPath : MonoBehaviour {
- //If updating graphs, graph info might be corrupt right now
- if (pathQueue != null && pathQueue.AllReceiversBlocked && workItems.Count > 0) return;
- + // Don't draw gizmos while scanning since graph info might not be ready yet
- + if (isScanning) return;
- +
- + AstarProfiler.StartProfile ("OnDrawGizmos");
- +
- if (showNavGraphs && !manualDebugFloorRoof) {
- debugFloor = float.PositiveInfinity;
- @@ -881,8 +885,13 @@ public class AstarPath : MonoBehaviour {
- * \see CallThreadSafeCallbacks
- */
- private void Update () {
- - PerformBlockingActions();
- -
- +
- + // Execute blocking actions such as graph updates
- + // when not scanning
- + if (!isScanning) {
- + PerformBlockingActions();
- + }
- +
- //Process paths
- if (threadEnumerator != null) {
- try {
- @@ -2004,7 +2013,7 @@ public class AstarPath : MonoBehaviour {
- };
- ScanLoop (info);
- #endif
- - ScanLoop (null);
- + foreach (var p in ScanLoop ()) {}
- }
- /** Scans all graphs. This is a IEnumerable, you can loop through it to get the progress
- @@ -2013,10 +2022,10 @@ Debug.Log ("Scanning... " + progress.description + " - " + (progress.progress*10
- } \endcode
- * \see Scan
- */
- - public void ScanLoop (OnScanStatus statusCallback) {
- + public IEnumerable<Progress> ScanLoop () {
- if (graphs == null) {
- - return;
- + yield break;
- }
- isScanning = true;
- @@ -2035,7 +2044,7 @@ Debug.Log ("Scanning... " + progress.description + " - " + (progress.progress*10
- astarData.UpdateShortcuts ();
- - if (statusCallback != null) statusCallback (new Progress (0.05F,"Pre processing graphs"));
- + yield return new Progress (0.05F,"Pre processing graphs");
- if (OnPreScan != null) {
- OnPreScan (this);
- @@ -2055,34 +2064,33 @@ Debug.Log ("Scanning... " + progress.description + " - " + (progress.progress*10
- }
- }
- + // Loop through all graphs and scan them one by one
- for (int i=0;i<graphs.Length;i++) {
- NavGraph graph = graphs[i];
- if (graph == null) {
- - if (statusCallback != null) statusCallback (new Progress (AstarMath.MapTo (0.05F,0.7F,(float)(i+0.5F)/(graphs.Length+1)),"Skipping graph "+(i+1)+" of "+graphs.Length+" because it is null"));
- + yield return new Progress (AstarMath.MapTo (0.05F,0.7F,(float)(i+0.5F)/(graphs.Length+1)),"Skipping graph "+(i+1)+" of "+graphs.Length+" because it is null");
- continue;
- }
- if (OnGraphPreScan != null) {
- - if (statusCallback != null) statusCallback (new Progress (AstarMath.MapToRange (0.1F,0.7F,(float)(i)/(graphs.Length)),"Scanning graph "+(i+1)+" of "+graphs.Length+" - Pre processing"));
- + yield return new Progress (Mathf.Lerp (0.1F,0.7F,(float)(i)/(graphs.Length)),"Scanning graph "+(i+1)+" of "+graphs.Length+" - Pre processing");
- OnGraphPreScan (graph);
- }
- - float minp = AstarMath.MapToRange (0.1F,0.7F,(float)(i)/(graphs.Length));
- - float maxp = AstarMath.MapToRange (0.1F,0.7F,(float)(i+0.95F)/(graphs.Length));
- -
- - if (statusCallback != null) statusCallback (new Progress (minp,"Scanning graph "+(i+1)+" of "+graphs.Length));
- + // Just used for progress information
- + // This graph will advance the progress bar from minp to maxp
- + float minp = Mathf.Lerp (0.1F,0.7F,(float)(i)/(graphs.Length));
- + float maxp = Mathf.Lerp (0.1F,0.7F,(float)(i+0.95F)/(graphs.Length));
- +
- + var progressDescriptionPrefix = "Scanning graph "+(i+1)+" of "+graphs.Length;
- +
- + yield return new Progress (minp,progressDescriptionPrefix);
- - OnScanStatus info = null;
- - if (statusCallback != null) {
- - info = delegate (Progress p) {
- - p.progress = AstarMath.MapToRange (minp, maxp, p.progress);
- - statusCallback (p);
- - };
- + foreach (var p in graph.ScanInternal ()) {
- + yield return new Progress(AstarMath.MapToRange (minp, maxp, p.progress), progressDescriptionPrefix + " - " + p.description);
- }
- -
- - graph.ScanInternal (info);
- // Assign the graph index to every node in the graph
- graph.GetNodes (delegate (GraphNode node) {
- @@ -2091,12 +2099,12 @@ Debug.Log ("Scanning... " + progress.description + " - " + (progress.progress*10
- });
- if (OnGraphPostScan != null) {
- - if (statusCallback != null) statusCallback (new Progress (AstarMath.MapToRange (0.1F,0.7F,(float)(i+0.95F)/(graphs.Length)),"Scanning graph "+(i+1)+" of "+graphs.Length+" - Post processing"));
- + yield return new Progress (AstarMath.MapToRange (0.1F,0.7F,(float)(i+0.95F)/(graphs.Length)),progressDescriptionPrefix + " - Post processing");
- OnGraphPostScan (graph);
- }
- }
- - if (statusCallback != null) statusCallback (new Progress (0.8F,"Post processing graphs"));
- + yield return new Progress (0.8F,"Post processing graphs");
- if (OnPostScan != null) {
- OnPostScan (this);
- @@ -2109,16 +2117,19 @@ Debug.Log ("Scanning... " + progress.description + " - " + (progress.progress*10
- } catch (System.Exception e) {
- Debug.LogException (e);
- }
- -
- - isScanning = false;
- - if (statusCallback != null) statusCallback (new Progress (0.90F,"Computing areas"));
- + yield return new Progress (0.90F,"Computing areas");
- FloodFill ();
- VerifyIntegrity ();
- -
- - if (statusCallback != null) statusCallback (new Progress (0.95F,"Late post processing"));
- +
- + yield return new Progress (0.95F,"Late post processing");
- +
- + // Signal that we have stopped scanning here
- + // Note that no yields can happen after this point
- + // since then other parts of the system can start to interfere
- + isScanning = false;
- if (OnLatePostScan != null) {
- OnLatePostScan (this);
- diff --git a/Assets/AstarPathfindingProject/Core/astarclasses.cs b/Assets/AstarPathfindingProject/Core/astarclasses.cs
- index 6d9f3df..5854189 100644
- --- a/Assets/AstarPathfindingProject/Core/astarclasses.cs
- +++ b/Assets/AstarPathfindingProject/Core/astarclasses.cs
- @@ -333,6 +333,10 @@ namespace Pathfinding {
- progress = p;
- description = d;
- }
- +
- + public override string ToString () {
- + return progress.ToString("0.0") + " " + description;
- + }
- }
- /** Graphs which can be updated during runtime */
- diff --git a/Assets/AstarPathfindingProject/Developer/TestingScripts/ScanButton.cs b/Assets/AstarPathfindingProject/Developer/TestingScripts/ScanButton.cs
- index 620cffc..1994d47 100644
- --- a/Assets/AstarPathfindingProject/Developer/TestingScripts/ScanButton.cs
- +++ b/Assets/AstarPathfindingProject/Developer/TestingScripts/ScanButton.cs
- @@ -6,7 +6,15 @@ public class ScanButton : MonoBehaviour {
- // Update is called once per frame
- void OnGUI () {
- if (GUI.Button(new Rect (5,5,100,30), "Scan")) {
- - AstarPath.active.Scan ();
- + StartCoroutine (Scan());
- + }
- + }
- +
- + IEnumerator Scan () {
- + //AstarPath.active.Scan ();
- + foreach (var p in AstarPath.active.ScanLoop()) {
- + Debug.Log (p);
- + yield return null;
- }
- }
- }
- diff --git a/Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs b/Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs
- index c8da287..ac54bb3 100644
- --- a/Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs
- +++ b/Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs
- @@ -2372,10 +2372,15 @@ public class AstarPathEditor : Editor {
- UnityEditor.EditorUtility.DisplayProgressBar ("Scanning","Scanning...",0);
- try {
- - OnScanStatus info = delegate (Progress p) {
- - UnityEditor.EditorUtility.DisplayProgressBar ("Scanning",p.description,p.progress);
- - };
- - AstarPath.active.ScanLoop (info);
- + var lastMessageTime = float.NegativeInfinity;
- + foreach (var p in AstarPath.active.ScanLoop ()) {
- + // Displaying the progress bar is pretty slow, so don't do it too often
- + if (Time.realtimeSinceStartup - lastMessageTime > 0.2f) {
- + // Display a progress bar of the scan
- + UnityEditor.EditorUtility.DisplayProgressBar ("Scanning",p.description,p.progress);
- + lastMessageTime = Time.realtimeSinceStartup;
- + }
- + }
- } catch (System.Exception e) {
- Debug.LogError ("There was an error generating the graphs:\n"+e.ToString ()+"\n\nIf you think this is a bug, please contact me on arongranberg.com (post a comment)\n");
- diff --git a/Assets/AstarPathfindingProject/Generators/Base.cs b/Assets/AstarPathfindingProject/Generators/Base.cs
- index f9400ee..c48502d 100644
- --- a/Assets/AstarPathfindingProject/Generators/Base.cs
- +++ b/Assets/AstarPathfindingProject/Generators/Base.cs
- @@ -278,8 +278,9 @@ namespace Pathfinding {
- if (AstarPath.OnGraphPreScan != null) {
- AstarPath.OnGraphPreScan (this);
- }
- -
- - ScanInternal ();
- +
- + var scan = ScanInternal ().GetEnumerator ();
- + while (scan.MoveNext()) {}
- if (AstarPath.OnGraphPostScan != null) {
- AstarPath.OnGraphPostScan (this);
- @@ -294,18 +295,13 @@ namespace Pathfinding {
- public void Scan () {
- throw new System.Exception ("This method is deprecated. Please use AstarPath.active.Scan or if you really want this.ScanInternal which has the same functionality as this method had.");
- }
- -
- - /** Internal method for scanning graphs */
- - public void ScanInternal () {
- - ScanInternal (null);
- - }
- /// <summary>
- /// Scans the graph, called from <see cref="AstarPath.ScanInternal"/>
- /// Override this function to implement custom scanning logic
- /// The statusCallback may be optionally called to show progress info in the editor
- /// </summary>
- - public abstract void ScanInternal (OnScanStatus statusCallback);
- + public abstract IEnumerable<Progress> ScanInternal ();
- /* Color to use for gizmos.
- * Returns a color to be used for the specified node with the current debug settings (editor only).
- diff --git a/Assets/AstarPathfindingProject/Generators/GridGenerator.cs b/Assets/AstarPathfindingProject/Generators/GridGenerator.cs
- index 462706f..d4325fc 100644
- --- a/Assets/AstarPathfindingProject/Generators/GridGenerator.cs
- +++ b/Assets/AstarPathfindingProject/Generators/GridGenerator.cs
- @@ -861,13 +861,13 @@ AstarPath.active.Scan();
- neighbourZOffsets[6] = 1;
- neighbourZOffsets[7] = -1;
- }
- -
- - public override void ScanInternal (OnScanStatus statusCallback) {
- +
- + public override IEnumerable<Progress> ScanInternal () {
- AstarPath.OnPostScan += new OnScanDelegate (OnPostScan);
- if (nodeSize <= 0) {
- - return;
- + yield break;
- }
- // Make sure the matrix is up to date
- @@ -875,7 +875,7 @@ AstarPath.active.Scan();
- if (width > 1024 || depth > 1024) {
- Debug.LogError ("One of the grid's sides is longer than 1024 nodes");
- - return;
- + yield break;
- }
- #if !AstarFree
- @@ -894,6 +894,8 @@ AstarPath.active.Scan();
- // Set a global reference to this graph so that nodes can find it
- GridNode.SetGridGraph (graphIndex,this);
- + yield return new Progress(0.05f, "Creating nodes");
- +
- // Create all nodes
- nodes = new GridNode[width*depth];
- for (int i=0;i<nodes.Length;i++) {
- @@ -906,12 +908,14 @@ AstarPath.active.Scan();
- collision = new GraphCollision ();
- }
- collision.Initialize (matrix,nodeSize);
- -
- +
- #if !AstarFree
- textureData.Initialize ();
- #endif
- for (int z = 0; z < depth; z ++) {
- + if (z % 5 == 0) yield return new Progress(Mathf.Lerp(0.1f,0.7f,z/(float)depth), "Scanning");
- +
- for (int x = 0; x < width; x++) {
- var node = nodes[z*width+x];
- @@ -931,6 +935,8 @@ AstarPath.active.Scan();
- for (int z = 0; z < depth; z ++) {
- + if (z % 5 == 0) yield return new Progress(Mathf.Lerp(0.7f,0.9f,z/(float)depth), "Scanning");
- +
- for (int x = 0; x < width; x++) {
- var node = nodes[z*width+x];
- @@ -940,6 +946,8 @@ AstarPath.active.Scan();
- }
- }
- + yield return new Progress(0.95f, "Calculating erosion");
- +
- // Apply erosion
- ErodeWalkableArea ();
- }
- diff --git a/Assets/AstarPathfindingProject/Generators/LayerGridGraphGenerator.cs b/Assets/AstarPathfindingProject/Generators/LayerGridGraphGenerator.cs
- index 6d0c72f..8209f86 100644
- --- a/Assets/AstarPathfindingProject/Generators/LayerGridGraphGenerator.cs
- +++ b/Assets/AstarPathfindingProject/Generators/LayerGridGraphGenerator.cs
- @@ -331,8 +331,13 @@ namespace Pathfinding {
- }
- }
- }
- -
- - public override void ScanInternal (OnScanStatus status) {
- +
- + public override IEnumerable<Progress> ScanInternal () {
- + ScanInternal ((p) => {});
- + yield break;
- + }
- +
- + public void ScanInternal (OnScanStatus status) {
- if (nodeSize <= 0) {
- return;
- diff --git a/Assets/AstarPathfindingProject/Generators/NavMeshGenerator.cs b/Assets/AstarPathfindingProject/Generators/NavMeshGenerator.cs
- index 7931932..2b20f97 100644
- --- a/Assets/AstarPathfindingProject/Generators/NavMeshGenerator.cs
- +++ b/Assets/AstarPathfindingProject/Generators/NavMeshGenerator.cs
- @@ -739,10 +739,17 @@ and have a low memory footprint because of their smaller size to describe the sa
- }
- sourceMesh = mesh;
- - ScanInternal ();
- +
- + var scan = ScanInternal ().GetEnumerator ();
- + while (scan.MoveNext()) {}
- }
- -
- - public override void ScanInternal (OnScanStatus statusCallback) {
- +
- + public override IEnumerable<Progress> ScanInternal () {
- + ScanInternal ((p) => {});
- + yield break;
- + }
- +
- + public void ScanInternal (OnScanStatus statusCallback) {
- if (sourceMesh == null) {
- return;
- diff --git a/Assets/AstarPathfindingProject/Generators/PointGenerator.cs b/Assets/AstarPathfindingProject/Generators/PointGenerator.cs
- index 265e764..b71885e 100644
- --- a/Assets/AstarPathfindingProject/Generators/PointGenerator.cs
- +++ b/Assets/AstarPathfindingProject/Generators/PointGenerator.cs
- @@ -544,7 +544,12 @@ namespace Pathfinding {
- #endif
- }
- - public override void ScanInternal (OnScanStatus statusCallback) {
- + public override IEnumerable<Progress> ScanInternal () {
- + ScanInternal ((p) => {});
- + yield break;
- + }
- +
- + public void ScanInternal (OnScanStatus statusCallback) {
- if (root == null) {
- //If there is no root object, try to find nodes with the specified tag instead
- diff --git a/Assets/AstarPathfindingProject/Generators/QuadtreeGraph.cs b/Assets/AstarPathfindingProject/Generators/QuadtreeGraph.cs
- index 456262d..a7ff4ec 100644
- --- a/Assets/AstarPathfindingProject/Generators/QuadtreeGraph.cs
- +++ b/Assets/AstarPathfindingProject/Generators/QuadtreeGraph.cs
- @@ -46,8 +46,13 @@ namespace Pathfinding {
- }
- return val ? 1 : 0;
- }
- -
- - public override void ScanInternal (OnScanStatus statusCallback)
- +
- + public override IEnumerable<Progress> ScanInternal () {
- + ScanInternal ((p) => {});
- + yield break;
- + }
- +
- + public void ScanInternal (OnScanStatus statusCallback)
- {
- Width = 1 << editorWidthLog2;
- Height = 1 << editorHeightLog2;
- diff --git a/Assets/AstarPathfindingProject/Generators/RecastGenerator.cs b/Assets/AstarPathfindingProject/Generators/RecastGenerator.cs
- index 6d9634c..d352759 100644
- --- a/Assets/AstarPathfindingProject/Generators/RecastGenerator.cs
- +++ b/Assets/AstarPathfindingProject/Generators/RecastGenerator.cs
- @@ -1195,8 +1195,13 @@ But this time, edit the setting named "Forward" to "Z forward" (not -Z as it is
- }
- #if !PhotonImplementation
- -
- - public override void ScanInternal (OnScanStatus statusCallback) {
- +
- + public override IEnumerable<Progress> ScanInternal () {
- + ScanInternal ((p) => {});
- + yield break;
- + }
- +
- + public void ScanInternal (OnScanStatus statusCallback) {
- AstarProfiler.Reset ();
- AstarProfiler.StartProfile ("Base Scan");
- //AstarProfiler.InitializeFastProfile (new string[] {"Rasterize", "Rasterize Inner 1", "Rasterize Inner 2", "Rasterize Inner 3"});
- diff --git a/Assets/AstarPathfindingProject/Generators/SimplestGraphPossible.cs b/Assets/AstarPathfindingProject/Generators/SimplestGraphPossible.cs
- index a932817..a82978c 100644
- --- a/Assets/AstarPathfindingProject/Generators/SimplestGraphPossible.cs
- +++ b/Assets/AstarPathfindingProject/Generators/SimplestGraphPossible.cs
- @@ -11,9 +11,10 @@ using Pathfinding.Serialization;
- //Inherit our new graph from a base graph type
- [JsonOptIn]
- public class SimpleGraph : NavGraph {
- -
- - public override void ScanInternal (OnScanStatus statusCallback) {
- +
- + public override IEnumerable<Progress> ScanInternal () {
- //Here we will place our code for scanning the graph
- + yield break;
- }
- public override void GetNodes (GraphNodeDelegateCancelable del) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement