aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBuckarooBanzay <BuckarooBanzay@users.noreply.github.com>2020-10-28 15:41:10 +0100
committerBuckarooBanzay <BuckarooBanzay@users.noreply.github.com>2020-10-28 15:41:10 +0100
commitfbf6777c299b665884875e2afe76f791c8f7ab74 (patch)
tree1885423887c4d74c05903b674151f9096d402eaa
parent6c6068f38ba9e3f96867d2598938f381bbab7eac (diff)
downloadmesecons_debug-fbf6777c299b665884875e2afe76f791c8f7ab74.tar.gz
mesecons_debug-fbf6777c299b665884875e2afe76f791c8f7ab74.zip
globalize context data
-rw-r--r--context.lua12
-rw-r--r--init.lua2
2 files changed, 6 insertions, 8 deletions
diff --git a/context.lua b/context.lua
index 5c08ae5..7e70c1c 100644
--- a/context.lua
+++ b/context.lua
@@ -7,15 +7,11 @@ if has_monitoring then
penalized_mapblock_count = monitoring.gauge("mesecons_debug_penalized_mapblock_count", "count of penalized mapblocks")
end
-
--- blockpos-hash => context
-local context_store = {}
-
mesecons_debug.get_context = function(pos)
local blockpos = mesecons_debug.get_blockpos(pos)
local hash = minetest.hash_node_position(blockpos)
- local ctx = context_store[hash]
+ local ctx = mesecons_debug.context_store[hash]
if not ctx then
-- create a new context
ctx = {
@@ -29,7 +25,7 @@ mesecons_debug.get_context = function(pos)
-- mtime
mtime = minetest.get_us_time(),
}
- context_store[hash] = ctx
+ mesecons_debug.context_store[hash] = ctx
end
-- update context
@@ -51,11 +47,11 @@ minetest.register_globalstep(function(dtime)
local cleanup_time_micros = 300 * 1000 * 1000
mesecons_debug.context_store_size = 0
- for hash, ctx in pairs(context_store) do
+ for hash, ctx in pairs(mesecons_debug.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[hash] = nil
else
-- calculate stuff
diff --git a/init.lua b/init.lua
index 365c728..a359583 100644
--- a/init.lua
+++ b/init.lua
@@ -2,6 +2,8 @@ local MP = minetest.get_modpath("mesecons_debug")
mesecons_debug = {
enabled = true,
+ -- blockpos-hash => context
+ context_store = {},
context_store_size = 0,
-- mapblock-hash -> true