Skip to content

Commit a645ca4

Browse files
authored
Fixed WMI being broken after engine savegame restore. (#3647)
* Fixed WMI being broken after engine savegame restore. Turns out engine savegames store the entire entity table, with no way to filter them before hand. This leads to partly applied entity states. Like that entities having certain values but not others such as functions. It results in a broken override state. To fix this I changed the system to also check for certain functions to exist before (re-)applying the custom logic. * Made spelling more "useful" again.
1 parent 97bfe3a commit a645ca4

6 files changed

Lines changed: 41 additions & 22 deletions

File tree

lua/entities/info_wiremapinterface/entitycontrol.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,17 @@ function ENT:AddSingleEntity(wireEnt)
8888

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

91-
if isInList and wireEnt._WireMapInterfaceEnt_HasPorts then
91+
if isInList and wireEnt._WireMapInterfaceEnt_HasPorts and wireEnt._WMI_AddPorts then
9292
return
9393
end
9494

9595
if not isInList then
9696
if not self.WireEntsUpdated then
9797
self:TriggerHammerOutputSafe("OnWireEntsStartChanging", self)
9898
end
99+
end
99100

101+
if not isInList or not wireEnt._WMI_AddPorts then
100102
self:OverrideEnt(wireEnt)
101103
end
102104

lua/entities/info_wiremapinterface/entityoverride.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ function WIREENT:_WMI_AddPorts(wireInputRegister, wireOutputRegister)
654654
return
655655
end
656656

657-
if wireInputRegister and wireInputRegister:hasPorts() then
657+
if wireInputRegister and wireInputRegister.hasPorts and wireInputRegister:hasPorts() then
658658
local split = wireInputRegister.wire
659659

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

673-
if wireOutputRegister and wireOutputRegister:hasPorts() then
673+
if wireOutputRegister and wireOutputRegister.hasPorts and wireOutputRegister:hasPorts() then
674674
local split = wireOutputRegister.wire
675675

676676
wmidata.outputs = table.Copy(split)
@@ -763,7 +763,7 @@ function ENT:OverrideEnt(wireEnt)
763763
return
764764
end
765765

766-
if not wireEnt._IsWireMapInterfaceSubEntity then
766+
if not wireEnt._IsWireMapInterfaceSubEntity or not wireEnt._WMI_AddPorts then
767767
WIREENT._WMI_OverrideEnt(wireEnt, self)
768768
end
769769

@@ -777,7 +777,7 @@ local function OverrideEntFromDupe(wireEnt, wireMapInterfaceEntDupeInfo, interfa
777777
return
778778
end
779779

780-
if wireEnt._IsWireMapInterfaceSubEntity then
780+
if wireEnt._IsWireMapInterfaceSubEntity and wireEnt._WMI_AddPorts then
781781
-- Already initialized
782782
return
783783
end

lua/entities/info_wiremapinterface/init.lua

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,6 @@ function ENT:Initialize()
272272

273273
self.PortsUpdated = true
274274

275-
local recipientFilter = RecipientFilter()
276-
recipientFilter:RemoveAllPlayers()
277-
278-
self.NetworkRecipientFilter = recipientFilter
279-
280275
self.NextNetworkTime = CurTime() + (1 + math.random() * 2) * (self.MIN_THINK_TIME * 4)
281276

282277
self:AddDupeHooks()
@@ -289,6 +284,19 @@ function ENT:OnReloaded()
289284
self:AttachToSaveStateEntity()
290285
end
291286

287+
function ENT:OnRestore()
288+
-- Auto repair on engine savegame restore.
289+
290+
-- Repair wired entities by re-adding them.
291+
self:AddEntitiesByTable(self:GetWiredEntities())
292+
self.PortsUpdated = true
293+
294+
-- Make sure networking and hooks are triggered
295+
self:AddDupeHooks()
296+
self:RequestNetworkEntities()
297+
self:AttachToSaveStateEntity()
298+
end
299+
292300
function ENT:IsActive()
293301
return self.Active and cvar_allow_interface:GetBool()
294302
end

lua/entities/info_wiremapinterface/io.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ end
100100

101101
-- To cleanup and get the in-/outputs information.
102102
local function copyAndSanitizeToPortRegister(register, registerTmp)
103-
register = register or newPortRegister()
103+
if not register or not register.empty then
104+
register = newPortRegister()
105+
end
106+
104107
register:empty()
105108

106109
if not registerTmp then
@@ -130,7 +133,9 @@ function ENT:UpdatePorts()
130133
local wireEnts = self:GetWiredEntities()
131134

132135
for key, wireEnt in ipairs(wireEnts) do
133-
wireEnt:_WMI_AddPorts(self.WireInputRegister, self.WireOutputRegister)
136+
if wireEnt._WMI_AddPorts then
137+
wireEnt:_WMI_AddPorts(self.WireInputRegister, self.WireOutputRegister)
138+
end
134139
end
135140
end
136141

@@ -174,7 +179,7 @@ function ENT:PrepairOutputGlobals(inputData, wireValue, wireEnt, wireDevice, own
174179
return
175180
end
176181

177-
-- This can be usefull if a lua_run entity is triggered
182+
-- This can be useful if a lua_run entity is triggered
178183
-- Because entity.Fire and entity.AcceptInput are not run synchronously in the same frame, we use them in a custom entity.AcceptInput detour.
179184
-- So we store them for later use in a custom entity.AcceptInput detour.
180185

@@ -202,7 +207,7 @@ function ENT:PrepairOutputGlobals(inputData, wireValue, wireEnt, wireDevice, own
202207
end
203208

204209
function ENT:SetupOutputGlobals(globals)
205-
-- This can be usefull if a lua_run entity is triggered
210+
-- This can be useful if a lua_run entity is triggered
206211

207212
local G = _G
208213

lua/entities/info_wiremapinterface/networking.lua

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,24 @@ function ENT:RequestNetworkEntities(ply, networkAtTime)
5555
self.NextNetworkTime = networkAtTime
5656
end
5757

58-
local recipientFilter = self.NetworkRecipientFilter
59-
6058
if not IsValid(ply) then
61-
recipientFilter:AddAllPlayers()
59+
self.NetworkRecipients = player.GetHumans()
6260
return
6361
end
6462

65-
recipientFilter:AddPlayer(ply)
63+
local networkRecipients = self.NetworkRecipients or {}
64+
self.NetworkRecipients = networkRecipients
65+
66+
networkRecipients[#networkRecipients + 1] = ply
6667
end
6768

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

72-
local recipientFilter = self.NetworkRecipientFilter
73+
local networkRecipients = self.NetworkRecipients
7374

74-
if recipientFilter:GetCount() <= 0 then
75+
if not networkRecipients or #networkRecipients <= 0 then
7576
return
7677
end
7778

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

93+
local recipientFilter = RecipientFilter()
94+
recipientFilter:AddPlayers(networkRecipients)
95+
9296
net.Send(recipientFilter)
9397

94-
recipientFilter:RemoveAllPlayers()
98+
self.NetworkRecipients = nil
9599
end
96100

wiremod.fgd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
: "Creates an interface between the map and Wiremod."
33
[
44
wire_entity_name(target_destination) : "Wire Entity" : "" : "The name of an entity or of the entities that will get wire ports."
5-
min_trigger_time(float) : "Minimum Trigger Time" : "0.01" : "Set the minimum time in seconds between two Wiremod input triggers. It's usefull to prevent lags."
5+
min_trigger_time(float) : "Minimum Trigger Time" : "0.01" : "Set the minimum time in seconds between two Wiremod input triggers. It's useful to prevent lags."
66

77
// Wire Inputs
88
input1_name(string) : "Wire Input 1 Name" : "" : "Sets the name of Wire Input 1."

0 commit comments

Comments
 (0)