Make DTIME_LIMIT and SAVE_INTERVAL globally accessible

This commit is contained in:
orwell96 2021-02-15 19:41:13 +01:00
parent 5569849401
commit 0bffd6ca64

View File

@ -51,8 +51,8 @@ local NO_SAVE = false
-- ========================================================================== -- ==========================================================================
-- Use a global slowdown factor to slow down train movements. Now a setting -- Use a global slowdown factor to slow down train movements. Now a setting
local DTIME_LIMIT = tonumber(minetest.settings:get("advtrains_dtime_limit")) or 0.2 advtrains.DTIME_LIMIT = tonumber(minetest.settings:get("advtrains_dtime_limit")) or 0.2
local SAVE_INTERVAL = tonumber(minetest.settings:get("advtrains_save_interval")) or 60 advtrains.SAVE_INTERVAL = tonumber(minetest.settings:get("advtrains_save_interval")) or 60
--Constant for maximum connection value/division of the circle --Constant for maximum connection value/division of the circle
AT_CMAX = 16 AT_CMAX = 16
@ -564,7 +564,7 @@ end
--## MAIN LOOP ##-- --## MAIN LOOP ##--
--Calls all subsequent main tasks of both advtrains and atlatc --Calls all subsequent main tasks of both advtrains and atlatc
local init_load=false local init_load=false
local save_timer = SAVE_INTERVAL local save_timer = advtrains.SAVE_INTERVAL
advtrains.mainloop_runcnt=0 advtrains.mainloop_runcnt=0
advtrains.global_slowdown = 1 advtrains.global_slowdown = 1
@ -592,14 +592,14 @@ minetest.register_globalstep(function(dtime_mt)
t = os.clock()+HOW_MANY_LAG t = os.clock()+HOW_MANY_LAG
end end
-- if dtime is too high, decrease global slowdown -- if dtime is too high, decrease global slowdown
if DTIME_LIMIT~=0 then if advtrains.DTIME_LIMIT~=0 then
if dtime > DTIME_LIMIT then if dtime > advtrains.DTIME_LIMIT then
if advtrains.global_slowdown > 0.1 then if advtrains.global_slowdown > 0.1 then
advtrains.global_slowdown = advtrains.global_slowdown - 0.05 advtrains.global_slowdown = advtrains.global_slowdown - 0.05
else else
advtrains.global_slowdown = advtrains.global_slowdown / 2 advtrains.global_slowdown = advtrains.global_slowdown / 2
end end
dtime = DTIME_LIMIT dtime = advtrains.DTIME_LIMIT
end end
-- recover global slowdown slowly over time -- recover global slowdown slowly over time
advtrains.global_slowdown = math.min(advtrains.global_slowdown*1.02, 1) advtrains.global_slowdown = math.min(advtrains.global_slowdown*1.02, 1)
@ -623,7 +623,7 @@ minetest.register_globalstep(function(dtime_mt)
local t=os.clock() local t=os.clock()
--save --save
advtrains.save() advtrains.save()
save_timer = SAVE_INTERVAL save_timer = advtrains.SAVE_INTERVAL
atprintbm("saving", t) atprintbm("saving", t)
end end
end) end)