inline Port.setstate; remove unused network codes
This commit is contained in:
parent
c62d7340b0
commit
09e65faec4
14
sim/gate.lua
14
sim/gate.lua
@ -6,6 +6,7 @@ function Gate.new(objref, definition)
|
||||
objref = objref,
|
||||
definition = definition,
|
||||
ports = {},
|
||||
port_nets = {},
|
||||
in_queue = false,
|
||||
logic = definition.logic,
|
||||
}
|
||||
@ -18,11 +19,20 @@ function Gate.addport(gate, port)
|
||||
end
|
||||
|
||||
function Gate.getportstate(gate, index)
|
||||
return gate.ports[index].group.state
|
||||
return gate.port_nets[index].state
|
||||
end
|
||||
|
||||
function Gate.setportstate(gate, index, state)
|
||||
Port.setstate(gate.ports[index], state)
|
||||
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)
|
||||
port.state = state
|
||||
|
||||
if (group.state_num>0) ~= group.state then
|
||||
Simulation.queuegroup(GSim, group)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Gate.initdata(gate)
|
||||
|
@ -82,7 +82,7 @@ function GateDefinition.constructgate(def, objref, position, rotation)
|
||||
pos[2] = x
|
||||
end
|
||||
|
||||
Gate.addport(gate, Port.new(type, dir, {position[1]+pos[1], position[2]+pos[2], position[3]+pos[3]}, portd.causeupdate))
|
||||
Gate.addport(gate, Port.new(type, dir, {position[1]+pos[1], position[2]+pos[2], position[3]+pos[3]}, portd.causeupdate, i))
|
||||
end
|
||||
|
||||
return gate
|
||||
|
@ -84,7 +84,7 @@ end
|
||||
|
||||
function Group.addport(group, port)
|
||||
if port.group~=nil then error("port already has group") end
|
||||
port.group = group
|
||||
Port.setgroup(port, group)
|
||||
|
||||
if port.type == PortTypes.output then
|
||||
if group.out_ports[port] then error("port already in group") end
|
||||
@ -112,7 +112,7 @@ end
|
||||
|
||||
function Group.removeport(group, port)
|
||||
if port.group~=group then error("port does not have group") end
|
||||
port.group = nil
|
||||
Port.setgroup(port, nil)
|
||||
|
||||
if port.type == PortTypes.output then
|
||||
if not group.out_ports[port] then error("port not in group") end
|
||||
|
14
sim/main.lua
14
sim/main.lua
@ -212,20 +212,6 @@ while 1 do
|
||||
Wire.setlayer(wire, tonumber(data[i+2]))
|
||||
end
|
||||
|
||||
i = i + 2
|
||||
elseif data[i] == "SP" then
|
||||
local gate = Simulation.getgatebyref(sim, tonumber(data[i+1]))
|
||||
if gate ~= nil then
|
||||
Port.setstate(gate.ports[tonumber(data[i+2])], toboolean(data[i+3]))
|
||||
end
|
||||
|
||||
i = i + 3
|
||||
elseif data[i] == "SG" then
|
||||
local wire = Simulation.getwirebyref(sim, tonumber(data[i+1]))
|
||||
if wire ~= nil then
|
||||
Group.setstate(Wire.getgroup(wire), toboolean(data[i+2]))
|
||||
end
|
||||
|
||||
i = i + 2
|
||||
elseif data[i] == "OPT" then
|
||||
local option = data[i+1]
|
||||
|
16
sim/port.lua
16
sim/port.lua
@ -15,7 +15,7 @@ PortDirections = {
|
||||
|
||||
Port = {}
|
||||
|
||||
function Port.new(type, direction, position, causeupdate)
|
||||
function Port.new(type, direction, position, causeupdate, idx)
|
||||
local o = {
|
||||
type = type,
|
||||
direction = direction,
|
||||
@ -24,22 +24,11 @@ function Port.new(type, direction, position, causeupdate)
|
||||
state = false,
|
||||
gate = nil,
|
||||
group = nil,
|
||||
idx = idx,
|
||||
}
|
||||
return o
|
||||
end
|
||||
|
||||
function Port.setstate(port, state) -- output state
|
||||
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)
|
||||
port.state = state
|
||||
|
||||
if (group.state_num>0) ~= group.state then
|
||||
Simulation.queuegroup(GSim, group)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Port.getconnectionposition(port)
|
||||
local offset = PortDirections[port.direction]
|
||||
return {port.position[1]+offset[1], port.position[2]+offset[2], port.position[3]+offset[3]}
|
||||
@ -69,6 +58,7 @@ end
|
||||
|
||||
function Port.setgroup(port, group)
|
||||
port.group = group
|
||||
Port.getgate(port).port_nets[port.idx] = group
|
||||
end
|
||||
|
||||
function Port.getgroup(port)
|
||||
|
Loading…
x
Reference in New Issue
Block a user