Page 1 of 1

Hint, performance Trackbuilding

Posted: Sat Apr 01, 2017 12:58 pm
by Lifeguard78
Hi,

after your Explanation, how Trackbuilding works today, I would suggest, to put a Segment layer in between.

So a Track is member of a Segment. A Segment is a Connection between 2 Points.
And only if A Track Action leads do a Change, that 2 connected Points are affekted, you Need to recalculate path finding.


So if you have a double sided connected Segment, and you delete a track, you get 2 new Segmentes, with open Ends.
In this case, you Need to recalculate only those paths, used by the Segment.

If you build a track. And only, if this Action leads to the Situation, that this Segments connect 2 Points with Connections to the Network, then, all paths Need to be recalculated.

To Stretch calculations, I would mark Train scedules as Calculated. Only if a new Segment closes a new Connection, I would reset this mark. So if a Train goes for new Destination, it calculates the way new, if this mark is false.

And at the end, recalculating the rest of the paths, not actualy used, is something, a backround working Task in a multithreading enviroment can handle.

Re: Hint, performance Trackbuilding

Posted: Sat Apr 01, 2017 1:27 pm
by Tekky
I believe OpenTTD, which is open source, also uses segments instead of individual track pieces when doing its pathfinding calculations.

Re: Hint, performance Trackbuilding

Posted: Sat Apr 01, 2017 1:48 pm
by Rseding91
Tekky wrote:I believe OpenTTD, which is open source, also uses segments instead of individual track pieces when doing its pathfinding calculations.
Factorio does as well but the result path is the list of rails the train needs to travel on.

Checking which segment was removed vs if the rail still exists is the same cost just it makes it far easier to check the rails.

Re: Hint, performance Trackbuilding

Posted: Sat Apr 01, 2017 4:40 pm
by Lifeguard78
Well, I do have a Segment, defined between 2 (Nodes) Points.
For each Segment, I store the distance between it s endpoints, so in pathfinding I do not have to run through all the tracks. Only through the nodes and it s corresponding segments.

If you bring up another Object, calles System. If you have some not connected Train Systems, you can directly adress Trains to the System affected, while setting recalculation flag.

So if you lay a track in the Dessert, it gets a new Segment identifier, as well System identifier. As Long it is not connected to any used tracks, it does not start any calculations.
It will rais cost of deleting tracks, because you have to figure out, if you end up with 2 Systems, and then renaming the smaller Portion. But, on the other Hand, with this calculation you easily can see broken paths, if a Train has stations of different Systems.