stop using self in class functions

This commit is contained in:
Redo0 2021-05-25 17:25:34 -05:00
parent 730ca3fd64
commit 4cf2231a01
4 changed files with 226 additions and 226 deletions

View File

@ -23,33 +23,33 @@ function Gate.new(self, objref, definition)
return o return o
end end
function Gate.addport(self, port) function Gate.addport(gate, port)
self.ports[#self.ports+1] = port gate.ports[#gate.ports+1] = port
Port.setgate(port, self) Port.setgate(port, gate)
end end
function Gate.getportstate(gate, index) function Gate.getportstate(gate, index)
return gate.ports[index].group.state return gate.ports[index].group.state
end end
function Gate.setportstate(self, index, state) function Gate.setportstate(gate, index, state)
Port.setstate(self.ports[index], state) Port.setstate(gate.ports[index], state)
end end
function Gate.initdata(self) function Gate.initdata(gate)
self.data = {} gate.data = {}
end end
function Gate.getdata(self) function Gate.getdata(gate)
return self.data return gate.data
end end
function Gate.getportisrising(self, index) function Gate.getportisrising(gate, index)
return Port.isrising(self.ports[index]) return Port.isrising(gate.ports[index])
end end
function Gate.getportisfalling(self, index) function Gate.getportisfalling(gate, index)
return Port.isfalling(self.ports[index]) return Port.isfalling(gate.ports[index])
end end
function Gate.cb(gate, ...) function Gate.cb(gate, ...)

View File

@ -37,88 +37,88 @@ function Group.new(self)
return o return o
end end
function Group.getsize(self) function Group.getsize(group)
return self.nwires + self.nout_ports + self.nin_ports return group.nwires + group.nout_ports + group.nin_ports
end end
function Group.addwire(self, wire) function Group.addwire(group, wire)
if Wire.getgroup(wire) ~= self then if Wire.getgroup(wire) ~= group then
if Wire.getgroup(wire) ~= nil then if Wire.getgroup(wire) ~= nil then
Group.mergewith(self, Wire.getgroup(wire)) Group.mergewith(group, Wire.getgroup(wire))
else else
self.wires[wire] = wire group.wires[wire] = wire
self.nwires = self.nwires + 1 group.nwires = group.nwires + 1
Wire.setgroup(wire, self) Wire.setgroup(wire, group)
Wire.update(wire) Wire.update(wire)
Simulation.queuegroup(GSim, self) Simulation.queuegroup(GSim, group)
end end
end end
end end
function Group.removewire(self, wire) function Group.removewire(group, wire)
Wire.setgroup(wire, nil) Wire.setgroup(wire, nil)
self.wires[wire] = nil group.wires[wire] = nil
local sim = GSim local sim = GSim
for k, wire in pairs(self.wires) do for k, wire in pairs(group.wires) do
Wire.setgroup(wire, nil) Wire.setgroup(wire, nil)
end end
for k, port in pairs(self.out_ports) do for k, port in pairs(group.out_ports) do
Port.setgroup(port, nil) Port.setgroup(port, nil)
end end
for k, port in pairs(self.in_ports) do for k, port in pairs(group.in_ports) do
Port.setgroup(port, nil) Port.setgroup(port, nil)
end end
for k, wire in pairs(self.wires) do for k, wire in pairs(group.wires) do
Simulation.connectwire(sim, wire) Simulation.connectwire(sim, wire)
end end
for k, port in pairs(self.out_ports) do for k, port in pairs(group.out_ports) do
Simulation.connectport(sim, port) Simulation.connectport(sim, port)
end end
for k, port in pairs(self.in_ports) do for k, port in pairs(group.in_ports) do
Simulation.connectport(sim, port) Simulation.connectport(sim, port)
end end
self.wires = {} group.wires = {}
self.out_ports = {} group.out_ports = {}
self.in_ports = {} group.in_ports = {}
self.nwires = 0 group.nwires = 0
self.nout_ports = 0 group.nout_ports = 0
self.nin_ports = 0 group.nin_ports = 0
Simulation.dequeuegroup(GSim, self) Simulation.dequeuegroup(GSim, group)
end end
function Group.addport(self, port) function Group.addport(group, port)
if port.group~=nil then error("port already has group") end if port.group~=nil then error("port already has group") end
port.group = self port.group = group
if port.type == PortTypes.output then if port.type == PortTypes.output then
if self.out_ports[port] then error("port already in group") end if group.out_ports[port] then error("port already in group") end
self.out_ports[port] = port group.out_ports[port] = port
self.nout_ports = self.nout_ports + 1 group.nout_ports = group.nout_ports + 1
if Port.getstate(port) then if Port.getstate(port) then
self.state_num = self.state_num + 1 group.state_num = group.state_num + 1
end end
Simulation.queuegroup(GSim, self) Simulation.queuegroup(GSim, group)
elseif port.type == PortTypes.input then elseif port.type == PortTypes.input then
if self.in_ports[port] then error("port already in group") end if group.in_ports[port] then error("port already in group") end
self.in_ports[port] = port group.in_ports[port] = port
self.nin_ports = self.nin_ports + 1 group.nin_ports = group.nin_ports + 1
if port.causeupdate then if port.causeupdate then
table.insert(self.in_ports_update, port) table.insert(group.in_ports_update, port)
end end
Simulation.queuegate(GSim, Port.getgate(port)) Simulation.queuegate(GSim, Port.getgate(port))
@ -126,83 +126,83 @@ function Group.addport(self, port)
end end
end end
function Group.removeport(self, port) function Group.removeport(group, port)
if port.group~=self then error("port does not have group") end if port.group~=group then error("port does not have group") end
port.group = nil port.group = nil
if port.type == PortTypes.output then if port.type == PortTypes.output then
if not self.out_ports[port] then error("port not in group") end if not group.out_ports[port] then error("port not in group") end
self.out_ports[port] = nil group.out_ports[port] = nil
self.nout_ports = self.nout_ports - 1 group.nout_ports = group.nout_ports - 1
if Port.getstate(port) then if Port.getstate(port) then
self.state_num = self.state_num - 1 group.state_num = group.state_num - 1
end end
Simulation.queuegroup(GSim, self) Simulation.queuegroup(GSim, group)
elseif port.type == PortTypes.input then elseif port.type == PortTypes.input then
if not self.in_ports[port] then error("port not in group") end if not group.in_ports[port] then error("port not in group") end
self.in_ports[port] = nil group.in_ports[port] = nil
self.nin_ports = self.nin_ports - 1 group.nin_ports = group.nin_ports - 1
if port.causeupdate then if port.causeupdate then
array_remove(self.in_ports_update, port) array_remove(group.in_ports_update, port)
end end
Simulation.queuegate(GSim, Port.getgate(port)) Simulation.queuegate(GSim, Port.getgate(port))
end end
end end
function Group.mergewith(self, group) function Group.mergewith(group, group2)
if Group.getsize(self) >= Group.getsize(group) then if Group.getsize(group) >= Group.getsize(group2) then
Group.mergeinto(group, self) Group.mergeinto(group2, group)
return self
else
Group.mergeinto(self, group)
return group return group
else
Group.mergeinto(group, group2)
return group2
end end
end end
function Group.mergeinto(self, group) function Group.mergeinto(group, group2)
for k, wire in pairs(self.wires) do for k, wire in pairs(group.wires) do
Wire.setgroup(wire, nil) Wire.setgroup(wire, nil)
Group.addwire(group, wire) Group.addwire(group2, wire)
end end
for k, port in pairs(self.out_ports) do for k, port in pairs(group.out_ports) do
Port.setgroup(port, nil) Port.setgroup(port, nil)
Group.addport(group, port) Group.addport(group2, port)
end end
for k, port in pairs(self.in_ports) do for k, port in pairs(group.in_ports) do
Port.setgroup(port, nil) Port.setgroup(port, nil)
Group.addport(group, port) Group.addport(group2, port)
end end
self.wires = {} group.wires = {}
self.out_ports = {} group.out_ports = {}
self.in_ports = {} group.in_ports = {}
self.nwires = 0 group.nwires = 0
self.nout_ports = 0 group.nout_ports = 0
self.nin_ports = 0 group.nin_ports = 0
Simulation.dequeuegroup(GSim, self) Simulation.dequeuegroup(GSim, group)
end end
function Group.setstate(self, state) function Group.setstate(group, state)
if state ~= self.state then if state ~= group.state then
local sim = GSim local sim = GSim
self.state = state group.state = state
self.updatetick = sim.currenttick group.updatetick = sim.currenttick
for k, port in ipairs(self.in_ports_update) do for k, port in ipairs(group.in_ports_update) do
Simulation.queuegate(sim, Port.getgate(port)) Simulation.queuegate(sim, Port.getgate(port))
end end
Simulation.queuegroupfx(sim, self) Simulation.queuegroupfx(sim, group)
end end
end end

View File

@ -1,7 +1,7 @@
Simulation = {} Simulation = {}
function Simulation.new(self) function Simulation.new(sim)
local o = { local o = {
definitions = {}, definitions = {},
wires = {}, wires = {},
@ -25,162 +25,162 @@ function Simulation.new(self)
currenttick = 0 currenttick = 0
} }
setmetatable(o, self) setmetatable(o, sim)
self.__index = self sim.__index = sim
return o return o
end end
function Simulation.addtoworld(self, obj, x, y, z) function Simulation.addtoworld(sim, obj, x, y, z)
if self[x] == nil then if sim[x] == nil then
self[x] = {} sim[x] = {}
end end
if self[x][y] == nil then if sim[x][y] == nil then
self[x][y] = {} sim[x][y] = {}
end end
if self[x][y][z] == nil then if sim[x][y][z] == nil then
self[x][y][z] = {} sim[x][y][z] = {}
end end
self[x][y][z][obj] = obj sim[x][y][z][obj] = obj
end end
function Simulation.getfromworld(self, x, y, z) function Simulation.getfromworld(sim, x, y, z)
if self[x] == nil or self[x][y] == nil or self[x][y][z] == nil then if sim[x] == nil or sim[x][y] == nil or sim[x][y][z] == nil then
return {} return {}
else else
return self[x][y][z] return sim[x][y][z]
end end
end end
function Simulation.getdefinitionbyref(self, objref) function Simulation.getdefinitionbyref(sim, objref)
return self.definitions[objref] return sim.definitions[objref]
end end
function Simulation.getgatebyref(self, objref) function Simulation.getgatebyref(sim, objref)
return self.gates[objref] return sim.gates[objref]
end end
function Simulation.getwirebyref(self, objref) function Simulation.getwirebyref(sim, objref)
return self.wires[objref] return sim.wires[objref]
end end
function Simulation.addgatedefinition(self, definition) function Simulation.addgatedefinition(sim, definition)
self.definitions[definition.objref] = definition sim.definitions[definition.objref] = definition
end end
function Simulation.addwire(self, wire) function Simulation.addwire(sim, wire)
self.wires[Wire.getobjref(wire)] = wire sim.wires[Wire.getobjref(wire)] = wire
local bounds = Wire.getbounds(wire) local bounds = Wire.getbounds(wire)
for x = bounds[1]+1, bounds[4]-1, 2 do for x = bounds[1]+1, bounds[4]-1, 2 do
for z = bounds[3]+1, bounds[6]-1, 2 do for z = bounds[3]+1, bounds[6]-1, 2 do
Simulation.addtoworld(self, wire, x, bounds[2], z) Simulation.addtoworld(sim, wire, x, bounds[2], z)
Simulation.addtoworld(self, wire, x, bounds[5], z) Simulation.addtoworld(sim, wire, x, bounds[5], z)
end end
end end
for y = bounds[2]+1, bounds[5]-1, 2 do for y = bounds[2]+1, bounds[5]-1, 2 do
for z = bounds[3]+1, bounds[6]-1, 2 do for z = bounds[3]+1, bounds[6]-1, 2 do
Simulation.addtoworld(self, wire, bounds[1], y, z) Simulation.addtoworld(sim, wire, bounds[1], y, z)
Simulation.addtoworld(self, wire, bounds[4], y, z) Simulation.addtoworld(sim, wire, bounds[4], y, z)
end end
end end
for x = bounds[1]+1, bounds[4]-1, 2 do for x = bounds[1]+1, bounds[4]-1, 2 do
for y = bounds[2]+1, bounds[5]-1, 2 do for y = bounds[2]+1, bounds[5]-1, 2 do
Simulation.addtoworld(self, wire, x, y, bounds[3]) Simulation.addtoworld(sim, wire, x, y, bounds[3])
Simulation.addtoworld(self, wire, x, y, bounds[6]) Simulation.addtoworld(sim, wire, x, y, bounds[6])
end end
end end
self.nwires = self.nwires + 1 sim.nwires = sim.nwires + 1
Simulation.connectwire(self, wire) Simulation.connectwire(sim, wire)
end end
function Simulation.addgate(self, gate) function Simulation.addgate(sim, gate)
self.gates[gate.objref] = gate sim.gates[gate.objref] = gate
for k, port in pairs(gate.ports) do for k, port in pairs(gate.ports) do
local offset = Port.getconnectionposition(port) local offset = Port.getconnectionposition(port)
Simulation.addtoworld(self, port, offset[1], offset[2], offset[3]) Simulation.addtoworld(sim, port, offset[1], offset[2], offset[3])
Simulation.connectport(self, port) Simulation.connectport(sim, port)
if Port.gettype(port) == PortTypes.input then if Port.gettype(port) == PortTypes.input then
self.ninports = self.ninports + 1 sim.ninports = sim.ninports + 1
elseif Port.gettype(port) == PortTypes.output then elseif Port.gettype(port) == PortTypes.output then
self.noutports = self.noutports + 1 sim.noutports = sim.noutports + 1
end end
end end
self.ngates = self.ngates + 1 sim.ngates = sim.ngates + 1
Simulation.queuegateinit(self, gate) Simulation.queuegateinit(sim, gate)
Simulation.queuegate(self, gate) Simulation.queuegate(sim, gate)
end end
function Simulation.removewire(self, objref) function Simulation.removewire(sim, objref)
local wire = self.wires[objref] local wire = sim.wires[objref]
if wire ~= nil then if wire ~= nil then
self.wires[objref] = nil sim.wires[objref] = nil
local bounds = Wire.getbounds(wire) local bounds = Wire.getbounds(wire)
for x = bounds[1]+1, bounds[4]-1, 2 do for x = bounds[1]+1, bounds[4]-1, 2 do
for z = bounds[3]+1, bounds[6]-1, 2 do for z = bounds[3]+1, bounds[6]-1, 2 do
self[x][bounds[2]][z][wire] = nil sim[x][bounds[2]][z][wire] = nil
self[x][bounds[5]][z][wire] = nil sim[x][bounds[5]][z][wire] = nil
end end
end end
for y = bounds[2]+1, bounds[5]-1, 2 do for y = bounds[2]+1, bounds[5]-1, 2 do
for z = bounds[3]+1, bounds[6]-1, 2 do for z = bounds[3]+1, bounds[6]-1, 2 do
self[bounds[1]][y][z][wire] = nil sim[bounds[1]][y][z][wire] = nil
self[bounds[4]][y][z][wire] = nil sim[bounds[4]][y][z][wire] = nil
end end
end end
for x = bounds[1]+1, bounds[4]-1, 2 do for x = bounds[1]+1, bounds[4]-1, 2 do
for y = bounds[2]+1, bounds[5]-1, 2 do for y = bounds[2]+1, bounds[5]-1, 2 do
self[x][y][bounds[3]][wire] = nil sim[x][y][bounds[3]][wire] = nil
self[x][y][bounds[6]][wire] = nil sim[x][y][bounds[6]][wire] = nil
end end
end end
self.nwires = self.nwires - 1 sim.nwires = sim.nwires - 1
Group.removewire(Wire.getgroup(wire), wire) Group.removewire(Wire.getgroup(wire), wire)
end end
end end
function Simulation.removegate(self, objref) function Simulation.removegate(sim, objref)
local gate = self.gates[objref] local gate = sim.gates[objref]
if gate ~= nil then if gate ~= nil then
for k, port in pairs(gate.ports) do for k, port in pairs(gate.ports) do
local pos = Port.getconnectionposition(port) local pos = Port.getconnectionposition(port)
self[pos[1]][pos[2]][pos[3]][port] = nil sim[pos[1]][pos[2]][pos[3]][port] = nil
Group.removeport(Port.getgroup(port), port) Group.removeport(Port.getgroup(port), port)
if Port.gettype(port) == PortTypes.input then if Port.gettype(port) == PortTypes.input then
self.ninports = self.ninports - 1 sim.ninports = sim.ninports - 1
elseif Port.gettype(port) == PortTypes.output then elseif Port.gettype(port) == PortTypes.output then
self.noutports = self.noutports - 1 sim.noutports = sim.noutports - 1
end end
end end
end end
Simulation.dequeuegate(self, gate) Simulation.dequeuegate(sim, gate)
self.gates[objref] = nil sim.gates[objref] = nil
self.ngates = self.ngates - 1 sim.ngates = sim.ngates - 1
end end
local function is_wire(obj) local function is_wire(obj)
return obj.layer~=nil return obj.layer~=nil
end end
function Simulation.connectwireat(self, wire, x, y, z) function Simulation.connectwireat(sim, wire, x, y, z)
local objs = Simulation.getfromworld(self, x, y, z) local objs = Simulation.getfromworld(sim, x, y, z)
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
if obj ~= wire and obj.group ~= nil then if obj ~= wire and obj.group ~= nil then
if is_wire(obj) then -- wire if is_wire(obj) then -- wire
@ -194,27 +194,27 @@ function Simulation.connectwireat(self, wire, x, y, z)
end end
end end
function Simulation.connectwire(self, wire) function Simulation.connectwire(sim, wire)
local bounds = Wire.getbounds(wire) local bounds = Wire.getbounds(wire)
for x = bounds[1]+1, bounds[4]-1, 2 do for x = bounds[1]+1, bounds[4]-1, 2 do
for z = bounds[3]+1, bounds[6]-1, 2 do for z = bounds[3]+1, bounds[6]-1, 2 do
Simulation.connectwireat(self, wire, x, bounds[2], z) Simulation.connectwireat(sim, wire, x, bounds[2], z)
Simulation.connectwireat(self, wire, x, bounds[5], z) Simulation.connectwireat(sim, wire, x, bounds[5], z)
end end
end end
for y = bounds[2]+1, bounds[5]-1, 2 do for y = bounds[2]+1, bounds[5]-1, 2 do
for z = bounds[3]+1, bounds[6]-1, 2 do for z = bounds[3]+1, bounds[6]-1, 2 do
Simulation.connectwireat(self, wire, bounds[1], y, z) Simulation.connectwireat(sim, wire, bounds[1], y, z)
Simulation.connectwireat(self, wire, bounds[4], y, z) Simulation.connectwireat(sim, wire, bounds[4], y, z)
end end
end end
for x = bounds[1]+1, bounds[4]-1, 2 do for x = bounds[1]+1, bounds[4]-1, 2 do
for y = bounds[2]+1, bounds[5]-1, 2 do for y = bounds[2]+1, bounds[5]-1, 2 do
Simulation.connectwireat(self, wire, x, y, bounds[3]) Simulation.connectwireat(sim, wire, x, y, bounds[3])
Simulation.connectwireat(self, wire, x, y, bounds[6]) Simulation.connectwireat(sim, wire, x, y, bounds[6])
end end
end end
@ -223,9 +223,9 @@ function Simulation.connectwire(self, wire)
end end
end end
function Simulation.connectport(self, port) function Simulation.connectport(sim, port)
local connpos = Port.getconnectionposition(port) local connpos = Port.getconnectionposition(port)
local objs = Simulation.getfromworld(self, connpos[1], connpos[2], connpos[3]) local objs = Simulation.getfromworld(sim, connpos[1], connpos[2], connpos[3])
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
if obj ~= port and obj.group ~= nil then if obj ~= port and obj.group ~= nil then
Group.addport(obj.group, port) Group.addport(obj.group, port)
@ -237,109 +237,109 @@ function Simulation.connectport(self, port)
end end
end end
function Simulation.queuegate(self, gate) function Simulation.queuegate(sim, gate)
if not gate.in_queue then if not gate.in_queue then
table.insert(self.gatequeue, gate) table.insert(sim.gatequeue, gate)
gate.in_queue = true gate.in_queue = true
end end
end end
function Simulation.queuegatelater(self, gate, delay) function Simulation.queuegatelater(sim, gate, delay)
local tick = self.currenttick + delay local tick = sim.currenttick + delay
if self.tickqueue[tick] == nil then if sim.tickqueue[tick] == nil then
self.tickqueue[tick] = {} sim.tickqueue[tick] = {}
end end
self.tickqueue[tick][gate] = gate sim.tickqueue[tick][gate] = gate
end end
function Simulation.queuegateinput(self, gate, argv) function Simulation.queuegateinput(sim, gate, argv)
self.inputqueue[gate] = self.inputqueue[gate] or {} sim.inputqueue[gate] = sim.inputqueue[gate] or {}
table.insert(self.inputqueue[gate], argv) table.insert(sim.inputqueue[gate], argv)
self.inputqueue_nonempty = true sim.inputqueue_nonempty = true
end end
function Simulation.queuegateinit(self, gate) function Simulation.queuegateinit(sim, gate)
self.initqueue[gate] = gate sim.initqueue[gate] = gate
self.initqueue_nonempty = true sim.initqueue_nonempty = true
end end
function Simulation.queuegroup(self, group) function Simulation.queuegroup(sim, group)
if not group.in_queue then if not group.in_queue then
table.insert(self.groupqueue, group) table.insert(sim.groupqueue, group)
group.in_queue = true group.in_queue = true
end end
end end
function Simulation.dequeuegroup(self, group) function Simulation.dequeuegroup(sim, group)
if group.in_queue then if group.in_queue then
array_remove(self.groupqueue, group) array_remove(sim.groupqueue, group)
end end
self.groupfxqueue[group] = nil sim.groupfxqueue[group] = nil
end end
function Simulation.dequeuegate(self, gate) function Simulation.dequeuegate(sim, gate)
if gate.in_queue then if gate.in_queue then
array_remove(self.gatequeue, gate) array_remove(sim.gatequeue, gate)
end end
self.initqueue[gate] = nil sim.initqueue[gate] = nil
self.inputqueue[gate] = nil sim.inputqueue[gate] = nil
for tick, tickq in pairs(self.tickqueue) do for tick, tickq in pairs(sim.tickqueue) do
tickq[gate] = nil tickq[gate] = nil
end end
end end
function Simulation.queuegroupfx(self, group) function Simulation.queuegroupfx(sim, group)
self.groupfxqueue[group] = group sim.groupfxqueue[group] = group
end end
function Simulation.queuecallback(self, gate, ...) function Simulation.queuecallback(sim, gate, ...)
self.callbacks = self.callbacks or {} sim.callbacks = sim.callbacks or {}
self.callbacks[gate.objref] = {...} sim.callbacks[gate.objref] = {...}
end end
function Simulation.tick(self) function Simulation.tick(sim)
for k, group in ipairs(self.groupqueue) do for k, group in ipairs(sim.groupqueue) do
Group.update(group) Group.update(group)
group.in_queue = false group.in_queue = false
end end
self.groupqueue = {} sim.groupqueue = {}
if self.initqueue_nonempty then if sim.initqueue_nonempty then
for k, gate in pairs(self.initqueue) do for k, gate in pairs(sim.initqueue) do
Gate.init(gate) Gate.init(gate)
end end
self.initqueue = {} sim.initqueue = {}
self.initqueue_nonempty = false sim.initqueue_nonempty = false
end end
if self.inputqueue_nonempty then if sim.inputqueue_nonempty then
for gate, inputs in pairs(self.inputqueue) do for gate, inputs in pairs(sim.inputqueue) do
for inputidx, argv in ipairs(inputs) do for inputidx, argv in ipairs(inputs) do
Gate.input(gate, argv) Gate.input(gate, argv)
end end
end end
self.inputqueue = {} sim.inputqueue = {}
self.inputqueue_nonempty = false sim.inputqueue_nonempty = false
end end
if self.tickqueue[self.currenttick] ~= nil then if sim.tickqueue[sim.currenttick] ~= nil then
for i, gate in pairs(self.tickqueue[self.currenttick]) do for i, gate in pairs(sim.tickqueue[sim.currenttick]) do
Simulation.queuegate(self, gate) Simulation.queuegate(sim, gate)
end end
self.tickqueue[self.currenttick] = nil sim.tickqueue[sim.currenttick] = nil
end end
for k, gate in ipairs(self.gatequeue) do for k, gate in ipairs(sim.gatequeue) do
Gate.logic(gate) Gate.logic(gate)
gate.in_queue = false gate.in_queue = false
end end
self.gatequeue = {} sim.gatequeue = {}
self.currenttick = self.currenttick + 1 sim.currenttick = sim.currenttick + 1
end end
function Simulation.sendfxupdate(self) function Simulation.sendfxupdate(sim)
for k, group in pairs(self.groupfxqueue) do for k, group in pairs(sim.groupfxqueue) do
if group.state ~= group.fxstate then if group.state ~= group.fxstate then
group.fxstate = group.state group.fxstate = group.state
@ -353,14 +353,14 @@ function Simulation.sendfxupdate(self)
end end
end end
self.groupfxqueue = {} sim.groupfxqueue = {}
end end
function Simulation.sendcallbacks(self) function Simulation.sendcallbacks(sim)
if self.callbacks ~= nil then if sim.callbacks ~= nil then
local data = "CB" local data = "CB"
for objref, args in pairs(self.callbacks) do for objref, args in pairs(sim.callbacks) do
local escargs = {} local escargs = {}
for argidx, argv in ipairs(args) do for argidx, argv in ipairs(args) do
table.insert(escargs, expandescape(tostring(argv))) table.insert(escargs, expandescape(tostring(argv)))
@ -369,6 +369,6 @@ function Simulation.sendcallbacks(self)
end end
client:send(data .. "\n") client:send(data .. "\n")
self.callbacks = nil sim.callbacks = nil
end end
end end

View File

@ -22,34 +22,34 @@ function Wire.new(self, objref, layer, bounds)
return o return o
end end
function Wire.setlayer(self, layer) function Wire.setlayer(wire, layer)
if self.group ~= nil then if wire.group ~= nil then
Group.removewire(self.group, self) Group.removewire(wire.group, wire)
end end
self.layer = layer wire.layer = layer
Simulation.connectwire(GSim, self) Simulation.connectwire(GSim, wire)
end end
function Wire.update(self) function Wire.update(wire)
client:send("WU\t" .. bool_to_int[self.group.state] .. "\t" .. self.objref .. "\n") client:send("WU\t" .. bool_to_int[wire.group.state] .. "\t" .. wire.objref .. "\n")
end end
function Wire.setgroup(self, group) function Wire.setgroup(wire, group)
self.group = group wire.group = group
end end
function Wire.getgroup(self) function Wire.getgroup(wire)
return self.group return wire.group
end end
function Wire.getobjref(self) function Wire.getobjref(wire)
return self.objref return wire.objref
end end
function Wire.getlayer(self) function Wire.getlayer(wire)
return self.layer return wire.layer
end end
function Wire.getbounds(self) function Wire.getbounds(wire)
return self.bounds return wire.bounds
end end