Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //public void ScanLoop (OnScanStatus statusCallback) {
- public IEnumerable<Progress> ScanLoop() {
- if (graphs == null) {
- yield break;
- }
- isScanning = true;
- euclideanEmbedding.dirty = false;
- VerifyIntegrity ();
- BlockUntilPathQueueBlocked ();
- if (!Application.isPlaying) {
- GraphModifier.FindAllModifiers ();
- RelevantGraphSurface.FindAllGraphSurfaces ();
- }
- RelevantGraphSurface.UpdateAllPositions ();
- 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);
- }
- GraphModifier.TriggerEvent (GraphModifier.EventType.PreScan);
- System.DateTime startTime = System.DateTime.UtcNow;
- // Destroy previous nodes
- for (int i=0;i<graphs.Length;i++) {
- if (graphs[i] != null) {
- graphs[i].GetNodes (delegate (GraphNode node) {
- node.Destroy ();
- return true;
- });
- }
- }
- 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) {
- node.GraphIndex = (uint)i;
- return true;
- });
- 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);
- }
- GraphModifier.TriggerEvent (GraphModifier.EventType.PostScan);
- try {
- FlushWorkItems(false, true);
- } 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);
- }
- GraphModifier.TriggerEvent (GraphModifier.EventType.LatePostScan);
- euclideanEmbedding.dirty = true;
- euclideanEmbedding.RecalculatePivots ();
- //Perform any blocking actions and unblock (probably, some tasks might take a few frames)
- PerformBlockingActions(true);
- lastScanTime = (float)(System.DateTime.UtcNow-startTime).TotalSeconds;
- System.GC.Collect ();
- AstarLog ("Scanning - Process took "+(lastScanTime*1000).ToString ("0")+" ms to complete");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement