aboutsummaryrefslogtreecommitdiff
path: root/penalty.lua
diff options
context:
space:
mode:
authorfluxionary <25628292+fluxionary@users.noreply.github.com>2023-01-25 23:25:46 -0800
committerGitHub <noreply@github.com>2023-01-26 08:25:46 +0100
commit18155b3ebedd24fba5c3cbf109063f64f882d8a6 (patch)
tree5d5d67f8108aa963bb229ee3d282f0eb5a18ca1d /penalty.lua
parent675e1e1943598893acf3d652caca18b0193746d9 (diff)
downloadmesecons_debug-18155b3ebedd24fba5c3cbf109063f64f882d8a6.tar.gz
mesecons_debug-18155b3ebedd24fba5c3cbf109063f64f882d8a6.zip
some more updates (#9)
* 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 * update lag even when mesecons isn't active * tweak default settings * move hud so it doesn't interfere w/ areas * tweak default settings * put the HUD in a place which doesn't conflict w/ areas mod * ensure that actions have a valid position to avoid a crash * stylua * make sure we don't update the wrong HUD * spaces not tabs Co-authored-by: AliasAlreadyTaken <aliasalreadytaken@noreply.example.org3>
Diffstat (limited to 'penalty.lua')
-rw-r--r--penalty.lua56
1 files changed, 39 insertions, 17 deletions
diff --git a/penalty.lua b/penalty.lua
index 23f3e2f..beeaeac 100644
--- a/penalty.lua
+++ b/penalty.lua
@@ -2,9 +2,13 @@ local expected_dtime = tonumber(minetest.settings:get("dedicated_server_step"))
local subscribe_for_modification = mesecons_debug.settings._subscribe_for_modification
local max_penalty = mesecons_debug.settings.max_penalty
-subscribe_for_modification("max_penalty", function(value) max_penalty = value end)
+subscribe_for_modification("max_penalty", function(value)
+ max_penalty = value
+end)
local moderate_lag_ratio = mesecons_debug.settings.moderate_lag_ratio
-subscribe_for_modification("moderate_lag_ratio", function(value) moderate_lag_ratio = value end)
+subscribe_for_modification("moderate_lag_ratio", function(value)
+ moderate_lag_ratio = value
+end)
local high_lag_ratio = mesecons_debug.settings.high_lag_ratio
local high_lag_dtime = expected_dtime * high_lag_ratio
subscribe_for_modification("high_lag_ratio", function(value)
@@ -12,21 +16,37 @@ subscribe_for_modification("high_lag_ratio", function(value)
high_lag_dtime = expected_dtime * value
end)
local high_load_threshold = mesecons_debug.settings.high_load_threshold
-subscribe_for_modification("high_load_threshold", function(value) high_load_threshold = value end)
+subscribe_for_modification("high_load_threshold", function(value)
+ high_load_threshold = value
+end)
local penalty_check_steps = mesecons_debug.settings.penalty_check_steps
-subscribe_for_modification("penalty_check_steps", function(value) penalty_check_steps = value end)
+subscribe_for_modification("penalty_check_steps", function(value)
+ penalty_check_steps = value
+end)
local high_penalty_scale = mesecons_debug.settings.high_penalty_scale
-subscribe_for_modification("high_penalty_scale", function(value) high_penalty_scale = value end)
+subscribe_for_modification("high_penalty_scale", function(value)
+ high_penalty_scale = value
+end)
local high_penalty_offset = mesecons_debug.settings.high_penalty_offset
-subscribe_for_modification("high_penalty_offset", function(value) high_penalty_offset = value end)
+subscribe_for_modification("high_penalty_offset", function(value)
+ high_penalty_offset = value
+end)
local medium_penalty_scale = mesecons_debug.settings.medium_penalty_scale
-subscribe_for_modification("medium_penalty_scale", function(value) medium_penalty_scale = value end)
+subscribe_for_modification("medium_penalty_scale", function(value)
+ medium_penalty_scale = value
+end)
local medium_penalty_offset = mesecons_debug.settings.medium_penalty_offset
-subscribe_for_modification("medium_penalty_offset", function(value) medium_penalty_offset = value end)
+subscribe_for_modification("medium_penalty_offset", function(value)
+ medium_penalty_offset = value
+end)
local low_penalty_scale = mesecons_debug.settings.low_penalty_scale
-subscribe_for_modification("low_penalty_scale", function(value) low_penalty_scale = value end)
+subscribe_for_modification("low_penalty_scale", function(value)
+ low_penalty_scale = value
+end)
local low_penalty_offset = mesecons_debug.settings.low_penalty_offset
-subscribe_for_modification("low_penalty_offset", function(value) low_penalty_offset = value end)
+subscribe_for_modification("low_penalty_offset", function(value)
+ low_penalty_offset = value
+end)
local relative_load_max = mesecons_debug.settings.relative_load_clamp
local relative_load_min = 1 / mesecons_debug.settings.relative_load_clamp
subscribe_for_modification("relative_load_clamp", function(value)
@@ -35,7 +55,9 @@ subscribe_for_modification("relative_load_clamp", function(value)
end)
-- see https://en.wikipedia.org/w/index.php?title=Moving_average&oldid=1069105690#Exponential_moving_average
local averaging_coefficient = mesecons_debug.settings.averaging_coefficient
-subscribe_for_modification("averaging_coefficient", function(value) averaging_coefficient = value end)
+subscribe_for_modification("averaging_coefficient", function(value)
+ averaging_coefficient = value
+end)
local max = math.max
local min = math.min
@@ -56,8 +78,8 @@ local has_monitoring = mesecons_debug.has.monitoring
local mapblock_count, penalized_mapblock_count
if has_monitoring then
mapblock_count = monitoring.gauge("mesecons_debug_mapblock_count", "count of tracked mapblocks")
- penalized_mapblock_count = monitoring.gauge("mesecons_debug_penalized_mapblock_count",
- "count of penalized mapblocks")
+ penalized_mapblock_count =
+ monitoring.gauge("mesecons_debug_penalized_mapblock_count", "count of penalized mapblocks")
end
local elapsed_steps = 0
@@ -76,11 +98,11 @@ minetest.register_globalstep(function(dtime)
return
end
- local context_store_size = mesecons_debug.context_store_size -- # of blocks w/ active mesecons
+ local context_store_size = mesecons_debug.context_store_size -- # of blocks w/ active mesecons
local total_micros = mesecons_debug.total_micros
local total_micros_per_second = total_micros / elapsed
- local avg_total_micros_per_second = update_average(total_micros_per_second,
- mesecons_debug.avg_total_micros_per_second)
+ local avg_total_micros_per_second =
+ update_average(total_micros_per_second, mesecons_debug.avg_total_micros_per_second)
mesecons_debug.avg_total_micros_per_second = avg_total_micros_per_second
-- how much lag is there?
@@ -134,7 +156,7 @@ minetest.register_globalstep(function(dtime)
-- avg load per active context
local avg_avg_micros_per_second = avg_total_micros_per_second / context_store_size
- local penalized_count = 0 -- for monitoring
+ local penalized_count = 0 -- for monitoring
for _, ctx in pairs(mesecons_debug.context_store) do
if not ctx.whitelisted then
-- moving avg