Skip to content

Commit

Permalink
Testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
PunkPun committed Aug 20, 2023
1 parent 9901bcc commit 9ffe713
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion OpenRA.Game/Graphics/Viewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public CPos ViewToWorld(int2 view)
}

/// <summary>Returns an unfiltered list of all cells that could potentially contain the mouse cursor.</summary>
IEnumerable<MPos> CandidateMouseoverCells(int2 world)
public IEnumerable<MPos> CandidateMouseoverCells(int2 world)
{
var map = worldRenderer.World.Map;
var tileScale = map.Grid.TileScale / 2;
Expand Down
29 changes: 26 additions & 3 deletions OpenRA.Mods.Common/Traits/World/TerrainGeometryOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,35 @@ void IChatCommand.InvokeCommand(string name, string arg)

IEnumerable<IRenderable> IRenderAnnotations.RenderAnnotations(Actor self, WorldRenderer wr)
{
if (!Enabled)
yield break;

var map = wr.World.Map;
var colors = wr.World.Map.Rules.TerrainInfo.HeightDebugColors;
var mouseCell = wr.Viewport.ViewToWorld(Viewport.LastMousePos).ToMPos(wr.World.Map);
var world = wr.Viewport.ViewToWorldPx(Viewport.LastMousePos);

foreach (var uv in wr.Viewport.CandidateMouseoverCells(world))
{
var height = (int)map.Height[uv];
var r = map.Grid.Ramps[map.Ramp[uv]];
var pos = map.CenterOfCell(uv.ToCPos(map)) - new WVec(0, 0, r.CenterHeightOffset);
var width = uv == mouseCell ? 3 : 1;

// Colors change between points, so render separately
foreach (var p in r.Polygons)
{
for (var i = 0; i < p.Length; i++)
{
var j = (i + 1) % p.Length;
var start = pos + p[i];
var end = pos + p[j];
var startColor = colors[height + p[i].Z / 512];
var endColor = colors[height + p[j].Z / 512];
yield return new LineAnnotationRenderable(start, end, width, startColor, endColor);
}
}
}

if (!Enabled)
yield break;

foreach (var uv in wr.Viewport.AllVisibleCells.CandidateMapCoords)
{
Expand Down

0 comments on commit 9ffe713

Please sign in to comment.