Shroud, combine IsVisible and IsExplored into a single function.

This commit is contained in:
Vapre
2021-08-10 23:02:05 +02:00
committed by teinarss
parent cc1f10dd35
commit 6e547469d6
4 changed files with 146 additions and 37 deletions

View File

@@ -155,14 +155,15 @@ namespace OpenRA.Traits
// PERF: Avoid LINQ.
foreach (var puv in Footprint)
{
if (shroud.IsVisible(puv))
var cv = shroud.GetVisibility(puv);
if (cv.HasFlag(Shroud.CellVisibility.Visible))
{
Visible = false;
Shrouded = false;
break;
}
if (Shrouded && shroud.IsExplored(puv))
if (Shrouded && cv.HasFlag(Shroud.CellVisibility.Explored))
Shrouded = false;
}

View File

@@ -83,6 +83,10 @@ namespace OpenRA.Traits
}
}
// Visible is not a super set of Explored. IsExplored may return false even if IsVisible returns true.
[Flags]
public enum CellVisibility : byte { Hidden = 0x0, Explored = 0x1, Visible = 0x2 }
readonly Actor self;
readonly ShroudInfo info;
readonly Map map;
@@ -423,5 +427,53 @@ namespace OpenRA.Traits
// about explored here: any of the CellLayers would have been suitable.
return explored.Contains(uv);
}
// PERF: Combine IsExplored and IsVisible.
public CellVisibility GetVisibility(PPos puv)
{
var state = CellVisibility.Hidden;
if (Disabled)
{
if (FogEnabled)
{
// Shroud disabled, Fog enabled
if (resolvedType.Contains(puv))
{
state |= CellVisibility.Explored;
if (resolvedType[puv] == ShroudCellType.Visible)
state |= CellVisibility.Visible;
}
}
else if (map.Contains(puv))
state |= CellVisibility.Explored | CellVisibility.Visible;
}
else
{
if (FogEnabled)
{
// Shroud and Fog enabled
if (resolvedType.Contains(puv))
{
var rt = resolvedType[puv];
if (rt == ShroudCellType.Visible)
state |= CellVisibility.Explored | CellVisibility.Visible;
else if (rt > ShroudCellType.Shroud)
state |= CellVisibility.Explored;
}
}
else if (resolvedType.Contains(puv))
{
// We do not set Explored since IsExplored may return false.
state |= CellVisibility.Visible;
if (resolvedType[puv] > ShroudCellType.Shroud)
state |= CellVisibility.Explored;
}
}
return state;
}
}
}