Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to have overheat cooldown in steps #562

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions mesecons/services.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down
34 changes: 31 additions & 3 deletions settingtypes.txt
Original file line number Diff line number Diff line change
@@ -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]
Expand Down