Remove region assumptions from fast shroud tests.

This commit is contained in:
Paul Chote
2015-05-03 19:28:07 +12:00
parent da3abb4e2e
commit aee951c86f
7 changed files with 66 additions and 49 deletions

View File

@@ -180,8 +180,8 @@ namespace OpenRA.Graphics
{
var colors = (int*)bitmapData.Scan0;
var stride = bitmapData.Stride / 4;
var shroudObscured = world.ShroudObscuresTest(map.CellsInsideBounds);
var fogObscured = world.FogObscuresTest(map.CellsInsideBounds);
var shroudObscured = world.ShroudObscuresTest;
var fogObscured = world.FogObscuresTest;
foreach (var uv in map.CellsInsideBounds.MapCoords)
{
var bitmapXy = new int2(uv.U - b.Left, uv.V - b.Top);

View File

@@ -42,12 +42,16 @@ namespace OpenRA.Traits
public bool NeedRenderables;
public bool IsRendering { get; private set; }
public FrozenActor(Actor self, MPos[] footprint, CellRegion footprintRegion, Shroud shroud)
public FrozenActor(Actor self, MPos[] footprint, Shroud shroud)
{
actor = self;
isVisibleTest = shroud.IsVisibleTest(footprintRegion);
isVisibleTest = shroud.IsVisibleTest;
// Consider all cells inside the map area (ignoring the current map bounds)
Footprint = footprint
.Where(m => shroud.Contains(m))
.ToArray();
Footprint = footprint;
CenterPosition = self.CenterPosition;
Bounds = self.Bounds;
@@ -80,11 +84,13 @@ namespace OpenRA.Traits
// Visible = !Footprint.Any(isVisibleTest);
Visible = true;
foreach (var uv in Footprint)
{
if (isVisibleTest(uv))
{
Visible = false;
break;
}
}
if (Visible && !wasVisible)
NeedRenderables = true;

View File

@@ -44,10 +44,8 @@ namespace OpenRA.Traits
static readonly Func<MPos, bool> TruthPredicate = _ => true;
readonly Func<MPos, bool> shroudEdgeTest;
readonly Func<MPos, bool> fastExploredTest;
readonly Func<MPos, bool> slowExploredTest;
readonly Func<MPos, bool> fastVisibleTest;
readonly Func<MPos, bool> slowVisibleTest;
readonly Func<MPos, bool> isExploredTest;
readonly Func<MPos, bool> isVisibleTest;
public Shroud(Actor self)
{
@@ -67,10 +65,8 @@ namespace OpenRA.Traits
fogVisibilities = Exts.Lazy(() => self.TraitsImplementing<IFogVisibilityModifier>().ToArray());
shroudEdgeTest = map.Contains;
fastExploredTest = IsExploredCore;
slowExploredTest = IsExplored;
fastVisibleTest = IsVisibleCore;
slowVisibleTest = IsVisible;
isExploredTest = IsExploredCore;
isVisibleTest = IsVisibleCore;
}
void Invalidate(IEnumerable<CPos> changed)
@@ -329,18 +325,16 @@ namespace OpenRA.Traits
return explored[uv] && (generatedShroudCount[uv] == 0 || visibleCount[uv] > 0);
}
public Func<MPos, bool> IsExploredTest(CellRegion region)
public Func<MPos, bool> IsExploredTest
{
// If the region to test extends outside the map we must use the slow test that checks the map boundary every time.
if (!map.CellsInsideBounds.Contains(region))
return slowExploredTest;
get
{
// If shroud isn't enabled, then we can see everything inside the map.
if (!ShroudEnabled)
return shroudEdgeTest;
// If shroud isn't enabled, then we can see everything inside the map.
if (!ShroudEnabled)
return shroudEdgeTest;
// If shroud is enabled, we can use the fast test that just does the core check.
return fastExploredTest;
return isExploredTest;
}
}
public bool IsExplored(Actor a)
@@ -377,18 +371,17 @@ namespace OpenRA.Traits
return visibleCount[uv] > 0;
}
public Func<MPos, bool> IsVisibleTest(CellRegion region)
public Func<MPos, bool> IsVisibleTest
{
// If the region to test extends outside the map we must use the slow test that checks the map boundary every time.
if (!map.CellsInsideBounds.Contains(region))
return slowVisibleTest;
get
{
// If fog isn't enabled, then we can see everything.
if (!FogEnabled)
return TruthPredicate;
// If fog isn't enabled, then we can see everything.
if (!FogEnabled)
return TruthPredicate;
// If fog is enabled, we can use the fast test that just does the core check.
return fastVisibleTest;
// If fog is enabled, we can use the fast test that just does the core check.
return isVisibleTest;
}
}
// Actors are hidden under shroud, but not under fog by default
@@ -415,5 +408,12 @@ namespace OpenRA.Traits
{
return fogVisibilities.Value.Any(f => f.HasFogVisibility(self.Owner));
}
public bool Contains(MPos uv)
{
// Check that uv is inside the map area. There is nothing special
// about explored here: any of the CellLayers would have been suitable.
return explored.Contains(uv);
}
}
}

View File

@@ -73,27 +73,37 @@ namespace OpenRA
public bool FogObscures(Actor a) { return RenderPlayer != null && !RenderPlayer.Shroud.IsVisible(a); }
public bool FogObscures(CPos p) { return RenderPlayer != null && !RenderPlayer.Shroud.IsVisible(p); }
public bool FogObscures(WPos pos) { return RenderPlayer != null && !RenderPlayer.Shroud.IsVisible(pos); }
public bool FogObscures(MPos uv) { return RenderPlayer != null && !RenderPlayer.Shroud.IsVisible(uv); }
public bool ShroudObscures(Actor a) { return RenderPlayer != null && !RenderPlayer.Shroud.IsExplored(a); }
public bool ShroudObscures(CPos p) { return RenderPlayer != null && !RenderPlayer.Shroud.IsExplored(p); }
public bool ShroudObscures(WPos pos) { return RenderPlayer != null && !RenderPlayer.Shroud.IsExplored(pos); }
public bool ShroudObscures(MPos uv) { return RenderPlayer != null && !RenderPlayer.Shroud.IsExplored(uv); }
public Func<MPos, bool> FogObscuresTest(CellRegion region)
public Func<MPos, bool> FogObscuresTest
{
var rp = RenderPlayer;
if (rp == null)
return FalsePredicate;
var predicate = rp.Shroud.IsVisibleTest(region);
return uv => !predicate(uv);
get
{
var rp = RenderPlayer;
if (rp == null)
return FalsePredicate;
var predicate = rp.Shroud.IsVisibleTest;
return uv => !predicate(uv);
}
}
public Func<MPos, bool> ShroudObscuresTest(CellRegion region)
public Func<MPos, bool> ShroudObscuresTest
{
var rp = RenderPlayer;
if (rp == null)
return FalsePredicate;
var predicate = rp.Shroud.IsExploredTest(region);
return uv => !predicate(uv);
get
{
var rp = RenderPlayer;
if (rp == null)
return FalsePredicate;
var predicate = rp.Shroud.IsExploredTest;
return uv => !predicate(uv);
}
}
public bool IsReplay