From c20a4b3a897b2c55ec6dd7b84fb6404c387d16d0 Mon Sep 17 00:00:00 2001 From: Jeija Date: Mon, 13 Aug 2012 09:37:55 +0200 Subject: [PATCH] Minimal speedup by not checking some nodes twice for receptors --- mesecons/init.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mesecons/init.lua b/mesecons/init.lua index 3697c7a..6715a2f 100644 --- a/mesecons/init.lua +++ b/mesecons/init.lua @@ -151,13 +151,16 @@ function mesecon:receptor_off(pos, rules) rules = mesecon:get_rules("default") end + local checked = {} + local connected = false local i = 1 while rules[i]~=nil do local np = {} np.x = pos.x + rules[i].x np.y = pos.y + rules[i].y np.z = pos.z + rules[i].z - if not mesecon:connected_to_pw_src(np) then + connected, checked = mesecon:connected_to_pw_src(np, checked) + if not connected then mesecon:turnoff(np) end i=i+1