Planning navigation in several frames – time-sliced search
When dealing with large graphs, computing paths can take a lot of time, even driving the game to a halt for a couple of seconds. This could lead to ruining the overall experience, to say the least. Luckily enough, there are methods for avoiding that.
Note
This recipe is built on top of the principles of using coroutines as a method for keeping the game running smoothly while finding a path in the background; some knowledge of coroutines is required.
Getting ready
We'll learn how to implement path-finding techniques using coroutines by refactoring the A* algorithm learned previously, but we will handle its signature as a different function.
How to do it...
Even though this recipe is only for defining a function, please take into consideration the comments in the code for a better understanding of the implementation and code flow:
- Modify the
Graph
class and add a couple of member variables, one for storing the path and the other for knowing...