fix bugs with queue inlining; inline gate queue as well

This commit is contained in:
Redo0 2021-06-05 19:12:21 -05:00
parent d3d03ce9a7
commit 00dc81948d
4 changed files with 30 additions and 16 deletions

View File

@ -34,7 +34,7 @@ function Gate.setportstate(gate, index, state)
--gate[index*2+1] = state
gate.port_states[index] = state
if (group.state_num>0) ~= (group.state==1) and (group.in_queue==0) then
if ((group.state_num>0) ~= (group.state==1)) and (group.in_queue==0) then
Simulation.queuegroup(GSim, group)
end
end

View File

@ -39,9 +39,7 @@ function Group.addwire(group, wire)
Wire.setgroup(wire, group)
Wire.update(wire)
if group.in_queue==0 then
Simulation.queuegroup(GSim, group)
end
Simulation.queuegroup_safe(GSim, group)
end
end
end
@ -98,7 +96,7 @@ function Group.addport(group, port)
group.nout_ports = group.nout_ports + 1
group.state_num = group.state_num + Port.getstate(port)
Simulation.queuegroup(GSim, group)
Simulation.queuegroup_safe(GSim, group)
elseif port.type == PortTypes.input then
if group.in_ports[port] then error("port already in group") end
@ -106,7 +104,7 @@ function Group.addport(group, port)
group.in_ports[port] = port
group.nin_ports = group.nin_ports + 1
Simulation.queuegate(GSim, Port.getgate(port))
Simulation.queuegate_safe(GSim, Port.getgate(port))
end
@ -124,7 +122,7 @@ function Group.removeport(group, port)
group.state_num = group.state_num - Port.getstate(port)
Simulation.queuegroup(GSim, group)
Simulation.queuegroup_safe(GSim, group)
elseif port.type == PortTypes.input then
if not group.in_ports[port] then error("port not in group") end
@ -132,7 +130,7 @@ function Group.removeport(group, port)
group.in_ports[port] = nil
group.nin_ports = group.nin_ports - 1
Simulation.queuegate(GSim, Port.getgate(port))
Simulation.queuegate_safe(GSim, Port.getgate(port))
end
Group.rebuild_ports(group)
@ -185,7 +183,10 @@ function Group.setstate(group, state)
local len = group.num_gates_update
for i = 1, len do
Simulation.queuegate(sim, group.gates_update[i])
local gate = group.gates_update[i]
if gate.in_queue==0 then
Simulation.queuegate(sim, gate)
end
end
Simulation.queuegroupfx(sim, group)

View File

@ -182,7 +182,7 @@ function network_update()
Simulation.tickinit(sim)
Simulation.tickinput(sim)
Simulation.ticklogic(sim)
ticks = ticks + 1
--ticks = ticks + 1
elseif data[i] == "IN" then
local gate = Simulation.getgatebyref(sim, tonumber(data[i+1]))
local argc = tonumber(data[i+2])

View File

@ -118,7 +118,7 @@ function Simulation.addgate(sim, gate)
Gate.preinit(gate)
Simulation.queuegateinit(sim, gate)
Simulation.queuegate(sim, gate)
Simulation.queuegate_safe(sim, gate)
end
function Simulation.removewire(sim, objref)
@ -239,12 +239,15 @@ end
-- Logic Critical
function Simulation.queuegate(sim, gate)
if gate.in_queue==0 then
--table.insert(sim.gatequeue, gate)
sim.gatequeue[sim.num_gatequeue+1] = gate
sim.num_gatequeue = sim.num_gatequeue + 1
gate.in_queue = 1
end
function Simulation.queuegate_safe(sim, gate)
if gate.in_queue==0 then
Simulation.queuegate(sim, gate)
end
end
function Simulation.queuegatelater(sim, gate, delay)
@ -272,6 +275,12 @@ function Simulation.queuegroup(sim, group)
group.in_queue = 1
end
function Simulation.queuegroup_safe(sim, group)
if group.in_queue==0 then
Simulation.queuegroup(sim, group)
end
end
function Simulation.dequeuegroup(sim, group)
if group.in_queue~=0 then
array_remove(sim.groupqueue, group, true)
@ -309,14 +318,17 @@ function Simulation.ticklogic(sim)
local group = sim.groupqueue[i]
Group.update(group)
group.in_queue = 0
sim.groupqueue[i] = nil
end
--sim.groupqueue = {}
sim.num_groupqueue = 0
if sim.tickqueue[sim.current_tick] ~= nil then
for i, gate in pairs(sim.tickqueue[sim.current_tick]) do
if gate.in_queue==0 then
Simulation.queuegate(sim, gate)
end
end
sim.tickqueue[sim.current_tick] = nil
end
@ -324,6 +336,7 @@ function Simulation.ticklogic(sim)
local gate = sim.gatequeue[i]
gate.logic(gate)
gate.in_queue = 0
sim.gatequeue[i] = nil
end
--sim.gatequeue = {}
sim.num_gatequeue = 0