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