diff options
author | fluxionary <25628292+fluxionary@users.noreply.github.com> | 2022-02-13 06:54:41 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-13 15:54:41 +0100 |
commit | 2651262fa3134415f349f63840c89486fabd9063 (patch) | |
tree | 3fa7f2ac228e662b4e9bc8071acc2f0650c44e65 /context.lua | |
parent | 1a41379e1d7ae69347f0e6ee6a997234f7590793 (diff) | |
download | mesecons_debug-2651262fa3134415f349f63840c89486fabd9063.tar.gz mesecons_debug-2651262fa3134415f349f63840c89486fabd9063.zip |
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
Diffstat (limited to '')
-rw-r--r-- | context.lua | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/context.lua b/context.lua index cf9b343..5f22100 100644 --- a/context.lua +++ b/context.lua @@ -1,30 +1,27 @@ +local storage = mesecons_debug.storage -- returns the context data for the node-position mesecons_debug.get_context = function(pos) - local blockpos = mesecons_debug.get_blockpos(pos) - local hash = minetest.hash_node_position(blockpos) + local hash = mesecons_debug.hashpos(pos) + local ctx = mesecons_debug.context_store[hash] - local ctx = mesecons_debug.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, + if not ctx then + -- create a new context + ctx = { + -- usage in us + micros = 0, + -- "running average" micros per second + avg_micros_per_second = 0, + -- time penalty + penalty = 0, + -- modification time + mtime = minetest.get_us_time(), + -- whitelist status + whitelisted = storage:contains(hash) + } + mesecons_debug.context_store[hash] = ctx + mesecons_debug.context_store_size = mesecons_debug.context_store_size + 1 + end - -- mtime - mtime = minetest.get_us_time(), - } - mesecons_debug.context_store[hash] = ctx - end - - -- update context - - -- whitelist flag - ctx.whitelisted = mesecons_debug.whitelist[hash] - - return ctx + return ctx end |