From 18155b3ebedd24fba5c3cbf109063f64f882d8a6 Mon Sep 17 00:00:00 2001 From: fluxionary <25628292+fluxionary@users.noreply.github.com> Date: Wed, 25 Jan 2023 23:25:46 -0800 Subject: some more updates (#9) * 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 * update lag even when mesecons isn't active * update lag even when mesecons isn't active * tweak default settings * move hud so it doesn't interfere w/ areas * tweak default settings * put the HUD in a place which doesn't conflict w/ areas mod * ensure that actions have a valid position to avoid a crash * stylua * make sure we don't update the wrong HUD * spaces not tabs Co-authored-by: AliasAlreadyTaken --- .github/workflows/luacheck.yml | 17 - .github/workflows/pre-commit.yml | 31 ++ .luacheckrc | 667 ++++++++++++++++++++++++++++++++++++++- .pre-commit-config.yaml | 25 ++ .stylua.toml | 1 + README.md | 43 +-- commands/admin_commands.lua | 26 +- commands/clear_penalty.lua | 6 +- commands/create_lag.lua | 3 +- commands/flush.lua | 2 +- commands/user_commands.lua | 25 +- context.lua | 2 +- hud.lua | 79 ++--- init.lua | 6 +- mod.conf | 15 +- nodes/mesecons_lagger.lua | 15 +- nodes/penalty_controller.lua | 12 +- overrides/mesecons_queue.lua | 17 +- overrides/node_timers.lua | 1 - penalty.lua | 56 +++- privs.lua | 2 +- settings.lua | 12 +- settingtypes.txt | 12 +- util.lua | 12 +- 24 files changed, 901 insertions(+), 186 deletions(-) delete mode 100644 .github/workflows/luacheck.yml create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .pre-commit-config.yaml create mode 100644 .stylua.toml diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml deleted file mode 100644 index 1d24ecc..0000000 --- a/.github/workflows/luacheck.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: luacheck - -on: [pull_request, push] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - name: apt - run: sudo apt-get install -y luarocks - - name: luacheck install - run: luarocks install --local luacheck - - name: luacheck run - run: $HOME/.luarocks/bin/luacheck ./ diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..37221d7 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,31 @@ +name: pre-commit +on: [push, pull_request, workflow_dispatch] + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@master + - uses: actions/setup-python@master + + - name: install luarocks + run: sudo apt-get install -y luarocks + + - name: add luarocks path + run: echo "$HOME/.luarocks/bin" >> $GITHUB_PATH + + - name: luacheck install + run: luarocks install --local luacheck + + - name: install cargo + run: sudo apt-get install -y cargo + + - name: install stylua + run: cargo install stylua + + - name: Install pre-commit + run: pip3 install pre-commit + + - name: Run pre-commit + run: pre-commit run --all-files diff --git a/.luacheckrc b/.luacheckrc index 61bc753..ae77756 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,21 +1,658 @@ +std = "lua51+luajit+minetest+mesecons_debug" +unused_args = false +max_line_length = 120 -ignore = {"212/_.*"} +stds.minetest = { + read_globals = { + "DIR_DELIM", + "dump", + "dump2", -globals = { - "mesecons_debug", - "mesecon", - "minetest" -} + math = { + fields = { + abs = {}, + acos = {}, + asin = {}, + atan = {}, + atan2 = {}, + ceil = {}, + cos = {}, + cosh = {}, + deg = {}, + exp = {}, + factorial = {}, + floor = {}, + fmod = {}, + frexp = {}, + huge = {}, + hypot = {}, + ldexp = {}, + log = {}, + log10 = {}, + max = {}, + min = {}, + modf = {}, + pi = {}, + pow = {}, + rad = {}, + random = {}, + randomseed = {}, + round = {}, + sign = {}, + sin = {}, + sinh = {}, + sqrt = {}, + tan = {}, + tanh = {}, + }, + }, + table = { + fields = { + copy = {}, + concat = {}, + foreach = {}, + foreachi = {}, + getn = {}, + indexof = {}, + insert = {}, + insert_all = {}, + key_value_swap = {}, + maxn = {}, + move = {}, + remove = {}, + shuffle = {}, + sort = {}, + }, + }, + string = { + fields = { + byte = {}, + char = {}, + dump = {}, + find = {}, + format = {}, + gmatch = {}, + len = {}, + lower = {}, + match = {}, + rep = {}, + reverse = {}, + split = {}, + sub = {}, + trim = {}, + upper = {}, + }, + }, + vector = { + fields = { + add = {}, + angle = {}, + apply = {}, + check = {}, + combine = {}, + copy = {}, + cross = {}, + dir_to_rotation = {}, + direction = {}, + distance = {}, + divide = {}, + dot = {}, + equals = {}, + floor = {}, + from_string = {}, + length = {}, + metatable = {}, + multiply = {}, + new = {}, + normalize = {}, + offset = {}, + rotate = {}, + rotate_around_axis = {}, + round = {}, + sort = {}, + subtract = {}, + to_string = {}, + zero = {}, + }, + }, -read_globals = { - -- Stdlib - string = {fields = {"split"}}, - table = {fields = {"copy", "getn"}}, + ItemStack = { + fields = { + add_item = {}, + add_wear = {}, + add_wear_by_uses = {}, + clear = {}, + get_count = {}, + get_definition = {}, + get_description = {}, + get_free_space = {}, + get_meta = {}, + get_metadata = {}, + get_name = {}, + get_short_description = {}, + get_stack_max = {}, + get_tool_capabilities = {}, + get_wear = {}, + is_empty = {}, + is_known = {}, + item_fits = {}, + peek_item = {}, + replace = {}, + set_count = {}, + set_metadata = {}, + set_name = {}, + set_wear = {}, + take_item = {}, + to_string = {}, + to_table = {}, + }, + }, + PerlinNoise = { + fields = { + get_2d = {}, + get_3d = {}, + }, + }, + PerlinNoiseMap = { + fields = { + calc_2d_map = {}, + calc_3d_map = {}, + get_2d_map = {}, + get_2d_map_flat = {}, + get_3d_map = {}, + get_3d_map_flat = {}, + get_map_slice = {}, + }, + }, + PseudoRandom = { + fields = { + next = {}, + }, + }, + PcgRandom = { + fields = { + next = {}, + rand_normal_dist = {}, + }, + }, + SecureRandom = { + fields = { + next_bytes = {}, + }, + }, + Settings = { + fields = { + get = {}, + get_bool = {}, + get_flags = {}, + get_names = {}, + get_np_group = {}, + remove = {}, + set = {}, + set_bool = {}, + set_np_group = {}, + to_table = {}, + write = {}, + }, + }, + VoxelArea = { + fields = { + MaxEdge = {}, + MinEdge = {}, + contains = {}, + containsi = {}, + containsp = {}, + getExtent = {}, + getVolume = {}, + index = {}, + indexp = {}, + iter = {}, + iterp = {}, + new = {}, + position = {}, + ystride = {}, + zstride = {}, + }, + }, + VoxelManip = { + fields = { + calc_lighting = {}, + get_data = {}, + get_emerged_area = {}, + get_light_data = {}, + get_node_at = {}, + get_param2_data = {}, + read_from_map = {}, + set_data = {}, + set_light_data = {}, + set_lighting = {}, + set_node_at = {}, + set_param2_data = {}, + update_liquids = {}, + update_map = {}, + was_modified = {}, + write_to_map = {}, + }, + }, - -- Minetest - "vector", "ItemStack", - "dump", + minetest = { + fields = { + CONTENT_AIR = {}, + CONTENT_IGNORE = {}, + CONTENT_UNKNOWN = {}, + EMERGE_CANCELLED = {}, + EMERGE_ERRORED = {}, + EMERGE_FROM_DISK = {}, + EMERGE_FROM_MEMORY = {}, + EMERGE_GENERATED = {}, + LIGHT_MAX = {}, + MAP_BLOCKSIZE = {}, + PLAYER_MAX_BREATH_DEFAULT = {}, + PLAYER_MAX_HP_DEFAULT = {}, + add_entity = {}, + add_item = {}, + add_node = {}, + add_node_level = {}, + add_particle = {}, + add_particlespawner = {}, + after = {}, + async_event_handler = {}, + async_jobs = {}, + auth_reload = {}, + ban_player = {}, + builtin_auth_handler = {}, + bulk_set_node = {}, + calculate_knockback = {}, + callback_origins = {}, + cancel_shutdown_requests = {}, + chat_send_all = {}, + chat_send_player = {}, + chatcommands = {}, + check_for_falling = {}, + check_password_entry = {}, + check_player_privs = {}, + check_single_for_falling = {}, + clear_craft = {}, + clear_objects = {}, + clear_registered_biomes = {}, + clear_registered_decorations = {}, + clear_registered_ores = {}, + clear_registered_schematics = {}, + close_formspec = {}, + colorize = {}, + colorspec_to_bytes = {}, + colorspec_to_colorstring = {}, + compare_block_status = {}, + compress = {}, + cpdir = {}, + craft_predict = {}, + craftitemdef_default = {}, + create_detached_inventory = {}, + create_detached_inventory_raw = {}, + create_schematic = {}, + debug = {}, + decode_base64 = {}, + decompress = {}, + delete_area = {}, + delete_particlespawner = {}, + deserialize = {}, + detached_inventories = {}, + dig_node = {}, + dir_to_facedir = {}, + dir_to_wallmounted = {}, + dir_to_yaw = {}, + disconnect_player = {}, + do_async_callback = {}, + do_item_eat = {}, + dynamic_add_media = {}, + dynamic_media_callbacks = {}, + emerge_area = {}, + encode_base64 = {}, + encode_png = {}, + env = {}, + explode_scrollbar_event = {}, + explode_table_event = {}, + explode_textlist_event = {}, + facedir_to_dir = {}, + features = {}, + find_node_near = {}, + find_nodes_in_area = {}, + find_nodes_in_area_under_air = {}, + find_nodes_with_meta = {}, + find_path = {}, + fix_light = {}, + forceload_block = {}, + forceload_free_block = {}, + format_chat_message = {}, + formspec_escape = {}, + generate_decorations = {}, + generate_ores = {}, + get_all_craft_recipes = {}, + get_artificial_light = {}, + get_auth_handler = {}, + get_background_escape_sequence = {}, + get_ban_description = {}, + get_ban_list = {}, + get_biome_data = {}, + get_biome_id = {}, + get_biome_name = {}, + get_builtin_path = {}, + get_color_escape_sequence = {}, + get_connected_players = {}, + get_content_id = {}, + get_craft_recipe = {}, + get_craft_result = {}, + get_current_modname = {}, + get_day_count = {}, + get_decoration_id = {}, + get_dig_params = {}, + get_dir_list = {}, + get_gametime = {}, + get_gen_notify = {}, + get_heat = {}, + get_hit_params = {}, + get_humidity = {}, + get_inventory = {}, + get_item_group = {}, + get_last_run_mod = {}, + get_mapgen_object = {}, + get_mapgen_params = {}, + get_mapgen_setting = {}, + get_mapgen_setting_noiseparams = {}, + get_meta = {}, + get_mod_storage = {}, + get_modnames = {}, + get_modpath = {}, + get_name_from_content_id = {}, + get_natural_light = {}, + get_node = {}, + get_node_drops = {}, + get_node_group = {}, + get_node_level = {}, + get_node_light = {}, + get_node_max_level = {}, + get_node_or_nil = {}, + get_node_timer = {}, + get_noiseparams = {}, + get_objects_in_area = {}, + get_objects_inside_radius = {}, + get_password_hash = {}, + get_perlin = {}, + get_perlin_map = {}, + get_player_by_name = {}, + get_player_information = {}, + get_player_ip = {}, + get_player_privs = {}, + get_player_radius_area = {}, + get_pointed_thing_position = {}, + get_position_from_hash = {}, + get_server_max_lag = {}, + get_server_status = {}, + get_server_uptime = {}, + get_spawn_level = {}, + get_timeofday = {}, + get_tool_wear_after_use = {}, + get_translated_string = {}, + get_translator = {}, + get_us_time = {}, + get_user_path = {}, + get_version = {}, + get_voxel_manip = {}, + get_worldpath = {}, + global_exists = {}, + handle_async = {}, + handle_node_drops = {}, + has_feature = {}, + hash_node_position = {}, + hud_replace_builtin = {}, + inventorycube = {}, + is_area_protected = {}, + is_colored_paramtype = {}, + is_creative_enabled = {}, + is_nan = {}, + is_player = {}, + is_protected = {}, + is_singleplayer = {}, + is_yes = {}, + item_drop = {}, + item_eat = {}, + item_place = {}, + item_place_node = {}, + item_place_object = {}, + item_secondary_use = {}, + itemstring_with_color = {}, + itemstring_with_palette = {}, + kick_player = {}, + line_of_sight = {}, + load_area = {}, + log = {}, + luaentities = {}, + mkdir = {}, + mod_channel_join = {}, + mvdir = {}, + node_dig = {}, + node_punch = {}, + nodedef_default = {}, + noneitemdef_default = {}, + notify_authentication_modified = {}, + object_refs = {}, + on_craft = {}, + override_chatcommand = {}, + override_item = {}, + parse_coordinates = {}, + parse_json = {}, + parse_relative_number = {}, + place_node = {}, + place_schematic = {}, + place_schematic_on_vmanip = {}, + player_exists = {}, + pointed_thing_to_face_pos = {}, + pos_to_string = {}, + print = {}, + privs_to_string = {}, + punch_node = {}, + raillike_group = {}, + raycast = {}, + read_schematic = {}, + record_protection_violation = {}, + register_abm = {}, + register_alias = {}, + register_alias_force = {}, + register_allow_player_inventory_action = {}, + register_async_dofile = {}, + register_authentication_handler = {}, + register_biome = {}, + register_can_bypass_userlimit = {}, + register_chatcommand = {}, + register_craft = {}, + register_craft_predict = {}, + register_craftitem = {}, + register_decoration = {}, + register_entity = {}, + register_globalstep = {}, + register_item = {}, + register_lbm = {}, + register_node = {}, + register_on_auth_fail = {}, + register_on_authplayer = {}, + register_on_chat_message = {}, + register_on_chatcommand = {}, + register_on_cheat = {}, + register_on_craft = {}, + register_on_dieplayer = {}, + register_on_dignode = {}, + register_on_generated = {}, + register_on_item_eat = {}, + register_on_joinplayer = {}, + register_on_leaveplayer = {}, + register_on_liquid_transformed = {}, + register_on_mapgen_init = {}, + register_on_modchannel_message = {}, + register_on_mods_loaded = {}, + register_on_newplayer = {}, + register_on_placenode = {}, + register_on_player_hpchange = {}, + register_on_player_inventory_action = {}, + register_on_player_receive_fields = {}, + register_on_prejoinplayer = {}, + register_on_priv_grant = {}, + register_on_priv_revoke = {}, + register_on_protection_violation = {}, + register_on_punchnode = {}, + register_on_punchplayer = {}, + register_on_respawnplayer = {}, + register_on_rightclickplayer = {}, + register_on_shutdown = {}, + register_ore = {}, + register_playerevent = {}, + register_privilege = {}, + register_schematic = {}, + register_tool = {}, + registered_abms = {other_fields = true}, + registered_aliases = {other_fields = true}, + registered_allow_player_inventory_actions = {other_fields = true}, + registered_biomes = {other_fields = true}, + registered_can_bypass_userlimit = {other_fields = true}, + registered_chatcommands = {other_fields = true}, + registered_craft_predicts = {other_fields = true}, + registered_craftitems = {other_fields = true}, + registered_decorations = {other_fields = true}, + registered_entities = {other_fields = true}, + registered_globalsteps = {other_fields = true}, + registered_items = {other_fields = true}, + registered_lbms = {other_fields = true}, + registered_nodes = {other_fields = true}, + registered_on_authplayers = {other_fields = true}, + registered_on_chat_messages = {other_fields = true}, + registered_on_chatcommands = {other_fields = true}, + registered_on_cheats = {other_fields = true}, + registered_on_crafts = {other_fields = true}, + registered_on_dieplayers = {other_fields = true}, + registered_on_dignodes = {other_fields = true}, + registered_on_generateds = {other_fields = true}, + registered_on_item_eats = {other_fields = true}, + registered_on_joinplayers = {other_fields = true}, + registered_on_leaveplayers = {other_fields = true}, + registered_on_liquid_transformed = {other_fields = true}, + registered_on_modchannel_message = {other_fields = true}, + registered_on_mods_loaded = {other_fields = true}, + registered_on_newplayers = {other_fields = true}, + registered_on_placenodes = {other_fields = true}, + registered_on_player_hpchange = {other_fields = true}, + registered_on_player_hpchanges = {other_fields = true}, + registered_on_player_inventory_actions = {other_fields = true}, + registered_on_player_receive_fields = {other_fields = true}, + registered_on_prejoinplayers = {other_fields = true}, + registered_on_priv_grant = {other_fields = true}, + registered_on_priv_revoke = {other_fields = true}, + registered_on_protection_violation = {other_fields = true}, + registered_on_punchnodes = {other_fields = true}, + registered_on_punchplayers = {other_fields = true}, + registered_on_respawnplayers = {other_fields = true}, + registered_on_rightclickplayers = {other_fields = true}, + registered_on_shutdown = {other_fields = true}, + registered_ores = {other_fields = true}, + registered_playerevents = {other_fields = true}, + registered_privileges = {other_fields = true}, + registered_tools = {other_fields = true}, + remove_detached_inventory = {}, + remove_detached_inventory_raw = {}, + remove_node = {}, + remove_player = {}, + remove_player_auth = {}, + request_http_api = {}, + request_insecure_environment = {}, + request_shutdown = {}, + rgba = {}, + rmdir = {}, + rollback_get_last_node_actor = {}, + rollback_get_node_actions = {}, + rollback_punch_callbacks = {}, + rollback_revert_actions_by = {}, + rotate_and_place = {}, + rotate_node = {}, + run_callbacks = {}, + run_priv_callbacks = {}, + safe_file_write = {}, + send_join_message = {}, + send_leave_message = {}, + serialize = {}, + serialize_roundtrip = {}, + serialize_schematic = {}, + set_gen_notify = {}, + set_last_run_mod = {}, + set_mapgen_params = {}, + set_mapgen_setting = {}, + set_mapgen_setting_noiseparams = {}, + set_node = {}, + set_node_level = {}, + set_noiseparams = {}, + set_player_password = {}, + set_player_privs = {}, + set_timeofday = {}, + setting_get = {}, + setting_get_pos = {}, + setting_getbool = {}, + setting_save = {}, + setting_set = {}, + setting_setbool = {}, + settings = { + fields = { + get = {}, + get_bool = {}, + get_np_group = {}, + get_flags = {}, + set = {}, + set_bool = {}, + set_np_group = {}, + remove = {}, + get_names = {}, + write = {}, + to_table = {}, + }, + }, + sha1 = {}, + show_formspec = {}, + show_general_help_formspec = {}, + show_privs_help_formspec = {}, + sound_fade = {}, + sound_play = {}, + sound_stop = {}, + spawn_falling_node = {}, + spawn_item = {}, + spawn_tree = {}, + string_to_area = {}, + string_to_pos = {}, + string_to_privs = {}, + strip_background_colors = {}, + strip_colors = {}, + strip_foreground_colors = {}, + strip_param2_color = {}, + swap_node = {}, + tooldef_default = {}, + transforming_liquid_add = {}, + translate = {}, + unban_player_or_ip = {}, + unregister_biome = {}, + unregister_chatcommand = {}, + unregister_item = {}, + wallmounted_to_dir = {}, + wrap_text = {}, + write_json = {}, + yaw_to_dir = {}, + }, + }, + } +} - "monitoring", - "digiline" +stds.mesecons_debug = { + globals = { + "mesecons_debug", + "mesecon", + "minetest", + }, + read_globals = { + "monitoring", + "digiline" + }, } diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..3d311a8 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,25 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.3.0 + hooks: + - id: fix-byte-order-marker + - id: end-of-file-fixer + - id: trailing-whitespace + - id: mixed-line-ending + args: [ --fix=lf ] + + - repo: local + hooks: + - id: luacheck + name: luacheck + language: system + entry: luacheck + pass_filenames: true + types: [ file, lua ] + args: [ -q ] + - id: stylua + name: stylua + language: system + entry: stylua + pass_filenames: true + types: [ file, lua ] diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..394e884 --- /dev/null +++ b/.stylua.toml @@ -0,0 +1 @@ +indent_type = "Spaces" diff --git a/README.md b/README.md index 8e066f5..7751983 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,61 @@ # Mesecons Debug Collection -Throttles mesecons if the server is lagging, in particular when mesecons is causing the lag. +Throttles mesecons if the server is lagging, in particular when mesecons is causing the lag. # Overview This mod can penalizes mesecons activity on a per-mapblock basis, which can help laggy or machine-heavy servers -to be less laggy overall. Penalties are implemented as delays on various events. +to be less laggy overall. Penalties are implemented as delays on various events. Lag and per-mapblock mesecons usage are tracked over time, in order to calculate how much to penalize each -mapblock, or whether to reduce the penalty. +mapblock, or whether to reduce the penalty. -The mod defines 3 regimes of lag, with different scales of penalties. +The mod defines 3 regimes of lag, with different scales of penalties. * If the server steps are not taking much longer than the time allotted for them, the "low penalty" regime will apply. -* If the server steps are taking too long on average, and mesecons usage isn't particularly high, the "medium penalty" +* If the server steps are taking too long on average, and mesecons usage isn't particularly high, the "medium penalty" regime will apply. * If the server steps are taking too long on average and mesecons usage is high, or the server steps are taking much too - long to execute, the "high penalty" regime will apply. + long to execute, the "high penalty" regime will apply. -Each of these regimes has an associated "scale" and "offset". Every time the penalties are re-evaluated, +Each of these regimes has an associated "scale" and "offset". Every time the penalties are re-evaluated, they are changed according to this formula: ```lua new_penalty = old_penalty + (relative_load * penalty_scale) + penalty_offset ``` -Here, relative_load is the ratio of how much time the current mapblock spends doing mesecons, to the mean time +Here, relative_load is the ratio of how much time the current mapblock spends doing mesecons, to the mean time (spent doing mesecons) across all mapblocks currently running mesecons. This value is currently clamped between 0.1 -and 10, to prevent certain edge cases from being penalized too rapidly. A value of 10 would mean that the mapblock +and 10, to prevent certain edge cases from being penalized too rapidly. A value of 10 would mean that the mapblock under consideration is using 10x as much mesecons as the average mapblock. Note that, depending on the values of `penalty_scale` and `penalty_offset`, the new penalty may be *less* than the old penalty. This is to allow penalties to reach equilibrium under a constant load, and to taper off over time if the -usage in the mapblock declines, or the regime changes. +usage in the mapblock declines, or the regime changes. ## Settings * `penalty_clear_cooldown = 120` Seconds that a player has to wait between using the `mesecons_clear_penalty` command * `max_penalty = 120` Upper limit of the per-mapblock penalty -* `penalty_mapblock_disabled = 110` +* `penalty_mapblock_disabled = 110` Completely disable mesecons in a mapblock, if the penalty exceeds this value. - Set above `max_penalty` to disable this feature. + Set above `max_penalty` to disable this feature. * `penalty_check_steps = 50` # of server steps between updating the penalties -* `gc_interval = 61` Seconds after which data about unloaded mapblocks is removed from memory. +* `gc_interval = 61` Seconds after which data about unloaded mapblocks is removed from memory. * `hud_refresh_interval = 1` Seconds between updating the client's HUD * `moderate_lag_ratio = 3` Ratio between actual and expected length of a server step at which lag is considered "moderate" * `high_lag_ratio = 9` Ratio between actual and expected length of a server step at which lag is considered "high" -* `high_load_threshold = 0.33` +* `high_load_threshold = 0.33` % of processing a server spends on mesecons at which the mescons load is considered "high". * `low_penalty_offset = -1` Offset of the penalty in the low-lag regime. -* `low_penalty_scale = 0.1` +* `low_penalty_scale = 0.1` Scale of the penalty in the low-lag regime. The default values ensure that nothing is penalized in the low-lag regime. * `medium_penalty_offset = -0.8` Offset of the penalty in the moderate-lag regime. * `medium_penalty_scale = 0.2` Scale of the penalty in the moderate-lag regime. * `high_penalty_offset = -0.5` Offset of the penalty in the high-lag regime. -* `high_penalty_scale = 0.5` Scale of the penalty in the high-lag regime. +* `high_penalty_scale = 0.5` Scale of the penalty in the high-lag regime. ## Privs @@ -63,7 +63,7 @@ usage in the mapblock declines, or the regime changes. ## Commands -* `/mesecons_clear_penalty` +* `/mesecons_clear_penalty` Clears the penalty for the current mapblock. Users can only execute this every `penalty_clear_cooldown` seconds * `/mesecons_global_stats` shows the mapblock with the most prominent usage of mesecons activity * `/mesecons_hud` toggles the hud @@ -74,10 +74,10 @@ usage in the mapblock declines, or the regime changes. All of these commands require the `mesecons_debug` privilege. -* `/create_lag ` +* `/create_lag ` Artificially slow down the server by `microseconds` every `chance` server steps. Useful for debugging this mod. * `/mesecons_debug_get ` Inspect the current value of a setting. -* `/mesecons_debug_set ` Change a setting value. This does *not* save the value between reboots! +* `/mesecons_debug_set ` Change a setting value. This does *not* save the value between reboots! * `/mesecons_disable` Disables mesecons entirely * `/mesecons_enable` Undoes the above command * `/mesecons_flush` Flushes the mesecons action queue @@ -89,7 +89,7 @@ All of these commands require the `mesecons_debug` privilege. ### Mesecons Lagger -A node which can create `n` microseconds of lag once every `chance` server steps. Useful for debugging this mod. +A node which can create `n` microseconds of lag once every `chance` server steps. Useful for debugging this mod. ### Penalty Controller @@ -118,5 +118,8 @@ end # License +* CODE: + * ??????????? + * textures/penalty_controller_top.png * CC BY-SA 3.0 https://cheapiesystems.com/git/digistuff diff --git a/commands/admin_commands.lua b/commands/admin_commands.lua index 19a7cb6..56b9e05 100644 --- a/commands/admin_commands.lua +++ b/commands/admin_commands.lua @@ -6,7 +6,7 @@ minetest.register_chatcommand("mesecons_enable", { mesecon.queue.actions = {} mesecons_debug.mesecons_enabled = true return true, "mesecons enabled" - end + end, }) minetest.register_chatcommand("mesecons_disable", { @@ -15,7 +15,7 @@ minetest.register_chatcommand("mesecons_disable", { func = function() mesecons_debug.mesecons_enabled = false return true, "mesecons disabled" - end + end, }) minetest.register_chatcommand("mesecons_whitelist_get", { @@ -29,15 +29,9 @@ minetest.register_chatcommand("mesecons_whitelist_get", { count = count + 1 end - return true, ( - "mesecons whitelist:\n" .. - "%s\n" .. - "%i mapblocks whitelisted" - ):format( - table.concat(list, "\n"), - count - ) - end + return true, + ("mesecons whitelist:\n" .. "%s\n" .. "%i mapblocks whitelisted"):format(table.concat(list, "\n"), count) + end, }) minetest.register_chatcommand("mesecons_whitelist_add", { @@ -55,7 +49,7 @@ minetest.register_chatcommand("mesecons_whitelist_add", { mesecons_debug.storage:set_string(hash, "1") return true, "mapblock whitlisted" - end + end, }) minetest.register_chatcommand("mesecons_whitelist_remove", { @@ -73,7 +67,7 @@ minetest.register_chatcommand("mesecons_whitelist_remove", { mesecons_debug.storage:set_string(hash, "") return true, "mapblock removed from whitelist" - end + end, }) minetest.register_chatcommand("mesecons_debug_set", { @@ -86,7 +80,7 @@ minetest.register_chatcommand("mesecons_debug_set", { return false end - local setting, value = params:match('^([a-zA-Z0-9_-]+)%s+(.*)$') + local setting, value = params:match("^([a-zA-Z0-9_-]+)%s+(.*)$") value = tonumber(value) if not setting or not value then return false @@ -99,7 +93,7 @@ minetest.register_chatcommand("mesecons_debug_set", { mesecons_debug.settings.modify_setting(setting, value) return true, "setting updated" - end + end, }) minetest.register_chatcommand("mesecons_debug_get", { @@ -118,5 +112,5 @@ minetest.register_chatcommand("mesecons_debug_get", { else return false, "unknown setting" end - end + end, }) diff --git a/commands/clear_penalty.lua b/commands/clear_penalty.lua index cf64103..e887ed9 100644 --- a/commands/clear_penalty.lua +++ b/commands/clear_penalty.lua @@ -3,10 +3,8 @@ local penalty_clear_cooldown = mesecons_debug.settings.penalty_clear_cooldown -- playername => time-of-last-cooldown local cooldown_expiry_by_name = {} - minetest.register_chatcommand("mesecons_clear_penalty", { - description = "clears the penalty in the current mapblock " .. - "(cooldown: " .. penalty_clear_cooldown .. ")", + description = "clears the penalty in the current mapblock " .. "(cooldown: " .. penalty_clear_cooldown .. ")", func = function(name) local player = minetest.get_player_by_name(name) if not player then @@ -29,5 +27,5 @@ minetest.register_chatcommand("mesecons_clear_penalty", { ctx.penalty = 0 return true, "penalty reset" - end + end, }) diff --git a/commands/create_lag.lua b/commands/create_lag.lua index 6598910..9f095da 100644 --- a/commands/create_lag.lua +++ b/commands/create_lag.lua @@ -3,13 +3,12 @@ local lag_chance = 0 local wait = mesecons_debug.wait - minetest.register_chatcommand("create_lag", { description = "foce a wait of us for 1 / server steps", params = " ", privs = { mesecons_debug = true }, func = function(_name, setting) - local lag, chance = setting:match('^(%S+)%s+(%S+)$') + local lag, chance = setting:match("^(%S+)%s+(%S+)$") lag = tonumber(lag) chance = tonumber(chance) if not (lag and chance) then diff --git a/commands/flush.lua b/commands/flush.lua index ba3f3cd..2988691 100644 --- a/commands/flush.lua +++ b/commands/flush.lua @@ -4,5 +4,5 @@ minetest.register_chatcommand("mesecons_flush", { func = function(name) minetest.log("warning", "Player " .. name .. " flushes mesecon actionqueue") mesecon.queue.actions = {} - end + end, }) diff --git a/commands/user_commands.lua b/commands/user_commands.lua index 5836373..b0e3c14 100644 --- a/commands/user_commands.lua +++ b/commands/user_commands.lua @@ -1,3 +1,5 @@ +local f = string.format + minetest.register_chatcommand("mesecons_hud", { description = "mesecons_hud toggle", func = function(name) @@ -8,7 +10,7 @@ minetest.register_chatcommand("mesecons_hud", { else return true, "mesecons hud disabled" end - end + end, }) minetest.register_chatcommand("mesecons_global_stats", { @@ -26,10 +28,8 @@ minetest.register_chatcommand("mesecons_global_stats", { local txt if top_ctx then - txt = ( - "Most prominent mesecons usage at mapblock %s" .. - " with %f seconds penalty and %i us average use" - ):format( + txt = f( + "Most prominent mesecons usage at mapblock %s" .. " with %f seconds penalty and %i us average use", minetest.pos_to_string(minetest.get_position_from_hash(top_hash)), top_ctx.penalty, top_ctx.avg_micros_per_second @@ -39,7 +39,7 @@ minetest.register_chatcommand("mesecons_global_stats", { end return true, txt - end + end, }) minetest.register_chatcommand("mesecons_stats", { @@ -51,10 +51,11 @@ minetest.register_chatcommand("mesecons_stats", { end local ctx = mesecons_debug.get_context(player:get_pos()) - return true, ("Mapblock usage: %i us/s (across %i mapblocks)"):format( - ctx.avg_micros_per_second, - mesecons_debug.context_store_size - ) - end + return true, + f( + "Mapblock usage: %i us/s (across %i mapblocks)", + ctx.avg_micros_per_second, + mesecons_debug.context_store_size + ) + end, }) - diff --git a/context.lua b/context.lua index 5f22100..511cf5c 100644 --- a/context.lua +++ b/context.lua @@ -17,7 +17,7 @@ mesecons_debug.get_context = function(pos) -- modification time mtime = minetest.get_us_time(), -- whitelist status - whitelisted = storage:contains(hash) + whitelisted = storage:contains(hash), } mesecons_debug.context_store[hash] = ctx mesecons_debug.context_store_size = mesecons_debug.context_store_size + 1 diff --git a/hud.lua b/hud.lua index d8a4e25..2f84b4f 100644 --- a/hud.lua +++ b/hud.lua @@ -1,10 +1,7 @@ - local hud_refresh_interval = mesecons_debug.settings.hud_refresh_interval -mesecons_debug.settings._subscribe_for_modification("hud_refresh_interval", - function(value) hud_refresh_interval = value end) - -local HUD_POSITION = { x = 0.1, y = 0.8 } -local HUD_ALIGNMENT = { x = 1, y = 0 } +mesecons_debug.settings._subscribe_for_modification("hud_refresh_interval", function(value) + hud_refresh_interval = value +end) local hudid_by_playername = {} @@ -18,40 +15,34 @@ local function get_info(player) local ctx = mesecons_debug.get_context(pos) local total = mesecons_debug.avg_total_micros_per_second - if total == 0 then total = 1 end + if total == 0 then + total = 1 + end local percent = ctx.avg_micros_per_second * 100 / total - local txt = ("mesecons @ %s\n"):format( - minetest.pos_to_string(blockpos) - ) + local txt = ("mesecons @ %s\n"):format(minetest.pos_to_string(blockpos)) if ctx.whitelisted then txt = txt .. "whitelisted, no limits" return txt, 0x00FFFF end - txt = txt .. ("usage: %.0f us/s .. (%.1f%%) penalty: %.2fs"):format( - ctx.avg_micros_per_second, - percent, - ctx.penalty - ) - txt = txt .. ("\nlag: %.2f (%s); mesecons load = %s"):format( - mesecons_debug.avg_lag, - mesecons_debug.lag_level, - mesecons_debug.load_level - ) - if minetest.get_server_max_lag then - txt = txt .. ("; max_lag: %.2f"):format( - minetest.get_server_max_lag() + txt = txt .. ("usage: %.0f us/s .. (%.1f%%) penalty: %.2fs"):format(ctx.avg_micros_per_second, percent, ctx.penalty) + txt = txt + .. ("\nlag: %.2f (%s); mesecons load = %s"):format( + mesecons_debug.avg_lag, + mesecons_debug.lag_level, + mesecons_debug.load_level ) + if minetest.get_server_max_lag then + txt = txt .. ("; max_lag: %.2f"):format(minetest.get_server_max_lag()) end - txt = txt .. ("; #players = %i"):format( - #minetest.get_connected_players() - ) - txt = txt .. ("\npenalties enabled = %s; mesecons enabled = %s"):format( - mesecons_debug.enabled, - mesecons_debug.mesecons_enabled - ) + txt = txt .. ("; #players = %i"):format(#minetest.get_connected_players()) + txt = txt + .. ("\npenalties enabled = %s; mesecons enabled = %s"):format( + mesecons_debug.enabled, + mesecons_debug.mesecons_enabled + ) if ctx.penalty <= 1 then return txt, 0x00FF00 @@ -78,24 +69,36 @@ minetest.register_globalstep(function(dtime) if hud_enabled then local text, color = get_info(player) if hudid then - player:hud_change(hudid, "text", text) - player:hud_change(hudid, "number", color) - + local hud_def = player:hud_get(hudid) + if hud_def and hud_def.name == "mesecons_debug:hud" then + player:hud_change(hudid, "text", text) + player:hud_change(hudid, "number", color) + else + minetest.chat_send_player( + playername, + "[mesecons_debug] another mod removed your hud, you must re-enable it or possibly relog" + ) + hudid_by_playername[playername] = nil + mesecons_debug.hud_enabled_by_playername[playername] = nil + end else hudid_by_playername[playername] = player:hud_add({ + name = "mesecons_debug:hud", hud_elem_type = "text", - position = HUD_POSITION, + position = { x = 0.5, y = 0.8 }, + alignment = { x = 0, y = 0 }, offset = { x = 0, y = 0 }, + scale = { x = 100, y = 100 }, text = text, number = color, - alignment = HUD_ALIGNMENT, - scale = { x = 100, y = 100 }, }) end - else if hudid then - player:hud_remove(hudid) + local hud_def = player:hud_get(hudid) + if hud_def.name == "mesecons_debug:hud" then + player:hud_remove(hudid) + end hudid_by_playername[playername] = nil end end diff --git a/init.lua b/init.lua index b9b5c1f..466abf8 100644 --- a/init.lua +++ b/init.lua @@ -23,8 +23,8 @@ mesecons_debug = { -- average lag avg_lag = 1, - lag_level = 'none', - load_level = 'none', + lag_level = "none", + load_level = "none", -- playername => true hud_enabled_by_playername = {}, @@ -37,7 +37,7 @@ mesecons_debug = { log = function(level, message_fmt, ...) minetest.log(level, ("[%s] "):format(modname) .. message_fmt:format(...)) - end + end, } dofile(modpath .. "/settings.lua") diff --git a/mod.conf b/mod.conf index b3bbbc0..5f034e3 100644 --- a/mod.conf +++ b/mod.conf @@ -1,3 +1,16 @@ name = mesecons_debug +title = mesecons debug +description = throttles mesecons if the server is lagging, in particular when mesecons is causing the lag. +license = ????? +media_license = CC-BY-SA 3.0 depends = mesecons -optional_depends = digilines, digistuff, mesecons_blinkyplant, mesecons_luacontroller, moremesecons_adjustable_blinkyplant, moremesecons_injector_controller, monitoring, pipeworks +optional_depends = """ +digilines, +digistuff, +mesecons_blinkyplant, +mesecons_luacontroller, +moremesecons_adjustable_blinkyplant, +moremesecons_injector_controller, +monitoring, +pipeworks +""" diff --git a/nodes/mesecons_lagger.lua b/nodes/mesecons_lagger.lua index e4d966e..7aa53aa 100644 --- a/nodes/mesecons_lagger.lua +++ b/nodes/mesecons_lagger.lua @@ -1,18 +1,16 @@ - local wait = mesecons_debug.wait mesecon.queue:add_function("create_lag", function(_pos, duration) wait(duration) end) - minetest.register_node("mesecons_debug:mesecons_lagger", { description = "machine for adding artificial mesecons lag", group = { not_in_creative_inventory = 1, unbreakable = 1, }, - tiles = {"default_mese_block.png^[colorize:#F00:128"}, + tiles = { "default_mese_block.png^[colorize:#F00:128" }, on_blast = function() end, drop = "", @@ -20,8 +18,7 @@ minetest.register_node("mesecons_debug:mesecons_lagger", { local meta = minetest.get_meta(pos) meta:set_float("lag", 0.0) meta:set_float("chance", 0.0) - meta:set_string("formspec", - ("field[lag;Lag (in us);%s]field[chance;Chance;%s]"):format(0.0, 0.0)) + meta:set_string("formspec", ("field[lag;Lag (in us);%s]field[chance;Chance;%s]"):format(0.0, 0.0)) local timer = minetest.get_node_timer(pos) timer:start(0) @@ -38,10 +35,10 @@ minetest.register_node("mesecons_debug:mesecons_lagger", { if fields.chance then meta:set_float("chance", fields.chance) end - meta:set_string("formspec", - ("field[lag;Lag (in us);%s]field[chance;Chance;%s]"):format( - meta:get_float("lag"), meta:get_float("chance"))) - + meta:set_string( + "formspec", + ("field[lag;Lag (in us);%s]field[chance;Chance;%s]"):format(meta:get_float("lag"), meta:get_float("chance")) + ) end, on_timer = function(pos, _elapsed) diff --git a/nodes/penalty_controller.lua b/nodes/penalty_controller.lua index 6e160c1..13f8e3e 100644 --- a/nodes/penalty_controller.lua +++ b/nodes/penalty_controller.lua @@ -16,7 +16,7 @@ minetest.register_node("mesecons_debug:penalty_controller", { "jeija_microcontroller_sides.png", "jeija_microcontroller_sides.png", "jeija_microcontroller_sides.png", - "jeija_microcontroller_sides.png" + "jeija_microcontroller_sides.png", }, inventory_image = "penalty_controller_top.png", @@ -33,7 +33,7 @@ minetest.register_node("mesecons_debug:penalty_controller", { { -8 / 16, -8 / 16, -8 / 16, 8 / 16, -7 / 16, 8 / 16 }, -- Bottom slab { -5 / 16, -7 / 16, -5 / 16, 5 / 16, -6 / 16, 5 / 16 }, -- Circuit board { -3 / 16, -6 / 16, -3 / 16, 3 / 16, -5 / 16, 3 / 16 }, -- IC - } + }, }, paramtype = "light", @@ -66,10 +66,10 @@ minetest.register_node("mesecons_debug:penalty_controller", { micros = ctx.micros, avg_micros = ctx.avg_micros_per_second, penalty = ctx.penalty, - whitelisted = ctx.whitelisted + whitelisted = ctx.whitelisted, }) end - end - } - } + end, + }, + }, }) diff --git a/overrides/mesecons_queue.lua b/overrides/mesecons_queue.lua index 4375d7d..d14b30c 100644 --- a/overrides/mesecons_queue.lua +++ b/overrides/mesecons_queue.lua @@ -1,8 +1,10 @@ local penalty_mapblock_disabled = mesecons_debug.settings.penalty_mapblock_disabled -mesecons_debug.settings._subscribe_for_modification("penalty_mapblock_disabled", - function(value) penalty_mapblock_disabled = value end) +mesecons_debug.settings._subscribe_for_modification("penalty_mapblock_disabled", function(value) + penalty_mapblock_disabled = value +end) + +local check_pos = mesecons_debug.check_pos --- execute() local old_execute = mesecon.queue.execute mesecon.queue.execute = function(self, action) if not mesecons_debug.enabled then @@ -11,6 +13,11 @@ mesecon.queue.execute = function(self, action) return end + if not check_pos(action.pos) then + mesecons_debug.log("error", "mesecons action has an invalid position and cannot be processed %s", dump(action)) + return + end + local ctx = mesecons_debug.get_context(action.pos) if ctx.whitelisted then return old_execute(self, action) @@ -22,18 +29,16 @@ mesecon.queue.execute = function(self, action) mesecons_debug.total_micros = mesecons_debug.total_micros + micros ctx.micros = ctx.micros + micros - ctx.mtime = t0 -- modification time + ctx.mtime = t0 -- modification time return rv end - -- add_action() local old_add_action = mesecon.queue.add_action mesecon.queue.add_action = function(self, pos, func, params, time, overwritecheck, priority) if not mesecons_debug.enabled then return old_add_action(self, pos, func, params, time, overwritecheck, priority) - elseif not mesecons_debug.mesecons_enabled then return end diff --git a/overrides/node_timers.lua b/overrides/node_timers.lua index ea37d6a..8f8043d 100644 --- a/overrides/node_timers.lua +++ b/overrides/node_timers.lua @@ -4,7 +4,6 @@ local function override_node_timer(node_name) on_timer = function(pos, elapsed) if not mesecons_debug.enabled then return old_node_timer(pos, elapsed) - elseif not mesecons_debug.mesecons_enabled then return true end diff --git a/penalty.lua b/penalty.lua index 23f3e2f..beeaeac 100644 --- a/penalty.lua +++ b/penalty.lua @@ -2,9 +2,13 @@ local expected_dtime = tonumber(minetest.settings:get("dedicated_server_step")) local subscribe_for_modification = mesecons_debug.settings._subscribe_for_modification local max_penalty = mesecons_debug.settings.max_penalty -subscribe_for_modification("max_penalty", function(value) max_penalty = value end) +subscribe_for_modification("max_penalty", function(value) + max_penalty = value +end) local moderate_lag_ratio = mesecons_debug.settings.moderate_lag_ratio -subscribe_for_modification("moderate_lag_ratio", function(value) moderate_lag_ratio = value end) +subscribe_for_modification("moderate_lag_ratio", function(value) + moderate_lag_ratio = value +end) local high_lag_ratio = mesecons_debug.settings.high_lag_ratio local high_lag_dtime = expected_dtime * high_lag_ratio subscribe_for_modification("high_lag_ratio", function(value) @@ -12,21 +16,37 @@ subscribe_for_modification("high_lag_ratio", function(value) high_lag_dtime = expected_dtime * value end) local high_load_threshold = mesecons_debug.settings.high_load_threshold -subscribe_for_modification("high_load_threshold", function(value) high_load_threshold = value end) +subscribe_for_modification("high_load_threshold", function(value) + high_load_threshold = value +end) local penalty_check_steps = mesecons_debug.settings.penalty_check_steps -subscribe_for_modification("penalty_check_steps", function(value) penalty_check_steps = value end) +subscribe_for_modification("penalty_check_steps", function(value) + penalty_check_steps = value +end) local high_penalty_scale = mesecons_debug.settings.high_penalty_scale -subscribe_for_modification("high_penalty_scale", function(value) high_penalty_scale = value end) +subscribe_for_modification("high_penalty_scale", function(value) + high_penalty_scale = value +end) local high_penalty_offset = mesecons_debug.settings.high_penalty_offset -subscribe_for_modification("high_penalty_offset", function(value) high_penalty_offset = value end) +subscribe_for_modification("high_penalty_offset", function(value) + high_penalty_offset = value +end) local medium_penalty_scale = mesecons_debug.settings.medium_penalty_scale -subscribe_for_modification("medium_penalty_scale", function(value) medium_penalty_scale = value end) +subscribe_for_modification("medium_penalty_scale", function(value) + medium_penalty_scale = value +end) local medium_penalty_offset = mesecons_debug.settings.medium_penalty_offset -subscribe_for_modification("medium_penalty_offset", function(value) medium_penalty_offset = value end) +subscribe_for_modification("medium_penalty_offset", function(value) + medium_penalty_offset = value +end) local low_penalty_scale = mesecons_debug.settings.low_penalty_scale -subscribe_for_modification("low_penalty_scale", function(value) low_penalty_scale = value end) +subscribe_for_modification("low_penalty_scale", function(value) + low_penalty_scale = value +end) local low_penalty_offset = mesecons_debug.settings.low_penalty_offset -subscribe_for_modification("low_penalty_offset", function(value) low_penalty_offset = value end) +subscribe_for_modification("low_penalty_offset", function(value) + low_penalty_offset = value +end) local relative_load_max = mesecons_debug.settings.relative_load_clamp local relative_load_min = 1 / mesecons_debug.settings.relative_load_clamp subscribe_for_modification("relative_load_clamp", function(value) @@ -35,7 +55,9 @@ subscribe_for_modification("relative_load_clamp", function(value) end) -- see https://en.wikipedia.org/w/index.php?title=Moving_average&oldid=1069105690#Exponential_moving_average local averaging_coefficient = mesecons_debug.settings.averaging_coefficient -subscribe_for_modification("averaging_coefficient", function(value) averaging_coefficient = value end) +subscribe_for_modification("averaging_coefficient", function(value) + averaging_coefficient = value +end) local max = math.max local min = math.min @@ -56,8 +78,8 @@ local has_monitoring = mesecons_debug.has.monitoring local mapblock_count, penalized_mapblock_count if has_monitoring then mapblock_count = monitoring.gauge("mesecons_debug_mapblock_count", "count of tracked mapblocks") - penalized_mapblock_count = monitoring.gauge("mesecons_debug_penalized_mapblock_count", - "count of penalized mapblocks") + penalized_mapblock_count = + monitoring.gauge("mesecons_debug_penalized_mapblock_count", "count of penalized mapblocks") end local elapsed_steps = 0 @@ -76,11 +98,11 @@ minetest.register_globalstep(function(dtime) return end - local context_store_size = mesecons_debug.context_store_size -- # of blocks w/ active mesecons + local context_store_size = mesecons_debug.context_store_size -- # of blocks w/ active mesecons local total_micros = mesecons_debug.total_micros local total_micros_per_second = total_micros / elapsed - local avg_total_micros_per_second = update_average(total_micros_per_second, - mesecons_debug.avg_total_micros_per_second) + local avg_total_micros_per_second = + update_average(total_micros_per_second, mesecons_debug.avg_total_micros_per_second) mesecons_debug.avg_total_micros_per_second = avg_total_micros_per_second -- how much lag is there? @@ -134,7 +156,7 @@ minetest.register_globalstep(function(dtime) -- avg load per active context local avg_avg_micros_per_second = avg_total_micros_per_second / context_store_size - local penalized_count = 0 -- for monitoring + local penalized_count = 0 -- for monitoring for _, ctx in pairs(mesecons_debug.context_store) do if not ctx.whitelisted then -- moving avg diff --git a/privs.lua b/privs.lua index c7d1075..7668e53 100644 --- a/privs.lua +++ b/privs.lua @@ -1,3 +1,3 @@ minetest.register_privilege("mesecons_debug", { - description = "Allows execution of mesecon debug chatcommands" + description = "Allows execution of mesecon debug chatcommands", }) diff --git a/settings.lua b/settings.lua index fa1254a..f877572 100644 --- a/settings.lua +++ b/settings.lua @@ -27,22 +27,22 @@ mesecons_debug.settings = { high_load_threshold = tonumber(minetest.settings:get("mesecons_debug.high_load_threshold")) or 0.33, -- scale of penalty during high load - high_penalty_scale = tonumber(minetest.settings:get("mesecons_debug.high_penalty_scale")) or 0.5, + high_penalty_scale = tonumber(minetest.settings:get("mesecons_debug.high_penalty_scale")) or 0.05, -- offset of penalty during high load - high_penalty_offset = tonumber(minetest.settings:get("mesecons_debug.high_penalty_offset")) or -0.5, + high_penalty_offset = tonumber(minetest.settings:get("mesecons_debug.high_penalty_offset")) or -0.05, -- scale of penalty during medium load - medium_penalty_scale = tonumber(minetest.settings:get("mesecons_debug.medium_penalty_scale")) or 0.2, + medium_penalty_scale = tonumber(minetest.settings:get("mesecons_debug.medium_penalty_scale")) or 0.05, -- offset of penalty during medium load - medium_penalty_offset = tonumber(minetest.settings:get("mesecons_debug.medium_penalty_offset")) or -0.67, + medium_penalty_offset = tonumber(minetest.settings:get("mesecons_debug.medium_penalty_offset")) or -0.1, -- scale of penalty during low load - low_penalty_scale = tonumber(minetest.settings:get("mesecons_debug.low_penalty_scale")) or 0.1, + low_penalty_scale = tonumber(minetest.settings:get("mesecons_debug.low_penalty_scale")) or 0.05, -- offset of penalty during low load - low_penalty_offset = tonumber(minetest.settings:get("mesecons_debug.low_penalty_offset")) or -1, + low_penalty_offset = tonumber(minetest.settings:get("mesecons_debug.low_penalty_offset")) or -0.5, -- forces (1 / clamp) <= relative load <= clamp relative_load_clamp = tonumber(minetest.settings:get("mesecons_debug.relative_load_clamp")) or 10, diff --git a/settingtypes.txt b/settingtypes.txt index 23cbbf5..1cdb655 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -26,22 +26,22 @@ mesecons_debug.high_load_threshold (high load threshold) float 0.33 0 1 mesecons_debug.penalty_check_steps (steps between penalty updates) float 50 1 10000 # scale of penalty during high load -mesecons_debug.high_penalty_scale (high penalty scale) float 0.5 0.01 1 +mesecons_debug.high_penalty_scale (high penalty scale) float 0.05 0.01 1 # offset of penalty during high load -mesecons_debug.high_penalty_offset (high penalty offset) float -0.5 -1 0 +mesecons_debug.high_penalty_offset (high penalty offset) float -0.05 -1 0 # scale of penalty during medium load -mesecons_debug.medium_penalty_scale (medium penalty scale) float 0.2 0.01 1 +mesecons_debug.medium_penalty_scale (medium penalty scale) float 0.05 0.01 1 # offset of penalty during medium load -mesecons_debug.medium_penalty_offset (medium penalty offset) float -0.8 -1 0 +mesecons_debug.medium_penalty_offset (medium penalty offset) float -0.1 -1 0 # scale of penalty during low load -mesecons_debug.low_penalty_scale (low penalty scale) float 0.1 0.01 1 +mesecons_debug.low_penalty_scale (low penalty scale) float 0.05 0.01 1 # offset of penalty during low load -mesecons_debug.low_penalty_offset (low penalty offset) float -1 -1 0 +mesecons_debug.low_penalty_offset (low penalty offset) float -0.5 -1 0 # forces (1 / clamp) <= relative load <= clamp mesecons_debug.relative_load_clamp (clamp of relative load value) float 10 1 100 diff --git a/util.lua b/util.lua index 1e45914..8639b19 100644 --- a/util.lua +++ b/util.lua @@ -1,8 +1,12 @@ +function mesecons_debug.check_pos(pos) + return type(pos) == "table" and type(pos.x) == "number" and type(pos.y) == "number" and type(pos.z) == "number" +end + 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) + z = math.floor(pos.z / 16), } end @@ -10,12 +14,12 @@ function mesecons_debug.hashpos(pos) return minetest.hash_node_position({ x = math.floor(pos.x / 16), y = math.floor(pos.y / 16), - z = math.floor(pos.z / 16) + z = math.floor(pos.z / 16), }) end - function mesecons_debug.wait(n) local wait_until = minetest.get_us_time() + n - while minetest.get_us_time() < wait_until do end + while minetest.get_us_time() < wait_until do + end end -- cgit v1.2.3