diff --git a/lua/entities/base_wire_entity.lua b/lua/entities/base_wire_entity.lua index ca144a1964..e4ed825de0 100644 --- a/lua/entities/base_wire_entity.lua +++ b/lua/entities/base_wire_entity.lua @@ -456,10 +456,6 @@ if SERVER then end end -function ENT:OnRemove() - WireLib.Remove(self) -end - function ENT:OnRestore() WireLib.Restored(self) end diff --git a/lua/entities/gmod_wire_adv_emarker.lua b/lua/entities/gmod_wire_adv_emarker.lua index 8c305b2750..75b532a887 100644 --- a/lua/entities/gmod_wire_adv_emarker.lua +++ b/lua/entities/gmod_wire_adv_emarker.lua @@ -119,6 +119,7 @@ end function ENT:OnRemove() self:ClearEntities() + BaseClass.OnRemove(self) end function ENT:BuildDupeInfo() diff --git a/lua/entities/gmod_wire_buoyancy.lua b/lua/entities/gmod_wire_buoyancy.lua index ff06264b20..8430ef3db8 100644 --- a/lua/entities/gmod_wire_buoyancy.lua +++ b/lua/entities/gmod_wire_buoyancy.lua @@ -117,6 +117,7 @@ end function ENT:OnRemove() self:ClearEntities() + BaseClass.OnRemove(self) end function ENT:BuildDupeInfo() diff --git a/lua/entities/gmod_wire_cameracontroller.lua b/lua/entities/gmod_wire_cameracontroller.lua index e9eeafe0e4..ea3eaad58a 100644 --- a/lua/entities/gmod_wire_cameracontroller.lua +++ b/lua/entities/gmod_wire_cameracontroller.lua @@ -675,6 +675,7 @@ function ENT:OnRemove() end self:ClearEntities() + BaseClass.OnRemove(self) end -------------------------------------------------- diff --git a/lua/entities/gmod_wire_characterlcd/cl_init.lua b/lua/entities/gmod_wire_characterlcd/cl_init.lua index fbe30408fa..e86b735faf 100644 --- a/lua/entities/gmod_wire_characterlcd/cl_init.lua +++ b/lua/entities/gmod_wire_characterlcd/cl_init.lua @@ -1,5 +1,6 @@ include("shared.lua") +DEFINE_BASECLASS("base_wire_entity") function ENT:Initialize() local mem = {} @@ -119,6 +120,7 @@ end function ENT:OnRemove() self.GPU:Finalize() + BaseClass.OnRemove(self) end function ENT:ReadCell(Address,value) diff --git a/lua/entities/gmod_wire_clutch.lua b/lua/entities/gmod_wire_clutch.lua index 4b4101884e..e59f3c7953 100644 --- a/lua/entities/gmod_wire_clutch.lua +++ b/lua/entities/gmod_wire_clutch.lua @@ -148,6 +148,8 @@ function ENT:OnRemove() for k in pairs( self.clutch_ballsockets ) do self:RemoveClutch( k ) end + + BaseClass.OnRemove(self) end diff --git a/lua/entities/gmod_wire_consolescreen/cl_init.lua b/lua/entities/gmod_wire_consolescreen/cl_init.lua index 158b84e52b..30df8925dd 100644 --- a/lua/entities/gmod_wire_consolescreen/cl_init.lua +++ b/lua/entities/gmod_wire_consolescreen/cl_init.lua @@ -1,5 +1,7 @@ include("shared.lua") +DEFINE_BASECLASS("base_wire_entity") + function ENT:SendData() net.Start("wire_interactiveprop_action") @@ -134,6 +136,7 @@ end function ENT:OnRemove() self.GPU:Finalize() self.NeedRefresh = true + BaseClass.OnRemove(self) end function ENT:ReadCell(Address,value) @@ -729,6 +732,3 @@ end function ENT:IsTranslucent() return true end - - - diff --git a/lua/entities/gmod_wire_datasocket.lua b/lua/entities/gmod_wire_datasocket.lua index a1b48f8e94..0e494c5a17 100644 --- a/lua/entities/gmod_wire_datasocket.lua +++ b/lua/entities/gmod_wire_datasocket.lua @@ -39,6 +39,8 @@ if CLIENT then if #sockets == 0 then hook.Remove("HUDPaint", "Wire_DataSocket_DrawLinkHelperLine") end + + BaseClass.OnRemove(self) end return diff --git a/lua/entities/gmod_wire_digitalscreen/cl_init.lua b/lua/entities/gmod_wire_digitalscreen/cl_init.lua index da411985f2..8d2cfaa342 100644 --- a/lua/entities/gmod_wire_digitalscreen/cl_init.lua +++ b/lua/entities/gmod_wire_digitalscreen/cl_init.lua @@ -1,6 +1,6 @@ include("shared.lua") - +DEFINE_BASECLASS("base_wire_entity") function ENT:SendData() net.Start("wire_interactiveprop_action") @@ -78,6 +78,7 @@ end function ENT:OnRemove() self.GPU:Finalize() self.NeedRefresh = true + BaseClass.OnRemove(self) end local function stringToNumber(index, str, bytes) diff --git a/lua/entities/gmod_wire_egp/cl_init.lua b/lua/entities/gmod_wire_egp/cl_init.lua index 8d8ec09917..038cc006b4 100644 --- a/lua/entities/gmod_wire_egp/cl_init.lua +++ b/lua/entities/gmod_wire_egp/cl_init.lua @@ -1,5 +1,6 @@ include('shared.lua') +DEFINE_BASECLASS("base_wire_entity") ENT.gmod_wire_egp = true function ENT:Initialize() @@ -49,4 +50,5 @@ end function ENT:OnRemove() self.GPU:Finalize() + BaseClass.OnRemove(self) end diff --git a/lua/entities/gmod_wire_egp_emitter.lua b/lua/entities/gmod_wire_egp_emitter.lua index 1e61dabde1..6e1e26bc8b 100644 --- a/lua/entities/gmod_wire_egp_emitter.lua +++ b/lua/entities/gmod_wire_egp_emitter.lua @@ -171,6 +171,7 @@ if CLIENT then function ENT:OnRemove() if self.GPU then self.GPU:Finalize() end + BaseClass.OnRemove(self) end end diff --git a/lua/entities/gmod_wire_egp_hud/init.lua b/lua/entities/gmod_wire_egp_hud/init.lua index 90ea840123..d575f167d5 100644 --- a/lua/entities/gmod_wire_egp_hud/init.lua +++ b/lua/entities/gmod_wire_egp_hud/init.lua @@ -91,6 +91,7 @@ end function ENT:OnRemove() EGP:UnlinkHUDFromVehicle( self ) + BaseClass.OnRemove(self) end function ENT:BuildDupeInfo() diff --git a/lua/entities/gmod_wire_emarker.lua b/lua/entities/gmod_wire_emarker.lua index 52ccb58184..763f360664 100644 --- a/lua/entities/gmod_wire_emarker.lua +++ b/lua/entities/gmod_wire_emarker.lua @@ -54,6 +54,8 @@ function ENT:OnRemove() self.Mark:RemoveCallOnRemove("EMarker.UnLink" .. self:EntIndex()) self.Mark = nil end + + BaseClass.OnRemove(self) end function ENT:BuildDupeInfo() diff --git a/lua/entities/gmod_wire_eyepod.lua b/lua/entities/gmod_wire_eyepod.lua index e79d56102b..9f9eb4b4a0 100644 --- a/lua/entities/gmod_wire_eyepod.lua +++ b/lua/entities/gmod_wire_eyepod.lua @@ -249,6 +249,7 @@ end) function ENT:OnRemove() self:UnlinkEnt() + BaseClass.OnRemove(self) end local function AngNorm(Ang) diff --git a/lua/entities/gmod_wire_freezer.lua b/lua/entities/gmod_wire_freezer.lua index 37c532799c..efb7887b7a 100644 --- a/lua/entities/gmod_wire_freezer.lua +++ b/lua/entities/gmod_wire_freezer.lua @@ -135,6 +135,7 @@ end function ENT:OnRemove() self:ClearEntities() + BaseClass.OnRemove(self) end function ENT:BuildDupeInfo() diff --git a/lua/entities/gmod_wire_gpu/cl_init.lua b/lua/entities/gmod_wire_gpu/cl_init.lua index c71b321e84..caab596bbc 100644 --- a/lua/entities/gmod_wire_gpu/cl_init.lua +++ b/lua/entities/gmod_wire_gpu/cl_init.lua @@ -1,6 +1,7 @@ include("cl_gpuvm.lua") include("shared.lua") +DEFINE_BASECLASS("base_wire_entity") local Monitors = {} local MonitorLookup = {} local HUDLookup = {} @@ -134,6 +135,7 @@ function ENT:OnRemove() GPULib.ClientCacheCallback(self,nil) self.GPU:Finalize() if self.SpriteGPU then self.SpriteGPU:Finalize() end + BaseClass.OnRemove(self) end diff --git a/lua/entities/gmod_wire_grabber.lua b/lua/entities/gmod_wire_grabber.lua index 2c57e68557..529323ebd4 100644 --- a/lua/entities/gmod_wire_grabber.lua +++ b/lua/entities/gmod_wire_grabber.lua @@ -31,7 +31,7 @@ function ENT:OnRemove() if self.Weld then self:ResetGrab() end - Wire_Remove(self) + BaseClass.OnRemove(self) end function ENT:Setup(Range, Gravity) diff --git a/lua/entities/gmod_wire_graphics_tablet.lua b/lua/entities/gmod_wire_graphics_tablet.lua index 746a5b23d2..42bbd59483 100644 --- a/lua/entities/gmod_wire_graphics_tablet.lua +++ b/lua/entities/gmod_wire_graphics_tablet.lua @@ -24,6 +24,7 @@ if CLIENT then function ENT:OnRemove() self.GPU:Finalize() + BaseClass.OnRemove(self) end local function cut_rect(x1,y1,w1,h1,x2,y2,w2,h2) diff --git a/lua/entities/gmod_wire_hdd.lua b/lua/entities/gmod_wire_hdd.lua index ab8adf8a10..e7f653ad91 100644 --- a/lua/entities/gmod_wire_hdd.lua +++ b/lua/entities/gmod_wire_hdd.lua @@ -9,6 +9,8 @@ function ENT:OnRemove() for k,v in pairs(self.CacheUpdated) do file.Write(self:GetStructName(k),self:MakeFloatTable(self.Cache[k])) end + + BaseClass.OnRemove(self) end function ENT:Initialize() diff --git a/lua/entities/gmod_wire_interactiveprop.lua b/lua/entities/gmod_wire_interactiveprop.lua index f97ead5a08..eff899b980 100644 --- a/lua/entities/gmod_wire_interactiveprop.lua +++ b/lua/entities/gmod_wire_interactiveprop.lua @@ -424,6 +424,7 @@ end function ENT:OnRemove() self:Unprompt( true ) + BaseClass.OnRemove(self) end diff --git a/lua/entities/gmod_wire_lamp.lua b/lua/entities/gmod_wire_lamp.lua index f495ab2096..60dcf68df6 100644 --- a/lua/entities/gmod_wire_lamp.lua +++ b/lua/entities/gmod_wire_lamp.lua @@ -144,6 +144,8 @@ if CLIENT then self.LastLampMatrix = nil self.LastLampColor = nil end + + BaseClass.OnRemove(self) end return diff --git a/lua/entities/gmod_wire_latch.lua b/lua/entities/gmod_wire_latch.lua index 752c8824ef..28b8cf7774 100644 --- a/lua/entities/gmod_wire_latch.lua +++ b/lua/entities/gmod_wire_latch.lua @@ -133,6 +133,7 @@ end function ENT:OnRemove() self:TriggerInput("Activate", 0) self:TriggerInput("NoCollide", 0) + BaseClass.OnRemove(self) end function ENT:UpdateOverlay() diff --git a/lua/entities/gmod_wire_numpad.lua b/lua/entities/gmod_wire_numpad.lua index e0d16ff718..ded21d807d 100644 --- a/lua/entities/gmod_wire_numpad.lua +++ b/lua/entities/gmod_wire_numpad.lua @@ -108,6 +108,8 @@ function ENT:OnRemove() for _,impulse in ipairs(self.impulses) do numpad.Remove(impulse) end + + BaseClass.OnRemove(self) end local function On( pl, ent, key ) diff --git a/lua/entities/gmod_wire_oscilloscope.lua b/lua/entities/gmod_wire_oscilloscope.lua index 10b6439332..81c75f2861 100644 --- a/lua/entities/gmod_wire_oscilloscope.lua +++ b/lua/entities/gmod_wire_oscilloscope.lua @@ -49,6 +49,7 @@ if CLIENT then function ENT:OnRemove() self.GPU:Finalize() + BaseClass.OnRemove(self) end function ENT:GetNodeList() diff --git a/lua/entities/gmod_wire_pod.lua b/lua/entities/gmod_wire_pod.lua index 3cd35610ba..5914096ecb 100644 --- a/lua/entities/gmod_wire_pod.lua +++ b/lua/entities/gmod_wire_pod.lua @@ -268,6 +268,7 @@ function ENT:OnRemove() hook.Remove("PlayerLeaveVehicle", "Wire_Pod_ExitVehicle") hook.Remove("CanExitVehicle","Wire_Pod_CanExitVehicle") end + BaseClass.OnRemove(self) end function ENT:GetPod() diff --git a/lua/entities/gmod_wire_rt_camera.lua b/lua/entities/gmod_wire_rt_camera.lua index 1037d14256..e9e5ac4171 100644 --- a/lua/entities/gmod_wire_rt_camera.lua +++ b/lua/entities/gmod_wire_rt_camera.lua @@ -1,6 +1,6 @@ AddCSLuaFile() -ENT.Base = "base_wire_entity" -ENT.Type = "anim" + +DEFINE_BASECLASS("base_wire_entity") ENT.PrintName = "Improved RT Camera" ENT.WireDebugName = "Improved RT Camera" @@ -89,6 +89,8 @@ if CLIENT then if not fullUpdate then SetCameraActive(self, false) end + + BaseClass.OnRemove(self) end function ENT:SetIsObserved(isObserved) diff --git a/lua/entities/gmod_wire_rt_screen.lua b/lua/entities/gmod_wire_rt_screen.lua index 05468a8642..9287a9a7f9 100644 --- a/lua/entities/gmod_wire_rt_screen.lua +++ b/lua/entities/gmod_wire_rt_screen.lua @@ -1,7 +1,6 @@ AddCSLuaFile() -ENT.Type = "anim" -ENT.Base = "base_wire_entity" +DEFINE_BASECLASS("base_wire_entity") ENT.PrintName = "Improved RT Screen" ENT.WireDebugName = "Improved RT Screen" @@ -131,6 +130,7 @@ if SERVER then if #screens == 0 then hook.Remove("SetupPlayerVisibility", "ImprovedRTCamera") end + BaseClass.OnRemove(self) end end diff --git a/lua/entities/gmod_wire_screen.lua b/lua/entities/gmod_wire_screen.lua index b535954fda..1d3a183ac5 100644 --- a/lua/entities/gmod_wire_screen.lua +++ b/lua/entities/gmod_wire_screen.lua @@ -38,6 +38,7 @@ if CLIENT then function ENT:OnRemove() self.GPU:Finalize() + BaseClass.OnRemove(self) end local large_font = "Trebuchet36" diff --git a/lua/entities/gmod_wire_socket.lua b/lua/entities/gmod_wire_socket.lua index 97d56e7da2..b8cdda6d9f 100644 --- a/lua/entities/gmod_wire_socket.lua +++ b/lua/entities/gmod_wire_socket.lua @@ -89,6 +89,7 @@ if CLIENT then if #sockets == 0 then hook.Remove("HUDPaint", "Wire_Socket_DrawLinkHelperLine") end + BaseClass.OnRemove(self) end return -- No more client diff --git a/lua/entities/gmod_wire_spawner.lua b/lua/entities/gmod_wire_spawner.lua index 20215d1350..872eb7dec8 100644 --- a/lua/entities/gmod_wire_spawner.lua +++ b/lua/entities/gmod_wire_spawner.lua @@ -249,6 +249,7 @@ function ENT:OnRemove() for _,ent in ipairs(self.UndoList) do GlobalUndoList[ent] = nil end + BaseClass.OnRemove(self) end duplicator.RegisterEntityClass("gmod_wire_spawner", WireLib.MakeWireEnt, "Data", "delay", "undo_delay", "spawn_effect", "mat", "r", "g", "b", "a", "skin") diff --git a/lua/entities/gmod_wire_spu/cl_init.lua b/lua/entities/gmod_wire_spu/cl_init.lua index 0155af6f94..1dbdee0d6b 100644 --- a/lua/entities/gmod_wire_spu/cl_init.lua +++ b/lua/entities/gmod_wire_spu/cl_init.lua @@ -1,7 +1,7 @@ include("cl_spuvm.lua") include("shared.lua") - +DEFINE_BASECLASS("base_wire_entity") -------------------------------------------------------------------------------- WireSPU_MaxChannels = 32 @@ -150,6 +150,7 @@ function ENT:OnRemove() v.Sound:Stop() end end + BaseClass.OnRemove(self) end diff --git a/lua/entities/gmod_wire_spu/init.lua b/lua/entities/gmod_wire_spu/init.lua index 520728ea98..cbfba3e2bc 100644 --- a/lua/entities/gmod_wire_spu/init.lua +++ b/lua/entities/gmod_wire_spu/init.lua @@ -69,6 +69,7 @@ function ENT:OnRemove() for i=0,WireSPU_MaxChannels-1 do self.SoundSources[i]:Remove() end + BaseClass.OnRemove(self) end diff --git a/lua/entities/gmod_wire_textentry.lua b/lua/entities/gmod_wire_textentry.lua index b1dcf2fa53..e9e1a42044 100644 --- a/lua/entities/gmod_wire_textentry.lua +++ b/lua/entities/gmod_wire_textentry.lua @@ -167,6 +167,7 @@ function ENT:OnRemove() self:RemoveHoldTimer() self:Unprompt( true ) + BaseClass.OnRemove(self) end ---------------------------------------------------- @@ -186,7 +187,7 @@ net.Receive("wire_textentry_action",function(len,ply) if ok and not self.BlockInput then self:OnTextEntered(text) - + end self:UpdateOverlay() diff --git a/lua/entities/gmod_wire_textreceiver.lua b/lua/entities/gmod_wire_textreceiver.lua index 6998ccc86d..7274fca193 100644 --- a/lua/entities/gmod_wire_textreceiver.lua +++ b/lua/entities/gmod_wire_textreceiver.lua @@ -72,6 +72,7 @@ end function ENT:OnRemove() RemoveReceiver( self ) + BaseClass.OnRemove(self) end local string_find = string.find diff --git a/lua/entities/gmod_wire_textscreen.lua b/lua/entities/gmod_wire_textscreen.lua index efeeb440f8..45c4d28016 100644 --- a/lua/entities/gmod_wire_textscreen.lua +++ b/lua/entities/gmod_wire_textscreen.lua @@ -136,6 +136,7 @@ if CLIENT then self.NeedRefresh = true if fullUpdate then return end self.GPU:Finalize() + BaseClass.OnRemove(self) end function ENT:Draw(flags) self:DrawModel(flags) diff --git a/lua/entities/gmod_wire_waypoint.lua b/lua/entities/gmod_wire_waypoint.lua index 7b43b69114..7f6d22c4b2 100644 --- a/lua/entities/gmod_wire_waypoint.lua +++ b/lua/entities/gmod_wire_waypoint.lua @@ -96,6 +96,8 @@ function ENT:OnRemove() ent:SetNextWaypoint(ent:GetNextWaypoint()) end end + + BaseClass.OnRemove(self) end duplicator.RegisterEntityClass("gmod_wire_waypoint", WireLib.MakeWireEnt, "Data", "range") diff --git a/lua/wire/server/wirelib.lua b/lua/wire/server/wirelib.lua index 8d4a268622..fb06981519 100644 --- a/lua/wire/server/wirelib.lua +++ b/lua/wire/server/wirelib.lua @@ -601,41 +601,48 @@ local function ClearPorts(ports, ConnectEnt, DontSendToCL, Removing) end -- Set DontUnList to true, if you want to call WireLib._RemoveWire(eid) manually. +-- Usually, you don't need to call this manually + function WireLib.Remove(ent, DontUnList) - --Clear the inputs - local ent_ports = ent.Inputs - if (ent_ports) then - for _,inport in pairs(ent_ports) do - local Source = inport.Src - if (IsValid(Source)) then - local Outports = Source.Outputs - if (Outports) then - local outport = Outports[inport.SrcId] - if (outport) then + -- Clear the inputs + local inputs = ent.Inputs + + if inputs then + for _, inport in pairs(inputs) do + local source = inport.Src + + if IsValid(source) then + local outputs = source.Outputs + + if outputs then + local outport = outputs[inport.SrcId] + + if outport then ClearPorts(outport.Connected, ent, true, true) end end end end + + ent.Inputs = nil end - --Clear the outputs - local ent_ports = ent.Outputs - if (ent_ports) then - for _,outport in pairs(ent_ports) do + -- Clear the outputs + local outputs = ent.Outputs + + if outputs then + for _, outport in pairs(outputs) do ClearPorts(outport.Connected) end - end - ent.Inputs = nil -- Remove the inputs - ent.Outputs = nil -- Remove the outputs - ent.IsWire = nil -- Remove the wire mark + ent.Outputs = nil + end - if (DontUnList) then return end -- Set DontUnList to true if you want to remove ent from the list manually. - WireLib._RemoveWire(ent:EntIndex()) -- Remove entity from the list, so it doesn't count as a wire able entity anymore. Very important for IsWire checks! + if not DontUnList then + WireLib._RemoveWire(ent:EntIndex()) -- Remove entity from the list, so it doesn't count as a wire able entity anymore. Very important for IsWire checks! + end end - local function Wire_Link(dst, dstid, src, srcid, path) if (not IsValid(dst) or not HasPorts(dst) or not dst.Inputs or not dst.Inputs[dstid]) then Msg("Wire_link: Invalid destination!\n") diff --git a/lua/wire/wireshared.lua b/lua/wire/wireshared.lua index 776d94cdc0..20a6c96e0c 100644 --- a/lua/wire/wireshared.lua +++ b/lua/wire/wireshared.lua @@ -761,7 +761,7 @@ if SERVER then if ent:IsPlayer() then WirePortQueue:cleanup(ent) else - WireLib._RemoveWire(entEntIndex(ent)) + WireLib.Remove(ent) end end)