diff options
Diffstat (limited to 'advtrains')
-rw-r--r-- | advtrains/path.lua | 12 | ||||
-rw-r--r-- | advtrains/trainlogic.lua | 9 |
2 files changed, 18 insertions, 3 deletions
diff --git a/advtrains/path.lua b/advtrains/path.lua index a0bcd04..64e0d1c 100644 --- a/advtrains/path.lua +++ b/advtrains/path.lua @@ -98,7 +98,15 @@ end -- Invalidates a path -- this is supposed to clear stuff from the occupation tables -function advtrains.path_invalidate(train) +-- This function throws a warning whenever any code calls it while the train steps are run, since that must not happen. +-- The ignore_lock parameter can be used to ignore this, however, it should then be accompanied by a call to train_ensure_init +-- before returning from the calling function. +function advtrains.path_invalidate(train, ignore_lock) + if advtrains.lock_path_inval and not ignore_lock then + atwarn("Train ",train.train_id,": Illegal path invalidation has occured during train step:") + atwarn(debug.traceback()) + end + if train.path then for i,p in pairs(train.path) do advtrains.occ.clear_item(train.id, advtrains.round_vector_floor_y(p)) @@ -122,11 +130,11 @@ end -- Prints a path using the passed print function -- This function should be 'atprint', 'atlog', 'atwarn' or 'atdebug', because it needs to use print_concat_table function advtrains.path_print(train, printf) + printf("path_print: tid =",train.train_id," index =",train.index," end_index =",train.end_index," vel =",train.velocity) if not train.path then printf("path_print: Path is invalidated/inexistant.") return end - printf("path_print: tid =",train.train_id," index =",train.index," end_index =",train.end_index," vel =",train.velocity) printf("i: CP Position Dir CN ->Dist->") for i = train.path_ext_b, train.path_ext_f do if i==train.path_trk_b then diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index 9c214bb..ff9abf4 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -83,6 +83,8 @@ advtrains.mainloop_trainlogic=function(dtime) advtrains.train_ensure_init(k, v) end + advtrains.lock_path_inval = true + for k,v in pairs(advtrains.trains) do advtrains.atprint_context_tid=k advtrains.train_step_b(k, v, dtime) @@ -93,6 +95,8 @@ advtrains.mainloop_trainlogic=function(dtime) advtrains.train_step_c(k, v, dtime) end + advtrains.lock_path_inval = false + advtrains.atprint_context_tid=nil atprintbm("trainsteps", t) @@ -1039,7 +1043,7 @@ function advtrains.invert_train(train_id) train.atc_arrow = not train.atc_arrow end - advtrains.path_invalidate(train) + advtrains.path_invalidate(train, true) advtrains.couple_invalidate(train) local old_trainparts=train.trainparts @@ -1049,6 +1053,9 @@ function advtrains.invert_train(train_id) end advtrains.update_trainpart_properties(train_id, true) + -- recalculate path + advtrains.train_ensure_init(train_id, train) + -- If interlocking present, check whether this train is in a section and then set as shunt move after reversion if advtrains.interlocking and train.il_sections and #train.il_sections > 0 then train.is_shunt = true |