ReturnPath() public méthode

public ReturnPath ( ) : void
Résultat void
        /**
         * Returns all paths in the return stack.
         * Paths which have been processed are put in the return stack.
         * This function will pop all items from the stack and return them to e.g the Seeker requesting them.
         *
         * \param timeSlice Do not return all paths at once if it takes a long time, instead return some and wait until the next call.
         */
        public void ReturnPaths(bool timeSlice)
        {
            // Pop all items from the stack
            Path p = pathReturnStack.PopAll();

            if (pathReturnPop == null)
            {
                pathReturnPop = p;
            }
            else
            {
                Path tail = pathReturnPop;
                while (tail.next != null)
                {
                    tail = tail.next;
                }
                tail.next = p;
            }

            // Hard coded limit on 1.0 ms
            long targetTick = timeSlice ? System.DateTime.UtcNow.Ticks + 1 * 10000 : 0;

            int counter = 0;

            // Loop through the linked list and return all paths
            while (pathReturnPop != null)
            {
                //Move to the next path
                Path prev = pathReturnPop;
                pathReturnPop = pathReturnPop.next;

                // Remove the reference to prevent possible memory leaks
                // If for example the first path computed was stored somewhere,
                // it would through the linked list contain references to all comming paths to be computed,
                // and thus the nodes those paths searched.
                // That adds up to a lot of memory not being released
                prev.next = null;

                //Return the path
                prev.ReturnPath();

                // Will increment to Returned
                // However since multithreading is annoying, it might be set to ReturnQueue for a small time until the pathfinding calculation
                // thread advanced the state as well
                prev.AdvanceState(PathState.Returned);

                prev.Release(pathsClaimedSilentlyBy);

                counter++;
                // At least 5 paths will be returned, even if timeSlice is enabled
                if (counter > 5 && timeSlice)
                {
                    counter = 0;
                    if (System.DateTime.UtcNow.Ticks >= targetTick)
                    {
                        return;
                    }
                }
            }
        }
 static int ReturnPath(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Pathfinding.Path obj = (Pathfinding.Path)ToLua.CheckObject <Pathfinding.Path>(L, 1);
         obj.ReturnPath();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemple #3
0
        public void ReturnPaths(bool timeSlice)
        {
            Path next = this.pathReturnStack.PopAll();

            if (this.pathReturnPop == null)
            {
                this.pathReturnPop = next;
            }
            else
            {
                Path next2 = this.pathReturnPop;
                while (next2.next != null)
                {
                    next2 = next2.next;
                }
                next2.next = next;
            }
            long num  = (!timeSlice) ? 0L : (DateTime.UtcNow.Ticks + 10000L);
            int  num2 = 0;

            while (this.pathReturnPop != null)
            {
                Path path = this.pathReturnPop;
                this.pathReturnPop = this.pathReturnPop.next;
                path.next          = null;
                path.ReturnPath();
                path.AdvanceState(PathState.Returned);
                path.Release(this.pathsClaimedSilentlyBy, true);
                num2++;
                if (num2 > 5 && timeSlice)
                {
                    num2 = 0;
                    if (DateTime.UtcNow.Ticks >= num)
                    {
                        return;
                    }
                }
            }
        }
        public void ReturnPaths(bool timeSlice)
        {
            Path path = this.pathReturnStack.PopAll();

            if (this.pathReturnPop == null)
            {
                this.pathReturnPop = path;
            }
            else
            {
                Path pathReturnPop = this.pathReturnPop;
                while (pathReturnPop.next != null)
                {
                    pathReturnPop = pathReturnPop.next;
                }
                pathReturnPop.next = path;
            }
            long num  = !timeSlice ? 0L : (DateTime.UtcNow.Ticks + 0x2710L);
            int  num2 = 0;

            while (this.pathReturnPop != null)
            {
                Path path3 = this.pathReturnPop;
                this.pathReturnPop = this.pathReturnPop.next;
                path3.next         = null;
                path3.ReturnPath();
                path3.AdvanceState(PathState.Returned);
                path3.Release(this.pathsClaimedSilentlyBy, true);
                num2++;
                if ((num2 > 5) && timeSlice)
                {
                    num2 = 0;
                    if (DateTime.UtcNow.Ticks >= num)
                    {
                        return;
                    }
                }
            }
        }
	/** Puts the Path in queue for calculation */
	public static void StartPath (Path p) {
		
		if (active == null) {
			Debug.LogError ("There is no AstarPath object in the scene");
			return;
		}
		
		if (!active.acceptNewPaths) {
			p.error = true;
			p.errorLog += "No new paths are accepted";
			p.ReturnPath ();
			return;
		}
		
		if (active.graphs == null || active.graphs.Length == 0) {
			Debug.LogError ("There are no graphs in the scene");
			p.error = true;
			p.errorLog = "There are no graphs in the scene";
			p.ReturnPath ();
			return;
		}
		
		/*int nextPath = lastAddedPath+1;
		if (nextPath >= active.pathQueueLength) {
			nextPath = 0;
		}
		
		if (nextPath == currentPath) {
			Debug.LogError ("Too many paths in queue");
			return;
		}
		
		pathQueue[nextPath] = p;
		
		if (!isCalculatingPaths) {
			lastAddedPath = nextPath;
			
			activeThread = new Thread (new ThreadStart (CalculatePathsThreaded));
			activeThread.Start ();
			//active.StartCoroutine (CalculatePaths ());
		} else {
			lastAddedPath = nextPath;
		}*/
		
		//@
		//p.callTime = Time.realtimeSinceStartup;
		//@Edit in - System.DateTime startTime = System.DateTime.Now;
		
		if (pathQueueEnd == null) {
			Debug.Log ("Initializing Path Queue...");
			
			pathQueueEnd = p;
			pathQueueStart = p;
			
			if (active.useMultithreading) {
				pathReturnQueueStart = p;
			}
			
		} else {
			
			pathQueueEnd.next = p;
			pathQueueEnd = p;
			
			if (pathQueueStart == null) {
				pathQueueStart = p;
			}
		}
		
			if (!isCalculatingPaths) {
					Debug.Log ("Starting Pathfinder...");
					
					active.StartCoroutine (CalculatePaths ());
			}
			
	}
	public static IEnumerator DelayedPathReturn (Path p) {
		yield return 0;
		p.ReturnPath ();
	}