Aaron Suen 3367ca1857 Fast optic path obstruction response
Optics keep track of path dependency info
used in calculating state.  When a node is
added/removed in the path via the mod API
(i.e. not schematics, vmanip, etc.) then the
nodes whose state decisions depended on
paths going through there are automatically
triggered for a recheck.

This should make things like furnace sand
auto-loaders respond snappily.

Granted, memory use with this approach is
a concern, but we will just have to monitor it
under normal usage patterns.
2020-06-19 10:01:25 -04:00

53 lines
1.4 KiB
Lua

-- LUALOCALS < ---------------------------------------------------------
local minetest, nodecore, pairs
= minetest, nodecore, pairs
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
nodecore.register_limited_abm({
label = "scaling decay",
interval = 1,
chance = 1,
limited_max = 100,
nodenames = {"group:" .. modname},
ignore_stasis = true,
action = function(pos)
local data = minetest.get_meta(pos):get_string("data")
if (not data) or (data == "") then
return minetest.remove_node(pos)
end
data = minetest.deserialize(data)
if minetest.get_node(data.pos).name ~= data.node then
return minetest.remove_node(pos)
end
for _, p in pairs(minetest.get_connected_players()) do
if nodecore.scaling_closenough(pos, p) then return end
end
return minetest.remove_node(pos)
end
})
local dntname = modname .. ":particles"
nodecore.register_dnt({
name = dntname,
time = 1,
loop = true,
nodenames = {"group:" .. modname .. "_fx"},
action = function(pos)
nodecore.scaling_particles(pos)
return nodecore.dnt_set(pos, dntname, 1)
end
})
nodecore.register_limited_abm({
label = "scaling particles",
interval = 1,
chance = 1,
limited_max = 100,
nodenames = {"group:" .. modname .. "_fx"},
action = function(pos)
return nodecore.dnt_set(pos, dntname)
end
})