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:
@@ -44,11 +44,19 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
|
|
||||||
void AddCellsToPlayerShroud(Player p, PPos[] uv)
|
void AddCellsToPlayerShroud(Player p, PPos[] uv)
|
||||||
{
|
{
|
||||||
if (validStances.HasRelationship(player.RelationshipWith(p)))
|
if (!validStances.HasRelationship(player.RelationshipWith(p)))
|
||||||
p.Shroud.AddSource(this, sourceType, uv);
|
return;
|
||||||
|
|
||||||
|
p.Shroud.AddSource(this, sourceType, uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveCellsFromPlayerShroud(Player p) { p.Shroud.RemoveSource(this); }
|
void RemoveCellsFromPlayerShroud(Player p)
|
||||||
|
{
|
||||||
|
if (!validStances.HasRelationship(player.RelationshipWith(p)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
p.Shroud.RemoveSource(this);
|
||||||
|
}
|
||||||
|
|
||||||
PPos[] ProjectedCells(World world)
|
PPos[] ProjectedCells(World world)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,7 +49,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
p.Shroud.AddSource(this, Shroud.SourceType.Shroud, uv);
|
p.Shroud.AddSource(this, Shroud.SourceType.Shroud, uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void RemoveCellsFromPlayerShroud(Actor self, Player p) { p.Shroud.RemoveSource(this); }
|
protected override void RemoveCellsFromPlayerShroud(Actor self, Player p)
|
||||||
|
{
|
||||||
|
if (!info.ValidRelationships.HasRelationship(self.Owner.RelationshipWith(p)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
p.Shroud.RemoveSource(this);
|
||||||
|
}
|
||||||
|
|
||||||
public override WDist Range
|
public override WDist Range
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,7 +44,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
p.Shroud.AddSource(this, type, uv);
|
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)
|
protected PPos[] ProjectedCells(Actor self)
|
||||||
{
|
{
|
||||||
@@ -58,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var cells = ProjectedCells(self);
|
var cells = ProjectedCells(self);
|
||||||
foreach (var player in self.World.Players)
|
foreach (var player in self.World.Players)
|
||||||
{
|
{
|
||||||
RemoveCellsFromPlayerShroud(player);
|
RemoveCellsFromPlayerShroud(self, player);
|
||||||
AddCellsToPlayerShroud(self, player, cells);
|
AddCellsToPlayerShroud(self, player, cells);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,13 +73,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
void INotifyActorDisposing.Disposing(Actor self)
|
void INotifyActorDisposing.Disposing(Actor self)
|
||||||
{
|
{
|
||||||
foreach (var player in self.World.Players)
|
foreach (var player in self.World.Players)
|
||||||
RemoveCellsFromPlayerShroud(player);
|
RemoveCellsFromPlayerShroud(self, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyKilled.Killed(Actor self, AttackInfo e)
|
void INotifyKilled.Killed(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
foreach (var player in self.World.Players)
|
foreach (var player in self.World.Players)
|
||||||
RemoveCellsFromPlayerShroud(player);
|
RemoveCellsFromPlayerShroud(self, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void TraitEnabled(Actor self)
|
protected override void TraitEnabled(Actor self)
|
||||||
@@ -86,7 +92,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
protected override void TraitDisabled(Actor self)
|
protected override void TraitDisabled(Actor self)
|
||||||
{
|
{
|
||||||
foreach (var player in self.World.Players)
|
foreach (var player in self.World.Players)
|
||||||
RemoveCellsFromPlayerShroud(player);
|
RemoveCellsFromPlayerShroud(self, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
p.Shroud.AddSource(this, type, uv);
|
p.Shroud.AddSource(this, type, uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void RemoveCellsFromPlayerShroud(Actor self, Player p) { p.Shroud.RemoveSource(this); }
|
protected override void RemoveCellsFromPlayerShroud(Actor self, Player p)
|
||||||
|
{
|
||||||
|
if (!info.ValidRelationships.HasRelationship(self.Owner.RelationshipWith(p)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
p.Shroud.RemoveSource(this);
|
||||||
|
}
|
||||||
|
|
||||||
public override WDist Range
|
public override WDist Range
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user