diff options
author | BuckarooBanzay <BuckarooBanzay@users.noreply.github.com> | 2020-10-28 15:39:14 +0100 |
---|---|---|
committer | BuckarooBanzay <BuckarooBanzay@users.noreply.github.com> | 2020-10-28 15:39:14 +0100 |
commit | 6c6068f38ba9e3f96867d2598938f381bbab7eac (patch) | |
tree | a8caf5f11237e2420ad451f10484a19d8a513015 | |
parent | d12f2651b50ad0a7214ce8337d84e36171bbde7c (diff) | |
download | mesecons_debug-6c6068f38ba9e3f96867d2598938f381bbab7eac.tar.gz mesecons_debug-6c6068f38ba9e3f96867d2598938f381bbab7eac.zip |
fix indents
Diffstat (limited to '')
-rw-r--r-- | chatcommands.lua | 2 | ||||
-rw-r--r-- | context.lua | 60 | ||||
-rw-r--r-- | functions.lua | 8 | ||||
-rw-r--r-- | hud.lua | 14 | ||||
-rw-r--r-- | luacontroller.lua | 18 | ||||
-rw-r--r-- | overrides.lua | 2 | ||||
-rw-r--r-- | whitelist.lua | 14 |
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 @@ -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() |