mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Bulk LBMs (#14954)
This commit is contained in:
parent
7ae51382c8
commit
811adf5d42
9 changed files with 126 additions and 49 deletions
|
@ -43,6 +43,7 @@ core.features = {
|
|||
moveresult_new_pos = true,
|
||||
override_item_remove_fields = true,
|
||||
hotbar_hud_element = true,
|
||||
bulk_lbms = true,
|
||||
}
|
||||
|
||||
function core.has_feature(arg)
|
||||
|
|
|
@ -298,3 +298,28 @@ do
|
|||
return valid_object_iterator(core.get_objects_in_area(min_pos, max_pos))
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
-- Helper for LBM execution, called from C++
|
||||
--
|
||||
|
||||
function core.run_lbm(id, pos_list, dtime_s)
|
||||
local lbm = core.registered_lbms[id]
|
||||
assert(lbm, "Entry with given id not found in registered_lbms table")
|
||||
core.set_last_run_mod(lbm.mod_origin)
|
||||
if lbm.bulk_action then
|
||||
return lbm.bulk_action(pos_list, dtime_s)
|
||||
end
|
||||
-- emulate non-bulk LBMs
|
||||
local expect = core.get_node(pos_list[1]).name
|
||||
-- engine guarantees that
|
||||
-- 1) all nodes are the same content type
|
||||
-- 2) the list is up-to-date when we're called
|
||||
assert(expect ~= "ignore")
|
||||
for _, pos in ipairs(pos_list) do
|
||||
local n = core.get_node(pos)
|
||||
if n.name == expect then -- might have been changed by previous call
|
||||
lbm.action(pos, n, dtime_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -105,7 +105,12 @@ function core.register_lbm(spec)
|
|||
-- Add to core.registered_lbms
|
||||
check_modname_prefix(spec.name)
|
||||
check_node_list(spec.nodenames, "nodenames")
|
||||
assert(type(spec.action) == "function", "Required field 'action' of type function")
|
||||
local have = spec.action ~= nil
|
||||
local have_bulk = spec.bulk_action ~= nil
|
||||
assert(not have or type(spec.action) == "function", "Field 'action' must be a function")
|
||||
assert(not have_bulk or type(spec.bulk_action) == "function", "Field 'bulk_action' must be a function")
|
||||
assert(have ~= have_bulk, "Either 'action' or 'bulk_action' must be present")
|
||||
|
||||
core.registered_lbms[#core.registered_lbms + 1] = spec
|
||||
spec.mod_origin = core.get_current_modname() or "??"
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue