TL;DR
Train path finding should not block the game, run in separate threadWhat ?
Track building/removal and trains needs some love. I guess there is a train path finding cache, but building/removing track may slow game a lot. This could be optimized in the following ways:1) track should have a property saying: there is a path going through here
- thanks to this, track removal cost (related to path finding) should be 0, if no paths go through this part of track
- if removed track had a paths going through it, bad luck you have to invalidate at least paths going through them
2) when new track is build, there is no need to invalidate all paths immediately. It can be delayed and run in separate nonblocking thread
- yes some train will have suboptimal paths for a moment
- yes, some trains will need to have path finding run immediately if they want to go on new route
- this should be fast enough for low amount of trains/track, and with high amount of trains/track it should be good enough
3) invalidating path cache could be delayed if there is track related blueprint being built in progress (with a timeout for sure) to not redo/restart everything
each time track is built