Skip to content

Commit

Permalink
Stop using expensive foreach Pawn + PRL.FindPlayer loops
Browse files Browse the repository at this point in the history
  • Loading branch information
wallabra committed Dec 2, 2023
1 parent 59af017 commit cac6353
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
40 changes: 14 additions & 26 deletions Classes/MushMatch.uc
Original file line number Diff line number Diff line change
Expand Up @@ -463,19 +463,12 @@ function GetAliveTeams(out int humans, out int mush) {
return;
}
for (p = Level.PawnList; p != none; p = p.nextPawn) {
if (p.bIsPlayer && p.PlayerReplicationInfo != none) {
PRL = MushMatchInfo(GameReplicationInfo).FindPRL(p.PlayerReplicationInfo);
if (PRL != None && !PRL.bDead) {
if (PRL.bMush) {
mush += 1;
}
else {
humans += 1;
}
}
for (PRL = MushMatchInfo(GameReplicationInfo).PRL; PRL != None; PRL = MushMatchPRL(PRL.next)) {
if (!PRL.bDead) {
if (PRL.bMush)
mush += 1;
else
humans += 1;
}
}
}
Expand Down Expand Up @@ -961,12 +954,11 @@ function int MushCount()
local Pawn p;
local MushMatchPRL PRL;

for (p = Level.PawnList; p != none; p = p.NextPawn) {
if (!p.bIsPlayer) continue;

PRL = FindPawnPRL(p);
for (PRL = MushMatchInfo(GameReplicationInfo).PRL; PRL != None; PRL = MushMatchPRL(PRL.next)) {
p = Pawn(PRL.Owner.Owner);

if (PRL == None) continue;
if (!p.bIsPlayer) continue;
if (PRL.bDead) continue;
if (!PRL.bMush) continue;

i++;
Expand All @@ -985,14 +977,10 @@ function Selected()
sp.MushSelected();
}

for ( p = Level.PawnList; p != none; p = p.NextPawn ) {
if ( p.bIsPlayer && p.PlayerReplicationInfo != none )
{
p.Health = Max(p.Health, p.Class.Default.Health);

PRL = MushMatchInfo(GameReplicationInfo).FindPRL(p.PlayerReplicationInfo);
PRL.SetInitialTeam();
}
for (PRL = MushMatchInfo(GameReplicationInfo).PRL; PRL != None; PRL = MushMatchPRL(PRL.next)) {
p = Pawn(PRL.Owner.Owner);
p.Health = Max(p.Health, p.Class.Default.Health);
PRL.SetInitialTeam();
}

BroadcastLocalizedMessage(MushSelectedMessageType);
Expand Down
2 changes: 1 addition & 1 deletion buildconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export name="Mush Match"
export package=MushMatch
export version=1.3.4
export build=20231207
export build=20231211
export debug=1
export makeint=1
export incl_readme=1
Expand Down

0 comments on commit cac6353

Please sign in to comment.