clamp radiation damage abm to 100 calls per second max
This commit is contained in:
parent
a76e90d9de
commit
1a625bc444
|
@ -28,6 +28,9 @@ or complex internal structure should show no radiation resistance.
|
||||||
Fractional resistance values are permitted.
|
Fractional resistance values are permitted.
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
|
local MP = minetest.get_modpath("technic")
|
||||||
|
local throttle = dofile(MP .. "/util/throttle.lua")
|
||||||
|
|
||||||
local S = technic.getter
|
local S = technic.getter
|
||||||
|
|
||||||
local rad_resistance_node = {
|
local rad_resistance_node = {
|
||||||
|
@ -362,7 +365,7 @@ if minetest.settings:get_bool("enable_damage") then
|
||||||
nodenames = {"group:radioactive"},
|
nodenames = {"group:radioactive"},
|
||||||
interval = 1,
|
interval = 1,
|
||||||
chance = 2,
|
chance = 2,
|
||||||
action = dmg_abm,
|
action = throttle(100, dmg_abm),
|
||||||
})
|
})
|
||||||
|
|
||||||
if longterm_damage then
|
if longterm_damage then
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
local function throttle(callspersecond, fn)
|
||||||
|
local time = 0
|
||||||
|
local count = 0
|
||||||
|
|
||||||
|
return function(...)
|
||||||
|
local now = minetest.get_us_time()
|
||||||
|
if (now - time) > 1000000 then
|
||||||
|
-- reset time
|
||||||
|
time = now
|
||||||
|
count = 0
|
||||||
|
else
|
||||||
|
-- check max calls
|
||||||
|
count = count + 1
|
||||||
|
if count > callspersecond then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return pcall(fn, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return throttle
|
Loading…
Reference in New Issue