make states numbers instead of booleans

This commit is contained in:
Redo0
2021-05-29 13:13:26 -05:00
parent ebc9a7f108
commit 8bb4ff4421
6 changed files with 31 additions and 45 deletions

View File

@@ -23,13 +23,15 @@ function Gate.getportstate(gate, index)
end
function Gate.setportstate(gate, index, state)
if type(state)~="number" then error("invalid state type - must be number (gate "..gate.objref..")") end
local port = gate.ports[index]
if state ~= port.state then
local group = port.group
group.state_num = group.state_num - (port.state and 1 or 0) + (state and 1 or 0)
group.state_num = group.state_num - port.state + state
port.state = state
if (group.state_num>0) ~= group.state then
if (group.state_num>0) ~= (group.state==1) then
Simulation.queuegroup(GSim, group)
end
end