New trigger queue management.
No longer "merges" triggers to the same node. Rate limits triggers. 16/s max. After that, exponentially decay limit triggers for a while to each node. Tight loop circuits are controlled well this way. Some larger loops will continue to function.
This commit is contained in:
parent
1b5d67e39f
commit
8dba8b3cfb
@ -45,20 +45,45 @@ local function dehash_vector(s)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local defer_tbl = {}
|
local defer_tbl = {}
|
||||||
|
local rate_tbl = {}
|
||||||
|
local rate_time = 1.0
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
local t = table.copy(defer_tbl)
|
local t = table.copy(defer_tbl)
|
||||||
defer_tbl = {}
|
defer_tbl = {}
|
||||||
for pos, func in pairs(t) do
|
for _, item in pairs(t) do
|
||||||
func(minetest.string_to_pos(pos))
|
item.func(item.pos)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- prune rate_tbl occasionally
|
||||||
|
rate_time = rate_time - dtime
|
||||||
|
if rate_time > 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
rate_time = 1.0
|
||||||
|
|
||||||
|
-- simple decay prune
|
||||||
|
local count = 0
|
||||||
|
for k, v in pairs(rate_tbl) do
|
||||||
|
count = count + 1
|
||||||
|
if v > 1 then
|
||||||
|
rate_tbl[k] = math.floor(v / 2)
|
||||||
|
else
|
||||||
|
rate_tbl[k] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function defer(pos, func)
|
local function defer(pos, func)
|
||||||
local p = minetest.pos_to_string(pos)
|
local p = minetest.pos_to_string(pos)
|
||||||
if not defer_tbl[p] then
|
|
||||||
defer_tbl[p] = func
|
local r = rate_tbl[p] or 1
|
||||||
|
rate_tbl[p] = r + 1
|
||||||
|
if r > 15 then
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defer_tbl[#defer_tbl + 1] = {pos = pos, func = func}
|
||||||
end
|
end
|
||||||
|
|
||||||
function mech.trigger(pos)
|
function mech.trigger(pos)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user