Integrate CellRegion with Map, Viewport.
This commit is contained in:
@@ -46,9 +46,9 @@ namespace OpenRA.Graphics
|
||||
public void Draw(WorldRenderer wr, Viewport viewport)
|
||||
{
|
||||
var verticesPerRow = 4*map.Bounds.Width;
|
||||
var bounds = viewport.CellBounds;
|
||||
var firstRow = bounds.Top - map.Bounds.Top;
|
||||
var lastRow = bounds.Bottom - map.Bounds.Top;
|
||||
var cells = viewport.VisibleCells;
|
||||
var firstRow = cells.TopLeft.Y - map.Bounds.Top;
|
||||
var lastRow = cells.BottomRight.Y - map.Bounds.Top + 1;
|
||||
|
||||
if (lastRow < 0 || firstRow > map.Bounds.Height)
|
||||
return;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
@@ -48,6 +49,9 @@ namespace OpenRA.Graphics
|
||||
int2 viewportSize;
|
||||
bool cellBoundsDirty = true;
|
||||
|
||||
CellRegion cells;
|
||||
bool cellsDirty = true;
|
||||
|
||||
float zoom = 1f;
|
||||
public float Zoom
|
||||
{
|
||||
@@ -61,6 +65,7 @@ namespace OpenRA.Graphics
|
||||
zoom = value;
|
||||
viewportSize = (1f / zoom * new float2(Game.Renderer.Resolution)).ToInt2();
|
||||
cellBoundsDirty = true;
|
||||
cellsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +116,7 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
CenterLocation = worldRenderer.ScreenPxPosition(pos).Clamp(mapBounds);
|
||||
cellBoundsDirty = true;
|
||||
cellsDirty = true;
|
||||
}
|
||||
|
||||
public void Scroll(float2 delta, bool ignoreBorders)
|
||||
@@ -118,6 +124,7 @@ namespace OpenRA.Graphics
|
||||
// Convert scroll delta from world-px to viewport-px
|
||||
CenterLocation += (1f / Zoom * delta).ToInt2();
|
||||
cellBoundsDirty = true;
|
||||
cellsDirty = true;
|
||||
|
||||
if (!ignoreBorders)
|
||||
CenterLocation = CenterLocation.Clamp(mapBounds);
|
||||
@@ -158,5 +165,24 @@ namespace OpenRA.Graphics
|
||||
return b.HasValue ? Rectangle.Intersect(cachedRect, b.Value) : cachedRect;
|
||||
}
|
||||
}
|
||||
|
||||
public CellRegion VisibleCells
|
||||
{
|
||||
get
|
||||
{
|
||||
if (cellsDirty)
|
||||
{
|
||||
// Calculate the intersection of the visible rectangle and the map.
|
||||
var map = worldRenderer.world.Map;
|
||||
var tl = map.Clamp(worldRenderer.Position(TopLeft).ToCPos() - new CVec(1, 1));
|
||||
var br = map.Clamp(worldRenderer.Position(BottomRight).ToCPos());
|
||||
|
||||
cells = new CellRegion(tl, br);
|
||||
cellsDirty = false;
|
||||
}
|
||||
|
||||
return cells;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user