mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Use a settings object for the main settings
This unifies the settings APIs. This also unifies the sync and async registration APIs, since the async registration API did not support adding non-functions to the API table.
This commit is contained in:
parent
a024042bf5
commit
43d1f375d1
46 changed files with 411 additions and 417 deletions
|
@ -17,8 +17,9 @@
|
|||
|
||||
local format, pairs, type = string.format, pairs, type
|
||||
local core, get_current_modname = core, core.get_current_modname
|
||||
local profiler, sampler = ...
|
||||
local instrument_builtin = core.setting_getbool("instrument.builtin") or false
|
||||
local profiler, sampler, get_bool_default = ...
|
||||
|
||||
local instrument_builtin = get_bool_default("instrument.builtin", false)
|
||||
|
||||
local register_functions = {
|
||||
register_globalstep = 0,
|
||||
|
@ -137,7 +138,7 @@ local function instrument_register(func, func_name)
|
|||
end
|
||||
|
||||
local function init_chatcommand()
|
||||
if core.setting_getbool("instrument.chatcommand") or true then
|
||||
if get_bool_default("instrument.chatcommand", true) then
|
||||
local orig_register_chatcommand = core.register_chatcommand
|
||||
core.register_chatcommand = function(cmd, def)
|
||||
def.func = instrument {
|
||||
|
@ -153,8 +154,7 @@ end
|
|||
-- Start instrumenting selected functions
|
||||
--
|
||||
local function init()
|
||||
local is_set = core.setting_getbool
|
||||
if is_set("instrument.entity") or true then
|
||||
if get_bool_default("instrument.entity", true) then
|
||||
-- Explicitly declare entity api-methods.
|
||||
-- Simple iteration would ignore lookup via __index.
|
||||
local entity_instrumentation = {
|
||||
|
@ -180,7 +180,7 @@ local function init()
|
|||
end
|
||||
end
|
||||
|
||||
if is_set("instrument.abm") or true then
|
||||
if get_bool_default("instrument.abm", true) then
|
||||
-- Wrap register_abm() to automatically instrument abms.
|
||||
local orig_register_abm = core.register_abm
|
||||
core.register_abm = function(spec)
|
||||
|
@ -193,7 +193,7 @@ local function init()
|
|||
end
|
||||
end
|
||||
|
||||
if is_set("instrument.lbm") or true then
|
||||
if get_bool_default("instrument.lbm", true) then
|
||||
-- Wrap register_lbm() to automatically instrument lbms.
|
||||
local orig_register_lbm = core.register_lbm
|
||||
core.register_lbm = function(spec)
|
||||
|
@ -206,13 +206,13 @@ local function init()
|
|||
end
|
||||
end
|
||||
|
||||
if is_set("instrument.global_callback") or true then
|
||||
if get_bool_default("instrument.global_callback", true) then
|
||||
for func_name, _ in pairs(register_functions) do
|
||||
core[func_name] = instrument_register(core[func_name], func_name)
|
||||
end
|
||||
end
|
||||
|
||||
if is_set("instrument.profiler") or false then
|
||||
if get_bool_default("instrument.profiler", false) then
|
||||
-- Measure overhead of instrumentation, but keep it down for functions
|
||||
-- So keep the `return` for better optimization.
|
||||
profiler.empty_instrument = instrument {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue