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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,8 +151,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
Author = "Westwood Studios"
|
||||
};
|
||||
|
||||
var tl = new MPos(offsetX, offsetY);
|
||||
var br = new MPos(offsetX + width - 1, offsetY + height - 1);
|
||||
var tl = new PPos(offsetX, offsetY);
|
||||
var br = new PPos(offsetX + width - 1, offsetY + height - 1);
|
||||
map.SetBounds(tl, br);
|
||||
|
||||
if (legacyMapFormat == IniMapFormat.RedAlert)
|
||||
|
||||
@@ -64,8 +64,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var tileset = modRules.TileSets[tilesetDropDown.Text];
|
||||
var map = new Map(tileset, width + 2, height + maxTerrainHeight + 2);
|
||||
|
||||
var tl = new MPos(1, 1);
|
||||
var br = new MPos(width, height + maxTerrainHeight);
|
||||
var tl = new PPos(1, 1);
|
||||
var br = new PPos(width, height + maxTerrainHeight);
|
||||
map.SetBounds(tl, br);
|
||||
|
||||
map.PlayerDefinitions = new MapPlayers(map.Rules, map.SpawnPoints.Value.Length).ToMiniYaml();
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
actorSprite = new Sprite(radarSheet, new Rectangle(0, height, width, height), TextureChannel.Alpha);
|
||||
|
||||
// Set initial terrain data
|
||||
foreach (var cell in world.Map.CellsInsideBounds)
|
||||
foreach (var cell in world.Map.AllCells)
|
||||
UpdateTerrainCell(cell);
|
||||
|
||||
world.Map.MapTiles.Value.CellEntryChanged += UpdateTerrainCell;
|
||||
@@ -290,7 +290,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (newRenderShroud != null)
|
||||
{
|
||||
// Redraw the full shroud sprite
|
||||
MarkShroudDirty(world.Map.CellsInsideBounds);
|
||||
MarkShroudDirty(world.Map.AllCells);
|
||||
|
||||
// Update the notification binding
|
||||
newRenderShroud.CellsChanged += MarkShroudDirty;
|
||||
|
||||
Reference in New Issue
Block a user