In RemoveCellsFromPlayerShroud, don't call RemoveSource unless required.

Since AddCellsToPlayerShroud only adds for players with a valid relationship, we can skip a dictionary lookup in RemoveSource by only attempting the remove if the relationship check passes as well.
This commit is contained in:
RoosterDragon
2024-10-02 19:32:03 +01:00
committed by Gustas
parent d010157611
commit 86b9227577
4 changed files with 36 additions and 10 deletions

View File

@@ -44,7 +44,13 @@ namespace OpenRA.Mods.Common.Traits
p.Shroud.AddSource(this, type, uv);
}
protected void RemoveCellsFromPlayerShroud(Player p) { p.Shroud.RemoveSource(this); }
protected void RemoveCellsFromPlayerShroud(Actor self, Player p)
{
if (!Info.ValidRelationships.HasRelationship(self.Owner.RelationshipWith(p)))
return;
p.Shroud.RemoveSource(this);
}
protected PPos[] ProjectedCells(Actor self)
{
@@ -58,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits
var cells = ProjectedCells(self);
foreach (var player in self.World.Players)
{
RemoveCellsFromPlayerShroud(player);
RemoveCellsFromPlayerShroud(self, player);
AddCellsToPlayerShroud(self, player, cells);
}
}
@@ -67,13 +73,13 @@ namespace OpenRA.Mods.Common.Traits
void INotifyActorDisposing.Disposing(Actor self)
{
foreach (var player in self.World.Players)
RemoveCellsFromPlayerShroud(player);
RemoveCellsFromPlayerShroud(self, player);
}
void INotifyKilled.Killed(Actor self, AttackInfo e)
{
foreach (var player in self.World.Players)
RemoveCellsFromPlayerShroud(player);
RemoveCellsFromPlayerShroud(self, player);
}
protected override void TraitEnabled(Actor self)
@@ -86,7 +92,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void TraitDisabled(Actor self)
{
foreach (var player in self.World.Players)
RemoveCellsFromPlayerShroud(player);
RemoveCellsFromPlayerShroud(self, player);
}
}
}