make queues 0 indexed
This commit is contained in:
parent
2376154957
commit
a83f4f8f8e
@ -247,7 +247,7 @@ end
|
|||||||
|
|
||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
function Simulation.queuegate_c(sim, cgate)
|
function Simulation.queuegate_c(sim, cgate)
|
||||||
sim.gatequeue[sim.num_gatequeue + 1] = cgate
|
sim.gatequeue[sim.num_gatequeue] = cgate
|
||||||
sim.num_gatequeue = sim.num_gatequeue + 1
|
sim.num_gatequeue = sim.num_gatequeue + 1
|
||||||
cgate.in_queue[0] = 1
|
cgate.in_queue[0] = 1
|
||||||
end
|
end
|
||||||
@ -285,7 +285,7 @@ end
|
|||||||
|
|
||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
function Simulation.queuegroup_c(sim, cnet)
|
function Simulation.queuegroup_c(sim, cnet)
|
||||||
sim.groupqueue[sim.num_groupqueue+1] = cnet
|
sim.groupqueue[sim.num_groupqueue] = cnet
|
||||||
sim.num_groupqueue = sim.num_groupqueue + 1
|
sim.num_groupqueue = sim.num_groupqueue + 1
|
||||||
cnet.in_queue[0] = 1
|
cnet.in_queue[0] = 1
|
||||||
end
|
end
|
||||||
@ -303,8 +303,7 @@ end
|
|||||||
|
|
||||||
function Simulation.dequeuegroup(sim, group)
|
function Simulation.dequeuegroup(sim, group)
|
||||||
if group.in_queue[0]~=0 then
|
if group.in_queue[0]~=0 then
|
||||||
array_remove(sim.groupqueue, group.c, true)
|
sim.num_groupqueue = array_remove(sim.groupqueue, sim.num_groupqueue, group.c, true)
|
||||||
sim.num_groupqueue = sim.num_groupqueue - 1
|
|
||||||
group.in_queue[0] = 0
|
group.in_queue[0] = 0
|
||||||
end
|
end
|
||||||
--sim.groupfxqueue[group] = nil
|
--sim.groupfxqueue[group] = nil
|
||||||
@ -312,8 +311,7 @@ end
|
|||||||
|
|
||||||
function Simulation.dequeuegate(sim, gate)
|
function Simulation.dequeuegate(sim, gate)
|
||||||
if gate.in_queue[0]~=0 then
|
if gate.in_queue[0]~=0 then
|
||||||
array_remove(sim.gatequeue, gate.c, true)
|
sim.num_gatequeue = array_remove(sim.gatequeue, sim.num_gatequeue, gate.c, true)
|
||||||
sim.num_gatequeue = sim.num_gatequeue - 1
|
|
||||||
gate.in_queue[0] = 0
|
gate.in_queue[0] = 0
|
||||||
end
|
end
|
||||||
if sim.inputqueue~=nil then sim.inputqueue[gate] = nil end
|
if sim.inputqueue~=nil then sim.inputqueue[gate] = nil end
|
||||||
@ -334,7 +332,7 @@ end
|
|||||||
|
|
||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
function Simulation.ticklogic(sim)
|
function Simulation.ticklogic(sim)
|
||||||
for i = 1, sim.num_groupqueue do
|
for i = 0, sim.num_groupqueue-1 do
|
||||||
local cnet = sim.groupqueue[i]
|
local cnet = sim.groupqueue[i]
|
||||||
Group.update_c(cnet, sim.current_tick)
|
Group.update_c(cnet, sim.current_tick)
|
||||||
cnet.in_queue[0] = 0
|
cnet.in_queue[0] = 0
|
||||||
@ -351,7 +349,7 @@ function Simulation.ticklogic(sim)
|
|||||||
sim.tickqueue[sim.current_tick] = nil
|
sim.tickqueue[sim.current_tick] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, sim.num_gatequeue do
|
for i = 1, sim.num_gatequeue-1 do
|
||||||
local cgate = sim.gatequeue[i]
|
local cgate = sim.gatequeue[i]
|
||||||
local gate = Simulation.gate_from_cgate(sim, cgate)
|
local gate = Simulation.gate_from_cgate(sim, cgate)
|
||||||
gate.logic(gate)
|
gate.logic(gate)
|
||||||
|
@ -68,24 +68,28 @@ function tobitstring(num, len)
|
|||||||
return bitstring
|
return bitstring
|
||||||
end
|
end
|
||||||
|
|
||||||
function array_remove(array, value, pass)
|
function array_remove(array, len, value, pass)
|
||||||
for i = 1, #array do
|
for i = 0, len-1 do
|
||||||
local v = array[i]
|
local v = array[i]
|
||||||
if v==value then
|
if v==value then
|
||||||
array[i] = array[#array]
|
array[i] = array[len-1]
|
||||||
array[#array] = nil
|
array[len-1] = nil
|
||||||
return
|
len = len - 1
|
||||||
|
return len
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not pass then error("element not in array") end
|
if not pass then error("element not in array") end
|
||||||
|
return len
|
||||||
end
|
end
|
||||||
|
|
||||||
function array_add(array, value)
|
function array_add(array, len, value)
|
||||||
for i = 1, #array do
|
for i = 0, len-1 do
|
||||||
local v = array[i]
|
local v = array[i]
|
||||||
if v==value then return end
|
if v==value then return len end
|
||||||
end
|
end
|
||||||
table.insert(array, value)
|
array[len] = value
|
||||||
|
len = len + 1
|
||||||
|
return len
|
||||||
end
|
end
|
||||||
|
|
||||||
function round(x)
|
function round(x)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user