xaguzman / pathfinding

Java pathfinding framework.
Apache License 2.0
96 stars 28 forks source link

Staggered isometric maps #6

Closed mendrik closed 9 years ago

mendrik commented 9 years ago

Hi,

this is more of a question, not a bug. I'm using libgdx with staggered isometric map, where the tiles are stored like so:

0/4   1/4   2/4   3/4   4/4   ...
   0/3   1/3   2/3   3/3   4/3   ...
0/2   1/2   2/2   3/2   4/2   ...
   0/1   1/1   2/1   3/1   4/1   ...
0/0   1/0   2/0   3/0   4/0   ...

This is a bit hard to map onto the GridCell array and I was hoping if I could just override the neighbour resolving:

new NavigationGrid<GridCell>(createCells()) {
            @Override
            public List<GridCell> getNeighbors(GridCell cell) {
                int x = cell.getX();
                int y = cell.getY();
                List<GridCell> neighbours = new ArrayList<GridCell>();
                for (StaggeredDirection dir : StaggeredDirection.PATH_AROUND) {
                    int x1 = x + dir.getX(y % 2 == 1);
                    int y1 = y + dir.getY();
                    neighbours.add(new GridCell(x1, y1, layer.getCell(x1, y1) == null));
                }
                return neighbours;
            }

            @Override
            public List<GridCell> getNeighbors(GridCell node, PathFinderOptions opt) {
                return this.getNeighbors(node);
            }
        };

However this method seems to never be called in the first place. Would you have any recommendations how to approach my problem?

mendrik commented 9 years ago

After some thinking it would be maybe nice if your lib wouldn't rely on a gridarray but only take an interface like this:

public interface DataProvider {
    public GridCell nextNeighbour(GridCell node);
    public GridCell getStartNode();
    public GridCell getDestinationNode();
}

That way the user can decide himself how neighbours are retrieved and no coordinate mapping is required.

xaguzman commented 9 years ago

It's strange that the getNeighbors method is not getting called, that's exactly what the path finders rely on.

Also, I think the data provider you are thinking off is already there, and is called NagivationGraph