From bc9d4c2d5a1d535f4abc001d527cc65c78227016 Mon Sep 17 00:00:00 2001 From: Christopher Head Date: Sat, 20 Aug 2016 21:54:15 -0700 Subject: [PATCH] Use VM transactions for conductor state changes. VoxelManipulator-based transactions are used to hopefully speed up scanning and replacing of networks of conductors when receptors start or stop driving signals into them. --- mesecons/init.lua | 8 ++++++++ mesecons/internal.lua | 6 ++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/mesecons/init.lua b/mesecons/init.lua index 6b36e69..944a86a 100644 --- a/mesecons/init.lua +++ b/mesecons/init.lua @@ -70,6 +70,8 @@ dofile(minetest.get_modpath("mesecons").."/internal.lua"); -- these are the only functions you need to remember mesecon.queue:add_function("receptor_on", 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 @@ -90,6 +92,8 @@ mesecon.queue:add_function("receptor_on", function (pos, rules) mesecon.turnon(np, rulename) end end + + mesecon.vm_commit() end) function mesecon.receptor_on(pos, rules) @@ -97,6 +101,8 @@ 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 @@ -119,6 +125,8 @@ mesecon.queue:add_function("receptor_off", function (pos, rules) end end end + + mesecon.vm_commit() end) function mesecon.receptor_off(pos, rules) diff --git a/mesecons/internal.lua b/mesecons/internal.lua index 4ef2b18..e11de4f 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -405,8 +405,7 @@ function mesecon.turnon(pos, link) end if success then - minetest.swap_node(f.pos, {name = mesecon.get_conductor_on(node, f.link), - param2 = node.param2}) + mesecon.swap_node_force(f.pos, mesecon.get_conductor_on(node, f.link)) for npos, links in pairs(neighborlinks) do -- links = all links to node, l = each single link @@ -465,8 +464,7 @@ function mesecon.turnoff(pos, link) end if success then - minetest.swap_node(f.pos, {name = mesecon.get_conductor_off(node, f.link), - param2 = node.param2}) + mesecon.swap_node_force(f.pos, mesecon.get_conductor_off(node, f.link)) for npos, links in pairs(neighborlinks) do -- links = all links to node, l = each single link