diff options
author | orwell96 <orwell@bleipb.de> | 2020-06-12 12:32:46 +0200 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2021-02-10 16:36:24 +0100 |
commit | 61329c11a28ca0d68f95f189d3a66c373d7dddc3 (patch) | |
tree | 8e57504f17c86efdadf2b8494e3427e4f947a001 /advtrains/path.lua | |
parent | d3b2f614be059e65869a615fe319118c0a354995 (diff) | |
download | advtrains-61329c11a28ca0d68f95f189d3a66c373d7dddc3.tar.gz advtrains-61329c11a28ca0d68f95f189d3a66c373d7dddc3.tar.bz2 advtrains-61329c11a28ca0d68f95f189d3a66c373d7dddc3.zip |
Start using path_invalidate_ahead()
Diffstat (limited to 'advtrains/path.lua')
-rw-r--r-- | advtrains/path.lua | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/advtrains/path.lua b/advtrains/path.lua index cd7d94a..7226a7b 100644 --- a/advtrains/path.lua +++ b/advtrains/path.lua @@ -141,22 +141,30 @@ end -- Keeps the path intact, but invalidates all path nodes from the specified index (inclusive) -- onwards. This has the advantage that we don't need to recalculate the whole path, and we can do it synchronously. -function advtrains.path_invalidate_ahead(train, start_idx) +function advtrains.path_invalidate_ahead(train, start_idx, ignore_when_passed) local idx = atfloor(start_idx) + --atdebug("Invalidate_ahead:",train.id,"start_index",start_idx,"cur_idx",train.index) - if(idx <= train.index) then + if(idx <= train.index - 0.5) then + if ignore_when_passed then + --atdebug("ignored passed") + return + end advtrains.path_print(train, atwarn) error("Train "+train.id+": Cannot path_invalidate_ahead start_idx="+idx+" as train has already passed!") end - local i = idx + -- leave current node in path, it won't change. What might change is the path onward from here (e.g. switch) + local i = idx + 1 while train.path[i] do advtrains.occ.clear_item(train.id, advtrains.round_vector_floor_y(train.path[i])) + i = i+1 end - train.path_ext_f=idx - 1 - train.path_trk_f=idx - 1 + train.path_ext_f=idx + train.path_trk_f=math.min(idx, train.path_trk_f) + -- callbacks called anyway for current node, because of LZB advtrains.run_callbacks_invahead(train.id, train, idx) end |