make in_queue int tptre
This commit is contained in:
parent
7823e413ee
commit
f1b909279c
@ -6,7 +6,7 @@ Gate = {}
|
|||||||
function Gate.new(objref, definition)
|
function Gate.new(objref, definition)
|
||||||
local gate = {
|
local gate = {
|
||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
in_queue = ffi.new("int"),
|
in_queue = ffi.new("int[1]"),
|
||||||
port_states = ffi.new("int["..(#definition.ports+1).."]"),
|
port_states = ffi.new("int["..(#definition.ports+1).."]"),
|
||||||
logic = definition.logic,
|
logic = definition.logic,
|
||||||
ports = {},
|
ports = {},
|
||||||
@ -27,10 +27,11 @@ end
|
|||||||
function Gate.setportstate(gate, index, state)
|
function Gate.setportstate(gate, index, state)
|
||||||
if state ~= gate.port_states[index] then
|
if state ~= gate.port_states[index] then
|
||||||
local group = gate.port_nets[index]
|
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
|
group.state_num = group.state_num - gate.port_states[index] + state
|
||||||
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)
|
Simulation.queuegroup(GSim, group)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -75,7 +75,7 @@ end
|
|||||||
function GateDefinition.constructgate(def, objref, position, rotation)
|
function GateDefinition.constructgate(def, objref, position, rotation)
|
||||||
local gate = Gate.new(objref, def)
|
local gate = Gate.new(objref, def)
|
||||||
|
|
||||||
gate.in_queue = 0
|
gate.in_queue[0] = 0
|
||||||
for i = 1, #def.ports do
|
for i = 1, #def.ports do
|
||||||
local portd = def.ports[i]
|
local portd = def.ports[i]
|
||||||
local type = portd.type
|
local type = portd.type
|
||||||
|
@ -1,16 +1,6 @@
|
|||||||
|
|
||||||
local ffi = FFI
|
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 = {}
|
Group = {}
|
||||||
|
|
||||||
function Group.new()
|
function Group.new()
|
||||||
@ -18,7 +8,7 @@ function Group.new()
|
|||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
state = 0,
|
state = 0,
|
||||||
state_num = 0,
|
state_num = 0,
|
||||||
in_queue = 0,
|
in_queue = ffi.new("int[1]"),
|
||||||
gates_update = {},
|
gates_update = {},
|
||||||
num_gates_update = 0,
|
num_gates_update = 0,
|
||||||
|
|
||||||
@ -195,7 +185,7 @@ function Group.setstate(group, state)
|
|||||||
local len = group.num_gates_update
|
local len = group.num_gates_update
|
||||||
for i = 1, len do
|
for i = 1, len do
|
||||||
local gate = group.gates_update[i]
|
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)
|
Simulation.queuegate(sim, gate)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -244,11 +244,11 @@ end
|
|||||||
function Simulation.queuegate(sim, gate)
|
function Simulation.queuegate(sim, gate)
|
||||||
sim.gatequeue[sim.num_gatequeue+1] = gate
|
sim.gatequeue[sim.num_gatequeue+1] = gate
|
||||||
sim.num_gatequeue = sim.num_gatequeue + 1
|
sim.num_gatequeue = sim.num_gatequeue + 1
|
||||||
gate.in_queue = 1
|
gate.in_queue[0] = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
function Simulation.queuegate_safe(sim, gate)
|
function Simulation.queuegate_safe(sim, gate)
|
||||||
if gate.in_queue==0 then
|
if gate.in_queue[0]==0 then
|
||||||
Simulation.queuegate(sim, gate)
|
Simulation.queuegate(sim, gate)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -277,29 +277,29 @@ end
|
|||||||
function Simulation.queuegroup(sim, group)
|
function Simulation.queuegroup(sim, group)
|
||||||
sim.groupqueue[sim.num_groupqueue+1] = group
|
sim.groupqueue[sim.num_groupqueue+1] = group
|
||||||
sim.num_groupqueue = sim.num_groupqueue + 1
|
sim.num_groupqueue = sim.num_groupqueue + 1
|
||||||
group.in_queue = 1
|
group.in_queue[0] = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
function Simulation.queuegroup_safe(sim, group)
|
function Simulation.queuegroup_safe(sim, group)
|
||||||
if group.in_queue==0 then
|
if group.in_queue[0]==0 then
|
||||||
Simulation.queuegroup(sim, group)
|
Simulation.queuegroup(sim, group)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Simulation.dequeuegroup(sim, group)
|
function Simulation.dequeuegroup(sim, group)
|
||||||
if group.in_queue~=0 then
|
if group.in_queue[0]~=0 then
|
||||||
array_remove(sim.groupqueue, group, true)
|
array_remove(sim.groupqueue, group, true)
|
||||||
sim.num_groupqueue = sim.num_groupqueue - 1
|
sim.num_groupqueue = sim.num_groupqueue - 1
|
||||||
group.in_queue = 0
|
group.in_queue[0] = 0
|
||||||
end
|
end
|
||||||
sim.groupfxqueue[group] = nil
|
sim.groupfxqueue[group] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function Simulation.dequeuegate(sim, gate)
|
function Simulation.dequeuegate(sim, gate)
|
||||||
if gate.in_queue~=0 then
|
if gate.in_queue[0]~=0 then
|
||||||
array_remove(sim.gatequeue, gate, true)
|
array_remove(sim.gatequeue, gate, true)
|
||||||
sim.num_gatequeue = sim.num_gatequeue - 1
|
sim.num_gatequeue = sim.num_gatequeue - 1
|
||||||
gate.in_queue = 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
|
||||||
if sim.initqueue ~=nil then sim.initqueue [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
|
for i = 1, sim.num_groupqueue do
|
||||||
local group = sim.groupqueue[i]
|
local group = sim.groupqueue[i]
|
||||||
Group.update(group)
|
Group.update(group)
|
||||||
group.in_queue = 0
|
group.in_queue[0] = 0
|
||||||
sim.groupqueue[i] = nil
|
sim.groupqueue[i] = nil
|
||||||
end
|
end
|
||||||
--sim.groupqueue = {}
|
--sim.groupqueue = {}
|
||||||
@ -330,7 +330,7 @@ function Simulation.ticklogic(sim)
|
|||||||
|
|
||||||
if sim.tickqueue[sim.current_tick] ~= nil then
|
if sim.tickqueue[sim.current_tick] ~= nil then
|
||||||
for i, gate in pairs(sim.tickqueue[sim.current_tick]) do
|
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)
|
Simulation.queuegate(sim, gate)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -340,7 +340,7 @@ function Simulation.ticklogic(sim)
|
|||||||
for i = 1, sim.num_gatequeue do
|
for i = 1, sim.num_gatequeue do
|
||||||
local gate = sim.gatequeue[i]
|
local gate = sim.gatequeue[i]
|
||||||
gate.logic(gate)
|
gate.logic(gate)
|
||||||
gate.in_queue = 0
|
gate.in_queue[0] = 0
|
||||||
sim.gatequeue[i] = nil
|
sim.gatequeue[i] = nil
|
||||||
end
|
end
|
||||||
--sim.gatequeue = {}
|
--sim.gatequeue = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user