diff --git a/lua/entities/gmod_wire_plug.lua b/lua/entities/gmod_wire_plug.lua index 3a00101364..c683be49d0 100644 --- a/lua/entities/gmod_wire_plug.lua +++ b/lua/entities/gmod_wire_plug.lua @@ -60,7 +60,7 @@ function ENT:Initialize() self:SetLinked( false ) - self.Memory = {} + self.Memory = nil end function ENT:Setup( ArrayInput ) @@ -84,6 +84,13 @@ function ENT:TriggerInput( name, value ) if (self.Socket and self.Socket:IsValid()) then self.Socket:SetValue( name, value ) end + if not self.ArrayInput then + if (self.Inputs['A'].Src and self.Inputs['A'].Src:IsValid()) then + self.Memory = self.Inputs['A'].Src + else + self.Memory = nil + end + end self:ShowOutput() end @@ -121,10 +128,20 @@ end -- Hi-speed support ------------------------------------------------------------ function ENT:WriteCell( Address, Value, WriteToMe ) - Address = math.floor(Address) + Address = math.floor(Address or 0) if (WriteToMe) then - self.Memory[Address or 1] = Value or 0 - return true + --this would allow the plug to work almost like a dhdd, which seems silly. + --[[if self.ArrayInput then + -- 256 KiB limit + if Address < 0 or Address >= 262144 then return false end + self.Inputs.In.Value[Address] = Value or 0 + return true + end]]-- + if (self.Memory and self.Memory.WriteCell) then + self.Memory:WriteCell(Address, Value) + return true + end + return false else if (self.Socket and self.Socket:IsValid()) then self.Socket:WriteCell( Address, Value, true ) @@ -139,9 +156,23 @@ end -- ReadCell -- Hi-speed support ------------------------------------------------------------ -function ENT:ReadCell( Address ) - Address = math.floor(Address) - return self.Memory[Address or 1] or 0 +function ENT:ReadCell( Address, ReadFromMe ) + Address = math.floor(Address or 0) + if (ReadFromMe) then + if self.ArrayInput then + return self.Inputs.In.Value[Address] or 0 + end + if (self.Memory and self.Memory.ReadCell) then + return self.Memory:ReadCell(Address) + end + return 0 + else + if (self.Socket and self.Socket:IsValid()) then + return self.Socket:ReadCell( Address, true ) + else + return 0 + end + end end function ENT:Think() @@ -157,7 +188,7 @@ function ENT:ResetValues() WireLib.TriggerOutput( self, LETTERS[i], 0 ) end end - self.Memory = {} + self.Memory = nil self:ShowOutput() end diff --git a/lua/entities/gmod_wire_socket.lua b/lua/entities/gmod_wire_socket.lua index 97d56e7da2..d055fd4b5c 100644 --- a/lua/entities/gmod_wire_socket.lua +++ b/lua/entities/gmod_wire_socket.lua @@ -110,7 +110,7 @@ function ENT:Initialize() self:SetLinked( false ) - self.Memory = {} + self.Memory = nil self.DoNextThink = CurTime() + 5 -- wait 5 seconds end @@ -140,6 +140,13 @@ function ENT:TriggerInput( name, value ) if (self.Plug and self.Plug:IsValid()) then self.Plug:SetValue( name, value ) end + if not self.ArrayInput then + if (self.Inputs['A'].Src and self.Inputs['A'].Src:IsValid()) then + self.Memory = self.Inputs['A'].Src + else + self.Memory = nil + end + end self:ShowOutput() end @@ -177,10 +184,20 @@ end -- Hi-speed support ------------------------------------------------------------ function ENT:WriteCell( Address, Value, WriteToMe ) - Address = math.floor(Address) + Address = math.floor(Address or 0) if (WriteToMe) then - self.Memory[Address or 1] = Value or 0 - return true + --this would allow the plug to work almost like a dhdd, which seems silly. + --[[if self.ArrayInput then + -- 256 KiB limit + if Address < 0 or Address >= 262144 then return false end + self.Inputs.In.Value[Address] = Value or 0 + return true + end]]-- + if (self.Memory and self.Memory.WriteCell) then + self.Memory:WriteCell(Address, Value) + return true + end + return false else if (self.Plug and self.Plug:IsValid()) then self.Plug:WriteCell( Address, Value, true ) @@ -195,9 +212,23 @@ end -- ReadCell -- Hi-speed support ------------------------------------------------------------ -function ENT:ReadCell( Address ) - Address = math.floor(Address) - return self.Memory[Address or 1] or 0 +function ENT:ReadCell( Address, ReadFromMe ) + Address = math.floor(Address or 0) + if (ReadFromMe) then + if self.ArrayInput then + return self.Inputs.In.Value[Address] or 0 + end + if (self.Memory and self.Memory.ReadCell) then + return self.Memory:ReadCell(Address) + end + return 0 + else + if (self.Plug and self.Plug:IsValid()) then + return self.Plug:ReadCell( Address, true ) + else + return 0 + end + end end function ENT:ResetValues() @@ -208,7 +239,7 @@ function ENT:ResetValues() WireLib.TriggerOutput( self, LETTERS[i], 0 ) end end - self.Memory = {} + self.Memory = nil self:ShowOutput() end