GetState() public method

public GetState ( ) : PathState
return PathState
 static int GetState(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Pathfinding.Path obj = (Pathfinding.Path)ToLua.CheckObject <Pathfinding.Path>(L, 1);
         PathState        o   = obj.GetState();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 2
0
	/** Puts the Path in queue for calculation.
	  * The callback specified when constructing the path will be called when the path has been calculated.
	  * Usually you should use the Seeker component instead of calling this function directly.
	  * 
	  * \param p The path that should be put in queue for calculation
	  * \param pushToFront If true, the path will be pushed to the front of the queue, bypassing all waiting paths and making it the next path to be calculated.
	  * This can be useful if you have a path which you want to prioritize over all others. Be careful to not overuse it though.
	  * If too many paths are put in the front of the queue often, this can lead to normal paths having to wait a very long time before being calculated.
	  */
	public static void StartPath (Path p, bool pushToFront = false) {
		
		if (active == null) {
			Debug.LogError ("There is no AstarPath object in the scene");
			return;
		}
		
		if (p.GetState() != PathState.Created) {
			throw new System.Exception ("The path has an invalid state. Expected " + PathState.Created + " found " + p.GetState() + "\n" +
				"Make sure you are not requesting the same path twice");
		}
		
		if (active.pathQueue.IsTerminating) {
			p.Error ();
			p.LogError ("No new paths are accepted");
			return;
		}
		
		if (active.graphs == null || active.graphs.Length == 0) {
			Debug.LogError ("There are no graphs in the scene");
			p.Error ();
			p.LogError ("There are no graphs in the scene");
			Debug.LogError (p.errorLog);
			return;
		}
		
		p.Claim (active);
		
		
		//Will increment to PathQueue
		p.AdvanceState (PathState.PathQueue);
		if (pushToFront) {
			active.pathQueue.PushFront (p);
		} else {
			active.pathQueue.Push (p);
		}
	}
Exemplo n.º 3
0
	/** Wait for the specified path to be calculated.
	 * Normally it takes a few frames for a path to get calculated and returned.
	 * This function will ensure that the path will be calculated when this function returns
	 * and that the callback for that path has been called.
	 * 
	 * \note Do not confuse this with Pathfinding.Path.WaitForPath. This one will halt all operations until the path has been calculated
	 * while Pathfinding.Path.WaitForPath will wait using yield until it has been calculated.
	 * 
	 * If requesting a lot of paths in one go and waiting for the last one to complete,
	 * it will calculate most of the paths in the queue (only most if using multithreading, all if not using multithreading).
	 * 
	 * Use this function only if you really need to.
	 * There is a point to spreading path calculations out over several frames.
	 * It smoothes out the framerate and makes sure requesting a large
	 * number of paths at the same time does not cause lag.
	 * 
	 * \note Graph updates and other callbacks might get called during the execution of this function.
	 * 
	 * When the pathfinder is shutting down. I.e in OnDestroy, this function will not do anything.
	 * 
	 * \param p The path to wait for. The path must be started, otherwise an exception will be thrown.
	 * 
	 * \throws Exception if pathfinding is not initialized properly for this scene (most likely no AstarPath object exists)
	 * or if the path has not been started yet.
	 * Also throws an exception if critical errors ocurr such as when the pathfinding threads have crashed (which should not happen in normal cases).
	 * This prevents an infinite loop while waiting for the path.
	 * 
	 * \see Pathfinding.Path.WaitForPath
	 */
	public static void WaitForPath (Path p) {
		
		if (active == null)
			throw new System.Exception ("Pathfinding is not correctly initialized in this scene (yet?). " +
				"AstarPath.active is null.\nDo not call this function in Awake");
		
		if (p == null) throw new System.ArgumentNullException ("Path must not be null");
		
		if (active.pathQueue.IsTerminating) return;
		
		if (p.GetState () == PathState.Created){
			throw new System.Exception ("The specified path has not been started yet.");
		}
		
		waitForPathDepth++;
		
		if (waitForPathDepth == 5) {
			Debug.LogError ("You are calling the WaitForPath function recursively (maybe from a path callback). Please don't do this.");
		}
		
		if (p.GetState() < PathState.ReturnQueue) {
			if (IsUsingMultithreading) {
				
				while (p.GetState() < PathState.ReturnQueue) {
					if (active.pathQueue.IsTerminating) {
						waitForPathDepth--;
						throw new System.Exception ("Pathfinding Threads seems to have crashed.");
					}
					
					//Wait for threads to calculate paths
					Thread.Sleep(1);
					active.PerformBlockingActions();
				}
			} else {
				while (p.GetState() < PathState.ReturnQueue) {
					if (active.pathQueue.IsEmpty && p.GetState () != PathState.Processing) {
						waitForPathDepth--;
						throw new System.Exception ("Critical error. Path Queue is empty but the path state is '" + p.GetState() + "'");
					}
					
					//Calculate some paths
					threadEnumerator.MoveNext ();
					active.PerformBlockingActions();
				}
			}
		}
		
		active.ReturnPaths (false);
		
		waitForPathDepth--;
	}
Exemplo n.º 4
0
	/** Puts the Path in queue for calculation.
	  * The callback specified when constructing the path will be called when the path has been calculated.
	  * Usually you should use the Seeker component instead of calling this function directly.
	  */
	public static void StartPath (Path p) {
		
		if (active == null) {
			Debug.LogError ("There is no AstarPath object in the scene");
			return;
		}
		
		if (p.GetState() != PathState.Created) {
			throw new System.Exception ("The path has an invalid state. Expected " + PathState.Created + " found " + p.GetState() + "\n" +
				"Make sure you are not requesting the same path twice");
		}
		
		if (!active.acceptNewPaths) {
			p.Error ();
			p.LogError ("No new paths are accepted");
			//Debug.LogError (p.errorLog);
			//p.ReturnPath ();
			return;
		}
		
		if (active.graphs == null || active.graphs.Length == 0) {
			Debug.LogError ("There are no graphs in the scene");
			p.Error ();
			p.LogError ("There are no graphs in the scene");
			Debug.LogError (p.errorLog);
			//p.ReturnPath ();
			return;
		}
		
		/*MultithreadPath p2 = p as MultithreadPath;
		if (p2 == null) {
			Debug.LogError ("Path Not Set Up For Multithreading");
			return;
		}*/
		
		p.Claim (active);
		
		lock (pathQueue) {
			//Will increment to PathQueue
			p.AdvanceState (PathState.PathQueue);
			pathQueue.Enqueue (p);
			if (doSetQueueState)
				pathQueueFlag.Set ();
		}
	}