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.
This commit is contained in:
RoosterDragon
2022-08-26 21:06:39 +01:00
committed by Gustas
parent 1fc1bdc849
commit 77779023d5

View File

@@ -105,6 +105,7 @@ namespace OpenRA.Traits
// Per-cell cache of the resolved cell type (shroud/fog/visible)
readonly ProjectedCellLayer<ShroudCellType> 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<PPos> ProjectedCellsInRange(Map map, WPos pos, WDist minRange, WDist maxRange, int maxHeightDelta = -1)