make net states pointers

This commit is contained in:
Redo 2022-11-04 15:39:08 -06:00
parent 20b05812df
commit 9e0c196b63
6 changed files with 25 additions and 22 deletions

View File

@ -27,11 +27,10 @@ end
function Gate.setportstate(gate, index, state)
if state ~= gate.port_states[index] then
local group = gate.port_nets[index]
-- local net_state_num = gate.port_net_state_nums[index]
group.state_num = group.state_num - gate.port_states[index] + state
group.state_num[0] = group.state_num[0] - 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)
end
end

View File

@ -4,16 +4,16 @@ local ffi = FFI
Group = {}
function Group.new()
local o = {
local net = {
-- Logic Critical
state = 0,
state_num = 0,
state = ffi.new("int[1]"),
state_num = ffi.new("int[1]"),
in_queue = ffi.new("int[1]"),
update_tick = ffi.new("int[1]"),
gates_update = {},
num_gates_update = 0,
fxstate = 0,
update_tick = 0,
wires = {},
out_ports = {},
@ -22,7 +22,11 @@ function Group.new()
nout_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
function Group.getsize(group)
@ -95,7 +99,7 @@ function Group.addport(group, port)
group.out_ports[port] = port
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)
@ -121,7 +125,7 @@ function Group.removeport(group, port)
group.out_ports[port] = nil
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)
@ -176,11 +180,11 @@ end
-- Logic Critical
function Group.setstate(group, state)
if state ~= group.state then
if state ~= group.state[0] then
local sim = GSim
group.state = state
group.update_tick = sim.current_tick
group.state[0] = state
group.update_tick[0] = sim.current_tick
local len = group.num_gates_update
for i = 1, len do
@ -196,7 +200,7 @@ end
-- Logic Critical
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
function Group.rebuild_ports(group)

View File

@ -148,12 +148,12 @@ function network_update()
if Port.getstate(port)==1 then numportson = numportson+1 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"..
"In Ports: " ..numportsi.."\n"..
"Out Ports: "..numportso.."\n"..
"Gates Update: "..numgatesu.."\n"..
"Out Ports On: "..(group.state_num)
"Out Ports On: "..(group.state_num[0])
;
end

View File

@ -36,11 +36,11 @@ function Port.getconnectionposition(port)
end
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
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
function Port.getgate(port)

View File

@ -371,10 +371,10 @@ end
function Simulation.sendfxupdate(sim)
for k, group in pairs(sim.groupfxqueue) do
if group.state ~= group.fxstate then
group.fxstate = group.state
if group.state[0] ~= group.fxstate then
group.fxstate = group.state[0]
local data = group.state
local data = group.state[0]
for i, wire in pairs(group.wires) do
data = data .. "\t" .. Wire.getobjref(wire)

View File

@ -21,7 +21,7 @@ end
function Wire.update(wire)
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