make sim queues use c objs
This commit is contained in:
@@ -11,9 +11,11 @@ ffi.cdef [[
|
||||
int* in_queue;
|
||||
int* update_tick;
|
||||
struct Gate** gates_update_c;
|
||||
int id;
|
||||
};
|
||||
]]
|
||||
|
||||
local last_net_id = 1
|
||||
function Group.new()
|
||||
local net = {
|
||||
-- Logic Critical
|
||||
@@ -33,7 +35,11 @@ function Group.new()
|
||||
nwires = 0,
|
||||
nout_ports = 0,
|
||||
nin_ports = 0,
|
||||
|
||||
id = last_net_id,
|
||||
}
|
||||
last_net_id = last_net_id + 1
|
||||
|
||||
net.state[0] = 0
|
||||
net.state_num[0] = 0
|
||||
net.in_queue[0] = 0
|
||||
@@ -45,6 +51,7 @@ function Group.new()
|
||||
net.c.in_queue = net.in_queue
|
||||
net.c.update_tick = net.update_tick
|
||||
net.c.gates_update_c = ffi.cast("struct Gate**", 0)
|
||||
net.c.id = net.id
|
||||
|
||||
return net
|
||||
end
|
||||
@@ -107,6 +114,7 @@ function Group.removewire(group, wire)
|
||||
group.nout_ports = 0
|
||||
group.nin_ports = 0
|
||||
|
||||
Simulation.remove_net(GSim, group)
|
||||
Simulation.dequeuegroup(GSim, group)
|
||||
end
|
||||
|
||||
@@ -195,34 +203,30 @@ function Group.mergeinto(group, group2)
|
||||
group.nout_ports = 0
|
||||
group.nin_ports = 0
|
||||
|
||||
Simulation.remove_net(GSim, group)
|
||||
Simulation.dequeuegroup(GSim, group)
|
||||
end
|
||||
|
||||
-- Logic Critical
|
||||
function Group.setstate(group, state)
|
||||
if state ~= group.state[0] then
|
||||
local sim = GSim
|
||||
function Group.update_net_c(netc, tick)
|
||||
local state = netc.state_num[0]>0 and 1 or 0
|
||||
if state ~= netc.state[0] then
|
||||
netc.state[0] = state
|
||||
netc.update_tick[0] = tick
|
||||
|
||||
group.state[0] = state
|
||||
group.update_tick[0] = sim.current_tick
|
||||
|
||||
local len = group.num_gates_update[0]
|
||||
local len = netc.num_gates_update[0]
|
||||
for i = 1, len do
|
||||
local gate = group.gates_update[i]
|
||||
if gate and gate.in_queue[0]==0 then
|
||||
Simulation.queuegate(sim, gate)
|
||||
local gatec = netc.gates_update_c[i]
|
||||
if gatec and gatec.in_queue[0]==0 then
|
||||
Simulation.queue_gate_c(GSim, gatec)
|
||||
end
|
||||
end
|
||||
|
||||
Simulation.queuegroupfx(sim, group)
|
||||
local net = Simulation.net_from_netc(GSim, netc)
|
||||
Simulation.queuegroupfx(GSim, net)
|
||||
end
|
||||
end
|
||||
|
||||
-- Logic Critical
|
||||
function Group.update(group)
|
||||
Group.setstate(group, group.state_num[0]>0 and 1 or 0)
|
||||
end
|
||||
|
||||
function Group.rebuild_ports(net)
|
||||
net.gates_update = {}
|
||||
net.num_gates_update[0] = 0
|
||||
|
||||
Reference in New Issue
Block a user