fix more oop and bugs

This commit is contained in:
Redo0 2021-05-22 18:45:04 -05:00
parent db7e2d06ad
commit 6c997a36fa
4 changed files with 20 additions and 18 deletions

@ -85,7 +85,7 @@ function Group.addport(self, port)
elseif port.type == PortTypes.input then elseif port.type == PortTypes.input then
self.in_ports[port] = port self.in_ports[port] = port
self.nin_ports = self.nin_ports + 1 self.nin_ports = self.nin_ports + 1
port:setinputstate(self.state) Port.setinputstate(port, self.state)
end end
end end
@ -138,11 +138,11 @@ function Group.setstate(self, state)
if state ~= self.state then if state ~= self.state then
self.state = state self.state = state
self.updatetick = sim.currenttick self.updatetick = sim.currenttick
for k, port in pairs(self.in_ports) do for k, port in pairs(self.in_ports) do
Port.setinputstate(port, state) Port.setinputstate(port, state)
end end
Simulation.queuegroupfx(sim, self) Simulation.queuegroupfx(sim, self)
end end
end end

@ -290,7 +290,9 @@ while 1 do
for a = i+3, i+3+argc-1 do for a = i+3, i+3+argc-1 do
argv[#argv+1] = collapseescape(data[a]) argv[#argv+1] = collapseescape(data[a])
end end
Simulation.queuegateinput(sim, gate, argv) if gate then
Simulation.queuegateinput(sim, gate, argv)
end
i = i+2+argc i = i+2+argc
elseif data[i] == "SAVE" then elseif data[i] == "SAVE" then

@ -32,18 +32,18 @@ function Port.new(self, type, direction, position, causeupdate)
return o return o
end end
function Port.setstate(self, state) function Port.setstate(port, state)
if state ~= self.state then if state ~= port.state then
self.state = state port.state = state
Simulation.queuegroup(sim, self.group) Simulation.queuegroup(sim, port.group)
end end
end end
function Port.setinputstate(self, state) function Port.setinputstate(port, state)
if state ~= self.state then if state ~= port.state then
self.state = state port.state = state
if self.causeupdate then if port.causeupdate then
Simulation.queuegate(sim, self.gate) Simulation.queuegate(sim, port.gate)
end end
end end
end end

@ -271,31 +271,31 @@ function Simulation.tick(self)
Group.setstate(group, newstate) Group.setstate(group, newstate)
end end
self.groupqueue = {} self.groupqueue = {}
for k, gate in pairs(self.initqueue) do for k, gate in pairs(self.initqueue) do
gate.definition.init(gate) gate.definition.init(gate)
end end
self.initqueue = {} self.initqueue = {}
for gate, inputs in pairs(self.inputqueue) do for gate, inputs in pairs(self.inputqueue) do
for inputidx, argv in ipairs(inputs) do for inputidx, argv in ipairs(inputs) do
gate.definition.input(gate, argv) gate.definition.input(gate, argv)
end end
end end
self.inputqueue = {} self.inputqueue = {}
if self.tickqueue[self.currenttick] ~= nil then if self.tickqueue[self.currenttick] ~= nil then
for i, gate in ipairs(self.tickqueue[self.currenttick]) do for i, gate in ipairs(self.tickqueue[self.currenttick]) do
Simulation.queuegate(self, gate) Simulation.queuegate(self, gate)
end end
self.tickqueue[self.currenttick] = nil self.tickqueue[self.currenttick] = nil
end end
for k, gate in pairs(self.gatequeue) do for k, gate in pairs(self.gatequeue) do
gate.definition.logic(gate) gate.definition.logic(gate)
end end
self.gatequeue = {} self.gatequeue = {}
self.currenttick = self.currenttick + 1 self.currenttick = self.currenttick + 1
end end