use get/set for parameters on ports and wires

This commit is contained in:
Redo
2021-02-03 09:32:05 -06:00
parent 941348002b
commit 54f45520c0
7 changed files with 118 additions and 74 deletions

View File

@@ -69,26 +69,28 @@ function Simulation.addgatedefinition(self, definition)
end
function Simulation.addwire(self, wire)
self.wires[wire.objref] = wire
self.wires[Wire.getobjref(wire)] = wire
local bounds = Wire.getbounds(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
Simulation.addtoworld(self, wire, x, wire.bounds[2], z)
Simulation.addtoworld(self, wire, x, wire.bounds[5], z)
for x = bounds[1]+1, bounds[4]-1, 2 do
for z = bounds[3]+1, bounds[6]-1, 2 do
Simulation.addtoworld(self, wire, x, bounds[2], z)
Simulation.addtoworld(self, wire, x, 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
Simulation.addtoworld(self, wire, wire.bounds[1], y, z)
Simulation.addtoworld(self, wire, wire.bounds[4], y, z)
for y = bounds[2]+1, bounds[5]-1, 2 do
for z = bounds[3]+1, bounds[6]-1, 2 do
Simulation.addtoworld(self, wire, bounds[1], y, z)
Simulation.addtoworld(self, 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
Simulation.addtoworld(self, wire, x, y, wire.bounds[3])
Simulation.addtoworld(self, wire, x, y, wire.bounds[6])
for x = bounds[1]+1, bounds[4]-1, 2 do
for y = bounds[2]+1, bounds[5]-1, 2 do
Simulation.addtoworld(self, wire, x, y, bounds[3])
Simulation.addtoworld(self, wire, x, y, bounds[6])
end
end
@@ -104,9 +106,9 @@ function Simulation.addgate(self, gate)
Simulation.addtoworld(self, port, offset[1], offset[2], offset[3])
Simulation.connectport(self, port)
if port.type == PortTypes.input then
if Port.gettype(port) == PortTypes.input then
self.ninports = self.ninports + 1
elseif port.type == PortTypes.output then
elseif Port.gettype(port) == PortTypes.output then
self.noutports = self.noutports + 1
end
end
@@ -118,30 +120,32 @@ function Simulation.removewire(self, objref)
local wire = self.wires[objref]
if wire ~= nil then
self.wires[objref] = nil
local bounds = Wire.getbounds(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
sim[x][wire.bounds[2]][z][wire] = nil
sim[x][wire.bounds[5]][z][wire] = nil
for x = bounds[1]+1, bounds[4]-1, 2 do
for z = bounds[3]+1, bounds[6]-1, 2 do
sim[x][bounds[2]][z][wire] = nil
sim[x][bounds[5]][z][wire] = nil
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
sim[wire.bounds[1]][y][z][wire] = nil
sim[wire.bounds[4]][y][z][wire] = nil
for y = bounds[2]+1, bounds[5]-1, 2 do
for z = bounds[3]+1, bounds[6]-1, 2 do
sim[bounds[1]][y][z][wire] = nil
sim[bounds[4]][y][z][wire] = nil
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
sim[x][y][wire.bounds[3]][wire] = nil
sim[x][y][wire.bounds[6]][wire] = nil
for x = bounds[1]+1, bounds[4]-1, 2 do
for y = bounds[2]+1, bounds[5]-1, 2 do
sim[x][y][bounds[3]][wire] = nil
sim[x][y][bounds[6]][wire] = nil
end
end
self.nwires = self.nwires - 1
Group.removewire(wire.group, wire)
Group.removewire(Wire.getgroup(wire), wire)
end
end
@@ -151,11 +155,11 @@ function Simulation.removegate(self, objref)
for k, port in pairs(gate.ports) do
local pos = Port.getconnectionposition(port)
self[pos[1]][pos[2]][pos[3]][port] = nil
Group.removeport(port.group, port)
Group.removeport(Port.getgroup(port), port)
if port.type == PortTypes.input then
if Port.gettype(port) == PortTypes.input then
self.ninports = self.ninports - 1
elseif port.type == PortTypes.output then
elseif Port.gettype(port) == PortTypes.output then
self.noutports = self.noutports - 1
end
end
@@ -169,10 +173,8 @@ 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
if obj.logictype == 0 and Wire.getlayer(obj) == Wire.getlayer(wire) then
Group.addwire(obj.group, wire)
end
elseif obj.logictype == 1 then
Group.addwire(obj.group, wire)
end
@@ -181,28 +183,30 @@ function Simulation.connectwireat(self, wire, x, y, z)
end
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)
self:connectwireat(wire, x, wire.bounds[5], z)
local bounds = Wire.getbounds(wire)
for x = bounds[1]+1, bounds[4]-1, 2 do
for z = bounds[3]+1, bounds[6]-1, 2 do
self:connectwireat(wire, x, bounds[2], z)
self:connectwireat(wire, x, 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:connectwireat(wire, wire.bounds[1], y, z)
self:connectwireat(wire, wire.bounds[4], y, z)
for y = bounds[2]+1, bounds[5]-1, 2 do
for z = bounds[3]+1, bounds[6]-1, 2 do
self:connectwireat(wire, bounds[1], y, z)
self:connectwireat(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:connectwireat(wire, x, y, wire.bounds[3])
self:connectwireat(wire, x, y, wire.bounds[6])
for x = bounds[1]+1, bounds[4]-1, 2 do
for y = bounds[2]+1, bounds[5]-1, 2 do
self:connectwireat(wire, x, y, bounds[3])
self:connectwireat(wire, x, y, bounds[6])
end
end
if wire.group == nil then
if Wire.getgroup(wire)==nil then
Group.addwire(Group.new(Group), wire)
end
end
@@ -216,7 +220,7 @@ function Simulation.connectport(self, port)
end
end
if port.group == nil then
if Port.getgroup(port) == nil then
Group.addport(Group.new(Group), port)
end
end
@@ -258,7 +262,7 @@ function Simulation.tick(self)
for k, group in pairs(self.groupqueue) do
local newstate = false
for j, port in pairs(group.out_ports) do
newstate = newstate or port.state
newstate = newstate or Port.getstate(port)
if newstate then
break
end
@@ -303,7 +307,7 @@ function Simulation.sendfxupdate(self)
local data = bool_to_int[group.state]
for i, wire in pairs(group.wires) do
data = data .. "\t" .. wire.objref
data = data .. "\t" .. Wire.getobjref(wire)
end
client:send("WU\t" .. data .. "\n")