Remove CurrentAdjacentCells update on each tick in Cargo
This commit is contained in:
@@ -14,6 +14,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Activities;
|
using OpenRA.Mods.Common.Activities;
|
||||||
using OpenRA.Mods.Common.Orders;
|
using OpenRA.Mods.Common.Orders;
|
||||||
|
using OpenRA.Mods.Common.Widgets;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
@@ -88,7 +89,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated, INotifyKilled,
|
public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated, INotifyKilled,
|
||||||
INotifyOwnerChanged, INotifyAddedToWorld, ITick, INotifySold, INotifyActorDisposing, IIssueDeployOrder,
|
INotifyOwnerChanged, ITick, INotifySold, INotifyActorDisposing, IIssueDeployOrder,
|
||||||
ITransformActorInitModifier
|
ITransformActorInitModifier
|
||||||
{
|
{
|
||||||
public readonly CargoInfo Info;
|
public readonly CargoInfo Info;
|
||||||
@@ -106,9 +107,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
int loadingToken = ConditionManager.InvalidConditionToken;
|
int loadingToken = ConditionManager.InvalidConditionToken;
|
||||||
Stack<int> loadedTokens = new Stack<int>();
|
Stack<int> loadedTokens = new Stack<int>();
|
||||||
bool takeOffAfterLoad;
|
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 IEnumerable<Actor> Passengers { get { return cargo; } }
|
||||||
public int PassengerCount { get { return cargo.Count; } }
|
public int PassengerCount { get { return cargo.Count; } }
|
||||||
|
|
||||||
@@ -121,6 +126,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
Info = info;
|
Info = info;
|
||||||
checkTerrainType = info.UnloadTerrainTypes.Count > 0;
|
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>())
|
if (init.Contains<RuntimeCargoInit>())
|
||||||
{
|
{
|
||||||
cargo = new List<Actor>(init.Get<RuntimeCargoInit, Actor[]>());
|
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)
|
public bool CanUnload(BlockedByActor check = BlockedByActor.None)
|
||||||
{
|
{
|
||||||
if (checkTerrainType)
|
if (checkTerrainType)
|
||||||
@@ -490,13 +495,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
p.ChangeOwner(newOwner);
|
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;
|
bool initialized;
|
||||||
void ITick.Tick(Actor self)
|
void ITick.Tick(Actor self)
|
||||||
{
|
{
|
||||||
@@ -516,13 +514,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cell = self.World.Map.CellContaining(self.CenterPosition);
|
|
||||||
if (currentCell != cell)
|
|
||||||
{
|
|
||||||
currentCell = cell;
|
|
||||||
CurrentAdjacentCells = GetAdjacentCells();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ITransformActorInitModifier.ModifyTransformActorInit(Actor self, TypeDictionary init)
|
void ITransformActorInitModifier.ModifyTransformActorInit(Actor self, TypeDictionary init)
|
||||||
|
|||||||
Reference in New Issue
Block a user