Merge pull request #7561 from RoosterDragon/fast-map-border-shroud

Speed up map border shroud & fix viewport visible cells
This commit is contained in:
Matthias Mailänder
2015-03-18 06:36:45 +01:00
2 changed files with 26 additions and 18 deletions

View File

@@ -269,22 +269,26 @@ namespace OpenRA.Mods.Common.Traits
void Render(CellRegion visibleRegion)
{
var renderRegion = CellRegion.Expand(visibleRegion, 1).MapCoords;
// Due to diamond tile staggering, we need to expand the cordon to get full shroud coverage.
if (map.TileShape == TileShape.Diamond)
visibleRegion = CellRegion.Expand(visibleRegion, 1);
if (currentShroud == null)
{
RenderMapBorderShroud(renderRegion);
return;
}
RenderPlayerShroud(visibleRegion, renderRegion);
RenderMapBorderShroud(visibleRegion);
else
RenderPlayerShroud(visibleRegion);
}
void RenderMapBorderShroud(CellRegion.MapCoordsRegion renderRegion)
void RenderMapBorderShroud(CellRegion visibleRegion)
{
// The map border shroud only affects the map border. If none of the visible cells are on the border, then
// we don't need to render anything and can bail early for performance.
if (CellRegion.Expand(map.Cells, -1).Contains(visibleRegion))
return;
// Render the shroud that just encroaches at the map border. This shroud is always fully cached, so we can
// just render straight from the cache.
foreach (var uv in renderRegion)
foreach (var uv in visibleRegion.MapCoords)
{
var offset = VertexArrayOffset(uv);
RenderCachedTile(shroudSpriteLayer[uv], shroudVertices, offset);
@@ -292,7 +296,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
void RenderPlayerShroud(CellRegion visibleRegion, CellRegion.MapCoordsRegion renderRegion)
void RenderPlayerShroud(CellRegion visibleRegion)
{
// Render the shroud by drawing the appropriate tile over each cell that is visible on-screen.
// For performance we keep a cache tiles we have drawn previously so we don't have to recalculate the
@@ -303,7 +307,7 @@ namespace OpenRA.Mods.Common.Traits
// cached vertices.
var visibleUnderShroud = currentShroud.IsExploredTest(visibleRegion);
var visibleUnderFog = currentShroud.IsVisibleTest(visibleRegion);
foreach (var uv in renderRegion)
foreach (var uv in visibleRegion.MapCoords)
{
var offset = VertexArrayOffset(uv);
if (shroudDirty[uv])