Greatly improve performance by making use of VoxelManips in turnoff

Instead of seperately looking for onstate receptors along equipotential
sections of the circuit before turning off, do that while already
modifying the VoxelManip. In case an onstate receptor is found, discard
the VoxelManip cache, otherwise commit it after turnoff is completed.
This commit is contained in:
Jeija
2016-08-30 19:12:09 +02:00
parent 89153f6909
commit e561be7fa3
2 changed files with 53 additions and 95 deletions

View File

@ -101,8 +101,6 @@ function mesecon.receptor_on(pos, rules)
end
mesecon.queue:add_function("receptor_off", function (pos, rules)
mesecon.vm_begin()
rules = rules or mesecon.rules.default
-- if area (any of the rule targets) is not loaded, keep trying and call this again later
@ -118,15 +116,19 @@ mesecon.queue:add_function("receptor_off", function (pos, rules)
local np = vector.add(pos, rule)
local rulenames = mesecon.rules_link_rule_all(pos, rule)
for _, rulename in ipairs(rulenames) do
if not mesecon.connected_to_receptor(np, mesecon.invertRule(rule)) then
mesecon.turnoff(np, rulename)
mesecon.vm_begin()
mesecon.changesignal(np, minetest.get_node(np), rulename, mesecon.state.off, 2)
-- Turnoff returns true if turnoff process was successful, no onstate receptor
-- was found along the way. Commit changes that were made in voxelmanip. If turnoff
-- returns true, an onstate receptor was found, abort voxelmanip transaction.
if (mesecon.turnoff(np, rulename)) then
mesecon.vm_commit()
else
mesecon.changesignal(np, minetest.get_node(np), rulename, mesecon.state.off, 2)
mesecon.vm_abort()
end
end
end
mesecon.vm_commit()
end)
function mesecon.receptor_off(pos, rules)