A* Pathfinding Project
3.1.4
The A* Pathfinding Project for Unity 3D
|
Holds one node in a navgraph. More...
Public Member Functions | |
void | AddConnection (Node node, int cost) |
Add a connection to the node with the specified cost. | |
void | BaseFloodFill (Stack< Node > stack, int area) |
Adds all connecting nodes to the stack and sets the area variable to area. | |
int[] | BaseInitialOpen (BinaryHeapM open, Int3 targetPosition, Int3 position, Path path, bool doOpen) |
void | BaseOpen (NodeRunData nodeRunData, NodeRun nodeR, Int3 targetPosition, Path path) |
Opens the nodes connected to this node. | |
void | BaseResetCosts (int[] costs) |
Resets the costs modified by the InitialOpen function when 'doOpen' was false (for the end node). | |
virtual bool | ContainsConnection (Node node) |
Returns true if this node has a connection to the node. | |
virtual void | FloodFill (Stack< Node > stack, int area) |
Adds all connecting nodes to the stack and sets the area variable to area. | |
virtual void | GetConnections (NodeDelegate callback) |
Get all connections for a node. | |
void | GetConnectionsBase (NodeDelegate callback) |
Get all connections for a node. | |
int | GetNodeIndex () |
Returns the global node index. | |
virtual int[] | InitialOpen (BinaryHeapM open, Int3 targetPosition, Int3 position, Path path, bool doOpen) |
virtual void | Open (NodeRunData nodeRunData, NodeRun nodeR, Int3 targetPosition, Path path) |
void | RecalculateConnectionCosts (bool neighbours) |
Recalculate costs for each connection. | |
virtual bool | RemoveConnection (Node node) |
Removes the connection to the node if it exists. | |
virtual void | ResetCosts (int[] costs) |
Resets the costs modified by the InitialOpen function when 'doOpen' was false (for the end node). | |
void | SetNodeIndex (int index) |
virtual void | UpdateAllG (NodeRun nodeR, NodeRunData nodeRunData) |
virtual void | UpdateConnections () |
Remove connections to unwalkable nodes. | |
void | UpdateG (NodeRun nodeR, NodeRunData nodeRunData) |
void | UpdateH (Int3 targetPosition, Heuristic heuristic, float scale, NodeRun nodeR) |
Calculates and updates the H score. | |
virtual void | UpdateNeighbourConnections () |
Calls UpdateConnections on all neighbours. | |
Static Public Member Functions | |
static int | Abs (int x) |
Implementation of the Absolute function. | |
Public Attributes | |
int[] | connectionCosts |
Cost for the connections to other nodes. | |
Node[] | connections |
List of all connections from this node. | |
int | flags |
Bit packed values for different fields. | |
Int3 | position |
Position in world space of the node. | |
Protected Member Functions | |
void | BaseUpdateAllG (NodeRun nodeR, NodeRunData nodeRunData) |
Properties | |
int | area [get, set] |
Area ID of the node. | |
bool | Bit15 [get, set] |
Returns bit 15 from flags. | |
bool | Bit16 [get, set] |
Returns bit 16 from flags. | |
bool | Bit8 [get, set] |
Returns bit 8 from flags. | |
int | graphIndex [get, set] |
The index of the graph this node is in. | |
uint | penalty [get, set] |
int | tags [get, set] |
Tags for walkability. | |
bool | walkable [get, set] |
Is the node walkable. | |
Private Attributes | |
uint | _penalty |
Penlty cost for walking on this node. | |
const int | AreaBitNumber = 24 |
1 << WalkableBitNumber | |
const int | AreaBitsSize = 0xFF |
Size of the area bits. | |
const int | GraphIndexBitNumber = 18 |
const int | GraphIndexBitsSize = 0x1F |
int | nodeIndex |
Global node index. | |
const int | NotAreaBits = ~(AreaBitsSize << AreaBitNumber) |
The bits in flags which are NOT area bits. | |
const int | NotGraphIndexBits = ~(GraphIndexBitsSize << GraphIndexBitNumber) |
Bits which are NOT graphIndex bits. | |
const int | WalkableBit = 1 << WalkableBitNumber |
const int | WalkableBitNumber = 23 |
Bit number for the walkable bool. | |
Holds one node in a navgraph.
A node is a simple object in the shape of a square (GridNode), triangle (NavMeshNode), or point (the rest).
A node has a position and a list of neighbour nodes which are the nodes this node can form a straight path to
Size: (4*3)+4+4+4+4+4+4+8+8*n = 44+8*n bytes where n is the number of connections (estimate)
void AddConnection | ( | Node | node, |
int | cost | ||
) |
Add a connection to the node with the specified cost.
If a connection to the node already exists, this function will only change the cost of it.
void BaseFloodFill | ( | Stack< Node > | stack, |
int | area | ||
) |
Adds all connecting nodes to the stack and sets the area variable to area.
This is a base function and can be called by node classes overriding the FloodFill function to add the connections in the connections array
void BaseOpen | ( | NodeRunData | nodeRunData, |
NodeRun | nodeR, | ||
Int3 | targetPosition, | ||
Path | path | ||
) |
Opens the nodes connected to this node.
This is a base call and can be called by node classes overriding the Open function to open all connections in the connections array.
void BaseResetCosts | ( | int[] | costs | ) |
Resets the costs modified by the InitialOpen function when 'doOpen' was false (for the end node).
This is called at the end of a pathfinding search
|
virtual |
Returns true if this node has a connection to the node.
|
virtual |
Get all connections for a node.
This function will call the callback with every node this node is connected to. In contrast to the connections array this function also includes custom connections which for example grid graphs use.
Reimplemented in GridNode.
void GetConnectionsBase | ( | NodeDelegate | callback | ) |
Get all connections for a node.
This function will call the callback with every node this node is connected to. This is a base function and will simply loop through the connections array.
int GetNodeIndex | ( | ) |
Returns the global node index.
Used for internal pathfinding purposes
void RecalculateConnectionCosts | ( | bool | neighbours | ) |
Recalculate costs for each connection.
All standard connections, which means those stored in the connections array will have their costs recalculated. Non-standard connections such as most grid graph connections will not be recalculated (mostly because they are constant and cannot be recalculated).
neighbours | If true, recalculates connection costs on this node's neighbours as well. This makes sure costs are calculated correctly (the same) in both directions. |
|
virtual |
Removes the connection to the node if it exists.
Returns true if a connection was removed, returns false if no connection to the node was found
Reimplemented in GridNode.
|
virtual |
Resets the costs modified by the InitialOpen function when 'doOpen' was false (for the end node).
This is called at the end of a pathfinding search
|
virtual |
Remove connections to unwalkable nodes.
This function loops through all connections and removes the ones which lead to unwalkable nodes.
This can speed up performance if a lot of nodes have connections to unwalkable nodes, they usually don't though
Reimplemented in GridNode.
Calculates and updates the H score.
Calculates the H score with respect to the target position and chosen heuristic.
targetPosition | The position to calculate the distance to. |
heuristic | Heuristic to use. The heuristic can also be hard coded using pre processor directives (check sourcecode) |
scale | Scale of the heuristic |
nodeR | NodeRun object associated with this node. |
|
virtual |
Calls UpdateConnections on all neighbours.
Neighbours are all nodes in the connections array. Good to use if the node has been set to unwalkable-
|
private |
Penlty cost for walking on this node.
This can be used to make it harder/slower to walk over certain areas.
|
private |
1 << WalkableBitNumber
Bit number at which area starts
int [] connectionCosts |
Cost for the connections to other nodes.
The cost of moving from this node to connections[x] is stored in connectionCosts[x].
Node [] connections |
List of all connections from this node.
This node's neighbour nodes are stored in this array.
int flags |
Bit packed values for different fields.
It's amazing how much information you can store in an integer! Below you can see a table showing how the different bits are used:
Area | Walkability | Graph Index | Graph Specific Values | Tags (tag) | Bit 8 - Path specific value | Graph specific values | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Walkable before erosion (Grid Graph and derived only) | Used as a tag by some path types | (GridGraph only) Connections | ||||||||||||||||||||||||||||||
Bit | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Int3 position |
Position in world space of the node.
The position is stored as integer coordinates to avoid precision loss when the node is far away from the world origin. The default precision is 0.001 (one millimeter).
|
getset |
Area ID of the node.
Nodes which there are no valid path between have different area values.
|
getset |
|
getset |
Returns bit 16 from flags.
Graphs can use this value for any kind of data storage. Grid Graphs use it as a temporary variable when updating graphs using erosion.
|
getset |
Returns bit 8 from flags.
Used to flag special nodes with special pathfinders
|
getset |
The index of the graph this node is in.
|
getset |
Tags for walkability.
Determines which tag is set for this node. 0...31.