From 55f5eff7dec7b452fec628abd01d2c9417dd52ba Mon Sep 17 00:00:00 2001 From: Desour Date: Mon, 29 Mar 2021 01:02:17 +0200 Subject: [PATCH 1/2] Add setting to have overheat cooldown in steps --- mesecons/services.lua | 15 +++++++++++---- settingtypes.txt | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/mesecons/services.lua b/mesecons/services.lua index b1388ec..43aefc6 100644 --- a/mesecons/services.lua +++ b/mesecons/services.lua @@ -74,9 +74,16 @@ minetest.register_on_placenode(mesecon.on_placenode) minetest.register_on_dignode(mesecon.on_dignode) -- Overheating service for fast circuits -local OVERHEAT_MAX = mesecon.setting("overheat_max", 20) -local COOLDOWN_TIME = mesecon.setting("cooldown_time", 2.0) -local COOLDOWN_STEP = mesecon.setting("cooldown_granularity", 0.5) +local OVERHEAT_MAX = math.max(1.0, mesecon.setting("overheat_max", 20.0)) +local COOLDOWN_MODE = mesecon.setting("cooldown_mode", "seconds") +local COOLDOWN_IN_STEPS = COOLDOWN_MODE == "steps" +-- default for steps assumes a dtime of 0.016 seconds +local COOLDOWN_TIME = math.max(0.0, COOLDOWN_IN_STEPS and + mesecon.setting("cooldown_time_steps", 125.0) or + mesecon.setting("cooldown_time", 2.0)) +local COOLDOWN_STEP = math.max(0.0, COOLDOWN_IN_STEPS and + mesecon.setting("cooldown_granularity_steps", 20) or + mesecon.setting("cooldown_granularity", 0.5)) local COOLDOWN_MULTIPLIER = OVERHEAT_MAX / COOLDOWN_TIME local cooldown_timer = 0.0 local object_heat = {} @@ -118,7 +125,7 @@ function mesecon.move_hot_nodes(moved_nodes) end local function global_cooldown(dtime) - cooldown_timer = cooldown_timer + dtime + cooldown_timer = cooldown_timer + (COOLDOWN_IN_STEPS and 1 or dtime) if cooldown_timer < COOLDOWN_STEP then return -- don't overload the CPU end diff --git a/settingtypes.txt b/settingtypes.txt index 5627440..9d6859c 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,9 +1,37 @@ [mesecons] +# Number of seconds to wait after server start before starting to execute actions +# from the actionqueue. mesecon.resumetime (Startup delay) int 4 1 10 -mesecon.overheat_max (Device heat limit) int 20 1 100 -mesecon.cooldown_time (Device cooldown time) float 2.0 0.1 10.0 -mesecon.cooldown_granularity (Cooldown step length) float 0.5 0.0 1.0 + +# Heat at which a device overheats. +# As a rule of thumb, a device gets 1 additional heat each time when it toggles. +mesecon.overheat_max (Device heat limit) float 20.0 1.0 + +# The method used to cooldown devices over time: +# - seconds: The cooldown will happen per seconds. +# Use mesecon.cooldown_time and mesecon.cooldown_granularity for further configuration. +# - steps: The cooldown will happen per server steps. +# Use mesecon.cooldown_time_steps and mesecon.cooldown_granularity_steps for further configuration. +mesecon.cooldown_mode (Device cooldown mode) enum seconds seconds,steps + +# The time in seconds it takes for a device to fully cool down from max heat. +# Only used if mesecon.cooldown_mode is seconds. +mesecon.cooldown_time (Device cooldown time in seconds) float 2.0 0.0 + +# Length in seconds of the interval in which devices are cooled down over time. +# This does not affect the cooldown speed. +# Only used if mesecon.cooldown_mode is seconds. +mesecon.cooldown_granularity (Cooldown step length in seconds) float 0.5 0.0 + +# The time in server steps it takes for a device to fully cool down from max heat. +# Only used if mesecon.cooldown_mode is steps. +mesecon.cooldown_time_steps (Device cooldown time in server steps) float 125.0 0.0 + +# Length in server steps of the interval in which devices are cooled down over time. +# This does not affect the cooldown speed. +# Only used if mesecon.cooldown_mode is steps. +mesecon.cooldown_granularity_steps (Cooldown step length in server steps) int 20 0 [mesecons_blinkyplant] From e37b6b6e9d30db7b84a40aecd862b6b0b70aa0be Mon Sep 17 00:00:00 2001 From: Desour Date: Mon, 29 Mar 2021 20:06:08 +0200 Subject: [PATCH 2/2] set default to steps --- mesecons/services.lua | 2 +- settingtypes.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mesecons/services.lua b/mesecons/services.lua index 43aefc6..5f823e0 100644 --- a/mesecons/services.lua +++ b/mesecons/services.lua @@ -75,7 +75,7 @@ minetest.register_on_dignode(mesecon.on_dignode) -- Overheating service for fast circuits local OVERHEAT_MAX = math.max(1.0, mesecon.setting("overheat_max", 20.0)) -local COOLDOWN_MODE = mesecon.setting("cooldown_mode", "seconds") +local COOLDOWN_MODE = mesecon.setting("cooldown_mode", "steps") local COOLDOWN_IN_STEPS = COOLDOWN_MODE == "steps" -- default for steps assumes a dtime of 0.016 seconds local COOLDOWN_TIME = math.max(0.0, COOLDOWN_IN_STEPS and diff --git a/settingtypes.txt b/settingtypes.txt index 9d6859c..e270320 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -13,7 +13,7 @@ mesecon.overheat_max (Device heat limit) float 20.0 1.0 # Use mesecon.cooldown_time and mesecon.cooldown_granularity for further configuration. # - steps: The cooldown will happen per server steps. # Use mesecon.cooldown_time_steps and mesecon.cooldown_granularity_steps for further configuration. -mesecon.cooldown_mode (Device cooldown mode) enum seconds seconds,steps +mesecon.cooldown_mode (Device cooldown mode) enum steps seconds,steps # The time in seconds it takes for a device to fully cool down from max heat. # Only used if mesecon.cooldown_mode is seconds.