Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lua/entities/info_wiremapinterface/entitycontrol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,17 @@ function ENT:AddSingleEntity(wireEnt)

local isInList = IsValid(oldWireEnt) and oldWireEnt == wireEnt

if isInList and wireEnt._WireMapInterfaceEnt_HasPorts then
if isInList and wireEnt._WireMapInterfaceEnt_HasPorts and wireEnt._WMI_AddPorts then
return
end

if not isInList then
if not self.WireEntsUpdated then
self:TriggerHammerOutputSafe("OnWireEntsStartChanging", self)
end
end

if not isInList or not wireEnt._WMI_AddPorts then
self:OverrideEnt(wireEnt)
end

Expand Down
8 changes: 4 additions & 4 deletions lua/entities/info_wiremapinterface/entityoverride.lua
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ function WIREENT:_WMI_AddPorts(wireInputRegister, wireOutputRegister)
return
end

if wireInputRegister and wireInputRegister:hasPorts() then
if wireInputRegister and wireInputRegister.hasPorts and wireInputRegister:hasPorts() then
local split = wireInputRegister.wire

wmidata.inputs = table.Copy(split)
Expand All @@ -670,7 +670,7 @@ function WIREENT:_WMI_AddPorts(wireInputRegister, wireOutputRegister)
self._WireMapInterfaceEnt_HasPorts = true
end

if wireOutputRegister and wireOutputRegister:hasPorts() then
if wireOutputRegister and wireOutputRegister.hasPorts and wireOutputRegister:hasPorts() then
local split = wireOutputRegister.wire

wmidata.outputs = table.Copy(split)
Expand Down Expand Up @@ -763,7 +763,7 @@ function ENT:OverrideEnt(wireEnt)
return
end

if not wireEnt._IsWireMapInterfaceSubEntity then
if not wireEnt._IsWireMapInterfaceSubEntity or not wireEnt._WMI_AddPorts then
WIREENT._WMI_OverrideEnt(wireEnt, self)
end

Expand All @@ -777,7 +777,7 @@ local function OverrideEntFromDupe(wireEnt, wireMapInterfaceEntDupeInfo, interfa
return
end

if wireEnt._IsWireMapInterfaceSubEntity then
if wireEnt._IsWireMapInterfaceSubEntity and wireEnt._WMI_AddPorts then
-- Already initialized
return
end
Expand Down
18 changes: 13 additions & 5 deletions lua/entities/info_wiremapinterface/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,6 @@ function ENT:Initialize()

self.PortsUpdated = true

local recipientFilter = RecipientFilter()
recipientFilter:RemoveAllPlayers()

self.NetworkRecipientFilter = recipientFilter

self.NextNetworkTime = CurTime() + (1 + math.random() * 2) * (self.MIN_THINK_TIME * 4)

self:AddDupeHooks()
Expand All @@ -289,6 +284,19 @@ function ENT:OnReloaded()
self:AttachToSaveStateEntity()
end

function ENT:OnRestore()
-- Auto repair on engine savegame restore.

-- Repair wired entities by re-adding them.
self:AddEntitiesByTable(self:GetWiredEntities())
self.PortsUpdated = true

-- Make sure networking and hooks are triggered
self:AddDupeHooks()
self:RequestNetworkEntities()
self:AttachToSaveStateEntity()
end

function ENT:IsActive()
return self.Active and cvar_allow_interface:GetBool()
end
Expand Down
9 changes: 7 additions & 2 deletions lua/entities/info_wiremapinterface/io.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ end

-- To cleanup and get the in-/outputs information.
local function copyAndSanitizeToPortRegister(register, registerTmp)
register = register or newPortRegister()
if not register or not register.empty then
register = newPortRegister()
end

register:empty()

if not registerTmp then
Expand Down Expand Up @@ -130,7 +133,9 @@ function ENT:UpdatePorts()
local wireEnts = self:GetWiredEntities()

for key, wireEnt in ipairs(wireEnts) do
wireEnt:_WMI_AddPorts(self.WireInputRegister, self.WireOutputRegister)
if wireEnt._WMI_AddPorts then
wireEnt:_WMI_AddPorts(self.WireInputRegister, self.WireOutputRegister)
end
end
end

Expand Down
18 changes: 11 additions & 7 deletions lua/entities/info_wiremapinterface/networking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,24 @@ function ENT:RequestNetworkEntities(ply, networkAtTime)
self.NextNetworkTime = networkAtTime
end

local recipientFilter = self.NetworkRecipientFilter

if not IsValid(ply) then
recipientFilter:AddAllPlayers()
self.NetworkRecipients = player.GetHumans()
return
end

recipientFilter:AddPlayer(ply)
local networkRecipients = self.NetworkRecipients or {}
self.NetworkRecipients = networkRecipients

networkRecipients[#networkRecipients + 1] = ply
end

function ENT:NetworkWireEntities()
-- Network the list and properties of the wire entities.
-- We need we know about them on the client. For cable rendering, tools etc.

local recipientFilter = self.NetworkRecipientFilter
local networkRecipients = self.NetworkRecipients

if recipientFilter:GetCount() <= 0 then
if not networkRecipients or #networkRecipients <= 0 then
return
end

Expand All @@ -89,8 +90,11 @@ function ENT:NetworkWireEntities()
net.WriteUInt(wireEnt:EntIndex(), MAX_EDICT_BITS)
end

local recipientFilter = RecipientFilter()
recipientFilter:AddPlayers(networkRecipients)

net.Send(recipientFilter)

recipientFilter:RemoveAllPlayers()
self.NetworkRecipients = nil
end

Loading