technic-cd2025/technic/max_lag.lua
OgelGames 86c50dc955 Fix and improve max_lag (#193)
* Monitor max lag from mod
* Add new max lag for technic_get_active_networks command

Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com>
2021-07-12 00:28:20 +10:00

24 lines
488 B
Lua

local multiplier = technic.config:get_int("max_lag_reduction_multiplier")
local last_step = minetest.get_us_time()
local max_lag = 0
minetest.register_globalstep(function()
-- Calculate own dtime as a workaround to 2 second limit
local now = minetest.get_us_time()
local dtime = now - last_step
last_step = now
max_lag = max_lag * multiplier -- Decrease slowly
if dtime > max_lag then
max_lag = dtime
end
end)
function technic.get_max_lag()
return max_lag / 1000000
end