diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index b208acad7c..860357c891 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -259,6 +259,8 @@ namespace OpenRA.Traits WDist LargestActorRadius { get; } WDist LargestBlockingActorRadius { get; } + + event Action> CellsUpdated; } [RequireExplicitImplementation] diff --git a/OpenRA.Mods.Common/Traits/World/ActorMap.cs b/OpenRA.Mods.Common/Traits/World/ActorMap.cs index 46496c4d06..d14c38908a 100644 --- a/OpenRA.Mods.Common/Traits/World/ActorMap.cs +++ b/OpenRA.Mods.Common/Traits/World/ActorMap.cs @@ -173,7 +173,7 @@ namespace OpenRA.Mods.Common.Traits readonly CellLayer influence; readonly Dictionary> customInfluence = new Dictionary>(); public readonly Dictionary CustomMovementLayers = new Dictionary(); - + public event Action> CellsUpdated; readonly Bin[] bins; readonly int rows, cols; @@ -182,6 +182,7 @@ namespace OpenRA.Mods.Common.Traits readonly HashSet addActorPosition = new HashSet(); readonly HashSet removeActorPosition = new HashSet(); readonly Predicate actorShouldBeRemoved; + readonly HashSet updatedCells = new HashSet(); public WDist LargestActorRadius { get; private set; } public WDist LargestBlockingActorRadius { get; private set; } @@ -370,6 +371,8 @@ namespace OpenRA.Mods.Common.Traits if (cellTriggerInfluence.TryGetValue(c.First, out triggers)) foreach (var t in triggers) t.Dirty = true; + + updatedCells.Add(c.First); } } @@ -390,6 +393,8 @@ namespace OpenRA.Mods.Common.Traits if (cellTriggerInfluence.TryGetValue(c.First, out triggers)) foreach (var t in triggers) t.Dirty = true; + + updatedCells.Add(c.First); } } @@ -437,6 +442,12 @@ namespace OpenRA.Mods.Common.Traits foreach (var t in proximityTriggers) t.Value.Tick(this); + + self.World.AddFrameEndTask(s => + { + if (CellsUpdated != null) + CellsUpdated(updatedCells); + }); } public int AddCellTrigger(CPos[] cells, Action onEntry, Action onExit) @@ -515,7 +526,7 @@ namespace OpenRA.Mods.Common.Traits public void AddPosition(Actor a, IOccupySpace ios) { - UpdatePosition(a, ios); + addActorPosition.Add(a); } public void RemovePosition(Actor a, IOccupySpace ios) @@ -526,7 +537,7 @@ namespace OpenRA.Mods.Common.Traits public void UpdatePosition(Actor a, IOccupySpace ios) { RemovePosition(a, ios); - addActorPosition.Add(a); + AddPosition(a, ios); } int CellCoordToBinIndex(int cell)