OpenTTD / OpenTTD

OpenTTD is an open source simulation game based upon Transport Tycoon Deluxe
https://www.openttd.org/
Other
6.06k stars 842 forks source link

Codechange: migrate aystar to use YAPF's nodelist infrastructure #12670

Closed rubidium42 closed 2 weeks ago

rubidium42 commented 1 month ago

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 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.