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

Precompute portal node graph in high-level pathfinder #1674

Closed
3 of 5 tasks
heinezen opened this issue Aug 25, 2024 · 7 comments
Closed
3 of 5 tasks

Precompute portal node graph in high-level pathfinder #1674

heinezen opened this issue Aug 25, 2024 · 7 comments
Labels
area: simulation Involved in the game mechanics and simulation good first issue Suitable for newcomers hacktoberfest For newcomers from Hacktoberfest event improvement Enhancement of an existing component just do it You can start working on this, there should be nothing left to discuss lang: c++ Done in C++ code

Comments

@heinezen
Copy link
Member

heinezen commented Aug 25, 2024

Required Skills: C++

Difficulty: Easy

In the openage pathfinder, a portal node graph is used in the first stage of the search to find the sectors the path travels through using an A* search algorithm. Currently, this node graph is created dynamically on every path request to the pathfinder which takes a significant amount of time. Since the node graph only changes very infrequently (i.e. only if the portals change), we can theoretically create it once on the first path request and then reuse it on subsequent requests.

To try out the current pathfinder, check out pathfinding demo 1 by running the following command:

./run test -d pathfinding.tests.path_demo 1

Tasks:

  • Implement a dedicated method that creates the portal node graph(s). Currently, the graph is created in Pathfinder::portal_a_star. Note that there may be multiple pathfinding grids and each of them creates a differ ent node graph.
  • Store the portal node graph(s) where they can be accessed when computing new paths. The Grid class should be a good candidate.
  • Change Pathfinder::portal_a_star in such a way that it uses the precomputed portal node graph.
  • (optional) Use callgrind to compare the speed of the old implementation with your solution that uses precomputed graphs.
valgrind --tool=callgrind ./run test -d pathfinding.tests.path_demo 1
  • (optional; Difficulty: medium) Recompute the portal node graph when the portals have changed. This can happen when a CostField on the grid gets changed.

Further Reading

@heinezen heinezen added improvement Enhancement of an existing component lang: c++ Done in C++ code area: simulation Involved in the game mechanics and simulation good first issue Suitable for newcomers just do it You can start working on this, there should be nothing left to discuss labels Aug 25, 2024
@heinezen heinezen moved this to pathfinder in openage beginner tasks Aug 25, 2024
@heinezen heinezen pinned this issue Aug 25, 2024
@heinezen heinezen added the hacktoberfest For newcomers from Hacktoberfest event label Sep 20, 2024
@jere8184
Copy link
Contributor

I would like to take on this issue.

@jere8184
Copy link
Contributor

So portal_a_star generates a path of portals right to get you from "source tile" to "dest tile", So we want to precompute these paths if I'm understanding correctly, would we precomompute these paths on a per tile basis i.e. calculate the portal path from every "source tile" to every "dest tile"?

@heinezen
Copy link
Member Author

So portal_a_star generates a path of portals right to get you from "source tile" to "dest tile",

Not exactly. The portals only connect sectors on the grid (a sector may be 10x10 tiles for example), so it will rather find a sector path from the "source sector" to "destination sector". Therefore, portal_a_star also only computes a high-level path that consists of the sectors that are visited. The tile-based search happens at a later stage using a different method.

So we want to precompute these paths if I'm understanding correctly, would we precomompute these paths on a per tile basis i.e. calculate the portal path from every "source tile" to every "dest tile"?

I'm not sure if I'm misunderstanding you, but the task is not about precomputing any paths. What we want to precompute is the portal node graph, i.e. the connections between all the portals between sectors on the grid. This
graph will then be searched in portal_a_star using A* to find a sector path as mentioned above.

@heinezen
Copy link
Member Author

I should also mention that if you work on this, please branch from this PR #1656

@heinezen
Copy link
Member Author

Solved by #1708

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in openage game simulation Nov 18, 2024
@jere8184
Copy link
Contributor

@heinezen For the optional task, I think I would have to change the way the graph's weights are calculated. Currently, when calculating the distance between two portal nodes, we are taking the physical distance. I guess this would have to change. Maybe flow_field way points could be used to calculate a more accurate distance that takes into account the path travelled.

@heinezen heinezen unpinned this issue Nov 20, 2024
@heinezen
Copy link
Member Author

@jere8184 I think I would group the optional task with a new issue to make the grid dynamic, which would include quite a few other changes. We would have to check what distance changes are still performant on a dynamic grid. We could always calculate the exact distance using flood-fill (i.e. also recording the distance to each portal, when we find the portal connections). However, this may be expensive to run during a gameplay session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: simulation Involved in the game mechanics and simulation good first issue Suitable for newcomers hacktoberfest For newcomers from Hacktoberfest event improvement Enhancement of an existing component just do it You can start working on this, there should be nothing left to discuss lang: c++ Done in C++ code
Projects
Archived in project
Status: ✅ Done
Development

No branches or pull requests

2 participants