make net states pointers
This commit is contained in:
parent
20b05812df
commit
9e0c196b63
@ -27,11 +27,10 @@ end
|
|||||||
function Gate.setportstate(gate, index, state)
|
function Gate.setportstate(gate, index, state)
|
||||||
if state ~= gate.port_states[index] then
|
if state ~= gate.port_states[index] then
|
||||||
local group = gate.port_nets[index]
|
local group = gate.port_nets[index]
|
||||||
-- local net_state_num = gate.port_net_state_nums[index]
|
group.state_num[0] = group.state_num[0] - gate.port_states[index] + state
|
||||||
group.state_num = group.state_num - gate.port_states[index] + state
|
|
||||||
gate.port_states[index] = state
|
gate.port_states[index] = state
|
||||||
|
|
||||||
if ((group.state_num>0) ~= (group.state==1)) and (group.in_queue[0]==0) then
|
if ((group.state_num[0]>0) ~= (group.state[0]==1)) and (group.in_queue[0]==0) then
|
||||||
Simulation.queuegroup(GSim, group)
|
Simulation.queuegroup(GSim, group)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,16 +4,16 @@ local ffi = FFI
|
|||||||
Group = {}
|
Group = {}
|
||||||
|
|
||||||
function Group.new()
|
function Group.new()
|
||||||
local o = {
|
local net = {
|
||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
state = 0,
|
state = ffi.new("int[1]"),
|
||||||
state_num = 0,
|
state_num = ffi.new("int[1]"),
|
||||||
in_queue = ffi.new("int[1]"),
|
in_queue = ffi.new("int[1]"),
|
||||||
|
update_tick = ffi.new("int[1]"),
|
||||||
gates_update = {},
|
gates_update = {},
|
||||||
num_gates_update = 0,
|
num_gates_update = 0,
|
||||||
|
|
||||||
fxstate = 0,
|
fxstate = 0,
|
||||||
update_tick = 0,
|
|
||||||
|
|
||||||
wires = {},
|
wires = {},
|
||||||
out_ports = {},
|
out_ports = {},
|
||||||
@ -22,7 +22,11 @@ function Group.new()
|
|||||||
nout_ports = 0,
|
nout_ports = 0,
|
||||||
nin_ports = 0,
|
nin_ports = 0,
|
||||||
}
|
}
|
||||||
return o
|
net.state[0] = 0
|
||||||
|
net.state_num[0] = 0
|
||||||
|
net.in_queue[0] = 0
|
||||||
|
net.update_tick[0] = 0
|
||||||
|
return net
|
||||||
end
|
end
|
||||||
|
|
||||||
function Group.getsize(group)
|
function Group.getsize(group)
|
||||||
@ -95,7 +99,7 @@ function Group.addport(group, port)
|
|||||||
|
|
||||||
group.out_ports[port] = port
|
group.out_ports[port] = port
|
||||||
group.nout_ports = group.nout_ports + 1
|
group.nout_ports = group.nout_ports + 1
|
||||||
group.state_num = group.state_num + Port.getstate(port)
|
group.state_num[0] = group.state_num[0] + Port.getstate(port)
|
||||||
|
|
||||||
Simulation.queuegroup_safe(GSim, group)
|
Simulation.queuegroup_safe(GSim, group)
|
||||||
|
|
||||||
@ -121,7 +125,7 @@ function Group.removeport(group, port)
|
|||||||
group.out_ports[port] = nil
|
group.out_ports[port] = nil
|
||||||
group.nout_ports = group.nout_ports - 1
|
group.nout_ports = group.nout_ports - 1
|
||||||
|
|
||||||
group.state_num = group.state_num - Port.getstate(port)
|
group.state_num[0] = group.state_num[0] - Port.getstate(port)
|
||||||
|
|
||||||
Simulation.queuegroup_safe(GSim, group)
|
Simulation.queuegroup_safe(GSim, group)
|
||||||
|
|
||||||
@ -176,11 +180,11 @@ end
|
|||||||
|
|
||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
function Group.setstate(group, state)
|
function Group.setstate(group, state)
|
||||||
if state ~= group.state then
|
if state ~= group.state[0] then
|
||||||
local sim = GSim
|
local sim = GSim
|
||||||
|
|
||||||
group.state = state
|
group.state[0] = state
|
||||||
group.update_tick = sim.current_tick
|
group.update_tick[0] = sim.current_tick
|
||||||
|
|
||||||
local len = group.num_gates_update
|
local len = group.num_gates_update
|
||||||
for i = 1, len do
|
for i = 1, len do
|
||||||
@ -196,7 +200,7 @@ end
|
|||||||
|
|
||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
function Group.update(group)
|
function Group.update(group)
|
||||||
Group.setstate(group, group.state_num>0 and 1 or 0)
|
Group.setstate(group, group.state_num[0]>0 and 1 or 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Group.rebuild_ports(group)
|
function Group.rebuild_ports(group)
|
||||||
|
@ -148,12 +148,12 @@ function network_update()
|
|||||||
if Port.getstate(port)==1 then numportson = numportson+1 end
|
if Port.getstate(port)==1 then numportson = numportson+1 end
|
||||||
end
|
end
|
||||||
|
|
||||||
info = "\\c5Net " .. tostring(group):match("table: 0x(.+)"):upper() .. "\n" .. (Wire.getgroup(wire).state==1 and "\\c2On" or "\\c0Off") .. "\n" ..
|
info = "\\c5Net " .. tostring(group):match("table: 0x(.+)"):upper() .. "\n" .. (Wire.getgroup(wire).state[0]==1 and "\\c2On" or "\\c0Off") .. "\n" ..
|
||||||
"Wires: "..numwires.."\n"..
|
"Wires: "..numwires.."\n"..
|
||||||
"In Ports: " ..numportsi.."\n"..
|
"In Ports: " ..numportsi.."\n"..
|
||||||
"Out Ports: "..numportso.."\n"..
|
"Out Ports: "..numportso.."\n"..
|
||||||
"Gates Update: "..numgatesu.."\n"..
|
"Gates Update: "..numgatesu.."\n"..
|
||||||
"Out Ports On: "..(group.state_num)
|
"Out Ports On: "..(group.state_num[0])
|
||||||
;
|
;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -36,11 +36,11 @@ function Port.getconnectionposition(port)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Port.isrising(port)
|
function Port.isrising(port)
|
||||||
return port.group.state==1 and (port.group.update_tick == GSim.current_tick)
|
return port.group.state[0]==1 and (port.group.update_tick[0] == GSim.current_tick)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Port.isfalling(port)
|
function Port.isfalling(port)
|
||||||
return port.group.state==0 and (port.group.update_tick == GSim.current_tick)
|
return port.group.state[0]==0 and (port.group.update_tick[0] == GSim.current_tick)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Port.getgate(port)
|
function Port.getgate(port)
|
||||||
|
@ -371,10 +371,10 @@ end
|
|||||||
|
|
||||||
function Simulation.sendfxupdate(sim)
|
function Simulation.sendfxupdate(sim)
|
||||||
for k, group in pairs(sim.groupfxqueue) do
|
for k, group in pairs(sim.groupfxqueue) do
|
||||||
if group.state ~= group.fxstate then
|
if group.state[0] ~= group.fxstate then
|
||||||
group.fxstate = group.state
|
group.fxstate = group.state[0]
|
||||||
|
|
||||||
local data = group.state
|
local data = group.state[0]
|
||||||
|
|
||||||
for i, wire in pairs(group.wires) do
|
for i, wire in pairs(group.wires) do
|
||||||
data = data .. "\t" .. Wire.getobjref(wire)
|
data = data .. "\t" .. Wire.getobjref(wire)
|
||||||
|
@ -21,7 +21,7 @@ end
|
|||||||
|
|
||||||
function Wire.update(wire)
|
function Wire.update(wire)
|
||||||
if wire.layer~=-1 then
|
if wire.layer~=-1 then
|
||||||
network_send("WU\t" .. (wire.group.state~=0 and "1" or "0") .. "\t" .. wire.objref .. "\n")
|
network_send("WU\t" .. (wire.group.state[0]~=0 and "1" or "0") .. "\t" .. wire.objref .. "\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user