From 2651262fa3134415f349f63840c89486fabd9063 Mon Sep 17 00:00:00 2001 From: fluxionary <25628292+fluxionary@users.noreply.github.com> Date: Sun, 13 Feb 2022 06:54:41 -0800 Subject: 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 --- commands/user_commands.lua | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 commands/user_commands.lua (limited to 'commands/user_commands.lua') 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 +}) + -- cgit v1.2.3