Skip to content

Commit 1a24c17

Browse files
committed
Multithreaded a bunch more scripts
1 parent d3206d8 commit 1a24c17

File tree

12 files changed

+105
-51
lines changed

12 files changed

+105
-51
lines changed

Data/Base.rte/Devices/Shared/Scripts/MuzzleSmoke.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
function Create(self)
2-
32
if self.Magazine then
43
local particleCount = self.Magazine.NextRound.ParticleCount;
54
local particleMass = self.Magazine.NextRound.NextParticle.Mass;
@@ -30,16 +29,13 @@ function Create(self)
3029
self.fireSmokeEffect.GravMult = 1;
3130

3231
self.particleUtility = require("Scripts/Utility/ParticleUtility");
33-
3432
end
3533

3634
function OnFire(self)
37-
3835
local flip = self.HFlipped and math.pi or 0;
3936
local angle = self.RotAngle + flip;
4037
self.fireSmokeEffect.Position = self.MuzzlePos;
4138
self.fireSmokeEffect.RadAngle = angle;
4239

4340
self.particleUtility:CreateDirectionalSmokeEffect(self.fireSmokeEffect);
44-
4541
end

Data/Base.rte/Devices/Shared/Scripts/RevolverCylinderReload.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,27 @@ function Create(self)
44
self.shellMOSRotating = self:StringValueExists("CylinderShellMOSRotating") and self:GetStringValue("CylinderShellMOSRotating") or nil;
55
end
66

7-
function Update(self)
7+
function ThreadedUpdate(self)
88
if self.Magazine then
99
self.shellsToEject = self.Magazine.Capacity - self.Magazine.RoundCount;
1010
elseif self.shellsToEject > 0 then
11+
self.ejectingShells = {};
1112
for i = 1, self.shellsToEject do
1213
local shell = self.shellMOSRotating and CreateMOSRotating(self.shellMOSRotating) or CreateMOSParticle(self.shellMOSParticle);
1314
shell.Pos = self.Pos;
1415
shell.Vel = self.Vel + Vector(RangeRand(-3, 0) * self.FlipFactor, 0):RadRotate(self.RotAngle + RangeRand(-0.3, 0.3));
1516
shell.AngularVel = RangeRand(-1, 1);
16-
MovableMan:AddParticle(shell);
17+
table.insert(self.ejectingShells, shell);
1718
end
1819

1920
self.shellsToEject = 0;
21+
self:RequestSyncedUpdate();
22+
end
23+
end
24+
25+
function SyncedUpdate(self)
26+
if self.ejectingShells then
27+
MovableMan:AddParticle(shell);
28+
self.ejectingShells = nil;
2029
end
2130
end

Data/Browncoats.rte/Devices/Weapons/Extinction/Extinction.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ function Create(self)
2222

2323
-- for some reason if this is added to sim while facing leftwards, StanceOffset will actually be flipped.
2424
-- but not sharpstanceoffset...............
25-
26-
2725
self.origStanceOffset = Vector(self.StanceOffset.X*self.FlipFactor, self.StanceOffset.Y);
2826
self.origSharpStanceOffset = Vector(self.SharpStanceOffset.X, self.SharpStanceOffset.Y);
2927

Data/Dummy.rte/Devices/Weapons/Destroyer/DestroyerCannon.lua

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Create(self)
1515
self.activeSound = CreateSoundContainer("Destroyer Emission Sound", "Dummy.rte");
1616
end
1717

18-
function Update(self)
18+
function ThreadedUpdate(self)
1919
if self.Magazine then
2020
if self.inventorySwapTimer:IsPastSimTimeLimit() then
2121
self.activeSound:Stop();
@@ -28,18 +28,18 @@ function Update(self)
2828
self.animTimer:Reset();
2929
self.Frame = self.Frame < (self.FrameCount - 1) and self.Frame + 1 or 0;
3030
if self.Frame == 1 then
31-
local effect = CreateMOPixel("Destroyer Muzzle Glow");
32-
effect.Pos = self.MuzzlePos;
33-
effect.Vel = self.Vel * 0.5;
34-
MovableMan:AddParticle(effect);
35-
36-
local damagePar = CreateMOPixel("Dummy.rte/Destroyer Emission Particle 2");
37-
damagePar.Pos = self.MuzzlePos;
38-
damagePar.Vel = self.Vel * 0.5 + Vector(math.random(5) * (1 + self.charge), 0):RadRotate(6.28 * math.random());
39-
damagePar.Team = self.Team;
40-
damagePar.IgnoresTeamHits = true;
41-
damagePar.Lifetime = 100 * (1 + self.charge);
42-
MovableMan:AddParticle(damagePar);
31+
self.effect = CreateMOPixel("Destroyer Muzzle Glow");
32+
self.effect.Pos = self.MuzzlePos;
33+
self.effect.Vel = self.Vel * 0.5;
34+
35+
self.damagePar = CreateMOPixel("Dummy.rte/Destroyer Emission Particle 2");
36+
self.damagePar.Pos = self.MuzzlePos;
37+
self.damagePar.Vel = self.Vel * 0.5 + Vector(math.random(5) * (1 + self.charge), 0):RadRotate(6.28 * math.random());
38+
self.damagePar.Team = self.Team;
39+
self.damagePar.IgnoresTeamHits = true;
40+
self.damagePar.Lifetime = 100 * (1 + self.charge);
41+
42+
self:RequestSyncedUpdate();
4343
end
4444
end
4545

@@ -83,13 +83,14 @@ function Update(self)
8383
else
8484
self.Frame = 0;
8585
end
86+
8687
if self.FiredFrame then
87-
local par = CreateAEmitter("Destroyer Cannon Shot");
88-
par.Team = self.Team;
89-
par.IgnoresTeamHits = true;
90-
par.Pos = self.MuzzlePos;
91-
par.Vel = Vector((self.minFireVel + (self.maxFireVel - self.minFireVel) * self.charge) * self.FlipFactor, 0):RadRotate(self.RotAngle);
92-
MovableMan:AddParticle(par);
88+
self.par = CreateAEmitter("Destroyer Cannon Shot");
89+
self.par.Team = self.Team;
90+
self.par.IgnoresTeamHits = true;
91+
self.par.Pos = self.MuzzlePos;
92+
self.par.Vel = Vector((self.minFireVel + (self.maxFireVel - self.minFireVel) * self.charge) * self.FlipFactor, 0):RadRotate(self.RotAngle);
93+
self:RequestSyncedUpdate();
9394

9495
self.charge = 0;
9596
self.activeSound:Stop();
@@ -98,6 +99,23 @@ function Update(self)
9899
end
99100
end
100101

102+
function SyncedUpdate(self)
103+
if self.effect then
104+
MovableMan:AddParticle(self.effect);
105+
self.effect = nil;
106+
end
107+
108+
if self.damagePar then
109+
MovableMan:AddParticle(self.par);
110+
self.damagePar = nil;
111+
end
112+
113+
if self.par then
114+
MovableMan:AddParticle(self.par);
115+
self.par = nil;
116+
end
117+
end
118+
101119
function Destroy(self)
102120
self.activeSound:Stop();
103121
end

Data/Imperatus.rte/Devices/Weapons/Marauder/Marauder.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function Create(self)
33
self.fireTimer = Timer();
44
end
55

6-
function Update(self)
6+
function ThreadedUpdate(self)
77
if self.FiredFrame or self:IsReloading() then
88
self.fireTimer:Reset();
99
end

Data/Ronin.rte/Devices/Weapons/357Magnum/357Magnum.lua

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function Create(self)
77
self.drawGun = false;
88
end
99

10-
function Update(self)
10+
function ThreadedUpdate(self)
1111
--Read RateOfFire on Update() to take Global Scripts to account
1212
if self.rof == nil then
1313
self.rof = self.RateOfFire;
@@ -17,12 +17,9 @@ function Update(self)
1717
self:SetOneHanded(false);
1818
self:SetDualWieldable(false);
1919
if MovableMan:IsOfActor(self.ID) then
20-
actor = ToActor(MovableMan:GetMOFromID(self.RootID));
20+
local actor = ToActor(MovableMan:GetMOFromID(self.RootID));
2121

22-
ToActor(actor):GetController():SetState(Controller.AIM_SHARP, false);
23-
ToActor(actor):GetController():SetState(Controller.BODY_PRONE, false);
2422
if ToActor(actor):GetController():IsState(Controller.WEAPON_FIRE) then
25-
2623
if self:GetNumberValue("CowboyMode") < 3 then
2724
self:Deactivate();
2825
self.triggerPulled = true;
@@ -94,4 +91,14 @@ function Update(self)
9491
self.StanceOffset = Vector(12, 0);
9592
self.drawGunAngle = 0;
9693
end
94+
end
95+
96+
function SyncedUpdate(self)
97+
if self:NumberValueExists("CowboyMode") then
98+
if MovableMan:IsOfActor(self.ID) then
99+
local actor = ToActor(MovableMan:GetMOFromID(self.RootID));
100+
ToActor(actor):GetController():SetState(Controller.AIM_SHARP, false);
101+
ToActor(actor):GetController():SetState(Controller.BODY_PRONE, false);
102+
end
103+
end
97104
end

Data/Ronin.rte/Devices/Weapons/K98K/K98K.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function Create(self)
55
self.boltPullSound = CreateSoundContainer("Ronin Kar98 Bolt Pull Sound", "Ronin.rte");
66
end
77

8-
function Update(self)
8+
function ThreadedUpdate(self)
99
local parent;
1010
local actor = self:GetRootParent();
1111
if actor and IsAHuman(actor) then
@@ -30,8 +30,7 @@ function Update(self)
3030
self.shell.Pos = self.Pos;
3131
self.shell.Vel = self.Vel + Vector(-6 * self.FlipFactor, -4):RadRotate(self.RotAngle);
3232
self.shell.Team = self.Team;
33-
MovableMan:AddParticle(self.shell);
34-
self.shell = nil;
33+
self.RequestSyncedUpdate();
3534
end
3635

3736
--Animate the gun to signify the bolt being pulled
@@ -55,4 +54,11 @@ function Update(self)
5554
else
5655
self.pullTimer:Reset();
5756
end
57+
end
58+
59+
function SyncedUpdate(self)
60+
if self.shell then
61+
MovableMan:AddParticle(self.shell);
62+
self.shell = nil;
63+
end;
5864
end

Data/Ronin.rte/Devices/Weapons/Model590/Model590.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Create(self)
66
self.cockSound = CreateSoundContainer("Ronin Model 590 Cock Sound", "Ronin.rte");
77
end
88

9-
function Update(self)
9+
function ThreadedUpdate(self)
1010
local actor = self:GetRootParent();
1111
if not (actor and IsAHuman(actor)) then
1212
self.pullTimer:Reset();
@@ -29,8 +29,7 @@ function Update(self)
2929
self.shell.Pos = self.Pos;
3030
self.shell.Vel = self.Vel + Vector(-6 * self.FlipFactor, -4):RadRotate(self.RotAngle);
3131
self.shell.Team = self.Team;
32-
MovableMan:AddParticle(self.shell);
33-
self.shell = nil;
32+
self:RequestSyncedUpdate();
3433
end
3534
self.Frame = 1;
3635
self.SupportOffset = Vector(-2, 4);
@@ -50,4 +49,11 @@ function Update(self)
5049
else
5150
self.pullTimer:Reset();
5251
end
52+
end
53+
54+
function SyncedUpdate(self)
55+
if self.shell then
56+
MovableMan:AddParticle(self.shell);
57+
self.shell = nil;
58+
end
5359
end

Data/Ronin.rte/Devices/Weapons/SPAS12/SPAS12.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Create(self)
66
self.cockSound = CreateSoundContainer("Ronin SPAS 12 Cock Sound", "Ronin.rte");
77
end
88

9-
function Update(self)
9+
function ThreadedUpdate(self)
1010
local actor = self:GetRootParent();
1111
if not (actor and IsAHuman(actor)) then
1212
self.pullTimer:Reset();

Data/Techion.rte/Devices/Weapons/GigaPulsar/GigaPulsar.lua

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,21 @@ function Update(self)
3232
self.lastMag.Sharpness = 1;
3333
self.lastMag.Vel = self.lastMag.Vel + Vector(-10 * self.FlipFactor, 0):RadRotate(self.RotAngle);
3434

35-
local effect = self.ejectEffect:Clone();
36-
effect.Pos = self.lastMag.Pos;
37-
effect.RotAngle = self.RotAngle;
38-
effect.HFlipped = self.HFlipped;
39-
MovableMan:AddParticle(effect);
35+
self.effect = self.ejectEffect:Clone();
36+
self.effect.Pos = self.lastMag.Pos;
37+
self.effect.RotAngle = self.RotAngle;
38+
self.effect.HFlipped = self.HFlipped;
39+
self:RequestSyncedUpdate();
4040
end
4141
end
4242

4343
self.dingSound = true;
4444
end
45+
end
46+
47+
function SyncedUpdate(self)
48+
if self.effect then
49+
MovableMan:AddParticle(self.effect);
50+
self.effect = nil;
51+
end
4552
end

0 commit comments

Comments
 (0)