remove colon syntax from oop

This commit is contained in:
Redo 2021-02-03 09:17:33 -06:00
parent 1b7915de4c
commit 941348002b
7 changed files with 124 additions and 120 deletions

View File

@ -1,6 +1,7 @@
Gate = {} Gate = {}
function Gate:new(objref, definition) function Gate.new(self, objref, definition)
local o = { local o = {
objref = objref, objref = objref,
definition = definition, definition = definition,
@ -11,33 +12,33 @@ function Gate:new(objref, definition)
return o return o
end end
function Gate:addport(port) function Gate.addport(self, port)
self.ports[#self.ports+1] = port self.ports[#self.ports+1] = port
port.gate = self port.gate = self
end end
function Gate:getportstate(index) function Gate.getportstate(self, index)
return self.ports[index].state return self.ports[index].state
end end
function Gate:setportstate(index, state) function Gate.setportstate(self, index, state)
self.ports[index]:setstate(state) Port.setstate(self.ports[index], state)
end end
function Gate:initdata() function Gate.initdata(self)
self.data = {} self.data = {}
end end
function Gate:getdata() function Gate.getdata(self)
return self.data return self.data
end end
function Gate:getportisrising(index) function Gate.getportisrising(self, index)
return self.ports[index]:isrising() return Port.isrising(self.ports[index])
end end
function Gate:getportisfalling(index) function Gate:getportisfalling(index)
return self.ports[index]:isfalling() return Port.isfalling(self.ports[index])
end end
-- function Gate:cb(...) -- function Gate:cb(...)
@ -52,15 +53,15 @@ end
-- sim:queuecallback(self, str) -- sim:queuecallback(self, str)
-- end -- end
function Gate:cb(...) function Gate.cb(self, ...)
sim:queuecallback(self, ...) Simulation.queuecallback(sim, self, ...)
end end
function Gate:queue(delay) function Gate.queue(self, delay)
sim:queuegatelater(self, delay) Simulation.queuegatelater(sim, self, delay)
end end
function Gate:testlogic(n) function Gate.testlogic(self, n)
--local time = os.clock() --local time = os.clock()
--for i = 1, n do --for i = 1, n do
-- self.definition.logic(self) -- self.definition.logic(self)
@ -68,6 +69,6 @@ function Gate:testlogic(n)
--client:send("TEST\t" .. (os.clock()-time) .. "\n") --client:send("TEST\t" .. (os.clock()-time) .. "\n")
end end
function Gate:gettick() function Gate.gettick(self)
return sim.currenttick return sim.currenttick
end end

View File

@ -5,7 +5,7 @@ GateDefinition = {
input = function(gate, argv) end input = function(gate, argv) end
} }
function GateDefinition:new(objref, name, description, init, logic, input, global, ports) function GateDefinition.new(self, objref, name, description, init, logic, input, global, ports)
name = collapseescape(name) name = collapseescape(name)
init = collapseescape(init) init = collapseescape(init)
@ -58,8 +58,8 @@ function GateDefinition:new(objref, name, description, init, logic, input, globa
return o return o
end end
function GateDefinition:constructgate(objref, position, rotation) function GateDefinition.constructgate(self, objref, position, rotation)
local gate = Gate:new(objref, self) local gate = Gate.new(Gate, objref, self)
for i = 1, #self.ports do for i = 1, #self.ports do
local port = self.ports[i] local port = self.ports[i]
@ -84,7 +84,7 @@ function GateDefinition:constructgate(objref, position, rotation)
pos[2] = x pos[2] = x
end end
gate:addport(Port:new(type, dir, {position[1]+pos[1], position[2]+pos[2], position[3]+pos[3]}, port.causeupdate)) Gate.addport(gate, Port.new(Port, type, dir, {position[1]+pos[1], position[2]+pos[2], position[3]+pos[3]}, port.causeupdate))
end end
return gate return gate

View File

@ -1,6 +1,7 @@
Group = {} Group = {}
function Group:new() function Group.new(self)
local o = { local o = {
state = false, state = false,
fxstate = false, fxstate = false,
@ -18,11 +19,11 @@ function Group:new()
return o return o
end end
function Group:getsize() function Group.getsize(self)
return self.nwires + self.nout_ports + self.nin_ports return self.nwires + self.nout_ports + self.nin_ports
end end
function Group:addwire(wire) function Group.addwire(self, wire)
if wire.group ~= self then if wire.group ~= self then
if wire.group ~= nil then if wire.group ~= nil then
self:mergewith(wire.group) self:mergewith(wire.group)
@ -37,7 +38,7 @@ function Group:addwire(wire)
end end
end end
function Group:removewire(wire) function Group.removewire(self, wire)
wire.group = nil wire.group = nil
self.wires[wire] = nil self.wires[wire] = nil
@ -74,7 +75,7 @@ function Group:removewire(wire)
self.nin_ports = 0 self.nin_ports = 0
end end
function Group:addport(port) function Group.addport(self, port)
port.group = self port.group = self
if port.type == PortTypes.output then if port.type == PortTypes.output then
@ -88,7 +89,7 @@ function Group:addport(port)
end end
end end
function Group:removeport(port) function Group.removeport(self, port)
if port.type == PortTypes.output then if port.type == PortTypes.output then
self.out_ports[port] = nil self.out_ports[port] = nil
self.nout_ports = self.nout_ports - 1 self.nout_ports = self.nout_ports - 1
@ -97,31 +98,31 @@ function Group:removeport(port)
self.nin_ports = self.nin_ports - 1 self.nin_ports = self.nin_ports - 1
end end
sim:queuegroup(self) Simulation.queuegroup(sim, self)
end end
function Group:mergewith(group) function Group.mergewith(self, group)
if self:getsize() >= group:getsize() then if self:getsize() >= group:getsize() then
group:mergeinto(self) Group.mergeinto(group, self)
return self return self
else else
self:mergeinto(group) Group.mergeinto(self, group)
return group return group
end end
end end
function Group:mergeinto(group) function Group.mergeinto(self, group)
for k, wire in pairs(self.wires) do for k, wire in pairs(self.wires) do
wire.group = nil wire.group = nil
group:addwire(wire) Group.addwire(group, wire)
end end
for k, port in pairs(self.out_ports) do for k, port in pairs(self.out_ports) do
group:addport(port) Group.addport(group, port)
end end
for k, port in pairs(self.in_ports) do for k, port in pairs(self.in_ports) do
group:addport(port) Group.addport(group, port)
end end
self.wires = {} self.wires = {}
@ -133,15 +134,15 @@ function Group:mergeinto(group)
self.nin_ports = 0 self.nin_ports = 0
end end
function Group:setstate(state) 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(state) Port.setinputstate(port, state)
end end
sim:queuegroupfx(self) Simulation.queuegroupfx(sim, self)
end end
end end

View File

@ -139,31 +139,31 @@ while 1 do
local max = vectotable(data[i+4]) local max = vectotable(data[i+4])
local bounds = {min[1], min[2], min[3], max[1], max[2], max[3]} local bounds = {min[1], min[2], min[3], max[1], max[2], max[3]}
local wire = Wire:new(tonumber(data[i+1]), tonumber(data[i+2]), bounds) local wire = Wire.new(Wire, tonumber(data[i+1]), tonumber(data[i+2]), bounds)
sim:addwire(wire) Simulation.addwire(sim, wire)
i = i + 4 i = i + 4
elseif data[i] == "G" then elseif data[i] == "G" then
local objref = tonumber(data[i+1]) local objref = tonumber(data[i+1])
local definition = sim:getdefinitionbyref(tonumber(data[i+2])) local definition = Simulation.getdefinitionbyref(sim, tonumber(data[i+2]))
assert(definition, "No gate definition for objref "..objref) assert(definition, "No gate definition for objref "..objref)
local position = vectotable(data[i+3]) local position = vectotable(data[i+3])
local rotation = tonumber(data[i+4]) local rotation = tonumber(data[i+4])
local gate = definition:constructgate(objref, position, rotation) local gate = GateDefitinion.constructgate(definition, objref, position, rotation)
sim:addgate(gate) Simulation.addgate(sim, gate)
--print(gate.objref) --print(gate.objref)
gate.definition.init(gate) gate.definition.init(gate)
gate.definition.logic(gate) gate.definition.logic(gate)
i = i + 4 i = i + 4
elseif data[i] == "RW" then elseif data[i] == "RW" then
sim:removewire(tonumber(data[i+1])) Simulation.removewire(sim, tonumber(data[i+1]))
i = i + 1 i = i + 1
elseif data[i] == "RG" then elseif data[i] == "RG" then
sim:removegate(tonumber(data[i+1])) Simulation.removegate(sim, tonumber(data[i+1]))
i = i + 1 i = i + 1
elseif data[i] == "GD" then elseif data[i] == "GD" then
--print("---------------------------------------[[[[") --print("---------------------------------------[[[[")
@ -192,28 +192,28 @@ while 1 do
if not port.direction then print(line) end if not port.direction then print(line) end
end end
local definition = GateDefinition:new(objref, name, desc, init, logic, input, global, ports) local definition = GateDefinition.new(GateDefitinion, objref, name, desc, init, logic, input, global, ports)
sim:addgatedefinition(definition) Simulation.addgatedefinition(sim, definition)
i = i + 8 + numports*5 i = i + 8 + numports*5
elseif data[i] == "SL" then elseif data[i] == "SL" then
local wire = sim:getwirebyref(tonumber(data[i+1])) local wire = Simulation.getwirebyref(sim, tonumber(data[i+1]))
if wire ~= nil then if wire ~= nil then
wire:setlayer(tonumber(data[i+2])) Wire.setlayer(wire, tonumber(data[i+2]))
end end
i = i + 2 i = i + 2
elseif data[i] == "SP" then elseif data[i] == "SP" then
local gate = sim:getgatebyref(tonumber(data[i+1])) local gate = Simulation.getgatebyref(sim, tonumber(data[i+1]))
if gate ~= nil then if gate ~= nil then
gate.ports[tonumber(data[i+2])]:setstate(toboolean(data[i+3])) Port.setstate(gate.ports[tonumber(data[i+2])], toboolean(data[i+3]))
end end
i = i + 3 i = i + 3
elseif data[i] == "SG" then elseif data[i] == "SG" then
local wire = sim:getwirebyref(tonumber(data[i+1])) local wire = Simulation.getwirebyref(sim, tonumber(data[i+1]))
if wire ~= nil then if wire ~= nil then
wire.group:setstate(toboolean(data[i+2])) Group.setstate(wire.group, toboolean(data[i+2]))
end end
i = i + 2 i = i + 2
@ -245,7 +245,7 @@ while 1 do
local userid = data[i+1] local userid = data[i+1]
local objref = tonumber(data[i+2]) local objref = tonumber(data[i+2])
local obj = sim:getwirebyref(objref) or sim:getgatebyref(objref) local obj = Simulation.getwirebyref(sim, objref) or Simulation.getgatebyref(sim, objref)
if obj ~= nil then if obj ~= nil then
local info = "" local info = ""
@ -277,20 +277,20 @@ while 1 do
client:send("SINFO\t" .. data[i+1] .. "\t" .. sim.nwires .. "\t" .. sim.ngates .. "\t" .. sim.ninports .. "\t" .. sim.noutports .. "\n") client:send("SINFO\t" .. data[i+1] .. "\t" .. sim.nwires .. "\t" .. sim.ngates .. "\t" .. sim.ninports .. "\t" .. sim.noutports .. "\n")
i = i + 1 i = i + 1
elseif data[i] == "TICK" then elseif data[i] == "TICK" then
sim:tick() Simulation.tick(sim)
ticks = ticks + 1 ticks = ticks + 1
elseif data[i] == "TEST" then elseif data[i] == "TEST" then
local gate = sim:getgatebyref(tonumber(data[i+1])) local gate = Simulation.getgatebyref(sim, tonumber(data[i+1]))
gate:testlogic(tonumber(data[i+2])) Gate.testlogic(gate, tonumber(data[i+2]))
i = i + 2 i = i + 2
elseif data[i] == "IN" then elseif data[i] == "IN" then
local gate = sim:getgatebyref(tonumber(data[i+1])) local gate = Simulation.getgatebyref(sim, tonumber(data[i+1]))
local argc = tonumber(data[i+2]) local argc = tonumber(data[i+2])
local argv = {} local argv = {}
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
sim:queuegateinput(gate, argv) Simulation.queuegateinput(sim, gate, argv)
i = i+2+argc i = i+2+argc
elseif data[i] == "SAVE" then elseif data[i] == "SAVE" then
@ -303,7 +303,7 @@ while 1 do
i = i + 1 i = i + 1
end end
elseif err == "closed" then elseif err == "closed" then
sim = Simulation:new() sim = Simulation.new(Simulation)
acceptclient() acceptclient()
end end
@ -339,9 +339,9 @@ while 1 do
if time-lastfxtime >= OPT_FX_TIME then if time-lastfxtime >= OPT_FX_TIME then
if OPT_FX_UPDATES then if OPT_FX_UPDATES then
sim:sendfxupdate() Simulation.sendfxupdate(sim)
end end
sim:sendcallbacks() Simulation.sendcallbacks(sim)
lastfxtime = time lastfxtime = time
end end

View File

@ -1,3 +1,4 @@
PortTypes = { PortTypes = {
output = 0, output = 0,
input = 1 input = 1
@ -16,7 +17,7 @@ Port = {
logictype = 1, logictype = 1,
} }
function Port:new(type, direction, position, causeupdate) function Port.new(self, type, direction, position, causeupdate)
local o = { local o = {
type = type, type = type,
direction = direction, direction = direction,
@ -31,35 +32,35 @@ function Port:new(type, direction, position, causeupdate)
return o return o
end end
function Port:setstate(state) function Port.setstate(self, state)
if state ~= self.state then if state ~= self.state then
self.state = state self.state = state
sim:queuegroup(self.group) Simulation.queuegroup(sim, self.group)
end end
end end
function Port:setinputstate(state) function Port.setinputstate(self, state)
if state ~= self.state then if state ~= self.state then
self.state = state self.state = state
if self.causeupdate then if self.causeupdate then
sim:queuegate(self.gate) Simulation.queuegate(sim, self.gate)
end end
end end
end end
function Port:getconnectionposition() function Port.getconnectionposition(self)
local offset = PortDirections[self.direction] local offset = PortDirections[self.direction]
return {self.position[1]+offset[1], self.position[2]+offset[2], self.position[3]+offset[3]} return {self.position[1]+offset[1], self.position[2]+offset[2], self.position[3]+offset[3]}
end end
function Port:isrising() function Port.isrising(self)
if self.group == nil then if self.group == nil then
return false return false
end end
return self.group.state and (self.group.updatetick == sim.currenttick) return self.group.state and (self.group.updatetick == sim.currenttick)
end end
function Port:isfalling() function Port.isfalling(self)
if self.group == nil then if self.group == nil then
return false return false
end end

View File

@ -1,7 +1,7 @@
Simulation = {} Simulation = {}
function Simulation:new() function Simulation.new(self)
local o = { local o = {
definitions = {}, definitions = {},
wires = {}, wires = {},
@ -28,7 +28,7 @@ function Simulation:new()
return o return o
end end
function Simulation:addtoworld(obj, x, y, z) function Simulation.addtoworld(self, obj, x, y, z)
if self[x] == nil then if self[x] == nil then
self[x] = {} self[x] = {}
end end
@ -44,7 +44,7 @@ function Simulation:addtoworld(obj, x, y, z)
self[x][y][z][obj] = obj self[x][y][z][obj] = obj
end end
function Simulation:getfromworld(x, y, z) function Simulation.getfromworld(self, x, y, z)
if self[x] == nil or self[x][y] == nil or self[x][y][z] == nil then if self[x] == nil or self[x][y] == nil or self[x][y][z] == nil then
return {} return {}
else else
@ -52,57 +52,57 @@ function Simulation:getfromworld(x, y, z)
end end
end end
function Simulation:getdefinitionbyref(objref) function Simulation.getdefinitionbyref(self, objref)
return self.definitions[objref] return self.definitions[objref]
end end
function Simulation:getgatebyref(objref) function Simulation.getgatebyref(self, objref)
return self.gates[objref] return self.gates[objref]
end end
function Simulation:getwirebyref(objref) function Simulation.getwirebyref(self, objref)
return self.wires[objref] return self.wires[objref]
end end
function Simulation:addgatedefinition(definition) function Simulation.addgatedefinition(self, definition)
self.definitions[definition.objref] = definition self.definitions[definition.objref] = definition
end end
function Simulation:addwire(wire) function Simulation.addwire(self, wire)
self.wires[wire.objref] = wire self.wires[wire.objref] = wire
for x = wire.bounds[1]+1, wire.bounds[4]-1, 2 do for x = wire.bounds[1]+1, wire.bounds[4]-1, 2 do
for z = wire.bounds[3]+1, wire.bounds[6]-1, 2 do for z = wire.bounds[3]+1, wire.bounds[6]-1, 2 do
self:addtoworld(wire, x, wire.bounds[2], z) Simulation.addtoworld(self, wire, x, wire.bounds[2], z)
self:addtoworld(wire, x, wire.bounds[5], z) Simulation.addtoworld(self, wire, x, wire.bounds[5], z)
end end
end end
for y = wire.bounds[2]+1, wire.bounds[5]-1, 2 do for y = wire.bounds[2]+1, wire.bounds[5]-1, 2 do
for z = wire.bounds[3]+1, wire.bounds[6]-1, 2 do for z = wire.bounds[3]+1, wire.bounds[6]-1, 2 do
self:addtoworld(wire, wire.bounds[1], y, z) Simulation.addtoworld(self, wire, wire.bounds[1], y, z)
self:addtoworld(wire, wire.bounds[4], y, z) Simulation.addtoworld(self, wire, wire.bounds[4], y, z)
end end
end end
for x = wire.bounds[1]+1, wire.bounds[4]-1, 2 do for x = wire.bounds[1]+1, wire.bounds[4]-1, 2 do
for y = wire.bounds[2]+1, wire.bounds[5]-1, 2 do for y = wire.bounds[2]+1, wire.bounds[5]-1, 2 do
self:addtoworld(wire, x, y, wire.bounds[3]) Simulation.addtoworld(self, wire, x, y, wire.bounds[3])
self:addtoworld(wire, x, y, wire.bounds[6]) Simulation.addtoworld(self, wire, x, y, wire.bounds[6])
end end
end end
self.nwires = self.nwires + 1 self.nwires = self.nwires + 1
self:connectwire(wire) Simulation.connectwire(self, wire)
end end
function Simulation:addgate(gate) function Simulation.addgate(self, gate)
self.gates[gate.objref] = gate self.gates[gate.objref] = gate
for k, port in pairs(gate.ports) do for k, port in pairs(gate.ports) do
local offset = port:getconnectionposition() local offset = Port.getconnectionposition(port)
self:addtoworld(port, offset[1], offset[2], offset[3]) Simulation.addtoworld(self, port, offset[1], offset[2], offset[3])
self:connectport(port) Simulation.connectport(self, port)
if port.type == PortTypes.input then if port.type == PortTypes.input then
self.ninports = self.ninports + 1 self.ninports = self.ninports + 1
@ -114,7 +114,7 @@ function Simulation:addgate(gate)
self.ngates = self.ngates + 1 self.ngates = self.ngates + 1
end end
function Simulation:removewire(objref) function Simulation.removewire(self, objref)
local wire = self.wires[objref] local wire = self.wires[objref]
if wire ~= nil then if wire ~= nil then
self.wires[objref] = nil self.wires[objref] = nil
@ -141,17 +141,17 @@ function Simulation:removewire(objref)
end end
self.nwires = self.nwires - 1 self.nwires = self.nwires - 1
wire.group:removewire(wire) Group.removewire(wire.group, wire)
end end
end end
function Simulation:removegate(objref) function Simulation.removegate(self, objref)
local gate = self.gates[objref] local gate = self.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() local pos = Port.getconnectionposition(port)
self[pos[1]][pos[2]][pos[3]][port] = nil self[pos[1]][pos[2]][pos[3]][port] = nil
port.group:removeport(port) Group.removeport(port.group, port)
if port.type == PortTypes.input then if port.type == PortTypes.input then
self.ninports = self.ninports - 1 self.ninports = self.ninports - 1
@ -165,22 +165,22 @@ function Simulation:removegate(objref)
self.ngates = self.ngates - 1 self.ngates = self.ngates - 1
end end
function Simulation:connectwireat(wire, x, y, z) function Simulation.connectwireat(self, wire, x, y, z)
local objs = self:getfromworld(x, y, z) local objs = Simulation.getfromworld(self, 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 obj.logictype == 0 and obj.layer == wire.layer then if obj.logictype == 0 and obj.layer == wire.layer then
if obj.layer == wire.layer then if obj.layer == wire.layer then
obj.group:addwire(wire) Group.addwire(obj.group, wire)
end end
elseif obj.logictype == 1 then elseif obj.logictype == 1 then
obj.group:addwire(wire) Group.addwire(obj.group, wire)
end end
end end
end end
end end
function Simulation:connectwire(wire) function Simulation.connectwire(self, wire)
for x = wire.bounds[1]+1, wire.bounds[4]-1, 2 do for x = wire.bounds[1]+1, wire.bounds[4]-1, 2 do
for z = wire.bounds[3]+1, wire.bounds[6]-1, 2 do for z = wire.bounds[3]+1, wire.bounds[6]-1, 2 do
self:connectwireat(wire, x, wire.bounds[2], z) self:connectwireat(wire, x, wire.bounds[2], z)
@ -203,29 +203,29 @@ function Simulation:connectwire(wire)
end end
if wire.group == nil then if wire.group == nil then
Group:new():addwire(wire) Group.addwire(Group.new(Group), wire)
end end
end end
function Simulation:connectport(port) function Simulation.connectport(self, port)
local connpos = port:getconnectionposition() local connpos = Port.getconnectionposition(port)
local objs = self:getfromworld(connpos[1], connpos[2], connpos[3]) local objs = self:getfromworld(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
obj.group:addport(port) Group.addport(obj.group, port)
end end
end end
if port.group == nil then if port.group == nil then
Group:new():addport(port) Group.addport(Group.new(Group), port)
end end
end end
function Simulation:queuegate(gate) function Simulation.queuegate(self, gate)
self.gatequeue[gate] = gate self.gatequeue[gate] = gate
end end
function Simulation:queuegatelater(gate, delay) function Simulation.queuegatelater(self, gate, delay)
local tick = self.currenttick + delay local tick = self.currenttick + delay
if self.tickqueue[tick] == nil then if self.tickqueue[tick] == nil then
self.tickqueue[tick] = {} self.tickqueue[tick] = {}
@ -233,28 +233,28 @@ function Simulation:queuegatelater(gate, delay)
table.insert(self.tickqueue[tick], gate) table.insert(self.tickqueue[tick], gate)
end end
function Simulation:queuegateinput(gate, argv) function Simulation.queuegateinput(self, gate, argv)
self.inputqueue[gate] = self.inputqueue[gate] or {} self.inputqueue[gate] = self.inputqueue[gate] or {}
table.insert(self.inputqueue[gate], argv) table.insert(self.inputqueue[gate], argv)
end end
function Simulation:queuegateinit(gate) function Simulation.queuegateinit(self, gate)
self.initqueue[gate] = gate self.initqueue[gate] = gate
end end
function Simulation:queuegroup(group) function Simulation.queuegroup(self, group)
self.groupqueue[group] = group self.groupqueue[group] = group
end end
function Simulation:queuegroupfx(group) function Simulation.queuegroupfx(self, group)
self.groupfxqueue[group] = group self.groupfxqueue[group] = group
end end
function Simulation:queuecallback(gate, ...) function Simulation.queuecallback(self, gate, ...)
self.callbacks[gate.objref] = {...} self.callbacks[gate.objref] = {...}
end end
function Simulation:tick() function Simulation.tick(self)
for k, group in pairs(self.groupqueue) do for k, group in pairs(self.groupqueue) do
local newstate = false local newstate = false
for j, port in pairs(group.out_ports) do for j, port in pairs(group.out_ports) do
@ -264,7 +264,7 @@ function Simulation:tick()
end end
end end
group:setstate(newstate) Group.setstate(group, newstate)
end end
self.groupqueue = {} self.groupqueue = {}
@ -282,7 +282,7 @@ function Simulation:tick()
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
self:queuegate(gate) Simulation.queuegate(self, gate)
end end
self.tickqueue[self.currenttick] = nil self.tickqueue[self.currenttick] = nil
end end
@ -295,7 +295,7 @@ function Simulation:tick()
self.currenttick = self.currenttick + 1 self.currenttick = self.currenttick + 1
end end
function Simulation:sendfxupdate() function Simulation.sendfxupdate(self)
for k, group in pairs(self.groupfxqueue) do for k, group in pairs(self.groupfxqueue) do
if group.state ~= group.fxstate then if group.state ~= group.fxstate then
group.fxstate = group.state group.fxstate = group.state
@ -313,7 +313,7 @@ function Simulation:sendfxupdate()
self.groupfxqueue = {} self.groupfxqueue = {}
end end
function Simulation:sendcallbacks() function Simulation.sendcallbacks(self)
if next(self.callbacks) ~= nil then if next(self.callbacks) ~= nil then
local data = "CB" local data = "CB"

View File

@ -1,8 +1,9 @@
Wire = { Wire = {
logictype = 0 logictype = 0
} }
function Wire:new(objref, layer, bounds) function Wire.new(self, objref, layer, bounds)
local o = { local o = {
objref = objref, objref = objref,
layer = layer, layer = layer,
@ -14,14 +15,14 @@ function Wire:new(objref, layer, bounds)
return o return o
end end
function Wire:setlayer(layer) function Wire.setlayer(self, layer)
if self.group ~= nil then if self.group ~= nil then
self.group:removewire(self) Group.removewire(self.group, self)
end end
self.layer = layer self.layer = layer
sim:connectwire(self) Simulation.connectwire(sim, self)
end end
function Wire:update() function Wire.update(self)
client:send("WU\t" .. bool_to_int[self.group.state] .. "\t" .. self.objref .. "\n") client:send("WU\t" .. bool_to_int[self.group.state] .. "\t" .. self.objref .. "\n")
end end