A unit with the CreatesShroud or RevealsShroud trait must update all shrouds when it changes position. Calculating the tiles it can currently see is an expensive calculation that previously had to be repeated for every shroud that needed to know these tiles. Now, we lazily populate a ref parameter to allow it to be reused for an actor if possible. The biggest improvement comes from the fact that allied players can re-use this calculation when updating their shrouds. Since many games includes a neutral player allied to both sides, most games will see a decent speedup.
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
#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.Linq;
|
|
|
|
namespace OpenRA.Traits
|
|
{
|
|
public class CreatesShroudInfo : ITraitInfo
|
|
{
|
|
public readonly WRange Range = WRange.Zero;
|
|
public object Create(ActorInitializer init) { return new CreatesShroud(this); }
|
|
}
|
|
|
|
public class CreatesShroud : ITick, ISync
|
|
{
|
|
CreatesShroudInfo info;
|
|
[Sync] CPos cachedLocation;
|
|
[Sync] bool cachedDisabled;
|
|
|
|
public CreatesShroud(CreatesShroudInfo info)
|
|
{
|
|
this.info = info;
|
|
}
|
|
|
|
public void Tick(Actor self)
|
|
{
|
|
var disabled = self.TraitsImplementing<IDisable>().Any(d => d.Disabled);
|
|
if (cachedLocation != self.Location || cachedDisabled != disabled)
|
|
{
|
|
cachedLocation = self.Location;
|
|
cachedDisabled = disabled;
|
|
Shroud.UpdateShroudGeneration(self.World.Players.Select(p => p.Shroud), self);
|
|
}
|
|
}
|
|
|
|
public WRange Range { get { return cachedDisabled ? WRange.Zero : info.Range; } }
|
|
}
|
|
} |