Skip to content

Commit

Permalink
Fix conductor lighting when aliases are used (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
TurkeyMcMac committed Jan 30, 2022
1 parent 4eea083 commit 4c5b13a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
11 changes: 2 additions & 9 deletions mesecons/internal.lua
Expand Up @@ -372,7 +372,6 @@ end
local light_update_conductors

-- Calculate the contents of the above set if they have not been calculated.
-- This must be called before get_update_light_conductor.
local function find_light_update_conductors()
-- The expensive calculation is only done the first time.
if light_update_conductors then return end
Expand Down Expand Up @@ -415,12 +414,6 @@ local function find_light_update_conductors()
end
end

-- This is the callback for swap_node_force in turnon and turnoff. It determines
-- whether a conductor node necessitates a lighting update.
local function get_update_light_conductor(pos, name)
return light_update_conductors[name] ~= nil
end

-- Turn off an equipotential section starting at `pos`, which outputs in the direction of `link`.
-- Breadth-first search. Map is abstracted away in a voxelmanip.
-- Follow all all conductor paths replacing conductors that were already
Expand Down Expand Up @@ -453,7 +446,7 @@ function mesecon.turnon(pos, link)
end
end

mesecon.swap_node_force(f.pos, mesecon.get_conductor_on(node, f.link), get_update_light_conductor)
mesecon.swap_node_force(f.pos, mesecon.get_conductor_on(node, f.link), light_update_conductors[node.name] ~= nil)
end

-- Only conductors with flat rules can be reliably skipped later
Expand Down Expand Up @@ -527,7 +520,7 @@ function mesecon.turnoff(pos, link)
end
end

mesecon.swap_node_force(f.pos, mesecon.get_conductor_off(node, f.link), get_update_light_conductor)
mesecon.swap_node_force(f.pos, mesecon.get_conductor_off(node, f.link), light_update_conductors[node.name] ~= nil)
end

-- Only conductors with flat rules can be reliably skipped later
Expand Down
16 changes: 8 additions & 8 deletions mesecons/util.lua
Expand Up @@ -389,10 +389,10 @@ end
--
-- Existing param1, param2, and metadata are left alone.
--
-- See mesecon.swap_node_force for documentation about get_update_light.
function mesecon.vm_swap_node(pos, name, get_update_light)
-- The swap will necessitate a light update unless update_light equals false.
function mesecon.vm_swap_node(pos, name, update_light)
local tbl = vm_get_or_create_entry(pos)
tbl.update_light = tbl.update_light or (get_update_light == nil or get_update_light(pos, name))
tbl.update_light = update_light ~= false or tbl.update_light
local index = tbl.va:indexp(pos)
tbl.data[index] = minetest.get_content_id(name)
tbl.dirty = true
Expand Down Expand Up @@ -426,15 +426,15 @@ end
-- Outside a VM transaction, if the mapblock is not loaded, it is pulled into
-- the servers main map data cache and then accessed from there.
--
-- Inside a VM transaction, the transactions VM cache is used. If a third
-- argument is supplied, it may be called. If it returns false, the swap does
-- not necessitate a lighting update.
-- Inside a VM transaction, the transactions VM cache is used.
--
-- This function can only be used to change the nodes name, not its parameters
-- or metadata.
function mesecon.swap_node_force(pos, name, get_update_light)
--
-- The swap will necessitate a light update unless update_light equals false.
function mesecon.swap_node_force(pos, name, update_light)
if vm_cache then
return mesecon.vm_swap_node(pos, name, get_update_light)
return mesecon.vm_swap_node(pos, name, update_light)
else
-- This serves to both ensure the mapblock is loaded and also hand us
-- the old node table so we can preserve param2.
Expand Down

0 comments on commit 4c5b13a

Please sign in to comment.