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 --- cleanup.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 cleanup.lua (limited to 'cleanup.lua') diff --git a/cleanup.lua b/cleanup.lua new file mode 100644 index 0000000..69bd20c --- /dev/null +++ b/cleanup.lua @@ -0,0 +1,29 @@ +local subscribe_for_modification = mesecons_debug.settings._subscribe_for_modification +local gc_interval = mesecons_debug.settings.gc_interval +local cleanup_time_micros = gc_interval * 1000000 + +subscribe_for_modification("gc_interval", function(value) + gc_interval = value + cleanup_time_micros = value * 1000000 +end) + +local context_store = mesecons_debug.context_store + +local cleanup_timer = 0 +minetest.register_globalstep(function(dtime) + cleanup_timer = cleanup_timer + dtime + if cleanup_timer < gc_interval then + return + end + cleanup_timer = 0 + + local now = minetest.get_us_time() + for hash, ctx in pairs(context_store) do + local time_diff = now - ctx.mtime + if time_diff > cleanup_time_micros then + -- remove item + context_store[hash] = nil + mesecons_debug.context_store_size = mesecons_debug.context_store_size - 1 + end + end +end) -- cgit v1.2.3