mirror of
https://github.com/minetest-mods/technic.git
synced 2025-02-23 15:20:19 +01:00
reduce technic_run interval if lag is too high / hot-reload offdelay setting / cache-flush command
This commit is contained in:
parent
60963ca454
commit
8ab47b2c78
@ -33,6 +33,10 @@ Recommended mods that build on the `technic mod`:
|
|||||||
* **technic.switch_max_range** max cable length (default: 256)
|
* **technic.switch_max_range** max cable length (default: 256)
|
||||||
* **technic.switch.off_delay_seconds** switching station off delay (default: 300 seconds)
|
* **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
|
# Open issues
|
||||||
|
|
||||||
* Documentation (markdown)
|
* Documentation (markdown)
|
||||||
|
@ -7,6 +7,7 @@ dofile(path.."/LV/init.lua")
|
|||||||
dofile(path.."/MV/init.lua")
|
dofile(path.."/MV/init.lua")
|
||||||
dofile(path.."/HV/init.lua")
|
dofile(path.."/HV/init.lua")
|
||||||
|
|
||||||
|
dofile(path.."/max_lag.lua")
|
||||||
dofile(path.."/switching_station.lua")
|
dofile(path.."/switching_station.lua")
|
||||||
dofile(path.."/switching_station_globalstep.lua")
|
dofile(path.."/switching_station_globalstep.lua")
|
||||||
|
|
||||||
|
15
technic/machines/max_lag.lua
Normal file
15
technic/machines/max_lag.lua
Normal 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
|
@ -44,19 +44,33 @@ minetest.register_abm({
|
|||||||
end
|
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
|
-- iterate over all collected switching stations and execute the technic_run function
|
||||||
local timer = 0
|
local timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
if timer < 1.0 then
|
if timer < technic_run_interval then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
timer = 0
|
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 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 off_delay_micros = off_delay_seconds*1000*1000
|
||||||
|
|
||||||
local active_switches = 0
|
local active_switches = 0
|
||||||
|
|
||||||
for hash, switch in pairs(switches) do
|
for hash, switch in pairs(switches) do
|
||||||
@ -121,3 +135,12 @@ minetest.register_globalstep(function(dtime)
|
|||||||
|
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_chatcommand("technic_flush_switch_cache", {
|
||||||
|
description = "removes all loaded switching stations from the cache",
|
||||||
|
privs = { server = true },
|
||||||
|
func = function()
|
||||||
|
switches = {}
|
||||||
|
end
|
||||||
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user