]> git.lizzy.rs Git - minetest.git/commit
Pathfinder: improve GridNode storage
authorest31 <MTest31@outlook.com>
Fri, 1 Apr 2016 01:13:24 +0000 (03:13 +0200)
committerest31 <MTest31@outlook.com>
Sun, 1 May 2016 13:32:03 +0000 (15:32 +0200)
commit9aec701a4cb999b3d1eb097d4b01df0480b4ebd0
treea34b397e126507df981aa1776604fcc7fbe75fa0
parentf0de237de729b7b68091210570f10545134b7cf2
Pathfinder: improve GridNode storage

Before, the GridNodes were stored in vector<vector<vector<T>>>,
and initialized in advance. Putting three vectors inside each other
puts lots of unneccessary stress onto the allocator, costs more memory,
and has worse cache locality than a flat vector<T>.

For larger search distances, an the array getting initialized means
essentially O(distance^3) complexity in both time and memory,
which makes the current path search a joke. In order to really
profit from the dijkstra/A* algorithms, other data structures
need to be used for larger distances.

For shorter distances, a map based GridNode storage may be slow as
it requires lots of levels of indirection, which is bad for things like
cache locality, and an array based storage may be faster.

This commit does:

1. remove the vector<vector<vector<T>>> based GridNodes storage that
is allocated and initialized in advance and for the whole
possible area.

2. Add a vector<T> based GridNodes storage that is allocated and
initialized in advance for the whole possible area.

3. Add a map<P,T> based GridNodes storage whose elements are
allocated and initialized, when the path search code
demands it.

4. Add code to decide between approach 2 and 3,
based on the length of the path.

5. Remove the unused "surfaces" member of the PathGridnode class.
Setting this isn't as easy anymore for the
map based GridNodes storage.
src/pathfinder.cpp