aboutsummaryrefslogtreecommitdiff
path: root/advtrains/init.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2021-01-02 19:56:12 +0100
committerorwell96 <orwell@bleipb.de>2021-02-10 16:39:46 +0100
commit0cef88ba7fec8d3ffefcd48671923b15255500f5 (patch)
treebabc27b0747277e01c3c38a94556c2b85d7c964a /advtrains/init.lua
parent4f7c1b1b5d5cdd4f6781ce115ab5110b05d8d13f (diff)
downloadadvtrains-0cef88ba7fec8d3ffefcd48671923b15255500f5.tar.gz
advtrains-0cef88ba7fec8d3ffefcd48671923b15255500f5.tar.bz2
advtrains-0cef88ba7fec8d3ffefcd48671923b15255500f5.zip
Add global slowdown factor instead of hard dtime limiting
Diffstat (limited to 'advtrains/init.lua')
-rw-r--r--advtrains/init.lua21
1 files changed, 19 insertions, 2 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua
index 7d400dc..a6cd2f0 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -47,6 +47,10 @@ advtrains.IGNORE_WORLD = true
local NO_SAVE = true
-- Do not save any data to advtrains save files
+
+-- Use a global slowdown factor to slow down train movements.
+local USE_SLOWDOWN = false
+local DTIME_LIMIT = 0.3
-- ==========================================================================
@@ -563,7 +567,7 @@ local init_load=false
local save_interval=60
local save_timer=save_interval
advtrains.mainloop_runcnt=0
-
+advtrains.global_slowdown = 1
local t = 0
minetest.register_globalstep(function(dtime_mt)
@@ -579,7 +583,7 @@ minetest.register_globalstep(function(dtime_mt)
advtrains.load()
end
- local dtime = dtime_mt
+ local dtime = dtime_mt * advtrains.global_slowdown
if GENERATE_ATRICIFIAL_LAG then
dtime = HOW_MANY_LAG
if os.clock()<t then
@@ -588,6 +592,19 @@ minetest.register_globalstep(function(dtime_mt)
t = os.clock()+HOW_MANY_LAG
end
+ -- if dtime is too high, decrease global slowdown
+ if USE_SLOWDOWN then
+ if dtime > DTIME_LIMIT then
+ if advtrains.global_slowdown > 0.1 then
+ advtrains.global_slowdown = advtrains.global_slowdown - 0.05
+ else
+ advtrains.global_slowdown = advtrains.global_slowdown / 2
+ end
+ dtime = DTIME_LIMIT
+ end
+ end
+ -- recover global slowdown slowly over time
+ advtrains.global_slowdown = math.min(advtrains.global_slowdown*1.02, 1)
advtrains.mainloop_trainlogic(dtime,advtrains.mainloop_runcnt)
if advtrains_itm_mainloop then