I'm looking for a fast way to merge signals read with get_circuit_network(defines.wire_type.green) and get_circuit_network(defines.wire_type.red).
Running recursive for loops is not what i want to do in on_tick handling just to get a complete list of signals.
It's a shame we don't have defines.wire_type.all
Merge signals read from get_circuit_network
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Merge signals read from get_circuit_network
It would help to know what you intend to do with the merged results.
Merging in any manner would be relatively slow compared to just iterating the results of both wires.
Merging in any manner would be relatively slow compared to just iterating the results of both wires.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Merge signals read from get_circuit_network
What I want is having all signals merged into one array.
Currently I'm doing it like this.
If we want to mod something that can handle inputs similar to combinators we'll need either an extension to the api, like get_circuit_network(defines.wire_type.all), or some really fast method of merging these two tables, as I can't imagine every combinator doing these two for each loops every tick.
Currently I'm doing it like this.
Code: Select all
function GetCircuitValues(entity)
local greenWire = entity.get_circuit_network(defines.wire_type.green)
local redWire = entity.get_circuit_network(defines.wire_type.red)
local items = {}
if greenWire then
for _, v in pairs (greenWire.signals) do
if v.signal.type == "item" then
items[v.signal.name] = v.count
end
end
end
if redWire then
for _, v in pairs (redWire.signals) do
if v.signal.type == "item" then
if items[v.signal.name] ~= nil then
items[v.signal.name] = items[v.signal.name] + v.count
else
items[v.signal.name] = v.count
end
end
end
end
return items
end
My Mods: mods.factorio.com
Re: Merge signals read from get_circuit_network
That's what the game doesOptera wrote:... as I can't imagine every combinator doing these two for each loops every tick.
If you want to get ahold of me I'm almost always on Discord.
Re: Merge signals read from get_circuit_network
Is that why feeding the whole content of the logistic network from roboports into several combinators causes network update to take noticeable more time?Rseding91 wrote:That's what the game doesOptera wrote:... as I can't imagine every combinator doing these two for each loops every tick.
My Mods: mods.factorio.com
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Merge signals read from get_circuit_network
Can't see many ways to make it faster via Lua, other than reducing number of table lookups and variables:
Code: Select all
local red , green
= defines.wire_type.red, defines.wire_type.green
function GetCircuitValues( entity )
local items, wire
= {} , entity.get_circuit_network( green )
if wire then
for _, data in pairs( wire.signals ) do
if data.signal.type == "item" then
items[data.signal.name] = data.count
end
end
end
wire = entity.get_circuit_network( red )
if wire then
local value
for _, data in pairs (wire.signals) do
if data.signal.type == "item" then
value = items[data.signal.name]
items[data.signal.name] = value and (value + data.count) or data.count
end
end
end
return items
end
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.