diff options
Diffstat (limited to 'advtrains/init.lua')
-rw-r--r-- | advtrains/init.lua | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua index 96352df..1cba255 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -24,6 +24,9 @@ minetest.log("action", "[advtrains] Loading...") -- There is no need to support 0.4.x anymore given that the compatitability with it is already broken by 1bb1d825f46af3562554c12fba35a31b9f7973ff attrans = minetest.get_translator ("advtrains") +function attrans_formspec(...) + return minetest.formspec_escape(attrans(...)) +end --advtrains advtrains = {trains={}, player_to_train_mapping={}} @@ -198,6 +201,9 @@ advtrains.meseconrules = advtrains.fpath=minetest.get_worldpath().."/advtrains" +advtrains.speed = dofile(advtrains.modpath.."/speed.lua") +advtrains.formspec = dofile(advtrains.modpath.."/formspec.lua") + dofile(advtrains.modpath.."/path.lua") dofile(advtrains.modpath.."/trainlogic.lua") dofile(advtrains.modpath.."/trainhud.lua") @@ -467,8 +473,8 @@ advtrains.avt_save = function(remove_players_from_wagons) "trainparts", "recently_collided_with_env", "atc_brake_target", "atc_wait_finish", "atc_command", "atc_delay", "door_open", "text_outside", "text_inside", "line", "routingcode", - "il_sections", "speed_restriction", "is_shunt", - "points_split", "autocouple", "ars_disable", + "il_sections", "speed_restriction", "speed_restrictions_t", "is_shunt", + "points_split", "autocouple", "atc_wait_autocouple", "ars_disable", }) --then save it tmp_trains[id]=v @@ -569,11 +575,13 @@ advtrains.mainloop_runcnt=0 advtrains.global_slowdown = 1 local t = 0 +local within_mainstep = false minetest.register_globalstep(function(dtime_mt) if no_action then -- the advtrains globalstep is skipped by command. Return immediately return end + within_mainstep = true advtrains.mainloop_runcnt=advtrains.mainloop_runcnt+1 --atprint("Running the main loop, runcnt",advtrains.mainloop_runcnt) @@ -586,6 +594,7 @@ minetest.register_globalstep(function(dtime_mt) if GENERATE_ATRICIFIAL_LAG then dtime = HOW_MANY_LAG if os.clock()<t then + within_mainstep = false return end @@ -616,7 +625,7 @@ minetest.register_globalstep(function(dtime_mt) if advtrains.lines then advtrains.lines.step(dtime) end - + --trigger a save when necessary save_timer=save_timer-dtime if save_timer<=0 then @@ -626,6 +635,9 @@ minetest.register_globalstep(function(dtime_mt) save_timer = advtrains.SAVE_INTERVAL atprintbm("saving", t) end + + within_mainstep = false + end) --if something goes wrong in these functions, there is no help. no pcall here. @@ -678,7 +690,13 @@ function advtrains.save(remove_players_from_wagons) --TODO very simple yet hacky workaround for the "green signals" bug advtrains.invalidate_all_paths() end -minetest.register_on_shutdown(advtrains.save) +minetest.register_on_shutdown(function() + if within_mainstep then + atwarn("Crash during advtrains main step - skipping the shutdown save operation to not save inconsistent data!") + else + advtrains.save() + end +end) -- This chat command provides a solution to the problem known on the LinuxWorks server -- There are many players that joined a single time, got on a train and then left forever |