diff --git a/sim/gate.lua b/sim/gate.lua index 798e02f..0098047 100644 --- a/sim/gate.lua +++ b/sim/gate.lua @@ -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 diff --git a/sim/group.lua b/sim/group.lua index 1437efb..29e5ee8 100644 --- a/sim/group.lua +++ b/sim/group.lua @@ -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) diff --git a/sim/network.lua b/sim/network.lua index 017cf0f..a2352cd 100644 --- a/sim/network.lua +++ b/sim/network.lua @@ -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 diff --git a/sim/port.lua b/sim/port.lua index 164f7ff..d38df55 100644 --- a/sim/port.lua +++ b/sim/port.lua @@ -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) diff --git a/sim/simulation.lua b/sim/simulation.lua index fba1c63..f90d475 100644 --- a/sim/simulation.lua +++ b/sim/simulation.lua @@ -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) diff --git a/sim/wire.lua b/sim/wire.lua index a9b39e1..8806e07 100644 --- a/sim/wire.lua +++ b/sim/wire.lua @@ -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