A* Pathfinding Project  3.8.5
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
PathProcessor Class Reference

Public Member Functions

 PathProcessor (AstarPath astar, PathReturnQueue returnQueue, int processors, bool multithreaded)
 
void AbortThreads ()
 Calls 'Abort' on each of the threads.
 
void BlockUntilPathQueueBlocked ()
 Blocks until all pathfinding threads are paused and blocked.
 
void DestroyNode (GraphNode node)
 Destroyes the given node.
 
int GetNewNodeIndex ()
 Returns a new global node index.
 
void InitializeNode (GraphNode node)
 Initializes temporary path data for a node.
 
void JoinThreads ()
 Calls 'Join' on each of the threads to block until they have completed.
 
void TickNonMultithreaded ()
 

Public Attributes

readonly ThreadControlQueue queue
 

Properties

bool IsUsingMultithreading [get]
 Returns whether or not multithreading is used.
 
int NumThreads [get]
 Number of parallel pathfinders.
 

Events

System.Action< PathOnPathPostSearch
 
System.Action< PathOnPathPreSearch
 

Private Member Functions

IEnumerator CalculatePaths (PathThreadInfo threadInfo)
 Main pathfinding method.
 
void CalculatePathsThreaded (PathThreadInfo threadInfo)
 Main pathfinding method (multithreaded).
 

Private Attributes

readonly AstarPath astar
 
int nextNodeIndex = 1
 Holds the next node index which has not been used by any previous node.
 
readonly Stack< int > nodeIndexPool = new Stack<int>()
 Holds indices for nodes that have been destroyed.
 
readonly PathReturnQueue returnQueue
 
IEnumerator threadCoroutine
 When no multithreading is used, the IEnumerator is stored here.
 
readonly PathThreadInfo[] threadInfos
 
readonly Thread[] threads
 References to each of the pathfinding threads.
 

Constructor & Destructor Documentation

PathProcessor ( AstarPath  astar,
PathReturnQueue  returnQueue,
int  processors,
bool  multithreaded 
)

Member Function Documentation

void AbortThreads ( )

Calls 'Abort' on each of the threads.

void BlockUntilPathQueueBlocked ( )

Blocks until all pathfinding threads are paused and blocked.

A call to pathProcessor.queue.Unblock is required to resume pathfinding calculations. However in most cases you should never unblock the path queue, instead let the pathfinding scripts do that in the next update. Unblocking the queue when other tasks (e.g graph updates) are running can interfere and cause invalid graphs.

Note
In most cases this should not be called from user code.
IEnumerator CalculatePaths ( PathThreadInfo  threadInfo)
private

Main pathfinding method.

This method will calculate the paths in the pathfinding queue.

See Also
CalculatePathsThreaded
StartPath
void CalculatePathsThreaded ( PathThreadInfo  threadInfo)
private

Main pathfinding method (multithreaded).

This method will calculate the paths in the pathfinding queue when multithreading is enabled.

See Also
CalculatePaths
StartPath
A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
void DestroyNode ( GraphNode  node)

Destroyes the given node.

This is to be called after the node has been disconnected from the graph so that it cannot be reached from any other nodes. It should only be called during graph updates, that is when the pathfinding threads are either not running or paused.

Warning
This method should not be called by user code. It is used internally by the system.
int GetNewNodeIndex ( )

Returns a new global node index.

Warning
This method should not be called directly. It is used by the GraphNode constructor.
void InitializeNode ( GraphNode  node)

Initializes temporary path data for a node.

Warning
This method should not be called directly. It is used by the GraphNode constructor.
void JoinThreads ( )

Calls 'Join' on each of the threads to block until they have completed.

void TickNonMultithreaded ( )

Member Data Documentation

readonly AstarPath astar
private
int nextNodeIndex = 1
private

Holds the next node index which has not been used by any previous node.

See Also
nodeIndexPool
readonly Stack<int> nodeIndexPool = new Stack<int>()
private

Holds indices for nodes that have been destroyed.

To avoid trashing a lot of memory structures when nodes are frequently deleted and created, node indices are reused.

readonly ThreadControlQueue queue
readonly PathReturnQueue returnQueue
private
IEnumerator threadCoroutine
private

When no multithreading is used, the IEnumerator is stored here.

When no multithreading is used, a coroutine is used instead. It is not directly called with StartCoroutine but a separate function has just a while loop which increments the main IEnumerator. This is done so other functions can step the thread forward at any time, without having to wait for Unity to update it.

See Also
CalculatePaths
CalculatePathsHandler
readonly PathThreadInfo [] threadInfos
private
readonly Thread [] threads
private

References to each of the pathfinding threads.

Property Documentation

bool IsUsingMultithreading
get

Returns whether or not multithreading is used.

int NumThreads
get

Number of parallel pathfinders.

Returns the number of concurrent processes which can calculate paths at once. When using multithreading, this will be the number of threads, if not using multithreading it is always 1 (since only 1 coroutine is used).

See Also
threadInfos
IsUsingMultithreading

Event Documentation

System.Action<Path> OnPathPostSearch
System.Action<Path> OnPathPreSearch

The documentation for this class was generated from the following file: