Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way of reusing GridMap instances? #3

Open
urgood2 opened this issue Jun 28, 2023 · 1 comment
Open

A way of reusing GridMap instances? #3

urgood2 opened this issue Jun 28, 2023 · 1 comment

Comments

@urgood2
Copy link

urgood2 commented Jun 28, 2023

Hi.
I've been using this library for a private game project but noticed a slight issue (which may stem from my lack of familiarity with the library code).
I have multiple agents that need to use the same map to pathfind at various points in the game (not necessarily batched together, which prevents me from effectively utilizing multi-agent maps as provided by this library). I've noticed that reusing gridmap objects simply by changing the goalnode will not provide correct results, and realize that the gridmap should be created anew every time I need to pathfind.

Since agents need to pathfind very often, this is a rather inefficient way to do things and I was wondering if there could be a way to reset the gridmap node information without actually creating a new gridmap every time I need a new path found?

Here is the code I use to pathfind, if it's needed (pathfindingMap is a shared pointer to a JumpPointMap instance):

`

pathfindingMap->goal_ = fudge::Coord(endX, endY); // needed for jps to work
 
auto start = fudge::Coord(startX, startY);
    
const std::vector<fudge::Coord> path0 = fudge::astar_search(
        *pathfindingMap, start, fudge::Coord(endX, endY), 
        fudge::GridMap<double>::diagonal_distance);

`

@silmerusse
Copy link
Owner

The grid map object holds the array of nodes to be explored and open node list, which are not reusable for another search. You could reset them but why not just create a new map instance instead, which does the same thing. I think there should not be much difference of performance. The cost matrix(terrain) could be used. When you create a new map instance, you should pass the cost matrix as an argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants