From 737eb4987f30a48bebf0ac4a78b0c62e73a813e4 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Fri, 12 Feb 2021 11:55:57 +0100 Subject: LZB: Look ahead before movement, not after --- advtrains/lzb.lua | 9 +++++++-- advtrains/trainlogic.lua | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'advtrains') diff --git a/advtrains/lzb.lua b/advtrains/lzb.lua index 6a899d6..cbdc422 100644 --- a/advtrains/lzb.lua +++ b/advtrains/lzb.lua @@ -123,6 +123,8 @@ local function look_ahead(id, train) lzb.trav_index = trav end +advtrains.lzb_look_ahead = look_ahead + local function call_runover_callbacks(id, train) if not train.lzb then return end @@ -254,7 +256,8 @@ end advtrains.te_register_on_new_path(function(id, train) advtrains.lzb_invalidate(train) - look_ahead(id, train) + -- Taken care of in pre-move hook (see train_step_b) + --look_ahead(id, train) end) advtrains.te_register_on_invalidate_ahead(function(id, train, start_idx) @@ -266,6 +269,8 @@ advtrains.te_register_on_update(function(id, train) atprint("LZB run: no path on train, skip step") return end - look_ahead(id, train) + -- Note: look_ahead called from train_step_b before applying movement + -- TODO: if more pre-move hooks are added, make a separate callback hook + --look_ahead(id, train) call_runover_callbacks(id, train) end, true) diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index a307256..c9c7e76 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -339,6 +339,10 @@ function advtrains.train_step_b(id, train, dtime) advtrains.path_get(train, atfloor(train.index + 2)) advtrains.path_get(train, atfloor(train.end_index - 1)) + -- run pre-move hooks + -- TODO: if more pre-move hooks are added, make a separate callback hook + advtrains.lzb_look_ahead(id, train) + --[[ again, new velocity control: There are two heterogenous means of control: -> set a fixed acceleration and ignore speed (user) -- cgit v1.2.3