aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chatcommands.lua2
-rw-r--r--context.lua60
-rw-r--r--functions.lua8
-rw-r--r--hud.lua14
-rw-r--r--luacontroller.lua18
-rw-r--r--overrides.lua2
-rw-r--r--whitelist.lua14
7 files changed, 60 insertions, 58 deletions
diff --git a/chatcommands.lua b/chatcommands.lua
index c48348e..87b7845 100644
--- a/chatcommands.lua
+++ b/chatcommands.lua
@@ -23,7 +23,7 @@ minetest.register_chatcommand("mesecons_stats", {
local ctx = mesecons_debug.get_context(player:get_pos())
return true, "Mapblock usage: " .. ctx.avg_micros .. " us/s " ..
- "(across " .. mesecons_debug.context_store_size .." mapblocks)"
+ "(across " .. mesecons_debug.context_store_size .." mapblocks)"
end
})
diff --git a/context.lua b/context.lua
index 6c6203c..5c08ae5 100644
--- a/context.lua
+++ b/context.lua
@@ -12,46 +12,46 @@ end
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]
- if not ctx then
- -- create a new context
- ctx = {
- -- usage in us
- micros = 0,
- -- average micros per second
- avg_micros = 0,
- -- time penalty
- penalty = 0,
+ local blockpos = mesecons_debug.get_blockpos(pos)
+ local hash = minetest.hash_node_position(blockpos)
+
+ local ctx = context_store[hash]
+ if not ctx then
+ -- create a new context
+ ctx = {
+ -- usage in us
+ micros = 0,
+ -- average micros per second
+ avg_micros = 0,
+ -- time penalty
+ penalty = 0,
-- mtime
mtime = minetest.get_us_time(),
- }
- context_store[hash] = ctx
- end
+ }
+ context_store[hash] = ctx
+ end
-- update context
-- whitelist flag
ctx.whitelisted = mesecons_debug.whitelist[hash]
- return ctx
+ return ctx
end
local timer = 0
minetest.register_globalstep(function(dtime)
- timer = timer + dtime
- if timer < 1 then return end
- timer=0
+ timer = timer + dtime
+ if timer < 1 then return end
+ timer=0
local penalized_count = 0
local now = minetest.get_us_time()
local cleanup_time_micros = 300 * 1000 * 1000
- mesecons_debug.context_store_size = 0
- for hash, ctx in pairs(context_store) do
+ mesecons_debug.context_store_size = 0
+ for hash, ctx in pairs(context_store) do
local time_diff = now - ctx.mtime
if time_diff > cleanup_time_micros then
-- remove item
@@ -60,22 +60,22 @@ minetest.register_globalstep(function(dtime)
else
-- calculate stuff
ctx.avg_micros = math.floor((ctx.avg_micros * 0.9) + (ctx.micros * 0.1))
- ctx.micros = 0
- if ctx.avg_micros > mesecons_debug.max_usage_micros then
+ ctx.micros = 0
+ if ctx.avg_micros > mesecons_debug.max_usage_micros then
-- add penalty
- ctx.penalty = math.min(ctx.penalty + 0.1, 20)
- elseif ctx.penalty > 0 then
+ ctx.penalty = math.min(ctx.penalty + 0.1, 20)
+ elseif ctx.penalty > 0 then
-- remove penalty (slowly)
- ctx.penalty = math.max(ctx.penalty - 0.01, 0)
- end
+ ctx.penalty = math.max(ctx.penalty - 0.01, 0)
+ end
- mesecons_debug.context_store_size = mesecons_debug.context_store_size + 1
+ mesecons_debug.context_store_size = mesecons_debug.context_store_size + 1
if ctx.penalty > 0 then
penalized_count = penalized_count + 1
end
end
- end
+ end
if has_monitoring then
mapblock_count.set(mesecons_debug.context_store_size)
diff --git a/functions.lua b/functions.lua
index 83887f8..d68396d 100644
--- a/functions.lua
+++ b/functions.lua
@@ -1,7 +1,9 @@
function mesecons_debug.get_blockpos(pos)
- return {x = math.floor(pos.x / 16),
- y = math.floor(pos.y / 16),
- z = math.floor(pos.z / 16)}
+ return {
+ x = math.floor(pos.x / 16),
+ y = math.floor(pos.y / 16),
+ z = math.floor(pos.z / 16)
+ }
end
diff --git a/hud.lua b/hud.lua
index fff431c..c769d37 100644
--- a/hud.lua
+++ b/hud.lua
@@ -43,8 +43,8 @@ local function get_info(player)
end
txt = txt ..
- " usage: " .. ctx.avg_micros .. " us/s .. (" .. percent .. "%) " ..
- "penalty: " .. math.floor(ctx.penalty*10)/10 .. " s"
+ " usage: " .. ctx.avg_micros .. " us/s .. (" .. percent .. "%) " ..
+ "penalty: " .. math.floor(ctx.penalty*10)/10 .. " s"
if ctx.penalty <= 0.1 then
return txt, 0x00FF00
@@ -57,11 +57,11 @@ end
local timer = 0
minetest.register_globalstep(function(dtime)
- timer = timer + dtime
- if timer < 1 then
- return
- end
- timer = 0
+ timer = timer + dtime
+ if timer < 1 then
+ return
+ end
+ timer = 0
for _, player in ipairs(minetest.get_connected_players()) do
local playername = player:get_player_name()
diff --git a/luacontroller.lua b/luacontroller.lua
index 615e4c6..c143bdc 100644
--- a/luacontroller.lua
+++ b/luacontroller.lua
@@ -29,15 +29,15 @@ end
-- luaC
local BASENAME = "mesecons_luacontroller:luacontroller"
for a = 0, 1 do -- 0 = off 1 = on
-for b = 0, 1 do
-for c = 0, 1 do
-for d = 0, 1 do
- local cid = tostring(d)..tostring(c)..tostring(b)..tostring(a)
- local node_name = BASENAME..cid
- override_node_timer(node_name)
-end
-end
-end
+ for b = 0, 1 do
+ for c = 0, 1 do
+ for d = 0, 1 do
+ local cid = tostring(d)..tostring(c)..tostring(b)..tostring(a)
+ local node_name = BASENAME..cid
+ override_node_timer(node_name)
+ end
+ end
+ end
end
-- blinky
diff --git a/overrides.lua b/overrides.lua
index d68fce3..21bf3b2 100644
--- a/overrides.lua
+++ b/overrides.lua
@@ -10,7 +10,7 @@ mesecon.queue.execute = function(self, action)
local ctx = mesecons_debug.get_context(action.pos)
ctx.micros = ctx.micros + micros
- ctx.mtime = t0
+ ctx.mtime = t0
--print("execute() func=" .. action.func .. " pos=" .. minetest.pos_to_string(action.pos) .. " micros=" .. micros)
end
diff --git a/whitelist.lua b/whitelist.lua
index b1a4046..3b713f0 100644
--- a/whitelist.lua
+++ b/whitelist.lua
@@ -2,13 +2,13 @@ local filename = minetest.get_worldpath() .. "/mesecons_debug_whiltelist"
function mesecons_debug.save_whitelist()
local file = io.open(filename,"w")
- local data = minetest.serialize(mesecons_debug.whitelist)
- if file and file:write(data) and file:close() then
- return
- else
- minetest.log("error","mesecons_debug: save failed")
- return
- end
+ local data = minetest.serialize(mesecons_debug.whitelist)
+ if file and file:write(data) and file:close() then
+ return
+ else
+ minetest.log("error","mesecons_debug: save failed")
+ return
+ end
end
function mesecons_debug.load_whitelist()