Fix Viewport.VisibleCells.
Reworked the visible cells calculation to ensure the visible region is actually minimal, which should reduce the amount of rendering to be done by a small amount. Previously, the region would tend to overdraw by 2-3 cells in either direction. For isometric maps, there was also a bug where it would draw far too much vertically above the top of the map.
This commit is contained in:
@@ -163,16 +163,20 @@ namespace OpenRA.Graphics
|
|||||||
var wtl = worldRenderer.Position(TopLeft);
|
var wtl = worldRenderer.Position(TopLeft);
|
||||||
var wbr = worldRenderer.Position(BottomRight);
|
var wbr = worldRenderer.Position(BottomRight);
|
||||||
|
|
||||||
// Visible rectangle in map coordinates
|
// Due to diamond tile staggering, we need to adjust the top-left bounds outwards by half a cell.
|
||||||
var ctl = new MPos(wtl.X / 1024, wtl.Y / 1024);
|
if (map.TileShape == TileShape.Diamond)
|
||||||
|
wtl -= new WVec(512, 512, 0);
|
||||||
|
|
||||||
|
// Visible rectangle in map coordinates.
|
||||||
var dy = map.TileShape == TileShape.Diamond ? 512 : 1024;
|
var dy = map.TileShape == TileShape.Diamond ? 512 : 1024;
|
||||||
var cbr = new MPos((wbr.X + 1023) / 1024, (wbr.Y + dy - 1) / dy);
|
var ctl = new MPos(wtl.X / 1024, wtl.Y / dy);
|
||||||
|
var cbr = new MPos(wbr.X / 1024, wbr.Y / dy);
|
||||||
|
|
||||||
// Add a 1 cell cordon to prevent holes, then convert back to cell coordinates
|
var tl = map.Clamp(ctl.ToCPos(map));
|
||||||
var tl = map.Clamp(new MPos(ctl.U - 1, ctl.V - 1).ToCPos(map));
|
|
||||||
|
|
||||||
// Also need to account for height of cells in rows below the bottom
|
// Also need to account for height of cells in rows below the bottom.
|
||||||
var br = map.Clamp(new MPos(cbr.U + 1, cbr.V + 2 + maxGroundHeight / 2).ToCPos(map));
|
var heightPadding = map.TileShape == TileShape.Diamond ? 2 : 0;
|
||||||
|
var br = map.Clamp(new MPos(cbr.U, cbr.V + heightPadding + maxGroundHeight / 2).ToCPos(map));
|
||||||
|
|
||||||
cells = new CellRegion(map.TileShape, tl, br);
|
cells = new CellRegion(map.TileShape, tl, br);
|
||||||
cellsDirty = false;
|
cellsDirty = false;
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public void RenderShroud(WorldRenderer wr, Shroud shroud)
|
public void RenderShroud(WorldRenderer wr, Shroud shroud)
|
||||||
{
|
{
|
||||||
Update(shroud);
|
Update(shroud);
|
||||||
Render(CellRegion.Expand(wr.Viewport.VisibleCells, 1));
|
Render(wr.Viewport.VisibleCells);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update(Shroud newShroud)
|
void Update(Shroud newShroud)
|
||||||
@@ -269,6 +269,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void Render(CellRegion visibleRegion)
|
void Render(CellRegion visibleRegion)
|
||||||
{
|
{
|
||||||
|
// 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)
|
if (currentShroud == null)
|
||||||
RenderMapBorderShroud(visibleRegion);
|
RenderMapBorderShroud(visibleRegion);
|
||||||
else
|
else
|
||||||
@@ -279,7 +283,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
// The map border shroud only affects the map border. If none of the visible cells are on the border, then
|
// 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.
|
// we don't need to render anything and can bail early for performance.
|
||||||
if (map.Cells.Contains(visibleRegion))
|
if (CellRegion.Expand(map.Cells, -1).Contains(visibleRegion))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Render the shroud that just encroaches at the map border. This shroud is always fully cached, so we can
|
// Render the shroud that just encroaches at the map border. This shroud is always fully cached, so we can
|
||||||
|
|||||||
Reference in New Issue
Block a user