Remove CurrentAdjacentCells update on each tick in Cargo

This commit is contained in:
teinarss
2019-11-23 10:34:15 +01:00
committed by tovl
parent af5d8a3bbe
commit 20610d05a2

View File

@@ -14,6 +14,7 @@ using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Orders;
using OpenRA.Mods.Common.Widgets;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -88,7 +89,7 @@ namespace OpenRA.Mods.Common.Traits
}
public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated, INotifyKilled,
INotifyOwnerChanged, INotifyAddedToWorld, ITick, INotifySold, INotifyActorDisposing, IIssueDeployOrder,
INotifyOwnerChanged, ITick, INotifySold, INotifyActorDisposing, IIssueDeployOrder,
ITransformActorInitModifier
{
public readonly CargoInfo Info;
@@ -106,9 +107,13 @@ namespace OpenRA.Mods.Common.Traits
int loadingToken = ConditionManager.InvalidConditionToken;
Stack<int> loadedTokens = new Stack<int>();
bool takeOffAfterLoad;
readonly CachedTransform<CPos, IEnumerable<CPos>> currentAdjacentCells;
public IEnumerable<CPos> CurrentAdjacentCells
{
get { return currentAdjacentCells.Update(self.Location); }
}
CPos currentCell;
public IEnumerable<CPos> CurrentAdjacentCells { get; private set; }
public IEnumerable<Actor> Passengers { get { return cargo; } }
public int PassengerCount { get { return cargo.Count; } }
@@ -121,6 +126,11 @@ namespace OpenRA.Mods.Common.Traits
Info = info;
checkTerrainType = info.UnloadTerrainTypes.Count > 0;
currentAdjacentCells = new CachedTransform<CPos, IEnumerable<CPos>>(loc =>
{
return Util.AdjacentCells(self.World, Target.FromActor(self)).Where(c => loc != c);
});
if (init.Contains<RuntimeCargoInit>())
{
cargo = new List<Actor>(init.Get<RuntimeCargoInit, Actor[]>());
@@ -210,11 +220,6 @@ namespace OpenRA.Mods.Common.Traits
}
}
IEnumerable<CPos> GetAdjacentCells()
{
return Util.AdjacentCells(self.World, Target.FromActor(self)).Where(c => self.Location != c);
}
public bool CanUnload(BlockedByActor check = BlockedByActor.None)
{
if (checkTerrainType)
@@ -490,13 +495,6 @@ namespace OpenRA.Mods.Common.Traits
p.ChangeOwner(newOwner);
}
void INotifyAddedToWorld.AddedToWorld(Actor self)
{
// Force location update to avoid issues when initial spawn is outside map
currentCell = self.Location;
CurrentAdjacentCells = GetAdjacentCells();
}
bool initialized;
void ITick.Tick(Actor self)
{
@@ -516,13 +514,6 @@ namespace OpenRA.Mods.Common.Traits
initialized = true;
}
var cell = self.World.Map.CellContaining(self.CenterPosition);
if (currentCell != cell)
{
currentCell = cell;
CurrentAdjacentCells = GetAdjacentCells();
}
}
void ITransformActorInitModifier.ModifyTransformActorInit(Actor self, TypeDictionary init)