make nets keep list of updated gates instead of ports

This commit is contained in:
Redo0
2021-05-25 20:22:02 -05:00
parent e92cc50186
commit c62d7340b0
7 changed files with 82 additions and 80 deletions

View File

@@ -1,20 +1,6 @@
Group = {}
FFI.cdef[[
struct Port;
struct Net {
bool state;
bool fxstate;
bool in_queue;
int updatetick;
int internal_ref;
int state_num;
int num_in_ports_update;
struct Port* in_ports_update[1];
};
]]
function Group.new()
local o = {
state = false,
@@ -23,7 +9,7 @@ function Group.new()
wires = {},
out_ports = {},
in_ports = {},
in_ports_update = {},
gates_update = {},
state_num = 0,
in_queue = false,
@@ -49,6 +35,7 @@ function Group.addwire(group, wire)
Wire.setgroup(wire, group)
Wire.update(wire)
Simulation.queuegroup(GSim, group)
end
end
@@ -115,13 +102,12 @@ function Group.addport(group, port)
group.in_ports[port] = port
group.nin_ports = group.nin_ports + 1
if port.causeupdate then
table.insert(group.in_ports_update, port)
end
Simulation.queuegate(GSim, Port.getgate(port))
end
Group.rebuild_ports(group)
end
function Group.removeport(group, port)
@@ -144,12 +130,11 @@ function Group.removeport(group, port)
group.in_ports[port] = nil
group.nin_ports = group.nin_ports - 1
if port.causeupdate then
array_remove(group.in_ports_update, port)
end
Simulation.queuegate(GSim, Port.getgate(port))
end
Group.rebuild_ports(group)
end
function Group.mergewith(group, group2)
@@ -196,8 +181,8 @@ function Group.setstate(group, state)
group.state = state
group.updatetick = sim.currenttick
for k, port in ipairs(group.in_ports_update) do
Simulation.queuegate(sim, Port.getgate(port))
for k, gate in ipairs(group.gates_update) do
Simulation.queuegate(sim, gate)
end
Simulation.queuegroupfx(sim, group)
@@ -207,3 +192,12 @@ end
function Group.update(group)
Group.setstate(group, group.state_num>0)
end
function Group.rebuild_ports(group)
group.gates_update = {}
for k, port in pairs(group.in_ports) do
if port.causeupdate then
array_add(group.gates_update, Port.getgate(port))
end
end
end