diff options
author | orwell96 <orwell@bleipb.de> | 2021-01-02 19:56:12 +0100 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2021-02-10 16:39:46 +0100 |
commit | 0cef88ba7fec8d3ffefcd48671923b15255500f5 (patch) | |
tree | babc27b0747277e01c3c38a94556c2b85d7c964a /advtrains | |
parent | 4f7c1b1b5d5cdd4f6781ce115ab5110b05d8d13f (diff) | |
download | advtrains-0cef88ba7fec8d3ffefcd48671923b15255500f5.tar.gz advtrains-0cef88ba7fec8d3ffefcd48671923b15255500f5.tar.bz2 advtrains-0cef88ba7fec8d3ffefcd48671923b15255500f5.zip |
Add global slowdown factor instead of hard dtime limiting
Diffstat (limited to 'advtrains')
-rw-r--r-- | advtrains/init.lua | 21 | ||||
-rw-r--r-- | advtrains/wagons.lua | 4 |
2 files changed, 21 insertions, 4 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 diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index 7b6a381..38d81db 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -495,8 +495,8 @@ function wagon:on_step(dtime) end --FIX: use index of the wagon, not of the train. - local velocity = train.velocity - local acceleration = (train.acceleration or 0) + local velocity = train.velocity * advtrains.global_slowdown + local acceleration = (train.acceleration or 0) * (advtrains.global_slowdown*advtrains.global_slowdown) local velocityvec = vector.multiply(vdir, velocity) local accelerationvec = vector.multiply(vdir, acceleration) |