Java 类com.badlogic.gdx.ai.pfa.PathFinderRequest 实例源码

项目:Mindustry    文件:Pathfind.java   
/**Reset and clear the paths.*/
public void resetPaths(){
    for(SpawnPoint point : Vars.control.getSpawnPoints()){
        point.finder = new OptimizedPathFinder<>(graph);

        point.path.clear();

        point.pathTiles = null;

        point.request = new PathFinderRequest<>(point.start, Vars.control.getCore(), Vars.control.getDifficulty().heuristic, point.path);
        point.request.statusChanged = true; //IMPORTANT!
    }
}
项目:gdx-ai    文件:InterruptibleHierarchicalTiledAStarTest.java   
@Override
public boolean handleMessage (Telegram telegram) {
    switch (telegram.message) {
    case PF_RESPONSE: // PathFinderQueue will call us directly, no need to register for this message
        if (PathFinderRequestControl.DEBUG) {
            @SuppressWarnings("unchecked")
            PathFinderQueue<HierarchicalTiledNode> pfQueue = (PathFinderQueue<HierarchicalTiledNode>)telegram.sender;
            System.out.println("pfQueue.size = " + pfQueue.size());
        }
        MyPathFinderRequest pfr = (MyPathFinderRequest)telegram.extraInfo;
        TiledSmoothableGraphPath<HierarchicalTiledNode> path = paths[pfr.pathIndex];
        int n = path.getCount();
        if (n > 0 && pfr.pathFound && pfr.endNode != path.get(n - 1)) {
            pfr.startNode = path.get(n - 1);
            if(pfr.pathIndex + 1 < paths.length) {
                pfr.pathIndex++;
            }
            pfr.resultPath = paths[pfr.pathIndex];
            pfr.changeStatus(PathFinderRequest.SEARCH_NEW);
            numPaths = pfr.pathIndex;
        } else {
            requestPool.free(pfr);
            numPaths = pfr.pathIndex + 1;
        }
        break;
    }
    return true;
}
项目:Inspiration    文件:IndexedAStarPathFinder.java   
@Override
public boolean search (PathFinderRequest<N> request, long timeToRun) {

    long lastTime = TimeUtils.nanoTime();

    // We have to initialize the search if the status has just changed
    if (request.statusChanged) {
        initSearch(request.startNode, request.endNode, request.heuristic);
        request.statusChanged = false;
    }

    // Iterate through processing each node
    do {

        // Check the available time
        long currentTime = TimeUtils.nanoTime();
        timeToRun -= currentTime - lastTime;
        if (timeToRun <= PathFinderQueue.TIME_TOLERANCE) return false;

        // Retrieve the node with smallest estimated total cost from the open list
        current = openList.pop();
        current.category = CLOSED;

        // Terminate if we reached the goal node; we've found a path.
        if (current.node == request.endNode) {
            request.pathFound = true;

            generateNodePath(request.startNode, request.resultPath);

            return true;
        }

        // Visit current node's children
        visitChildren(request.endNode, request.heuristic);

        // Store the current time
        lastTime = currentTime;

    } while (openList.size > 0);

    // The open list is empty and we've not found a path.
    request.pathFound = false;
    return true;
}
项目:ns2-scc-profiler    文件:RouteCalculationSystem.java   
@Override
public void run() {

    if (!finished) {

        if (request == null) {

            if (!a.isActive() || !b.isActive())
            {
                finished=true;
                return;
            }

            // offset to center on the image, and convert to pathing space.
            // @todo cleanup the space difference.
            final Pos posA = mPos.get(a);
            final Pos posB = mPos.get(b);

            Bounds boundsA = mBounds.get(a);
            Bounds boundsB = mBounds.get(b);

            int aX = (int) (posA.x + boundsA.cx()) / LayerManager.CELL_SIZE;
            int aY = (int) (posA.y + boundsA.cy()) / LayerManager.CELL_SIZE;
            final GridNode cellA = graph.get(aX, aY);

            int bX = (int) (posB.x + boundsB.cx()) / LayerManager.CELL_SIZE;
            int bY = (int) (posB.y + boundsB.cy()) / LayerManager.CELL_SIZE;
            final GridNode cellB = graph.get(bX, bY);

            entityA().setX(aX);
            entityA().setY(aY);
            entityB().setX(bX);
            entityB().setY(bY);

            if ( cellA == null || cellB == null )
            {
                finished=true;
                return;
            }

            request = new PathFinderRequest<GridNode>(cellA, cellB, new GridNodeEuclideanHeuristic(), new DefaultGraphPath<GridNode>(128));
            request.changeStatus(PathFinderRequest.SEARCH_INITIALIZED);
        }

        if ( finder.search(request, TimeUtils.millisToNanos(MAX_RUNTIME_MS))) {
            finished = true;
            if (request.pathFound) {
                generatePath(request.resultPath);
                request = null;
            }
        }

        if ( request != null ) request.statusChanged = false;
    }
}
项目:ns2-scc-profiler    文件:RouteCalculationSystem.java   
@Override
public void run() {

    if (!finished) {

        if (request == null) {

            if (!a.isActive() || !b.isActive())
            {
                finished=true;
                return;
            }

            // offset to center on the image, and convert to pathing space.
            // @todo cleanup the space difference.
            final Pos posA = mPos.get(a);
            final Pos posB = mPos.get(b);

            Bounds boundsA = mBounds.get(a);
            Bounds boundsB = mBounds.get(b);

            int aX = (int) (posA.x + boundsA.cx()) / LayerManager.CELL_SIZE;
            int aY = (int) (posA.y + boundsA.cy()) / LayerManager.CELL_SIZE;
            final GridNode cellA = graph.get(aX, aY);

            int bX = (int) (posB.x + boundsB.cx()) / LayerManager.CELL_SIZE;
            int bY = (int) (posB.y + boundsB.cy()) / LayerManager.CELL_SIZE;
            final GridNode cellB = graph.get(bX, bY);

            entityA().setX(aX);
            entityA().setY(aY);
            entityB().setX(bX);
            entityB().setY(bY);

            if ( cellA == null || cellB == null )
            {
                finished=true;
                return;
            }

            request = new PathFinderRequest<GridNode>(cellA, cellB, new GridNodeEuclideanHeuristic(), new DefaultGraphPath<GridNode>(128));
            request.changeStatus(PathFinderRequest.SEARCH_INITIALIZED);
        }

        if ( finder.search(request, TimeUtils.millisToNanos(MAX_RUNTIME_MS))) {
            finished = true;
            if (request.pathFound) {
                generatePath(request.resultPath);
                request = null;
            }
        }

        if ( request != null ) request.statusChanged = false;
    }
}
项目:gdx-ai    文件:IndexedAStarPathFinder.java   
@Override
public boolean search (PathFinderRequest<N> request, long timeToRun) {

    long lastTime = TimeUtils.nanoTime();

    // We have to initialize the search if the status has just changed
    if (request.statusChanged) {
        initSearch(request.startNode, request.endNode, request.heuristic);
        request.statusChanged = false;
    }

    // Iterate through processing each node
    do {

        // Check the available time
        long currentTime = TimeUtils.nanoTime();
        timeToRun -= currentTime - lastTime;
        if (timeToRun <= PathFinderQueue.TIME_TOLERANCE) return false;

        // Retrieve the node with smallest estimated total cost from the open list
        current = openList.pop();
        current.category = CLOSED;

        // Terminate if we reached the goal node; we've found a path.
        if (current.node == request.endNode) {
            request.pathFound = true;

            generateNodePath(request.startNode, request.resultPath);

            return true;
        }

        // Visit current node's children
        visitChildren(request.endNode, request.heuristic);

        // Store the current time
        lastTime = currentTime;

    } while (openList.size > 0);

    // The open list is empty and we've not found a path.
    request.pathFound = false;
    return true;
}