- Made Array.IndexOf available via extension method. - Made ToHashSet extension method. - Change collections queried often via Contains into sets. - Avoid Count() extension if Count or Length property exist. - Made Count() > 0 checks and variations calls to Any() instead. - Don't call ToList/ToArray if there is no benefit to materializing the sequence. - If the sequence does benefit from materialization, follow this general pattern: - Collection queried often via Contains use ToHashSet to speed up lookups. - Short lived variables use ToList. This is because ToArray requires an extra copy to output the final size. - Collections persisted into fields or for a long time use ToArray to minimize memory overhead.
55 lines
1.3 KiB
C#
Executable File
55 lines
1.3 KiB
C#
Executable File
#region Copyright & License Information
|
|
/*
|
|
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
|
* This file is part of OpenRA, which is free software. It is made
|
|
* available to you under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation. For more information,
|
|
* see COPYING.
|
|
*/
|
|
#endregion
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using OpenRA.Graphics;
|
|
|
|
namespace OpenRA.Effects
|
|
{
|
|
public class FlashTarget : IEffect
|
|
{
|
|
Actor target;
|
|
Player player;
|
|
int remainingTicks;
|
|
|
|
public FlashTarget(Actor target, Player asPlayer = null, int ticks = 4)
|
|
{
|
|
this.target = target;
|
|
player = asPlayer;
|
|
remainingTicks = ticks;
|
|
target.World.RemoveAll(effect =>
|
|
{
|
|
var flashTarget = effect as FlashTarget;
|
|
return flashTarget != null && flashTarget.target == target;
|
|
});
|
|
}
|
|
|
|
public void Tick(World world)
|
|
{
|
|
if (--remainingTicks == 0 || !target.IsInWorld)
|
|
world.AddFrameEndTask(w => w.Remove(this));
|
|
}
|
|
|
|
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
|
{
|
|
if (target.IsInWorld && remainingTicks % 2 == 0)
|
|
{
|
|
var palette = wr.Palette(player == null ? "highlight" : "highlight" + player.InternalName);
|
|
return target.Render(wr)
|
|
.Where(r => !r.IsDecoration)
|
|
.Select(r => r.WithPalette(palette));
|
|
}
|
|
|
|
return SpriteRenderable.None;
|
|
}
|
|
}
|
|
}
|