diff options
author | fluxionary <25628292+fluxionary@users.noreply.github.com> | 2023-01-25 23:25:46 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-26 08:25:46 +0100 |
commit | 18155b3ebedd24fba5c3cbf109063f64f882d8a6 (patch) | |
tree | 5d5d67f8108aa963bb229ee3d282f0eb5a18ca1d /hud.lua | |
parent | 675e1e1943598893acf3d652caca18b0193746d9 (diff) | |
download | mesecons_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 'hud.lua')
-rw-r--r-- | hud.lua | 79 |
1 files changed, 41 insertions, 38 deletions
@@ -1,10 +1,7 @@ - local hud_refresh_interval = mesecons_debug.settings.hud_refresh_interval -mesecons_debug.settings._subscribe_for_modification("hud_refresh_interval", - function(value) hud_refresh_interval = value end) - -local HUD_POSITION = { x = 0.1, y = 0.8 } -local HUD_ALIGNMENT = { x = 1, y = 0 } +mesecons_debug.settings._subscribe_for_modification("hud_refresh_interval", function(value) + hud_refresh_interval = value +end) local hudid_by_playername = {} @@ -18,40 +15,34 @@ local function get_info(player) local ctx = mesecons_debug.get_context(pos) local total = mesecons_debug.avg_total_micros_per_second - if total == 0 then total = 1 end + if total == 0 then + total = 1 + end local percent = ctx.avg_micros_per_second * 100 / total - local txt = ("mesecons @ %s\n"):format( - minetest.pos_to_string(blockpos) - ) + local txt = ("mesecons @ %s\n"):format(minetest.pos_to_string(blockpos)) if ctx.whitelisted then txt = txt .. "whitelisted, no limits" return txt, 0x00FFFF end - txt = txt .. ("usage: %.0f us/s .. (%.1f%%) penalty: %.2fs"):format( - ctx.avg_micros_per_second, - percent, - ctx.penalty - ) - txt = txt .. ("\nlag: %.2f (%s); mesecons load = %s"):format( - mesecons_debug.avg_lag, - mesecons_debug.lag_level, - mesecons_debug.load_level - ) - if minetest.get_server_max_lag then - txt = txt .. ("; max_lag: %.2f"):format( - minetest.get_server_max_lag() + txt = txt .. ("usage: %.0f us/s .. (%.1f%%) penalty: %.2fs"):format(ctx.avg_micros_per_second, percent, ctx.penalty) + txt = txt + .. ("\nlag: %.2f (%s); mesecons load = %s"):format( + mesecons_debug.avg_lag, + mesecons_debug.lag_level, + mesecons_debug.load_level ) + if minetest.get_server_max_lag then + txt = txt .. ("; max_lag: %.2f"):format(minetest.get_server_max_lag()) end - txt = txt .. ("; #players = %i"):format( - #minetest.get_connected_players() - ) - txt = txt .. ("\npenalties enabled = %s; mesecons enabled = %s"):format( - mesecons_debug.enabled, - mesecons_debug.mesecons_enabled - ) + txt = txt .. ("; #players = %i"):format(#minetest.get_connected_players()) + txt = txt + .. ("\npenalties enabled = %s; mesecons enabled = %s"):format( + mesecons_debug.enabled, + mesecons_debug.mesecons_enabled + ) if ctx.penalty <= 1 then return txt, 0x00FF00 @@ -78,24 +69,36 @@ minetest.register_globalstep(function(dtime) if hud_enabled then local text, color = get_info(player) if hudid then - player:hud_change(hudid, "text", text) - player:hud_change(hudid, "number", color) - + local hud_def = player:hud_get(hudid) + if hud_def and hud_def.name == "mesecons_debug:hud" then + player:hud_change(hudid, "text", text) + player:hud_change(hudid, "number", color) + else + minetest.chat_send_player( + playername, + "[mesecons_debug] another mod removed your hud, you must re-enable it or possibly relog" + ) + hudid_by_playername[playername] = nil + mesecons_debug.hud_enabled_by_playername[playername] = nil + end else hudid_by_playername[playername] = player:hud_add({ + name = "mesecons_debug:hud", hud_elem_type = "text", - position = HUD_POSITION, + position = { x = 0.5, y = 0.8 }, + alignment = { x = 0, y = 0 }, offset = { x = 0, y = 0 }, + scale = { x = 100, y = 100 }, text = text, number = color, - alignment = HUD_ALIGNMENT, - scale = { x = 100, y = 100 }, }) end - else if hudid then - player:hud_remove(hudid) + local hud_def = player:hud_get(hudid) + if hud_def.name == "mesecons_debug:hud" then + player:hud_remove(hudid) + end hudid_by_playername[playername] = nil end end |