diff options
author | fluxionary <25628292+fluxionary@users.noreply.github.com> | 2022-02-13 06:54:41 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-13 15:54:41 +0100 |
commit | 2651262fa3134415f349f63840c89486fabd9063 (patch) | |
tree | 3fa7f2ac228e662b4e9bc8071acc2f0650c44e65 /commands/user_commands.lua | |
parent | 1a41379e1d7ae69347f0e6ee6a997234f7590793 (diff) | |
download | mesecons_debug-2651262fa3134415f349f63840c89486fabd9063.tar.gz mesecons_debug-2651262fa3134415f349f63840c89486fabd9063.zip |
rework mesecons debug to be more flexible (#7)
* 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
Diffstat (limited to 'commands/user_commands.lua')
-rw-r--r-- | commands/user_commands.lua | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/commands/user_commands.lua b/commands/user_commands.lua new file mode 100644 index 0000000..5836373 --- /dev/null +++ b/commands/user_commands.lua @@ -0,0 +1,60 @@ +minetest.register_chatcommand("mesecons_hud", { + description = "mesecons_hud toggle", + func = function(name) + local enabled = (not mesecons_debug.hud_enabled_by_playername[name]) or nil + mesecons_debug.hud_enabled_by_playername[name] = enabled + if enabled then + return true, "mesecons hud enabled" + else + return true, "mesecons hud disabled" + end + end +}) + +minetest.register_chatcommand("mesecons_global_stats", { + description = "shows the global mesecons stats", + func = function() + local top_ctx, top_hash + + for hash, ctx in pairs(mesecons_debug.context_store) do + if not top_ctx or top_ctx.avg_micros_per_second < ctx.avg_micros_per_second then + -- store context with the most average time + top_ctx = ctx + top_hash = hash + end + end + + local txt + if top_ctx then + txt = ( + "Most prominent mesecons usage at mapblock %s" .. + " with %f seconds penalty and %i us average use" + ):format( + minetest.pos_to_string(minetest.get_position_from_hash(top_hash)), + top_ctx.penalty, + top_ctx.avg_micros_per_second + ) + else + txt = "no context available" + end + + return true, txt + end +}) + +minetest.register_chatcommand("mesecons_stats", { + description = "shows some mesecons stats for the current position", + func = function(name) + local player = minetest.get_player_by_name(name) + if not player then + return + end + + local ctx = mesecons_debug.get_context(player:get_pos()) + return true, ("Mapblock usage: %i us/s (across %i mapblocks)"):format( + ctx.avg_micros_per_second, + mesecons_debug.context_store_size + ) + end +}) + |