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