Sped up shroud rendering.

- Only update shroud within the visible screen area, rather than the whole map. This improves performance on larger maps significantly when scrolling around since large portions of the shroud do not need to be updated.
- Provide methods in Shroud to return delegates to check for explored/visibility for tiles within a certain region. This allows it to return more efficient delegates whenever the region is within the map bounds, or shroud/fog is disabled. In the typical case where the region is in bounds and shroud/fog is enabled, the fast check is almost twice as fast as the slow check.
- Use the Shroud delegate functions in shroud rendering, frozen actors, minimap rendering and resource layer areas to provide a speedup since these areas of code can often take advantage of the fact they perform checks within the map boundary.
- Cache current element in CellRegionEnumerator to prevent repeated work if the element is accessed more than once.
- Decrease the size of elements in some arrays in hopes of reducing memory needs and improving cache hits.
This commit is contained in:
RoosterDragon
2014-07-06 22:33:42 +01:00
parent 2351c43237
commit a512d9ad0a
8 changed files with 235 additions and 101 deletions

View File

@@ -30,6 +30,7 @@ namespace OpenRA.Mods.RA
readonly bool startsRevealed;
readonly CPos[] footprint;
readonly CellRegion footprintRegion;
readonly Lazy<IToolTip> tooltip;
readonly Lazy<Health> health;
@@ -44,6 +45,7 @@ namespace OpenRA.Mods.RA
// Spawned actors (e.g. building husks) shouldn't be revealed
startsRevealed = info.StartsRevealed && !init.Contains<ParentActorInit>();
footprint = FootprintUtils.Tiles(init.self).ToArray();
footprintRegion = CellRegion.BoundingRegion(init.world.Map.TileShape, footprint);
tooltip = Exts.Lazy(() => init.self.TraitsImplementing<IToolTip>().FirstOrDefault());
tooltip = Exts.Lazy(() => init.self.TraitsImplementing<IToolTip>().FirstOrDefault());
health = Exts.Lazy(() => init.self.TraitOrDefault<Health>());
@@ -65,15 +67,7 @@ namespace OpenRA.Mods.RA
VisibilityHash = 0;
foreach (var p in self.World.Players)
{
var isVisible = false;
foreach (var pos in footprint)
{
if (p.Shroud.IsVisible(pos))
{
isVisible = true;
break;
}
}
var isVisible = footprint.Any(p.Shroud.IsVisibleTest(footprintRegion));
visible[p] = isVisible;
if (isVisible)
VisibilityHash += p.ClientIndex;
@@ -84,7 +78,7 @@ namespace OpenRA.Mods.RA
foreach (var p in self.World.Players)
{
visible[p] |= startsRevealed;
p.PlayerActor.Trait<FrozenActorLayer>().Add(frozen[p] = new FrozenActor(self, footprint));
p.PlayerActor.Trait<FrozenActorLayer>().Add(frozen[p] = new FrozenActor(self, footprint, footprintRegion));
}
initialized = true;