reduce technic_run interval if lag is too high / hot-reload offdelay setting / cache-flush command

This commit is contained in:
BuckarooBanzay 2020-02-03 10:29:20 +01:00
parent 60963ca454
commit 8ab47b2c78
4 changed files with 45 additions and 2 deletions

View File

@ -33,6 +33,10 @@ Recommended mods that build on the `technic mod`:
* **technic.switch_max_range** max cable length (default: 256)
* **technic.switch.off_delay_seconds** switching station off delay (default: 300 seconds)
# Chat commands
* **/technic_flush_switch_cache** clears the switching station cache (stops all unloaded switches)
# Open issues
* Documentation (markdown)

View File

@ -7,6 +7,7 @@ dofile(path.."/LV/init.lua")
dofile(path.."/MV/init.lua")
dofile(path.."/HV/init.lua")
dofile(path.."/max_lag.lua")
dofile(path.."/switching_station.lua")
dofile(path.."/switching_station_globalstep.lua")

View File

@ -0,0 +1,15 @@
local function explode(sep, input)
local t={}
local i=0
for k in string.gmatch(input,"([^"..sep.."]+)") do
t[i]=k
i=i+1
end
return t
end
function technic.get_max_lag()
local arrayoutput = explode(", ",minetest.get_server_status())
local arrayoutput2 = explode("=",arrayoutput[4])
return tonumber(arrayoutput2[1])
end

View File

@ -44,19 +44,33 @@ minetest.register_abm({
end
})
local off_delay_seconds = tonumber(minetest.settings:get("technic.switch.off_delay_seconds") or "300")
-- the interval between technic_run calls
local technic_run_interval = 1.0
-- iterate over all collected switching stations and execute the technic_run function
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < 1.0 then
if timer < technic_run_interval then
return
end
timer = 0
local max_lag = technic.get_max_lag()
if max_lag > 1.5 then
-- slow down technic execution if the lag is higher than usual
technic_run_interval = 1.5
else
-- normal run_interval
technic_run_interval = 1.0
end
local now = minetest.get_us_time()
local off_delay_seconds = tonumber(minetest.settings:get("technic.switch.off_delay_seconds") or "300")
local off_delay_micros = off_delay_seconds*1000*1000
local active_switches = 0
for hash, switch in pairs(switches) do
@ -121,3 +135,12 @@ minetest.register_globalstep(function(dtime)
end)
minetest.register_chatcommand("technic_flush_switch_cache", {
description = "removes all loaded switching stations from the cache",
privs = { server = true },
func = function()
switches = {}
end
})