123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- #define DECREASE_KEY
- using System.Collections.Generic;
- namespace Pathfinding {
-
-
-
-
-
-
-
-
-
- public class PathNode {
-
- public GraphNode node;
-
- public PathNode parent;
-
- public ushort pathID;
- #if DECREASE_KEY
-
-
-
-
-
-
- public ushort heapIndex = BinaryHeap.NotInHeap;
- #endif
-
- private uint flags;
-
- private const uint CostMask = (1U << 28) - 1U;
-
- private const int Flag1Offset = 28;
- private const uint Flag1Mask = (uint)(1 << Flag1Offset);
-
- private const int Flag2Offset = 29;
- private const uint Flag2Mask = (uint)(1 << Flag2Offset);
- public uint cost {
- get {
- return flags & CostMask;
- }
- set {
- flags = (flags & ~CostMask) | value;
- }
- }
-
-
-
-
-
-
- public bool flag1 {
- get {
- return (flags & Flag1Mask) != 0;
- }
- set {
- flags = (flags & ~Flag1Mask) | (value ? Flag1Mask : 0U);
- }
- }
-
-
-
-
-
-
- public bool flag2 {
- get {
- return (flags & Flag2Mask) != 0;
- }
- set {
- flags = (flags & ~Flag2Mask) | (value ? Flag2Mask : 0U);
- }
- }
-
- private uint g;
-
- private uint h;
-
- public uint G { get { return g; } set { g = value; } }
-
- public uint H { get { return h; } set { h = value; } }
-
- public uint F { get { return g+h; } }
- public void UpdateG (Path path) {
- #if ASTAR_NO_TRAVERSAL_COST
- g = parent.g + cost;
- #else
- g = parent.g + cost + path.GetTraversalCost(node);
- #endif
- }
- }
-
- public class PathHandler {
-
-
-
-
- private ushort pathID;
- public readonly int threadID;
- public readonly int totalThreadCount;
-
-
-
-
- public readonly BinaryHeap heap = new BinaryHeap(128);
-
- public ushort PathID { get { return pathID; } }
-
- public PathNode[] nodes = new PathNode[0];
-
-
-
-
- public readonly System.Text.StringBuilder DebugStringBuilder = new System.Text.StringBuilder();
- public PathHandler (int threadID, int totalThreadCount) {
- this.threadID = threadID;
- this.totalThreadCount = totalThreadCount;
- }
- public void InitializeForPath (Path p) {
- pathID = p.pathID;
- heap.Clear();
- }
-
- public void DestroyNode (GraphNode node) {
- PathNode pn = GetPathNode(node);
-
- pn.node = null;
- pn.parent = null;
-
-
- pn.pathID = 0;
- pn.G = 0;
- pn.H = 0;
- }
-
- public void InitializeNode (GraphNode node) {
-
- int ind = node.NodeIndex;
- if (ind >= nodes.Length) {
-
- PathNode[] newNodes = new PathNode[System.Math.Max(128, nodes.Length*2)];
- nodes.CopyTo(newNodes, 0);
-
-
-
-
-
-
- for (int i = nodes.Length; i < newNodes.Length; i++) newNodes[i] = new PathNode();
- nodes = newNodes;
- }
- nodes[ind].node = node;
- }
- public PathNode GetPathNode (int nodeIndex) {
- return nodes[nodeIndex];
- }
-
-
-
-
-
- public PathNode GetPathNode (GraphNode node) {
- return nodes[node.NodeIndex];
- }
-
-
-
-
- public void ClearPathIDs () {
- for (int i = 0; i < nodes.Length; i++) {
- if (nodes[i] != null) nodes[i].pathID = 0;
- }
- }
- }
- }
|