This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revision Both sides next revision | ||
dev:core:path [2020-04-28 20:27] orwell |
dev:core:path [2020-06-24 12:26] orwell more documentation, note on invalidate_ahead |
||
---|---|---|---|
Line 57: | Line 57: | ||
The path is generated on the fly, as path items are requested. | The path is generated on the fly, as path items are requested. | ||
- | Every call to '' | + | Every call to '' |
+ | |||
+ | The path system deletes path items that are behind the train and no longer needed automatically. | ||
+ | |||
+ | ===== Invalidation and restoration ===== | ||
+ | |||
+ | Whenever the tracks in the world change (e.g. a switch is switched), it is required to update (say ' | ||
+ | |||
+ | //With the '' | ||
+ | |||
+ | A path invalidation clears all path-related tables and variables. They remain cleared until the next call to '' | ||
+ | |||
+ | To restore the path from save files or after a path invalidation, | ||
+ | |||
+ | < | ||
+ | train.last_pos -- the world position of the path item currently at floor(train.index) | ||
+ | train.last_connid = the connid of the track connection pointing forward | ||
+ | train.last_frac = the fractional part of train.index | ||
+ | </ | ||
+ | |||
+ | To restore, train.last_pos becomes path item 0, train.index becomes last_frac, and path generation continues in last_connid direction. This causes an index shift, which also prevents integer overflows. | ||
+ | |||
+ | Note that, to have an estimated rough position of a train, you can simply query '' | ||
+ | |||
+ | A path invalidation can also occur when LZB checkpoints change, see [[dev: | ||
+ | |||
+ | ===== Invalidate Ahead ===== | ||
+ | |||
+ | In order to prevent a complete path recalculation when a far-away rail changes, '' | ||
+ | |||
+ | Obviously, due to the way the path restoration works, this would cause problems when the starting index is behind the train' | ||
+ | |||
+ | '' | ||
+ | |||
+ | In the future, path_invalidate_ahead() is to be preferred over path_invalidate(). | ||