Example usage for com.badlogic.gdx.utils BinaryHeap clear

List of usage examples for com.badlogic.gdx.utils BinaryHeap clear

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils BinaryHeap clear.

Prototype

public void clear() 

Source Link

Usage

From source file:com.bladecoder.engine.pathfinder.AStarPathFinder.java

License:Apache License

@Override
public boolean findPath(Object mover, N startNode, N targetNode, NavPath<N> out) {
    this.mover = mover;
    distance = 0;/*from  ww w.j  a v  a  2s . com*/

    if (isBlocked(targetNode, targetNode))
        return false;

    checkedID++;
    if (checkedID < 0)
        checkedID = 1;

    BinaryHeap<AStarAlgoData> openList = this.openList;
    AStarHeuristicCalculator<N> heuristicCalculator = this.heuristicCalculator;
    int maxSearchDistance = this.maxSearchDistance;

    openList.clear();
    addToOpenList(getAlgoData(startNode));
    getAlgoData(targetNode);

    AStarAlgoData currentData = null;
    int maxDepth = 0;
    while (maxDepth < maxSearchDistance && openList.size != 0) {
        AStarAlgoData lastData = currentData;
        currentData = openList.pop();
        currentData.open = false;
        distance = currentData.depth;
        currentData.closed = true;

        if (currentData.node == targetNode && lastData != null && !isBlocked(lastData.node, targetNode))
            break;

        float currentCost = currentData.cost;
        for (N neighborNode : currentData.node.neighbors) {
            AStarAlgoData neighborData = getAlgoData(neighborNode);
            if (!isBlocked(currentData.node, neighborNode)) {
                sourceNodeInContext = startNode;
                float nextStepCost = currentCost + graph.getCost(this, neighborNode);
                if (nextStepCost < neighborData.cost) {
                    if (neighborData.open) {
                        openList.remove(neighborData);
                        neighborData.open = false;
                    }
                    neighborData.closed = false;
                }
                if (!neighborData.open && !neighborData.closed) {
                    neighborData.cost = nextStepCost;
                    neighborData.heuristic = heuristicCalculator.getCost(this, mover, neighborNode, targetNode);
                    neighborData.depth = currentData.depth + 1;
                    neighborNode.parent = currentData.node;
                    maxDepth = Math.max(maxDepth, neighborData.depth);
                    addToOpenList(neighborData);
                }
            }
        }
    }

    boolean pathFound = targetNode.parent != null;
    if (pathFound)
        out.fill(startNode, targetNode);
    return pathFound;
}

From source file:org.bladecoder.bladeengine.pathfinder.AStarPathFinder.java

License:Apache License

@Override
public boolean findPath(Object mover, NavNode startNode, NavNode targetNode, NavPath out) {
    this.mover = mover;
    distance = 0;/*w w  w .j a va2 s  . c  om*/

    if (isBlocked(targetNode, targetNode))
        return false;

    checkedID++;
    if (checkedID < 0)
        checkedID = 1;

    BinaryHeap<AStarAlgoData> openList = this.openList;
    AStarHeuristicCalculator heuristicCalculator = this.heuristicCalculator;
    int maxSearchDistance = this.maxSearchDistance;

    openList.clear();
    addToOpenList(getAlgoData(startNode));
    getAlgoData(targetNode);

    AStarAlgoData currentData = null;
    int maxDepth = 0;
    while (maxDepth < maxSearchDistance && openList.size != 0) {
        AStarAlgoData lastData = currentData;
        currentData = openList.pop();
        currentData.open = false;
        distance = currentData.depth;
        currentData.closed = true;

        if (currentData.node == targetNode && lastData != null && !isBlocked(lastData.node, targetNode))
            break;

        float currentCost = currentData.cost;
        for (NavNode neighborNode : currentData.node.neighbors) {
            AStarAlgoData neighborData = getAlgoData(neighborNode);
            if (!isBlocked(currentData.node, neighborNode)) {
                sourceNodeInContext = startNode;
                float nextStepCost = currentCost + graph.getCost(this, neighborNode);
                if (nextStepCost < neighborData.cost) {
                    if (neighborData.open) {
                        openList.remove(neighborData);
                        neighborData.open = false;
                    }
                    neighborData.closed = false;
                }
                if (!neighborData.open && !neighborData.closed) {
                    neighborData.cost = nextStepCost;
                    neighborData.heuristic = heuristicCalculator.getCost(this, mover, neighborNode, targetNode);
                    neighborData.depth = currentData.depth + 1;
                    neighborNode.parent = currentData.node;
                    maxDepth = Math.max(maxDepth, neighborData.depth);
                    addToOpenList(neighborData);
                }
            }
        }
    }

    boolean pathFound = targetNode.parent != null;
    if (pathFound)
        out.fill(startNode, targetNode);
    return pathFound;
}