diff --git a/mesecons/services.lua b/mesecons/services.lua index b1388ec2..5f823e02 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", "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 + 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 56274400..e270320a 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 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. +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]