Replace IRemoveFrozenActor with FrozenActorLayer.Remove.
The IRemoveFrozenActor interface is replaced with a Remove method on FrozenActorLayer. IRemoveFrozenActor is a performance problem for FrozenActorLayer.Tick as it incurs a large cache miss penalty in order to load and enumerate the array of these interfaces for every frozen actor. Instead, we invert control and allow traits to remove frozen actors directly which eliminates the performance penalty.
This commit is contained in:
@@ -90,7 +90,6 @@
|
||||
<Compile Include="Traits\Chronoshiftable.cs" />
|
||||
<Compile Include="Traits\Cloneable.cs" />
|
||||
<Compile Include="Traits\Disguise.cs" />
|
||||
<Compile Include="Traits\GpsRemoveFrozenActor.cs" />
|
||||
<Compile Include="Traits\HarvesterHuskModifier.cs" />
|
||||
<Compile Include="Traits\Infiltration\InfiltrateForCash.cs" />
|
||||
<Compile Include="Traits\Infiltration\InfiltrateForExploration.cs" />
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
#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.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Removes frozen actors of actors that are dead or sold," +
|
||||
" when having an active GPS power.")]
|
||||
public class GpsRemoveFrozenActorInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Should this trait also affect allied players?")]
|
||||
public bool GrantAllies = true;
|
||||
|
||||
public object Create(ActorInitializer init) { return new GpsRemoveFrozenActor(init.Self, this); }
|
||||
}
|
||||
|
||||
public class GpsRemoveFrozenActor : IRemoveFrozenActor
|
||||
{
|
||||
readonly GpsWatcher[] watchers;
|
||||
readonly GpsRemoveFrozenActorInfo info;
|
||||
|
||||
public GpsRemoveFrozenActor(Actor self, GpsRemoveFrozenActorInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
watchers = self.World.ActorsWithTrait<GpsWatcher>().Select(w => w.Trait).ToArray();
|
||||
}
|
||||
|
||||
public bool RemoveActor(Actor self, Player owner)
|
||||
{
|
||||
if (!self.IsDead)
|
||||
return false;
|
||||
|
||||
foreach (var w in watchers)
|
||||
{
|
||||
if (w.Owner != owner && !(info.GrantAllies && w.Owner.IsAlliedWith(owner)))
|
||||
continue;
|
||||
|
||||
if (w.Launched)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user