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:
One layer for most applications in long, flat stretches, allowing for 3 nodes of up/down deviation, maxes out on 381 x and z deviation.
One smaller, but higher cuboid on top and bottom of it each, stretching 123 in every x and z direction and 67 up/down
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).
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 andprove enough foralmost everythingmost lines.This PR builds on the changes in #15.
Screenshot: Line properly following the tracks (highlighted), defined by only 3 trainline blocks (circled).