Update lag-hud (#8)

* add proper settings (untested)

* more constants -> settings

* normalize whitespace between code files

* refactor globalsteps in order to simplify logic

* minor refactoring

* rename file

* use mod_storage for persistent data; optimize context initialization

* refactoring (moving files around)

* rewrite penalty

* add settings; document; allow changing while game is running

* add command to update settings

* update init after splitting commands into files

* fix bugs; add debugging tools; too much for one commit...

* fix whitelist conversion

* add adjustable blinky plant to timer overrides

* add some more mesecons nodes with repeating timers

* resolve luacheck warnings

* tweak hud

* Update documentation; parameterize more things; refactor some logic for readability

* update lag even when mesecons isn't active
This commit is contained in:
fluxionary 2022-05-15 21:55:33 -07:00 committed by GitHub
parent 2651262fa3
commit 675e1e1943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,15 +83,6 @@ minetest.register_globalstep(function(dtime)
mesecons_debug.avg_total_micros_per_second)
mesecons_debug.avg_total_micros_per_second = avg_total_micros_per_second
if context_store_size == 0 or avg_total_micros_per_second == 0 then
-- nothing to do, but reset counters
elapsed = 0
elapsed_steps = 0
mesecons_debug.total_micros = 0
return
end
-- how much lag is there?
local lag = elapsed / (elapsed_steps * expected_dtime)
local avg_lag = update_average(lag, mesecons_debug.avg_lag)
@ -99,25 +90,33 @@ minetest.register_globalstep(function(dtime)
local is_high_lag = avg_lag > high_lag_ratio
local is_moderate_lag = avg_lag > moderate_lag_ratio
-- for use by HUD
if is_high_lag then
mesecons_debug.lag_level = "high"
elseif is_moderate_lag then
mesecons_debug.lag_level = "moderate"
else
mesecons_debug.lag_level = "low"
end
if context_store_size == 0 or avg_total_micros_per_second == 0 then
-- nothing to do, but reset counters
elapsed = 0
elapsed_steps = 0
mesecons_debug.total_micros = 0
mesecons_debug.load_level = "none"
return
end
-- how much of the lag was mesecons?
local mesecons_load = avg_total_micros_per_second / 1000000
local is_high_load = mesecons_load > high_load_threshold
-- for use by HUD
if is_high_lag then
mesecons_debug.lag_level = 'high'
elseif is_moderate_lag then
mesecons_debug.lag_level = 'moderate'
else
mesecons_debug.lag_level = 'low'
end
-- for use by HUD
if is_high_load then
mesecons_debug.load_level = 'high'
mesecons_debug.load_level = "high"
else
mesecons_debug.load_level = 'low'
mesecons_debug.load_level = "low"
end
local penalty_scale, penalty_offset