HUGE speed improvement

This commit is contained in:
Jeija 2012-08-12 10:57:00 +02:00
parent d72c0e6bdd
commit 9829abc74d
14 changed files with 72 additions and 71 deletions

@ -88,6 +88,7 @@ mesecon.actions_off={} -- Saves registered function callbacks for mesecon off
mesecon.actions_change={} -- Saves registered function callbacks for mesecon change
mesecon.pwr_srcs={}
mesecon.pwr_srcs_off={}
mesecon.effectors={}
mesecon.rules={}
mesecon.conductors={}
@ -135,7 +136,21 @@ function mesecon:receptor_on(pos, rules)
end
function mesecon:receptor_off(pos, rules)
mesecon:turnoff(pos, 0, 0, 0, true, rules)
if rules == nil then
rules = mesecon:get_rules("default")
end
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 mesecon:connected_to_pw_src(np, 0, 0, 0, {}) == false then
mesecon:turnoff(np)
end
i=i+1
end
end
function mesecon:register_on_signal_on(action)

@ -161,7 +161,6 @@ function mesecon:is_conductor_off(name)
return false
end
--Rules rotation Functions:
function mesecon:rotate_rules_right(rules)
local i=1
@ -257,49 +256,38 @@ function mesecon:turnon(p, x, y, z, firstcall, rules)
end
end
function mesecon:turnoff(pos, x, y, z, firstcall, rules)
if rules==nil then
rules=mesecon:get_rules("default")
end
local lpos = {}
lpos.x=pos.x+x
lpos.y=pos.y+y
lpos.z=pos.z+z
local node = minetest.env:get_node(lpos)
function mesecon:turnoff(pos)
local node = minetest.env:get_node(pos)
local connected = 0
local checked = {}
--Send Signals to effectors:
mesecon:changesignal(lpos)
if not mesecon:check_if_turnon(lpos) then
mesecon:deactivate(lpos)
end
if not(firstcall) and connected==0 then
connected=mesecon:connected_to_pw_src(lpos, 0, 0, 0, checked)
end
if connected == 0 and mesecon:is_conductor_on(node.name) then
--minetest.env:remove_node(lpos)
minetest.env:add_node(lpos, {name=mesecon:get_conductor_off(node.name)})
nodeupdate(lpos)
if minetest.get_item_group(node.name, "mesecon_effector_on") == 1 then
if not mesecon:check_if_turnon(pos) then --Check if the signal comes from another source
--Send Signals to effectors:
mesecon:deactivate(pos)
end
mesecon:changesignal(pos) --Changesignal is always thrown because nodes can be both receptors and effectors
end
if mesecon:is_conductor_on(node.name) or firstcall then
if connected == 0 then
local i=1
while rules[i]~=nil do
mesecon:turnoff(lpos, rules[i].x, rules[i].y, rules[i].z, false)
i=i+1
end
if mesecon:is_conductor_on(node.name) then
minetest.env:add_node(pos, {name=mesecon:get_conductor_off(node.name)})
nodeupdate(pos)
rules = mesecon:get_rules("default")
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
mesecon:turnoff(np)
i=i+1
end
end
end
function mesecon:connected_to_pw_src(pos, x, y, z, checked, firstcall)
function mesecon:connected_to_pw_src(pos, x, y, z, checked)
local i=1
local lpos = {}
@ -315,7 +303,7 @@ function mesecon:connected_to_pw_src(pos, x, y, z, checked, firstcall)
i=i+1
if checked[i]==nil then checked[i]={} break end
if checked[i].x==lpos.x and checked[i].y==lpos.y and checked[i].z==lpos.z then
return 0
return false
end
until false
@ -324,23 +312,19 @@ function mesecon:connected_to_pw_src(pos, x, y, z, checked, firstcall)
checked[i].z=lpos.z
if mesecon:is_receptor_node(node.name, lpos, pos) == true then -- receptor nodes (power sources) can be added using mesecon:add_receptor_node
return 1
return true
end
if mesecon:is_conductor_on(node.name) or firstcall then -- add other conductors here
local pw_source_found=0
if mesecon:is_conductor_on(node.name) then
local rules=mesecon:get_rules("default")
local i=1
while rules[i]~=nil do
pw_source_found=pw_source_found+mesecon:connected_to_pw_src(lpos, rules[i].x, rules[i].y, rules[i].z, checked, false)
if mesecon:connected_to_pw_src(lpos, rules[i].x, rules[i].y, rules[i].z, checked) == true then return true end
i=i+1
end
if pw_source_found > 0 then
return 1
end
end
end
return 0
return false
end
function mesecon:check_if_turnon(pos)
@ -378,7 +362,7 @@ function mesecon:updatenode(pos)
if mesecon:connected_to_pw_src(pos, 0, 0, 0, {}) then
mesecon:turnon(pos, 0, 0, 0)
else
mesecon:turnoff(pos, 0, 0, 0)
mesecon:turnoff(pos)
end
end
@ -396,7 +380,9 @@ end)
minetest.register_on_dignode(
function(pos, oldnode, digger)
if mesecon:is_conductor_on(oldnode.name) then
mesecon:turnoff(pos, 0, 0, 0, true)
local i = 1
mesecon:receptor_off(pos)
end
end
)

@ -19,7 +19,7 @@ for i = 1, 5 do
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
},
groups = {dig_immediate=2, mesecon = 2},
groups = {dig_immediate=2, mesecon = 2, mesecon_effector_on = 1},
description="Battery",
})
mesecon:add_receptor_node_off("mesecons_battery:battery_charging_"..i)
@ -46,7 +46,7 @@ for i = 1, 5 do
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
},
groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 2},
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 2, mesecon_effector_off = 1},
description="Battery",
})
mesecon:add_receptor_node("mesecons_battery:battery_discharging_"..i)

@ -1,9 +1,9 @@
for i = 1, 4 do
local groups = {}
if i == 1 then
groups = {bendy=2,snappy=1,dig_immediate=2, mesecon = 2}
groups = {bendy=2,snappy=1,dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}
else
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1, mesecon = 2}
groups = {bendy=2,snappy=1,dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, not_in_creative_inventory=1, mesecon = 2}
end
boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab

@ -20,7 +20,7 @@ minetest.register_node("mesecons_lamp:lamp_on", {
wall_bottom = {-0.3125,-0.5,-0.3125,0.3125,-0.375,0.3125},
wall_side = {-0.375,-0.3125,-0.3125,-0.5,0.3125,0.3125},
},
groups = {dig_immediate=3,not_in_creative_inventory=1, mesecon = 2},
groups = {dig_immediate=3,not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon = 2},
drop='"mesecons_lamp:lamp_off" 1',
})
@ -45,7 +45,7 @@ minetest.register_node("mesecons_lamp:lamp_off", {
wall_bottom = {-0.3125,-0.5,-0.3125,0.3125,-0.375,0.3125},
wall_side = {-0.375,-0.3125,-0.3125,-0.5,0.3125,0.3125},
},
groups = {dig_immediate=3, mesecon = 2},
groups = {dig_immediate=3, mesecon_receptor_off = 1, mesecon = 2},
description="Meselamp",
})

@ -2,13 +2,13 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_off", {
tile_images = {texture_off},
inventory_image = minetest.inventorycube(texture_off),
groups = {cracky=2, mesecon = 2},
groups = {cracky=2, mesecon_effector_off = 1, mesecon = 2},
description=name.." Lightstone",
})
minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_on", {
tile_images = {texture_on},
inventory_image = minetest.inventorycube(texture_on),
groups = {cracky=2,not_in_creative_inventory=1, mesecon = 2},
groups = {cracky=2,not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon = 2},
drop = "node mesecons_lightstone:lightstone_" .. name .. "_off 1",
light_source = LIGHT_MAX-2,
description=name.." Lightstone",

@ -6,9 +6,9 @@ for c = 0, 1 do
for d = 0, 1 do
local nodename = "mesecons_microcontroller:microcontroller"..tostring(d)..tostring(c)..tostring(b)..tostring(a)
if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 2}
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}
else
groups = {dig_immediate=2, mesecon = 2}
groups = {dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}
end
minetest.register_node(nodename, {
description = "Microcontroller",

@ -39,7 +39,7 @@ minetest.register_node("mesecons_movestones:movestone", {
tile_images = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"},
paramtype2 = "facedir",
legacy_facedir_simple = true,
groups = {cracky=3},
groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1},
description="Movestone",
})
@ -116,7 +116,7 @@ minetest.register_node("mesecons_movestones:sticky_movestone", {
inventory_image = minetest.inventorycube("jeija_sticky_movestone.png", "jeija_movestone_side.png", "jeija_movestone_side.png"),
paramtype2 = "facedir",
legacy_facedir_simple = true,
groups = {cracky=3},
groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1},
description="Sticky Movestone",
})

@ -1,7 +1,7 @@
minetest.register_node("mesecons_noteblock:noteblock", {
description = "Noteblock",
tile_images = {"mesecons_noteblock.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon_effector_off = 1, mesecon = 2},
drawtype = "allfaces_optional",
visual_scale = 1.3,
paramtype="light",

@ -3,7 +3,7 @@
minetest.register_node("mesecons_pistons:piston_normal", {
description = "Piston",
tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_side.png"},
groups = {cracky=3, mesecon = 2},
groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
paramtype2 = "facedir",
after_dig_node = function(pos, oldnode)
local dir = mesecon:piston_get_direction(oldnode)
@ -23,7 +23,7 @@ minetest.register_node("mesecons_pistons:piston_normal", {
minetest.register_node("mesecons_pistons:piston_sticky", {
description = "Sticky Piston",
tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_sticky_side.png"},
groups = {cracky=3, mesecon = 2},
groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
paramtype2 = "facedir",
after_dig_node = function(pos, oldnode)
local dir = mesecon:piston_get_direction(oldnode)

@ -3,7 +3,7 @@
minetest.register_node("mesecons_pistons:piston_down_normal", {
description = "Piston DOWN",
tiles = {"jeija_piston_tb.png", "jeija_piston_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
groups = {cracky=3, mesecon = 2},
groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
after_dig_node = function(pos, oldnode)
local dir = {x=0, y=-1, z=0}
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
@ -22,7 +22,7 @@ minetest.register_node("mesecons_pistons:piston_down_normal", {
minetest.register_node("mesecons_pistons:piston_down_sticky", {
description = "Sticky Piston DOWN",
tiles = {"jeija_piston_tb.png", "jeija_piston_sticky_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
groups = {cracky=3, mesecon = 2},
groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
after_dig_node = function(pos, oldnode)
local dir = {x=0, y=-1, z=0}
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check

@ -3,7 +3,7 @@
minetest.register_node("mesecons_pistons:piston_up_normal", {
description = "Piston UP",
tiles = {"jeija_piston_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
groups = {cracky=3, mesecon = 2},
groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
after_dig_node = function(pos, oldnode)
local dir = {x=0, y=1, z=0}
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
@ -22,7 +22,7 @@ minetest.register_node("mesecons_pistons:piston_up_normal", {
minetest.register_node("mesecons_pistons:piston_up_sticky", {
description = "Sticky Piston UP",
tiles = {"jeija_piston_sticky_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
groups = {cracky=3, mesecon = 2},
groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
after_dig_node = function(pos, oldnode)
local dir = {x=0, y=1, z=0}
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check

@ -4,7 +4,7 @@ minetest.register_node("mesecons_random:removestone", {
tile_images = {"jeija_removestone.png"},
inventory_image = minetest.inventorycube("jeija_removestone_inv.png"),
material = minetest.digprop_stonelike(1.0),
groups = {cracky=3, mesecon = 2},
groups = {cracky=3, mesecon_effector_off = 1, mesecon = 2},
description="Removestone",
})

@ -105,7 +105,7 @@ minetest.register_node("mesecons_temperest:mesecon_plug", {
tile_images = {"jeija_mesecon_plug.png"},
inventory_image = "jeija_mesecon_plug.png",
wield_image = "jeija_mesecon_plug.png",
groups = {dig_immediate=2, mesecon = 2},
groups = {dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
walkable = false,
selection_box = {
type = "fixed",
@ -139,7 +139,7 @@ minetest.register_node("mesecons_temperest:mesecon_socket_off", {
tile_images = {"jeija_mesecon_socket_off.png"},
inventory_image = "jeija_mesecon_socket_off.png",
wield_image = "jeija_mesecon_socket_off.png",
groups = {dig_immediate=2, mesecon = 2},
groups = {dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
walkable = false,
selection_box = {
type = "fixed",
@ -156,7 +156,7 @@ minetest.register_node("mesecons_temperest:mesecon_socket_on", {
paramtype = "light",
is_ground_content = true,
tile_images = {"jeija_mesecon_socket_on.png"},
groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 2},
groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
walkable = false,
selection_box = {
type = "fixed",
@ -191,7 +191,7 @@ if ENABLE_TEMPEREST then
paramtype = "light",
is_ground_content = true,
tile_images = {"jeija_mesecon_inverter_off.png"},
groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 2},
groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
walkable = false,
selection_box = {
type = "fixed",
@ -212,7 +212,7 @@ if ENABLE_TEMPEREST then
tile_images = {"jeija_mesecon_inverter_on.png"},
inventory_image = "jeija_mesecon_inverter_on.png",
wield_image = "jeija_mesecon_inverter_on.png",
groups = {dig_immediate=2, mesecon = 2},
groups = {dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
walkable = false,
selection_box = {
type = "fixed",