Skip to content

Commit 830fbe1

Browse files
committed
Made GenericCapturable multithreaded
1 parent 26a7ad4 commit 830fbe1

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

Data/Base.rte/Scenes/Objects/Bunkers/BunkerSystems/GenericCapturable/GenericCapturable.lua

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
function OnGlobalMessage(self, message, object)
2-
3-
--print("capturablegotglobalmessage")
4-
52
if message == self.deactivationMessage or message == "DEACTIVATEALLCAPTURABLES" then
63
self.Deactivated = true;
74
self.dominantTeam = self.Team;
@@ -10,11 +7,9 @@ function OnGlobalMessage(self, message, object)
107
elseif message == self.activationMessage or message == "ACTIVATEALLCAPTURABLES" then
118
self.Deactivated = false;
129
end
13-
1410
end
1511

1612
function OnMessage(self, message, object)
17-
1813
if message == self.deactivationMessage or message == "DEACTIVATEALLCAPTURABLES" then
1914
self.Deactivated = true;
2015
self.dominantTeam = self.Team;
@@ -23,11 +18,9 @@ function OnMessage(self, message, object)
2318
elseif message == self.activationMessage or message == "ACTIVATEALLCAPTURABLES" then
2419
self.Deactivated = false;
2520
end
26-
2721
end
2822

2923
function Create(self)
30-
3124
self.Team = self:NumberValueExists("StartTeam") and self:GetNumberValue("StartTeam") or 0;
3225

3326
self.useGlobalMessaging = self:GetNumberValue("SendCaptureMessageGlobally") == 1 and true or false;
@@ -76,25 +69,22 @@ function Create(self)
7669

7770
self.teamHasBrainTable = {};
7871

72+
self.shouldSendCaptureMessage = false;
7973
end
8074

81-
function Update(self)
82-
75+
function ThreadedUpdate(self)
8376
if self.actorCheckTimer:IsPastSimMS(self.actorCheckDelay) then
84-
8577
self.actorCheckTimer:Reset();
86-
78+
8779
self.actorTeamNumTable = { [-1] = 0,
8880
[0] = 0,
8981
[1] = 0,
9082
[2] = 0,
9183
[3] = 0};
9284

9385
self.teamHasBrainTable = {};
94-
95-
86+
9687
if self.captureArea then
97-
9888
for box in self.captureArea.Boxes do
9989
for actor in MovableMan:GetMOsInBox(box, -1, true) do
10090
if IsActor(actor) then
@@ -105,9 +95,7 @@ function Update(self)
10595
end
10696
end
10797
end
108-
10998
else -- fallback
110-
11199
local actorList = MovableMan:GetMOsInRadius(self.Pos, self.Diameter * 2, -1, true);
112100
for actor in actorList do
113101
if IsActor(actor) then
@@ -117,7 +105,6 @@ function Update(self)
117105
self.teamHasBrainTable[actor.Team] = true;
118106
end
119107
end
120-
121108
end
122109

123110
local largestNum = 0;
@@ -148,7 +135,6 @@ function Update(self)
148135
end
149136

150137
local brainOnlyRestrictionCheck = self.dominantTeam == self.Team or (self.dominantTeam ~= self.Team and not (self.onlyBrainCanCapture and not self.teamHasBrainTable[self.dominantTeam]));
151-
152138
if self.dominantTeam ~= self.Team and not (self.onlyBrainCanCapture and not self.teamHasBrainTable[self.dominantTeam]) then
153139
if not self.FXcapturing then
154140
self.FXstartCapture = not self.Deactivated and true or false;
@@ -162,9 +148,7 @@ function Update(self)
162148
end
163149

164150
if not self.Contested and not self.Deactivated and brainOnlyRestrictionCheck then
165-
166151
if self.dominantTeam ~= self.capturingTeam then
167-
168152
if self.captureProgress > 0 then
169153
self.captureProgress = math.max(0, self.captureProgress - TimerMan.DeltaTimeSecs * self.captureRate);
170154
else
@@ -174,9 +158,7 @@ function Update(self)
174158
self.Team = -1;
175159
end
176160
end
177-
178161
else
179-
180162
if self.captureProgress < 1 then
181163
self.captureProgress = math.min(1, self.captureProgress + TimerMan.DeltaTimeSecs * self.captureRate);
182164
if self.Team == -1 and self.dominantTeam == self.Team then
@@ -187,25 +169,19 @@ function Update(self)
187169
if self.dominantTeam ~= self.Team then
188170
self.Team = self.dominantTeam;
189171
self.FXcaptureSuccess = true;
190-
print("shouldhavesentmessage: " .. self.messageOnCapture)
191-
if self.useGlobalMessaging then
192-
MovableMan:SendGlobalMessage(self.messageOnCapture, self.dominantTeam);
193-
else
194-
self.Activity:SendMessage(self.messageOnCapture, self.dominantTeam);
195-
end
172+
self:RequestSyncedUpdate();
173+
self.shouldSendCaptureMessage = true;
196174
if self.deactivateOnCapture then
197175
self.Deactivated = true;
198176
end
199177
end
200178
end
201-
202179
end
203180

204181
if self.instantReset and self.dominantTeam == self.Team then
205182
self.captureProgress = self.Team ~= -1 and 1 or 0;
206183
self.capturingTeam = self.Team;
207184
end
208-
209185
end
210186

211187
PrimitiveMan:DrawTextPrimitive(self.Pos + Vector(0, -20), tostring("Team: " .. self.Team), true, 1);
@@ -219,10 +195,20 @@ function Update(self)
219195
end
220196
end
221197

222-
function OnSave(self)
198+
function SyncedUpdate(self)
199+
if self.shouldSendCaptureMessage then
200+
print("shouldhavesentmessage: " .. self.messageOnCapture)
201+
if self.useGlobalMessaging then
202+
MovableMan:SendGlobalMessage(self.messageOnCapture, self.dominantTeam);
203+
else
204+
self.Activity:SendMessage(self.messageOnCapture, self.dominantTeam);
205+
end
206+
self.shouldSendCaptureMessage = false;
207+
end
208+
end
223209

210+
function OnSave(self)
224211
self:SetNumberValue("captureProgress", self.captureProgress);
225212
self:SetNumberValue("dominantTeam", self.dominantTeam);
226213
self:SetNumberValue("capturingTeam", self.capturingTeam);
227-
228214
end

0 commit comments

Comments
 (0)