Skip to content

Commit

Permalink
Renamed net variable to network_id in multiple places, removed unnecc…
Browse files Browse the repository at this point in the history
…esarily checking technic.network[network_id] for nil, moved network_id nil checking inside clear_network function
  • Loading branch information
SomeName42 committed Nov 21, 2024
1 parent 234a9e9 commit 67c7441
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions technic/machines/register/cables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ end

local clear_networks

local function clear_network(net)
for _,v in pairs(technic.networks[net].all_nodes) do
local function clear_network(network_id)
if not network_id then
return
end

for _,v in pairs(technic.networks[network_id].all_nodes) do
local pos1 = minetest.hash_node_position(v)
technic.cables[pos1] = nil
end
local network_bckup = technic.networks[net]
technic.networks[net] = nil
local network_bckup = technic.networks[network_id]
technic.networks[network_id] = nil

for _,n_pos in pairs(network_bckup.PR_nodes) do
clear_networks(n_pos)
Expand Down Expand Up @@ -86,7 +90,6 @@ clear_networks = function(pos)

-- Actually add it to the (cached) network
-- !! IMPORTANT: ../switching_station.lua -> check_node_subp() must be kept in sync
pos.visited = 1
if technic.is_tier_cable(node.name, tier) then
technic.cables[minetest.hash_node_position(pos)] = network_id
table.insert(network.all_nodes,pos)
Expand Down Expand Up @@ -134,17 +137,12 @@ clear_networks = function(pos)
return
end

local net = technic.cables[minetest.hash_node_position(pos)]
if net and technic.networks[net] then
clear_network(net)
end
clear_network(technic.cables[minetest.hash_node_position(pos)])

for _,connected_pos in pairs(positions) do
local net = technic.cables[minetest.hash_node_position(connected_pos)]
if net and technic.networks[net] then
-- Not a dead end, so the whole network needs to be recalculated
clear_network(net)
end
local network_id = technic.cables[minetest.hash_node_position(connected_pos)]
-- Not a dead end, so the whole network needs to be recalculated
clear_network(network_id)
end
end

Expand Down

0 comments on commit 67c7441

Please sign in to comment.