Aaron Suen 9555a1ecba Optimize ABM delay
Only register a single job with after() per tick.
Store actual node processing to do in a much
simpler linear array.
2022-01-23 17:28:48 -05:00

33 lines
733 B
Lua

-- LUALOCALS < ---------------------------------------------------------
local minetest
= minetest
-- LUALOCALS > ---------------------------------------------------------
local pending
local oldreg = minetest.register_abm
function minetest.register_abm(def, ...)
if not def.action_delay then return oldreg(def, ...) end
local oldact = def.action
function def.action(pos, node)
if not pending then
pending = {}
minetest.after(0, function()
for i = 1, #pending do
(pending[i])()
end
pending = nil
end)
end
pending[#pending + 1] = function()
local nn = minetest.get_node(pos)
if nn.name == node.name then
return oldact(pos, node)
end
end
end
return oldreg(def, ...)
end