From 77779023d58ca12416d74bf963625d7126582565 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Fri, 26 Aug 2022 21:06:39 +0100 Subject: [PATCH] Notify of shroud state changes when using DevVisibility cheat. When this cheat is used by notifying of shroud changes we invoke the usual logic that would occur if the visibility had been granted by units. Without this change any cached information about the visibility is not refreshed. Without this refresh actors with different visibility may not act correctly. One aspect this improves is frozen actors. Using the visibility cheat will show up all actors on the map. If the cheat is then disabled than frozen actors will appear in their place. Prior to this change a frozen actor would fail to appear if the cheat had caused it to be revealed. Healthbars and selection boxes are also made consistent for similar reasons. --- OpenRA.Game/Traits/Player/Shroud.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/OpenRA.Game/Traits/Player/Shroud.cs b/OpenRA.Game/Traits/Player/Shroud.cs index d6a4744b20..7f4e694930 100644 --- a/OpenRA.Game/Traits/Player/Shroud.cs +++ b/OpenRA.Game/Traits/Player/Shroud.cs @@ -105,6 +105,7 @@ namespace OpenRA.Traits // Per-cell cache of the resolved cell type (shroud/fog/visible) readonly ProjectedCellLayer resolvedType; + bool disabledChanged; [Sync] bool disabled; public bool Disabled @@ -117,6 +118,7 @@ namespace OpenRA.Traits return; disabled = value; + disabledChanged = true; } } @@ -159,13 +161,16 @@ namespace OpenRA.Traits void ITick.Tick(Actor self) { - if (!anyCellTouched) + if (!anyCellTouched && !disabledChanged) return; anyCellTouched = false; if (OnShroudChanged == null) + { + disabledChanged = false; return; + } // PERF: Parts of this loop are very hot. // We loop over the direct index that represents the PPos in @@ -175,7 +180,7 @@ namespace OpenRA.Traits for (var index = 0; index < maxIndex; index++) { // PERF: Most cells are not touched - if (!touched[index]) + if (!touched[index] && !disabledChanged) continue; touched[index] = false; @@ -196,16 +201,17 @@ namespace OpenRA.Traits // PERF: Most cells are unchanged var oldResolvedType = resolvedType[index]; - if (type != oldResolvedType) + if (type != oldResolvedType || disabledChanged) { resolvedType[index] = type; - var uv = touched.PPosFromIndex(index); - if (map.Contains(uv)) - OnShroudChanged(uv); + var puv = touched.PPosFromIndex(index); + if (map.Contains(puv)) + OnShroudChanged(puv); } } Hash = Sync.HashPlayer(self.Owner) + self.World.WorldTick; + disabledChanged = false; } public static IEnumerable ProjectedCellsInRange(Map map, WPos pos, WDist minRange, WDist maxRange, int maxHeightDelta = -1)