Both aystar and YAPF have node lists with open/closed nodes and a priority queue. Heck, they are even based on the same code because both refer to the same website for the idea. So essentially we got the same code twice.
Next to that there's manual memory management with free, malloc and friends. @PeterN suggested to call Free from the destructor, but not having that at all is even better.
Description
Replace aystar's queue/hash tables with YAPF's incantations, and remove the C-style variants.
Replace C-style array with count, with std::vector for the neighbours. After all, it allocates 12 though there can be at most 4 potential neighbours.
Limitations
There are many things that could be done better in the code, but I'd deliberately chosen to stop here and not completely rewrite the code to keep reviewing this feasible.
Think of not using void pointers for "user data" with the associated nasty casts, or using references instead of pointers.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.
The bug fix is important enough to be backported? (label: 'backport requested')
This PR touches english.txt or translations? Check the guidelines
This PR affects the save game format? (label 'savegame upgrade')
This PR affects the GS/AI API? (label 'needs review: Script API')
ai_changelog.hpp, game_changelog.hpp need updating.
The compatibility wrappers (compat_*.nut) need updating.
This PR affects the NewGRF API? (label 'needs review: NewGRF')
Motivation / Problem
Both aystar and YAPF have node lists with open/closed nodes and a priority queue. Heck, they are even based on the same code because both refer to the same website for the idea. So essentially we got the same code twice.
Next to that there's manual memory management with
free
,malloc
and friends. @PeterN suggested to callFree
from the destructor, but not having that at all is even better.Description
Replace aystar's queue/hash tables with YAPF's incantations, and remove the C-style variants.
Replace C-style array with count, with std::vector for the neighbours. After all, it allocates 12 though there can be at most 4 potential neighbours.
Limitations
There are many things that could be done better in the code, but I'd deliberately chosen to stop here and not completely rewrite the code to keep reviewing this feasible.
Think of not using void pointers for "user data" with the associated nasty casts, or using references instead of pointers.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.