diff options
author | ywang <yw05@forksworld.de> | 2020-04-07 19:40:35 +0200 |
---|---|---|
committer | ywang <yw05@forksworld.de> | 2020-04-12 16:11:15 +0200 |
commit | 7bfccc78a097201c4a3106b9f3142ddd6534bca1 (patch) | |
tree | 88b449ade134ed9b59878978292fb213daf027a8 /advtrains/init.lua | |
parent | b6c58022b6d011f1733062faf73508b991c8dd5a (diff) | |
download | advtrains-7bfccc78a097201c4a3106b9f3142ddd6534bca1.tar.gz advtrains-7bfccc78a097201c4a3106b9f3142ddd6534bca1.tar.bz2 advtrains-7bfccc78a097201c4a3106b9f3142ddd6534bca1.zip |
hostfix for trains ignoring ATC tracks
Diffstat (limited to 'advtrains/init.lua')
-rw-r--r-- | advtrains/init.lua | 79 |
1 files changed, 45 insertions, 34 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua index 5a55312..d36d2dd 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -61,7 +61,7 @@ end function advtrains.pcall(fun) if no_action then return end - + local succ, return1, return2, return3, return4=xpcall(fun, function(err) atwarn("Lua Error occured: ", err) atwarn(debug.traceback()) @@ -160,11 +160,11 @@ if minetest.settings:get_bool("advtrains_enable_debugging") then if not context then return end local text=advtrains.print_concat_table({t, ...}) advtrains.drb_record(context, text) - + --atlog("@@",advtrains.atprint_context_tid,t,...) end dofile(advtrains.modpath.."/debugringbuffer.lua") - + end function assertt(var, typ) @@ -176,7 +176,7 @@ end dofile(advtrains.modpath.."/helpers.lua"); --dofile(advtrains.modpath.."/debugitems.lua"); -advtrains.meseconrules = +advtrains.meseconrules = {{x=0, y=0, z=-1}, {x=1, y=0, z=0}, {x=-1, y=0, z=0}, @@ -243,7 +243,7 @@ end function advtrains.avt_load() -- check for new, split advtrains save file - + local version = advtrains.read_component("version") local tbl if version and version == 3 then @@ -263,7 +263,7 @@ function advtrains.avt_load() wagon_save = true, ptmap = true, atc = true, - ndb = true, + ndb = true, lines = true, version = 2, } @@ -274,7 +274,7 @@ function advtrains.avt_load() tbl[i] = advtrains.read_component(i) end tbl["interlocking"] = il_save - else + else local file, err = io.open(advtrains.fpath, "r") if not file then minetest.log("warning", " Failed to read advtrains save data from file "..advtrains.fpath..": "..(err or "Unknown Error")) @@ -370,19 +370,26 @@ advtrains.save_component = function (tbl, name) if not success then minetest.log("error", " Failed to write advtrains save data to file "..path) end +<<<<<<< HEAD +======= + file:write(datastr) + file:close() + os.rename(temppath, advtrains.fpath.."_"..name) + +>>>>>>> hostfix for trains ignoring ATC tracks end advtrains.avt_save = function(remove_players_from_wagons) --atprint("saving") - + if remove_players_from_wagons then for w_id, data in pairs(advtrains.wagons) do data.seatp={} end advtrains.player_to_train_mapping={} end - + local tmp_trains={} for id, train in pairs(advtrains.trains) do --first, deep_copy the train @@ -401,7 +408,7 @@ advtrains.avt_save = function(remove_players_from_wagons) advtrains.remove_train(id) end end - + for id, wdata in pairs(advtrains.wagons) do local _,proto = advtrains.get_wagon_prototype(wdata) if proto.has_inventory then @@ -415,7 +422,7 @@ advtrains.avt_save = function(remove_players_from_wagons) -- TODO temp wdata.dcpl_lock = nil end - + --versions: -- 1 - Initial new save format. -- 2 - version as of tss branch 11-2018+ @@ -444,11 +451,11 @@ advtrains.avt_save = function(remove_players_from_wagons) for i,k in pairs(save_tbl) do advtrains.save_component(k,i) end - + for i,k in pairs(il_save) do advtrains.save_component(k,"interlocking_"..i) end - + if DUMP_DEBUG_SAVE then local file, err = io.open(advtrains.fpath.."_DUMP", "w") if err then @@ -476,7 +483,7 @@ minetest.register_globalstep(function(dtime_mt) if not init_load then advtrains.load() end - + --[[ local dtime if GENERATE_ATRICIFIAL_LAG then @@ -484,7 +491,7 @@ minetest.register_globalstep(function(dtime_mt) if os.clock()<t then return end - + t = os.clock()+0.2 else --limit dtime: if trains move too far in one step, automation may cause stuck and wrongly braking trains @@ -494,23 +501,28 @@ minetest.register_globalstep(function(dtime_mt) dtime=0.2 end end - - ]] - local dtime = dtime_mt - advtrains.mainloop_trainlogic(dtime) - if advtrains_itm_mainloop then - advtrains_itm_mainloop(dtime) - end - if atlatc then - atlatc.mainloop_stepcode(dtime) - atlatc.interrupt.mainloop(dtime) - end - if advtrains.lines then - advtrains.lines.step(dtime) + ]] + + -- hotfix to prevent bugs related to ATC tracks. + while (dtime_mt>0) do + local dtime = dtime_mt + if dtime > 0.2 then dtime = 0.2 end + advtrains.mainloop_trainlogic(dtime) + if advtrains_itm_mainloop then + advtrains_itm_mainloop(dtime) + end + if atlatc then + atlatc.mainloop_stepcode(dtime) + atlatc.interrupt.mainloop(dtime) + end + if advtrains.lines then + advtrains.lines.step(dtime) + end + dtime_mt = dtime_mt - dtime end - + --trigger a save when necessary - save_timer=save_timer-dtime + save_timer=save_timer-dtime_mt if save_timer<=0 then local t=os.clock() --save @@ -552,7 +564,7 @@ function advtrains.save(remove_players_from_wagons) atlatc.save() end atprint("[save_all]Saved advtrains save files") - + --TODO very simple yet hacky workaround for the "green signals" bug advtrains.invalidate_all_paths() end @@ -577,8 +589,8 @@ minetest.register_chatcommand("at_empty_seats", -- This chat command solves another problem: Trains getting randomly stuck. minetest.register_chatcommand("at_reroute", { - params = "", - description = "Delete all train routes, force them to recalculate", + params = "", + description = "Delete all train routes, force them to recalculate", privs = {train_operator=true}, -- Only train operator is required, since this is relatively safe. func = function(name, param) return advtrains.pcall(function() @@ -591,4 +603,3 @@ minetest.register_chatcommand("at_reroute", local tot=(os.clock()-lot)*1000 minetest.log("action", "[advtrains] Loaded in "..tot.."ms") - |