make in_queue int tptre

This commit is contained in:
Redo 2022-11-04 15:32:30 -06:00
parent 7823e413ee
commit f1b909279c
4 changed files with 17 additions and 26 deletions

View File

@ -6,7 +6,7 @@ Gate = {}
function Gate.new(objref, definition)
local gate = {
-- Logic Critical
in_queue = ffi.new("int"),
in_queue = ffi.new("int[1]"),
port_states = ffi.new("int["..(#definition.ports+1).."]"),
logic = definition.logic,
ports = {},
@ -27,10 +27,11 @@ end
function Gate.setportstate(gate, index, state)
if state ~= gate.port_states[index] then
local group = gate.port_nets[index]
local net_state_num = gate.port_net_state_nums[index]
group.state_num = group.state_num - gate.port_states[index] + 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]==0) then
Simulation.queuegroup(GSim, group)
end
end

View File

@ -75,7 +75,7 @@ end
function GateDefinition.constructgate(def, objref, position, rotation)
local gate = Gate.new(objref, def)
gate.in_queue = 0
gate.in_queue[0] = 0
for i = 1, #def.ports do
local portd = def.ports[i]
local type = portd.type

View File

@ -1,16 +1,6 @@
local ffi = FFI
ffi.cdef[[
struct Net {
int in_queue;
int num_out_ports_on;
int state;
int update_tick;
struct Gate* gates_update[0];
};
]]
Group = {}
function Group.new()
@ -18,7 +8,7 @@ function Group.new()
-- Logic Critical
state = 0,
state_num = 0,
in_queue = 0,
in_queue = ffi.new("int[1]"),
gates_update = {},
num_gates_update = 0,
@ -195,7 +185,7 @@ function Group.setstate(group, state)
local len = group.num_gates_update
for i = 1, len do
local gate = group.gates_update[i]
if gate and gate.in_queue==0 then
if gate and gate.in_queue[0]==0 then
Simulation.queuegate(sim, gate)
end
end

View File

@ -244,11 +244,11 @@ end
function Simulation.queuegate(sim, gate)
sim.gatequeue[sim.num_gatequeue+1] = gate
sim.num_gatequeue = sim.num_gatequeue + 1
gate.in_queue = 1
gate.in_queue[0] = 1
end
function Simulation.queuegate_safe(sim, gate)
if gate.in_queue==0 then
if gate.in_queue[0]==0 then
Simulation.queuegate(sim, gate)
end
end
@ -277,29 +277,29 @@ end
function Simulation.queuegroup(sim, group)
sim.groupqueue[sim.num_groupqueue+1] = group
sim.num_groupqueue = sim.num_groupqueue + 1
group.in_queue = 1
group.in_queue[0] = 1
end
function Simulation.queuegroup_safe(sim, group)
if group.in_queue==0 then
if group.in_queue[0]==0 then
Simulation.queuegroup(sim, group)
end
end
function Simulation.dequeuegroup(sim, group)
if group.in_queue~=0 then
if group.in_queue[0]~=0 then
array_remove(sim.groupqueue, group, true)
sim.num_groupqueue = sim.num_groupqueue - 1
group.in_queue = 0
group.in_queue[0] = 0
end
sim.groupfxqueue[group] = nil
end
function Simulation.dequeuegate(sim, gate)
if gate.in_queue~=0 then
if gate.in_queue[0]~=0 then
array_remove(sim.gatequeue, gate, true)
sim.num_gatequeue = sim.num_gatequeue - 1
gate.in_queue = 0
gate.in_queue[0] = 0
end
if sim.inputqueue~=nil then sim.inputqueue[gate] = nil end
if sim.initqueue ~=nil then sim.initqueue [gate] = nil end
@ -322,7 +322,7 @@ function Simulation.ticklogic(sim)
for i = 1, sim.num_groupqueue do
local group = sim.groupqueue[i]
Group.update(group)
group.in_queue = 0
group.in_queue[0] = 0
sim.groupqueue[i] = nil
end
--sim.groupqueue = {}
@ -330,7 +330,7 @@ function Simulation.ticklogic(sim)
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
if gate.in_queue[0]==0 then
Simulation.queuegate(sim, gate)
end
end
@ -340,7 +340,7 @@ function Simulation.ticklogic(sim)
for i = 1, sim.num_gatequeue do
local gate = sim.gatequeue[i]
gate.logic(gate)
gate.in_queue = 0
gate.in_queue[0] = 0
sim.gatequeue[i] = nil
end
--sim.gatequeue = {}