Add terrain geometry visualisation.
This commit is contained in:
@@ -188,6 +188,27 @@ namespace OpenRA
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(Color[]))
|
||||
{
|
||||
var parts = value.Split(',');
|
||||
|
||||
if (parts.Length % 4 != 0)
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
|
||||
var colors = new Color[parts.Length / 4];
|
||||
|
||||
for (var i = 0; i < colors.Length; i++)
|
||||
{
|
||||
colors[i] = Color.FromArgb(
|
||||
Exts.ParseIntegerInvariant(parts[4 * i]).Clamp(0, 255),
|
||||
Exts.ParseIntegerInvariant(parts[4 * i + 1]).Clamp(0, 255),
|
||||
Exts.ParseIntegerInvariant(parts[4 * i + 2]).Clamp(0, 255),
|
||||
Exts.ParseIntegerInvariant(parts[4 * i + 3]).Clamp(0, 255));
|
||||
}
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(HSLColor))
|
||||
{
|
||||
var parts = value.Split(',');
|
||||
|
||||
@@ -158,6 +158,7 @@ namespace OpenRA
|
||||
public readonly string[] Extensions;
|
||||
public readonly int WaterPaletteRotationBase = 0x60;
|
||||
public readonly byte MaxGroundHeight = 0;
|
||||
public readonly Color[] HeightDebugColors = new[] { Color.Red };
|
||||
public readonly string[] EditorTemplateOrder;
|
||||
public readonly bool IgnoreTileSpriteOffsets;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace OpenRA.Traits
|
||||
public bool BuildAnywhere;
|
||||
public bool ShowCombatGeometry;
|
||||
public bool ShowDebugGeometry;
|
||||
public bool ShowTerrainGeometry;
|
||||
|
||||
public object Create(ActorInitializer init) { return new DeveloperMode(this); }
|
||||
}
|
||||
@@ -41,6 +42,7 @@ namespace OpenRA.Traits
|
||||
// Client side only
|
||||
public bool ShowCombatGeometry;
|
||||
public bool ShowDebugGeometry;
|
||||
public bool ShowTerrainGeometry;
|
||||
|
||||
public DeveloperMode(DeveloperModeInfo info)
|
||||
{
|
||||
@@ -53,6 +55,7 @@ namespace OpenRA.Traits
|
||||
BuildAnywhere = info.BuildAnywhere;
|
||||
ShowCombatGeometry = info.ShowCombatGeometry;
|
||||
ShowDebugGeometry = info.ShowDebugGeometry;
|
||||
ShowTerrainGeometry = info.ShowTerrainGeometry;
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
|
||||
@@ -147,6 +147,7 @@
|
||||
<Compile Include="SpriteLoaders\ShpD2Loader.cs" />
|
||||
<Compile Include="Widgets\Logic\SettingsLogic.cs" />
|
||||
<Compile Include="Widgets\TerrainTemplatePreviewWidget.cs" />
|
||||
<Compile Include="World\TerrainGeometryOverlay.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
||||
127
OpenRA.Mods.Common/World/TerrainGeometryOverlay.cs
Normal file
127
OpenRA.Mods.Common/World/TerrainGeometryOverlay.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Mods.Common
|
||||
{
|
||||
[Desc("Renders a debug overlay showing the terrain cells. Attach this to the world actor.")]
|
||||
public class TerrainGeometryOverlayInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new TerrainGeometryOverlay(init.self); }
|
||||
}
|
||||
|
||||
public class TerrainGeometryOverlay : IRenderOverlay
|
||||
{
|
||||
readonly int[][] vertices = new int[][]
|
||||
{
|
||||
// Flat
|
||||
new[] { 0, 0, 0, 0 },
|
||||
|
||||
// Slopes (two corners high)
|
||||
new[] { 0, 0, 1, 1 },
|
||||
new[] { 1, 0, 0, 1 },
|
||||
new[] { 1, 1, 0, 0 },
|
||||
new[] { 0, 1, 1, 0 },
|
||||
|
||||
// Slopes (one corner high)
|
||||
new[] { 0, 0, 0, 1 },
|
||||
new[] { 1, 0, 0, 0 },
|
||||
new[] { 0, 1, 0, 0 },
|
||||
new[] { 0, 0, 1, 0 },
|
||||
|
||||
// Slopes (three corners high)
|
||||
new[] { 1, 0, 1, 1 },
|
||||
new[] { 1, 1, 0, 1 },
|
||||
new[] { 1, 1, 1, 0 },
|
||||
new[] { 0, 1, 1, 1 },
|
||||
|
||||
// Slopes (two corners high, one corner double high)
|
||||
new[] { 1, 0, 1, 2 },
|
||||
new[] { 2, 1, 0, 1 },
|
||||
new[] { 1, 2, 1, 0 },
|
||||
new[] { 0, 1, 2, 1 },
|
||||
|
||||
// Slopes (two corners high, alternating)
|
||||
new[] { 1, 0, 1, 0 },
|
||||
new[] { 0, 1, 0, 1 },
|
||||
new[] { 1, 0, 1, 0 },
|
||||
new[] { 0, 1, 0, 1 }
|
||||
};
|
||||
|
||||
readonly Lazy<DeveloperMode> devMode;
|
||||
|
||||
public TerrainGeometryOverlay(Actor self)
|
||||
{
|
||||
devMode = Exts.Lazy(() => self.World.LocalPlayer != null ? self.World.LocalPlayer.PlayerActor.Trait<DeveloperMode>() : null);
|
||||
}
|
||||
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
if (devMode.Value == null || !devMode.Value.ShowTerrainGeometry)
|
||||
return;
|
||||
|
||||
var ts = wr.world.Map.TileShape;
|
||||
var colors = wr.world.TileSet.HeightDebugColors;
|
||||
|
||||
var leftDelta = ts == TileShape.Diamond ? new WVec(-512, 0, 0) : new WVec(-512, -512, 0);
|
||||
var topDelta = ts == TileShape.Diamond ? new WVec(0, -512, 0) : new WVec(512, -512, 0);
|
||||
var rightDelta = ts == TileShape.Diamond ? new WVec(512, 0, 0) : new WVec(512, 512, 0);
|
||||
var bottomDelta = ts == TileShape.Diamond ? new WVec(0, 512, 0) : new WVec(-512, 512, 0);
|
||||
|
||||
foreach (var cell in wr.Viewport.VisibleCells)
|
||||
{
|
||||
var lr = Game.Renderer.WorldLineRenderer;
|
||||
var pos = wr.world.Map.CenterOfCell(cell);
|
||||
|
||||
var height = (int)wr.world.Map.MapHeight.Value[cell];
|
||||
var tile = wr.world.Map.MapTiles.Value[cell];
|
||||
|
||||
TerrainTileInfo tileInfo = null;
|
||||
|
||||
// TODO: This is a temporary workaround for our sloppy tileset definitions
|
||||
// (ra/td templates omit Clear tiles from templates)
|
||||
try
|
||||
{
|
||||
tileInfo = wr.world.TileSet.Templates[tile.Type][tile.Index];
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
if (tileInfo == null)
|
||||
continue;
|
||||
|
||||
var leftHeight = vertices[tileInfo.RampType][0];
|
||||
var topHeight = vertices[tileInfo.RampType][1];
|
||||
var rightHeight = vertices[tileInfo.RampType][2];
|
||||
var bottomHeight = vertices[tileInfo.RampType][3];
|
||||
|
||||
var leftColor = colors[height + leftHeight];
|
||||
var topColor = colors[height + topHeight];
|
||||
var rightColor = colors[height + rightHeight];
|
||||
var bottomColor = colors[height + bottomHeight];
|
||||
|
||||
var left = wr.ScreenPxPosition(pos + leftDelta + new WVec(0, 0, 512 * leftHeight)).ToFloat2();
|
||||
var top = wr.ScreenPxPosition(pos + topDelta + new WVec(0, 0, 512 * topHeight)).ToFloat2();
|
||||
var right = wr.ScreenPxPosition(pos + rightDelta + new WVec(0, 0, 512 * rightHeight)).ToFloat2();
|
||||
var bottom = wr.ScreenPxPosition(pos + bottomDelta + new WVec(0, 0, 512 * bottomHeight)).ToFloat2();
|
||||
|
||||
lr.DrawLine(left, top, leftColor, topColor);
|
||||
lr.DrawLine(top, right, topColor, rightColor);
|
||||
lr.DrawLine(right, bottom, rightColor, bottomColor);
|
||||
lr.DrawLine(bottom, left, bottomColor, leftColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
showGeometryCheckbox.OnClick = () => devTrait.ShowDebugGeometry ^= true;
|
||||
}
|
||||
|
||||
var showTerrainGeometryCheckbox = widget.GetOrNull<CheckboxWidget>("SHOW_TERRAIN_OVERLAY");
|
||||
if (showTerrainGeometryCheckbox != null)
|
||||
{
|
||||
showTerrainGeometryCheckbox.IsChecked = () => devTrait.ShowTerrainGeometry;
|
||||
showTerrainGeometryCheckbox.OnClick = () => devTrait.ShowTerrainGeometry ^= true;
|
||||
}
|
||||
|
||||
var allTechCheckbox = widget.GetOrNull<CheckboxWidget>("ENABLE_TECH");
|
||||
if (allTechCheckbox != null)
|
||||
{
|
||||
|
||||
@@ -83,30 +83,36 @@ Container@DEBUG_PANEL:
|
||||
Width: PARENT_RIGHT
|
||||
Checkbox@SHOW_UNIT_PATHS:
|
||||
X: 45
|
||||
Y: 285
|
||||
Y: 275
|
||||
Width: 200
|
||||
Height: 20
|
||||
Font: Regular
|
||||
Text: Show Unit Paths
|
||||
Checkbox@SHOW_ASTAR:
|
||||
X: 45
|
||||
Y: 315
|
||||
Y: 305
|
||||
Height: 20
|
||||
Width: 200
|
||||
Font: Regular
|
||||
Text: Show A* Cost
|
||||
Checkbox@SHOW_COMBATOVERLAY:
|
||||
X: 290
|
||||
Y: 285
|
||||
Y: 275
|
||||
Height: 20
|
||||
Width: 200
|
||||
Font: Regular
|
||||
Text: Show Combat Geometry
|
||||
Checkbox@SHOW_GEOMETRY:
|
||||
X: 290
|
||||
Y: 315
|
||||
Y: 305
|
||||
Height: 20
|
||||
Width: 200
|
||||
Font: Regular
|
||||
Text: Show Render Geometry
|
||||
|
||||
Checkbox@SHOW_TERRAIN_OVERLAY:
|
||||
X: 290
|
||||
Y: 335
|
||||
Height: 20
|
||||
Width: 200
|
||||
Font: Regular
|
||||
Text: Show Terrain Geometry
|
||||
|
||||
@@ -125,6 +125,7 @@ World:
|
||||
AllowedTerrainTypes: Clear,Road
|
||||
AllowUnderActors: false
|
||||
PathfinderDebugOverlay:
|
||||
TerrainGeometryOverlay:
|
||||
SpawnMapActors:
|
||||
MPStartLocations:
|
||||
CreateMPPlayers:
|
||||
|
||||
@@ -104,6 +104,7 @@ World:
|
||||
Race: ordos
|
||||
DomainIndex:
|
||||
PathfinderDebugOverlay:
|
||||
TerrainGeometryOverlay:
|
||||
BuildableTerrainLayer:
|
||||
D2kResourceLayer:
|
||||
ResourceClaimLayer:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Container@DEBUG_PANEL:
|
||||
Logic: DebugMenuLogic
|
||||
Y: 20
|
||||
Y: 10
|
||||
Width: PARENT_RIGHT
|
||||
Height: PARENT_BOTTOM
|
||||
Children:
|
||||
@@ -88,30 +88,36 @@ Container@DEBUG_PANEL:
|
||||
Width: PARENT_RIGHT
|
||||
Checkbox@SHOW_UNIT_PATHS:
|
||||
X: 45
|
||||
Y: 285
|
||||
Y: 275
|
||||
Width: 200
|
||||
Height: 20
|
||||
Font: Regular
|
||||
Text: Show Unit Paths
|
||||
Checkbox@SHOW_ASTAR:
|
||||
X: 45
|
||||
Y: 315
|
||||
Y: 305
|
||||
Height: 20
|
||||
Width: 200
|
||||
Font: Regular
|
||||
Text: Show A* Cost
|
||||
Checkbox@SHOW_COMBATOVERLAY:
|
||||
X: 290
|
||||
Y: 285
|
||||
Y: 275
|
||||
Height: 20
|
||||
Width: 200
|
||||
Font: Regular
|
||||
Text: Show Combat Geometry
|
||||
Checkbox@SHOW_GEOMETRY:
|
||||
X: 290
|
||||
Y: 315
|
||||
Y: 305
|
||||
Height: 20
|
||||
Width: 200
|
||||
Font: Regular
|
||||
Text: Show Render Geometry
|
||||
|
||||
Checkbox@SHOW_TERRAIN_OVERLAY:
|
||||
X: 290
|
||||
Y: 335
|
||||
Height: 20
|
||||
Width: 200
|
||||
Font: Regular
|
||||
Text: Show Terrain Geometry
|
||||
|
||||
@@ -133,6 +133,7 @@ World:
|
||||
AllowUnderActors: false
|
||||
TerrainType: Gems
|
||||
PathfinderDebugOverlay:
|
||||
TerrainGeometryOverlay:
|
||||
SpawnMapActors:
|
||||
CreateMPPlayers:
|
||||
MPStartUnits@mcvonly:
|
||||
|
||||
@@ -148,6 +148,7 @@ World:
|
||||
AllowUnderActors: false
|
||||
TerrainType: BlueTiberium
|
||||
PathfinderDebugOverlay:
|
||||
TerrainGeometryOverlay:
|
||||
SpawnMapActors:
|
||||
CreateMPPlayers:
|
||||
MPStartUnits@MCV:
|
||||
|
||||
@@ -4,6 +4,7 @@ General:
|
||||
Extensions: .tem, .shp
|
||||
Palette: isotem.pal
|
||||
MaxGroundHeight: 16
|
||||
HeightDebugColors: 128,0,0,0, 128,0,0,68, 128,0,0,136, 128,0,0,204, 128,0,0,255, 128,68,0,204, 128,136,0,136, 128,204,0,68, 128,255,17,0, 128,255,85,0, 128,255,153,0, 128,255,221,0, 128,221,255,0, 128,153,255,0, 128,85,255,0, 128,17,255,0
|
||||
EditorTemplateOrder: Misc Buildings, Clear, Cliff Pieces, Ice Flow, House, Blank, Ice Ramps, Cliff Set, Civilian Buildings, Shore Pieces, Rough LAT tile, Clear/Rough LAT, Cliff/Water pieces, Bendy Dirt Roads, Dirt Road Junctions, Straight Dirt Roads, Bridges, Paved Roads, Water, Dirt Road Slopes, Slope Set Pieces, Dead Oil Tanker, Ruins, Waterfalls, Ground 01, Ground 02, Sand, Sand/Clear LAT, Rough ground, Paved Road Ends, TrainBridges, Pavement, Pavement/Clear LAT, Paved road bits, Green, Green/Clear LAT, Ramp edge fixup, Water slopes, Pavement (Use for LAT), Paved Road Slopes, Monorail Slopes, Waterfalls-B, Waterfalls-C, Waterfalls-D, Tunnel Floor, Tunnel Side, TrackTunnel Floor, Destroyable Cliffs, Water Caves, Scrin Wreckage, DirtTrackTunnel Floor, DirtTunnel Floor
|
||||
SheetSize: 2048
|
||||
|
||||
|
||||
Reference in New Issue
Block a user