minetest-mapserver / mapserver_mod

Complementary mod for the minetest mapserver
17 stars 14 forks source link

Trainlines: Follow tracks #19

Open PeterNerlich opened 2 years ago

PeterNerlich commented 2 years ago

This pull request uses advtrains functions to find the exact path along the tracks between two trainline blocks.

In order to achieve this, a rail node can be associated with a block, similar to how advtrains TCBs or influence points are set. When placing or saving on a block, we search for the blocks belonging to the same line in the surrounding area and figure out the immediately previous and next block using the index. If this block and one of its neighbours have a rail node associated with it, we use advtrains functions to march from one rail towards the position of the other until we find it (or 1000 nodes were traversed). Every time the heading changes, the current position is added to the list eventually saved to the linepath_from_prv metadata attribute so it can be read by the mapserver.

Searching an area for nodes is expensive. Minetest limits the amount to 4,096,000 nodes. Because there is not a good way to form one cuboid to fit all major long-distance usecases and this will not be frequently executed on a server (only every time a player manually sets or updates a train map block), we take all we can with 3 separate ranges:

This should be very luxurious and prove enough for almost everything most lines.

This PR builds on the changes in #15.


Screenshot: Line properly following the tracks (highlighted), defined by only 3 trainline blocks (circled). image