void SearchOpenNode(PathNode toCheck, PathNode fromNode, DirectionType dir = DirectionType.None) { if (!mapPath.CheckWalkable(toCheck) || toCheck.status == NodeStatus.Close) { return; } if (dir == DirectionType.TopRight && (!mapPath.CheckWalkable(fromNode.neighbor.top) || !mapPath.CheckWalkable(fromNode.neighbor.right))) { return; } if (dir == DirectionType.TopLeft && (!mapPath.CheckWalkable(fromNode.neighbor.top) || !mapPath.CheckWalkable(fromNode.neighbor.left))) { return; } if (dir == DirectionType.BottomRight && (!mapPath.CheckWalkable(fromNode.neighbor.bottom) || !mapPath.CheckWalkable(fromNode.neighbor.right))) { return; } if (dir == DirectionType.BottomLeft && (!mapPath.CheckWalkable(fromNode.neighbor.bottom) || !mapPath.CheckWalkable(fromNode.neighbor.left))) { return; } if (toCheck.status == NodeStatus.Open) { var cost = ComputeG(dir); var gTemp = fromNode.g + cost; if (gTemp < toCheck.g) { toCheck.parent = fromNode; toCheck.g = gTemp; toCheck.f = gTemp + toCheck.h; } mapPath.OpenHeap.TryUpAdjust(toCheck); return; } toCheck.parent = fromNode; toCheck.g = fromNode.g + ComputeG(dir); toCheck.h = PathNode.ComputeH(toCheck, endNode); toCheck.f = toCheck.g + toCheck.h; toCheck.status = NodeStatus.Open; mapPath.OpenHeap.Enqueue(toCheck); }
private PathNode GetNext(PathNode toCheck, PathNode fromNode, DirectionType dir, JumpType jumpType) { if (!mapPath.CheckWalkable(toCheck) || toCheck.status == NodeStatus.Close) { return(null); } DirectionType jumpNodeDir; var tempValue = jumpType == JumpType.Line ? IsLineJumpNode(toCheck, dir, out jumpNodeDir) : IsTitleJumpNode(toCheck, dir, out jumpNodeDir); if (tempValue) // toCheck是跳点 { if (toCheck.status == NodeStatus.Open) // 已经在openlist里了 判断是否更新G值 更新parent { var cost = ComputeG(dir, fromNode, toCheck); var gTemp = fromNode.g + cost; if (gTemp < toCheck.g) { var oldDir = GetDirection(toCheck.parent, toCheck); toCheck.dir = (toCheck.dir ^ oldDir) | jumpNodeDir; // 去掉旧的父亲方向 保留自身方向 添加新的方向 toCheck.parent = fromNode; toCheck.g = gTemp; toCheck.f = gTemp + toCheck.h; } mapPath.OpenHeap.TryUpAdjust(toCheck); return(null); } //加入openlist toCheck.parent = fromNode; toCheck.g = fromNode.g + ComputeG(dir, toCheck, fromNode); toCheck.h = PathNode.ComputeH(toCheck, endNode); toCheck.f = toCheck.g + toCheck.h; toCheck.status = NodeStatus.Open; toCheck.dir = jumpNodeDir; mapPath.OpenHeap.Enqueue(toCheck); return(null); } return(toCheck); }