add various optimizations

This commit is contained in:
Redo0
2021-06-05 17:37:52 -05:00
parent bdcf2b384a
commit 5b8a1ea850
6 changed files with 71 additions and 32 deletions

View File

@@ -3,25 +3,26 @@ Simulation = {}
function Simulation.new(sim)
local o = {
groupqueue = {},
num_groupqueue = 0,
gatequeue = {},
num_gatequeue = 0,
groupfxqueue = {},
current_tick = 0,
definitions = {},
wires = {},
gates = {},
nwires = 0,
ngates = 0,
ninports = 0,
noutports = 0,
groupqueue = {},
groupfxqueue = {},
gatequeue = {},
initqueue = nil,
inputqueue = nil,
tickqueue = {},
callbacks = nil,
current_tick = 0,
}
setmetatable(o, sim)
sim.__index = sim
@@ -237,9 +238,10 @@ end
-- Logic Critical
function Simulation.queuegate(sim, gate)
if not gate.in_queue then
if gate.in_queue==0 then
table.insert(sim.gatequeue, gate)
gate.in_queue = true
sim.num_gatequeue = sim.num_gatequeue + 1
gate.in_queue = 1
end
end
@@ -263,22 +265,28 @@ end
-- Logic Critical
function Simulation.queuegroup(sim, group)
if not group.in_queue then
table.insert(sim.groupqueue, group)
group.in_queue = true
if group.in_queue==0 then
--table.insert(sim.groupqueue, group)
sim.groupqueue[sim.num_groupqueue+1] = group
sim.num_groupqueue = sim.num_groupqueue + 1
group.in_queue = 1
end
end
function Simulation.dequeuegroup(sim, group)
if group.in_queue then
if group.in_queue~=0 then
array_remove(sim.groupqueue, group)
sim.num_groupqueue = sim.num_groupqueue - 1
group.in_queue = 0
end
sim.groupfxqueue[group] = nil
end
function Simulation.dequeuegate(sim, gate)
if gate.in_queue then
if gate.in_queue~=0 then
array_remove(sim.gatequeue, gate)
sim.num_gatequeue = sim.num_gatequeue - 1
gate.in_queue = 0
end
if sim.inputqueue~=nil then sim.inputqueue[gate] = nil end
if sim.initqueue ~=nil then sim.initqueue [gate] = nil end
@@ -298,11 +306,15 @@ end
-- Logic Critical
function Simulation.ticklogic(sim)
for k, group in ipairs(sim.groupqueue) do
--for k, group in ipairs(sim.groupqueue) do
local len = sim.num_groupqueue
for i = 1, len do
local group = sim.groupqueue[i]
Group.update(group)
group.in_queue = false
group.in_queue = 0
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
@@ -311,11 +323,15 @@ function Simulation.ticklogic(sim)
sim.tickqueue[sim.current_tick] = nil
end
for k, gate in ipairs(sim.gatequeue) do
--for k, gate in ipairs(sim.gatequeue) do
local len = sim.num_gatequeue
for i = 1, len do
local gate = sim.gatequeue[i]
gate.logic(gate)
gate.in_queue = false
gate.in_queue = 0
end
sim.gatequeue = {}
sim.num_gatequeue = 0
sim.current_tick = sim.current_tick + 1
end