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

@@ -23,6 +23,7 @@ namespace OpenRA.Traits
public class FrozenActor
{
public readonly CPos[] Footprint;
public readonly CellRegion FootprintRegion;
public readonly WPos CenterPosition;
public readonly Rectangle Bounds;
readonly Actor actor;
@@ -38,10 +39,12 @@ namespace OpenRA.Traits
public bool Visible;
public FrozenActor(Actor self, IEnumerable<CPos> footprint)
public FrozenActor(Actor self, CPos[] footprint, CellRegion footprintRegion)
{
actor = self;
Footprint = footprint.ToArray();
Footprint = footprint;
FootprintRegion = footprintRegion;
CenterPosition = self.CenterPosition;
Bounds = self.Bounds.Value;
}
@@ -54,16 +57,7 @@ namespace OpenRA.Traits
int flashTicks;
public void Tick(World world, Shroud shroud)
{
Visible = true;
foreach (var pos in Footprint)
{
if (shroud.IsVisible(pos))
{
Visible = false;
break;
}
}
Visible = !Footprint.Any(shroud.IsVisibleTest(FootprintRegion));
if (flashTicks > 0)
flashTicks--;
}