make sim global; make nonessential queues optional
This commit is contained in:
@@ -6,6 +6,7 @@ FFI.cdef[[
|
||||
struct Net {
|
||||
bool state;
|
||||
bool fxstate;
|
||||
bool in_queue;
|
||||
int updatetick;
|
||||
int internal_ref;
|
||||
int state_num;
|
||||
@@ -14,7 +15,7 @@ FFI.cdef[[
|
||||
};
|
||||
]]
|
||||
|
||||
function Group.new(self, sim)
|
||||
function Group.new(self)
|
||||
local o = {
|
||||
state = false,
|
||||
fxstate = false,
|
||||
@@ -25,12 +26,11 @@ function Group.new(self, sim)
|
||||
in_ports_update = {},
|
||||
|
||||
state_num = 0,
|
||||
in_queue = false,
|
||||
|
||||
nwires = 0,
|
||||
nout_ports = 0,
|
||||
nin_ports = 0,
|
||||
|
||||
sim = sim,
|
||||
}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
@@ -51,7 +51,7 @@ function Group.addwire(self, wire)
|
||||
|
||||
Wire.setgroup(wire, self)
|
||||
Wire.update(wire)
|
||||
Simulation.queuegroup(Group.getsim(self), self)
|
||||
Simulation.queuegroup(GSim, self)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -60,7 +60,7 @@ function Group.removewire(self, wire)
|
||||
Wire.setgroup(wire, nil)
|
||||
self.wires[wire] = nil
|
||||
|
||||
local sim = Group.getsim(self)
|
||||
local sim = GSim
|
||||
|
||||
for k, wire in pairs(self.wires) do
|
||||
Wire.setgroup(wire, nil)
|
||||
@@ -94,7 +94,7 @@ function Group.removewire(self, wire)
|
||||
self.nout_ports = 0
|
||||
self.nin_ports = 0
|
||||
|
||||
Simulation.dequeuegroup(Group.getsim(self), self)
|
||||
Simulation.dequeuegroup(GSim, self)
|
||||
end
|
||||
|
||||
function Group.addport(self, port)
|
||||
@@ -110,7 +110,7 @@ function Group.addport(self, port)
|
||||
self.state_num = self.state_num + 1
|
||||
end
|
||||
|
||||
Simulation.queuegroup(Group.getsim(self), self)
|
||||
Simulation.queuegroup(GSim, self)
|
||||
|
||||
elseif port.type == PortTypes.input then
|
||||
if self.in_ports[port] then error("port already in group") end
|
||||
@@ -121,7 +121,7 @@ function Group.addport(self, port)
|
||||
self.in_ports_update[port] = port
|
||||
end
|
||||
|
||||
Simulation.queuegate(Port.getsim(port), Port.getgate(port))
|
||||
Simulation.queuegate(GSim, Port.getgate(port))
|
||||
|
||||
end
|
||||
end
|
||||
@@ -139,7 +139,7 @@ function Group.removeport(self, port)
|
||||
self.state_num = self.state_num - 1
|
||||
end
|
||||
|
||||
Simulation.queuegroup(Group.getsim(self), self)
|
||||
Simulation.queuegroup(GSim, self)
|
||||
|
||||
elseif port.type == PortTypes.input then
|
||||
if not self.in_ports[port] then error("port not in group") end
|
||||
@@ -150,7 +150,7 @@ function Group.removeport(self, port)
|
||||
self.in_ports_update[port] = nil
|
||||
end
|
||||
|
||||
Simulation.queuegate(Port.getsim(port), Port.getgate(port))
|
||||
Simulation.queuegate(GSim, Port.getgate(port))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -188,26 +188,24 @@ function Group.mergeinto(self, group)
|
||||
self.nout_ports = 0
|
||||
self.nin_ports = 0
|
||||
|
||||
Simulation.dequeuegroup(Group.getsim(self), self)
|
||||
Simulation.dequeuegroup(GSim, self)
|
||||
end
|
||||
|
||||
function Group.setstate(self, state)
|
||||
if state ~= self.state then
|
||||
local sim = GSim
|
||||
|
||||
self.state = state
|
||||
self.updatetick = Group.getsim(self).currenttick
|
||||
self.updatetick = sim.currenttick
|
||||
|
||||
for k, port in pairs(self.in_ports_update) do
|
||||
Simulation.queuegate(Port.getsim(port), Port.getgate(port))
|
||||
Simulation.queuegate(sim, Port.getgate(port))
|
||||
end
|
||||
|
||||
Simulation.queuegroupfx(Group.getsim(self), self)
|
||||
Simulation.queuegroupfx(sim, self)
|
||||
end
|
||||
end
|
||||
|
||||
function Group.getsim(group)
|
||||
return group.sim
|
||||
end
|
||||
|
||||
function Group.update(group)
|
||||
Group.setstate(group, group.state_num>0)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user