Introduce initial PPos plumbing.
PPos is best thought of as a cell grid applied in screen space. Multiple cells with different terrain heights may be projected to the same PPos, or to multiple PPos if they do not align with the screen grid. PPos coordinates are used primarily for map edge checks and shroud / visibility queries.
This commit is contained in:
@@ -60,23 +60,24 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var doDim = refreshTick - world.WorldTick <= 0;
|
||||
if (doDim) refreshTick = world.WorldTick + 20;
|
||||
|
||||
var map = wr.World.Map;
|
||||
foreach (var pair in layers)
|
||||
{
|
||||
var c = (pair.Key != null) ? pair.Key.Color.RGB : Color.PaleTurquoise;
|
||||
var layer = pair.Value;
|
||||
|
||||
// Only render quads in viewing range:
|
||||
foreach (var cell in wr.Viewport.VisibleCellsInsideBounds)
|
||||
foreach (var uv in wr.Viewport.VisibleCellsInsideBounds.CandidateMapCoords)
|
||||
{
|
||||
if (layer[cell] <= 0)
|
||||
if (layer[uv] <= 0)
|
||||
continue;
|
||||
|
||||
var w = Math.Max(0, Math.Min(layer[cell], 128));
|
||||
var w = Math.Max(0, Math.Min(layer[uv], 128));
|
||||
if (doDim)
|
||||
layer[cell] = layer[cell] * 5 / 6;
|
||||
layer[uv] = layer[uv] * 5 / 6;
|
||||
|
||||
// TODO: This doesn't make sense for isometric terrain
|
||||
var pos = wr.World.Map.CenterOfCell(cell);
|
||||
var pos = wr.World.Map.CenterOfCell(uv.ToCPos(map));
|
||||
var tl = wr.ScreenPxPosition(pos - new WVec(512, 512, 0));
|
||||
var br = wr.ScreenPxPosition(pos + new WVec(511, 511, 0));
|
||||
qr.FillRect(RectangleF.FromLTRB(tl.X, tl.Y, br.X, br.Y), Color.FromArgb(w, c));
|
||||
|
||||
@@ -249,7 +249,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
currentShroud = shroud;
|
||||
DirtyCells(map.CellsInsideBounds);
|
||||
var dirty = map.ProjectedCellBounds
|
||||
.SelectMany(puv => map.Unproject(puv).Select(uv => uv.ToCPos(map)));
|
||||
DirtyCells(dirty);
|
||||
}
|
||||
|
||||
// We need to update newly dirtied areas of the shroud.
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var colors = wr.World.TileSet.HeightDebugColors;
|
||||
var mouseCell = wr.Viewport.ViewToWorld(Viewport.LastMousePos).ToMPos(wr.World.Map);
|
||||
|
||||
foreach (var uv in wr.Viewport.AllVisibleCells.MapCoords)
|
||||
foreach (var uv in wr.Viewport.AllVisibleCells.CandidateMapCoords)
|
||||
{
|
||||
var height = (int)map.MapHeight.Value[uv];
|
||||
var tile = map.MapTiles.Value[uv];
|
||||
@@ -80,6 +80,22 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
lr.LineWidth = 1;
|
||||
}
|
||||
|
||||
// Projected cell coordinates for the current cell
|
||||
var projectedCorners = map.CellCorners[0];
|
||||
lr.LineWidth = 3;
|
||||
foreach (var puv in map.ProjectedCellsCovering(mouseCell))
|
||||
{
|
||||
var pos = map.CenterOfCell(((MPos)puv).ToCPos(map));
|
||||
var screen = projectedCorners.Select(c => wr.ScreenPxPosition(pos + c - new WVec(0, 0, pos.Z)).ToFloat2()).ToArray();
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
var j = (i + 1) % 4;
|
||||
lr.DrawLine(screen[i], screen[j], Color.Navy);
|
||||
}
|
||||
}
|
||||
|
||||
lr.LineWidth = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user