make queues c arrays
This commit is contained in:
parent
e35d0aa5f5
commit
2cf3040aa2
@ -1,12 +1,19 @@
|
||||
|
||||
local ffi = FFI or require("ffi")
|
||||
|
||||
ffi.cdef [[
|
||||
struct Gate;
|
||||
struct Net;
|
||||
]]
|
||||
|
||||
Simulation = {}
|
||||
|
||||
function Simulation.new(sim)
|
||||
local o = {
|
||||
groupqueue = {},
|
||||
num_groupqueue = 0,
|
||||
gatequeue = {},
|
||||
num_gatequeue = 0,
|
||||
groupqueue = ffi.new("struct Gate*[131072]"),
|
||||
num_groupqueue = ffi.new("int[1]"),
|
||||
gatequeue = ffi.new("struct Net*[131072]"),
|
||||
num_gatequeue = ffi.new("int[1]"),
|
||||
--groupfxqueue = {},
|
||||
current_tick = 0,
|
||||
|
||||
@ -27,6 +34,8 @@ function Simulation.new(sim)
|
||||
}
|
||||
setmetatable(o, sim)
|
||||
sim.__index = sim
|
||||
o.num_groupqueue[0] = 0
|
||||
o.num_gatequeue[0] = 0
|
||||
return o
|
||||
end
|
||||
|
||||
@ -247,8 +256,8 @@ end
|
||||
|
||||
-- Logic Critical
|
||||
function Simulation.queuegate_c(sim, cgate)
|
||||
sim.gatequeue[sim.num_gatequeue] = cgate
|
||||
sim.num_gatequeue = sim.num_gatequeue + 1
|
||||
sim.gatequeue[sim.num_gatequeue[0]] = cgate
|
||||
sim.num_gatequeue[0] = sim.num_gatequeue[0] + 1
|
||||
cgate.in_queue[0] = 1
|
||||
end
|
||||
|
||||
@ -285,8 +294,8 @@ end
|
||||
|
||||
-- Logic Critical
|
||||
function Simulation.queuegroup_c(sim, cnet)
|
||||
sim.groupqueue[sim.num_groupqueue] = cnet
|
||||
sim.num_groupqueue = sim.num_groupqueue + 1
|
||||
sim.groupqueue[sim.num_groupqueue[0]] = cnet
|
||||
sim.num_groupqueue[0] = sim.num_groupqueue[0] + 1
|
||||
cnet.in_queue[0] = 1
|
||||
end
|
||||
|
||||
@ -303,7 +312,7 @@ end
|
||||
|
||||
function Simulation.dequeuegroup(sim, group)
|
||||
if group.in_queue[0]~=0 then
|
||||
sim.num_groupqueue = array_remove(sim.groupqueue, sim.num_groupqueue, group.c, true)
|
||||
sim.num_groupqueue[0] = array_remove(sim.groupqueue, sim.num_groupqueue[0], group.c, true)
|
||||
group.in_queue[0] = 0
|
||||
end
|
||||
--sim.groupfxqueue[group] = nil
|
||||
@ -311,7 +320,7 @@ end
|
||||
|
||||
function Simulation.dequeuegate(sim, gate)
|
||||
if gate.in_queue[0]~=0 then
|
||||
sim.num_gatequeue = array_remove(sim.gatequeue, sim.num_gatequeue, gate.c, true)
|
||||
sim.num_gatequeue[0] = array_remove(sim.gatequeue, sim.num_gatequeue[0], gate.c, true)
|
||||
gate.in_queue[0] = 0
|
||||
end
|
||||
if sim.inputqueue~=nil then sim.inputqueue[gate] = nil end
|
||||
@ -332,13 +341,13 @@ end
|
||||
|
||||
-- Logic Critical
|
||||
function Simulation.ticklogic(sim)
|
||||
for i = 0, sim.num_groupqueue-1 do
|
||||
for i = 0, sim.num_groupqueue[0]-1 do
|
||||
local cnet = sim.groupqueue[i]
|
||||
Group.update_c(cnet, sim.current_tick)
|
||||
cnet.in_queue[0] = 0
|
||||
sim.groupqueue[i] = nil
|
||||
end
|
||||
sim.num_groupqueue = 0
|
||||
sim.num_groupqueue[0] = 0
|
||||
|
||||
if sim.tickqueue[sim.current_tick] ~= nil then
|
||||
for i, gate in pairs(sim.tickqueue[sim.current_tick]) do
|
||||
@ -349,14 +358,14 @@ function Simulation.ticklogic(sim)
|
||||
sim.tickqueue[sim.current_tick] = nil
|
||||
end
|
||||
|
||||
for i = 0, sim.num_gatequeue-1 do
|
||||
for i = 0, sim.num_gatequeue[0]-1 do
|
||||
local cgate = sim.gatequeue[i]
|
||||
local gate = Simulation.gate_from_cgate(sim, cgate)
|
||||
gate.logic(gate)
|
||||
cgate.in_queue[0] = 0
|
||||
sim.gatequeue[i] = nil
|
||||
end
|
||||
sim.num_gatequeue = 0
|
||||
sim.num_gatequeue[0] = 0
|
||||
|
||||
sim.current_tick = sim.current_tick + 1
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user