Add terrain geometry visualisation.

This commit is contained in:
Paul Chote
2014-11-01 18:02:09 +13:00
parent 18f65552a1
commit 118275b376
13 changed files with 188 additions and 11 deletions

View File

@@ -188,6 +188,27 @@ namespace OpenRA
return InvalidValueAction(value, fieldType, fieldName); 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)) else if (fieldType == typeof(HSLColor))
{ {
var parts = value.Split(','); var parts = value.Split(',');

View File

@@ -158,6 +158,7 @@ namespace OpenRA
public readonly string[] Extensions; public readonly string[] Extensions;
public readonly int WaterPaletteRotationBase = 0x60; public readonly int WaterPaletteRotationBase = 0x60;
public readonly byte MaxGroundHeight = 0; public readonly byte MaxGroundHeight = 0;
public readonly Color[] HeightDebugColors = new[] { Color.Red };
public readonly string[] EditorTemplateOrder; public readonly string[] EditorTemplateOrder;
public readonly bool IgnoreTileSpriteOffsets; public readonly bool IgnoreTileSpriteOffsets;

View File

@@ -23,6 +23,7 @@ namespace OpenRA.Traits
public bool BuildAnywhere; public bool BuildAnywhere;
public bool ShowCombatGeometry; public bool ShowCombatGeometry;
public bool ShowDebugGeometry; public bool ShowDebugGeometry;
public bool ShowTerrainGeometry;
public object Create(ActorInitializer init) { return new DeveloperMode(this); } public object Create(ActorInitializer init) { return new DeveloperMode(this); }
} }
@@ -41,6 +42,7 @@ namespace OpenRA.Traits
// Client side only // Client side only
public bool ShowCombatGeometry; public bool ShowCombatGeometry;
public bool ShowDebugGeometry; public bool ShowDebugGeometry;
public bool ShowTerrainGeometry;
public DeveloperMode(DeveloperModeInfo info) public DeveloperMode(DeveloperModeInfo info)
{ {
@@ -53,6 +55,7 @@ namespace OpenRA.Traits
BuildAnywhere = info.BuildAnywhere; BuildAnywhere = info.BuildAnywhere;
ShowCombatGeometry = info.ShowCombatGeometry; ShowCombatGeometry = info.ShowCombatGeometry;
ShowDebugGeometry = info.ShowDebugGeometry; ShowDebugGeometry = info.ShowDebugGeometry;
ShowTerrainGeometry = info.ShowTerrainGeometry;
} }
public void ResolveOrder(Actor self, Order order) public void ResolveOrder(Actor self, Order order)

View File

@@ -147,6 +147,7 @@
<Compile Include="SpriteLoaders\ShpD2Loader.cs" /> <Compile Include="SpriteLoaders\ShpD2Loader.cs" />
<Compile Include="Widgets\Logic\SettingsLogic.cs" /> <Compile Include="Widgets\Logic\SettingsLogic.cs" />
<Compile Include="Widgets\TerrainTemplatePreviewWidget.cs" /> <Compile Include="Widgets\TerrainTemplatePreviewWidget.cs" />
<Compile Include="World\TerrainGeometryOverlay.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>

View 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);
}
}
}
}

View File

@@ -74,6 +74,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
showGeometryCheckbox.OnClick = () => devTrait.ShowDebugGeometry ^= true; 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"); var allTechCheckbox = widget.GetOrNull<CheckboxWidget>("ENABLE_TECH");
if (allTechCheckbox != null) if (allTechCheckbox != null)
{ {

View File

@@ -83,30 +83,36 @@ Container@DEBUG_PANEL:
Width: PARENT_RIGHT Width: PARENT_RIGHT
Checkbox@SHOW_UNIT_PATHS: Checkbox@SHOW_UNIT_PATHS:
X: 45 X: 45
Y: 285 Y: 275
Width: 200 Width: 200
Height: 20 Height: 20
Font: Regular Font: Regular
Text: Show Unit Paths Text: Show Unit Paths
Checkbox@SHOW_ASTAR: Checkbox@SHOW_ASTAR:
X: 45 X: 45
Y: 315 Y: 305
Height: 20 Height: 20
Width: 200 Width: 200
Font: Regular Font: Regular
Text: Show A* Cost Text: Show A* Cost
Checkbox@SHOW_COMBATOVERLAY: Checkbox@SHOW_COMBATOVERLAY:
X: 290 X: 290
Y: 285 Y: 275
Height: 20 Height: 20
Width: 200 Width: 200
Font: Regular Font: Regular
Text: Show Combat Geometry Text: Show Combat Geometry
Checkbox@SHOW_GEOMETRY: Checkbox@SHOW_GEOMETRY:
X: 290 X: 290
Y: 315 Y: 305
Height: 20 Height: 20
Width: 200 Width: 200
Font: Regular Font: Regular
Text: Show Render Geometry Text: Show Render Geometry
Checkbox@SHOW_TERRAIN_OVERLAY:
X: 290
Y: 335
Height: 20
Width: 200
Font: Regular
Text: Show Terrain Geometry

View File

@@ -125,6 +125,7 @@ World:
AllowedTerrainTypes: Clear,Road AllowedTerrainTypes: Clear,Road
AllowUnderActors: false AllowUnderActors: false
PathfinderDebugOverlay: PathfinderDebugOverlay:
TerrainGeometryOverlay:
SpawnMapActors: SpawnMapActors:
MPStartLocations: MPStartLocations:
CreateMPPlayers: CreateMPPlayers:

View File

@@ -104,6 +104,7 @@ World:
Race: ordos Race: ordos
DomainIndex: DomainIndex:
PathfinderDebugOverlay: PathfinderDebugOverlay:
TerrainGeometryOverlay:
BuildableTerrainLayer: BuildableTerrainLayer:
D2kResourceLayer: D2kResourceLayer:
ResourceClaimLayer: ResourceClaimLayer:

View File

@@ -1,6 +1,6 @@
Container@DEBUG_PANEL: Container@DEBUG_PANEL:
Logic: DebugMenuLogic Logic: DebugMenuLogic
Y: 20 Y: 10
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: PARENT_BOTTOM Height: PARENT_BOTTOM
Children: Children:
@@ -88,30 +88,36 @@ Container@DEBUG_PANEL:
Width: PARENT_RIGHT Width: PARENT_RIGHT
Checkbox@SHOW_UNIT_PATHS: Checkbox@SHOW_UNIT_PATHS:
X: 45 X: 45
Y: 285 Y: 275
Width: 200 Width: 200
Height: 20 Height: 20
Font: Regular Font: Regular
Text: Show Unit Paths Text: Show Unit Paths
Checkbox@SHOW_ASTAR: Checkbox@SHOW_ASTAR:
X: 45 X: 45
Y: 315 Y: 305
Height: 20 Height: 20
Width: 200 Width: 200
Font: Regular Font: Regular
Text: Show A* Cost Text: Show A* Cost
Checkbox@SHOW_COMBATOVERLAY: Checkbox@SHOW_COMBATOVERLAY:
X: 290 X: 290
Y: 285 Y: 275
Height: 20 Height: 20
Width: 200 Width: 200
Font: Regular Font: Regular
Text: Show Combat Geometry Text: Show Combat Geometry
Checkbox@SHOW_GEOMETRY: Checkbox@SHOW_GEOMETRY:
X: 290 X: 290
Y: 315 Y: 305
Height: 20 Height: 20
Width: 200 Width: 200
Font: Regular Font: Regular
Text: Show Render Geometry Text: Show Render Geometry
Checkbox@SHOW_TERRAIN_OVERLAY:
X: 290
Y: 335
Height: 20
Width: 200
Font: Regular
Text: Show Terrain Geometry

View File

@@ -133,6 +133,7 @@ World:
AllowUnderActors: false AllowUnderActors: false
TerrainType: Gems TerrainType: Gems
PathfinderDebugOverlay: PathfinderDebugOverlay:
TerrainGeometryOverlay:
SpawnMapActors: SpawnMapActors:
CreateMPPlayers: CreateMPPlayers:
MPStartUnits@mcvonly: MPStartUnits@mcvonly:

View File

@@ -148,6 +148,7 @@ World:
AllowUnderActors: false AllowUnderActors: false
TerrainType: BlueTiberium TerrainType: BlueTiberium
PathfinderDebugOverlay: PathfinderDebugOverlay:
TerrainGeometryOverlay:
SpawnMapActors: SpawnMapActors:
CreateMPPlayers: CreateMPPlayers:
MPStartUnits@MCV: MPStartUnits@MCV:

View File

@@ -4,6 +4,7 @@ General:
Extensions: .tem, .shp Extensions: .tem, .shp
Palette: isotem.pal Palette: isotem.pal
MaxGroundHeight: 16 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 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 SheetSize: 2048