A* Pathfinding Project  4.1.12
The A* Pathfinding Project for Unity 3D
PathProcessor Class Reference

Classes

struct  GraphUpdateLock
 Prevents pathfinding from running while held. More...
 

Public Member Functions

void AbortThreads ()
 Calls 'Abort' on each of the threads. More...
 
void DestroyNode (GraphNode node)
 Destroyes the given node. More...
 
int GetNewNodeIndex ()
 Returns a new global node index. More...
 
void InitializeNode (GraphNode node)
 Initializes temporary path data for a node. More...
 
void JoinThreads ()
 Calls 'Join' on each of the threads to block until they have completed. More...
 
GraphUpdateLock PausePathfinding (bool block)
 Prevents pathfinding threads from starting to calculate any new paths. More...
 
void TickNonMultithreaded ()
 

Package Functions

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

Package Attributes

readonly ThreadControlQueue queue
 

Properties

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

Events

System.Action< PathOnPathPostSearch
 
System.Action< PathOnPathPreSearch
 
System.Action OnQueueUnblocked
 

Private Member Functions

IEnumerator CalculatePaths (PathHandler pathHandler)
 Main pathfinding method. More...
 
void CalculatePathsThreaded (PathHandler pathHandler)
 Main pathfinding method (multithreaded). More...
 
int Lock (bool block)
 
void Unlock (int id)
 

Private Attributes

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

Constructor & Destructor Documentation

◆ PathProcessor()

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

Member Function Documentation

◆ AbortThreads()

void AbortThreads ( )

Calls 'Abort' on each of the threads.

◆ CalculatePaths()

IEnumerator CalculatePaths ( PathHandler  pathHandler)
private

Main pathfinding method.

This method will calculate the paths in the pathfinding queue.

See also
CalculatePathsThreaded
StartPath

◆ CalculatePathsThreaded()

void CalculatePathsThreaded ( PathHandler  pathHandler)
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

◆ DestroyNode()

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.

◆ GetNewNodeIndex()

int GetNewNodeIndex ( )

Returns a new global node index.

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

◆ InitializeNode()

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.

◆ JoinThreads()

void JoinThreads ( )

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

◆ Lock()

int Lock ( bool  block)
private

◆ PausePathfinding()

GraphUpdateLock PausePathfinding ( bool  block)

Prevents pathfinding threads from starting to calculate any new paths.

Parameters
blockIf true, this call will block until all pathfinding threads are paused. otherwise the threads will be paused as soon as they are done with what they are currently doing.
Returns
A lock object. You need to call Unlock on that object to allow pathfinding to resume.
Note
In most cases this should not be called from user code.

◆ TickNonMultithreaded()

void TickNonMultithreaded ( )

◆ Unlock()

void Unlock ( int  id)
private

Member Data Documentation

◆ astar

readonly AstarPath astar
private

◆ locks

readonly List<int> locks = new List<int>()
private

◆ nextLockID

int nextLockID = 0
private

◆ nextNodeIndex

int nextNodeIndex = 1
private

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

See also
nodeIndexPool

◆ 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.

◆ pathHandlers

readonly PathHandler [] pathHandlers
private

◆ queue

readonly ThreadControlQueue queue
package

◆ returnQueue

readonly PathReturnQueue returnQueue
private

◆ threadCoroutine

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

◆ threads

readonly Thread [] threads
private

References to each of the pathfinding threads.

Property Documentation

◆ IsUsingMultithreading

bool IsUsingMultithreading
get

Returns whether or not multithreading is used.

◆ NumThreads

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

◆ OnPathPostSearch

System.Action<Path> OnPathPostSearch

◆ OnPathPreSearch

System.Action<Path> OnPathPreSearch

◆ OnQueueUnblocked

System.Action OnQueueUnblocked

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