- Create an overload that renders a line in one color, as this allows most existing calls to be simplified. This also allows a slight performance improvement by only normalizing the components once. - Introduce a DrawLineStrip method. This improves performance by allowing the color components to be normalized once for the whole strip, and only needing to calculate vertices once per point rather than twice since we can reuse the last result.
60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
#region Copyright & License Information
|
|
/*
|
|
* Copyright 2007-2015 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.Drawing;
|
|
using OpenRA.Graphics;
|
|
|
|
namespace OpenRA.Mods.Common.Graphics
|
|
{
|
|
public struct BeamRenderable : IRenderable, IFinalizedRenderable
|
|
{
|
|
readonly WPos pos;
|
|
readonly int zOffset;
|
|
readonly WVec length;
|
|
readonly Color color;
|
|
readonly float width;
|
|
|
|
public BeamRenderable(WPos pos, int zOffset, WVec length, float width, Color color)
|
|
{
|
|
this.pos = pos;
|
|
this.zOffset = zOffset;
|
|
this.length = length;
|
|
this.color = color;
|
|
this.width = width;
|
|
}
|
|
|
|
public WPos Pos { get { return pos; } }
|
|
public PaletteReference Palette { get { return null; } }
|
|
public int ZOffset { get { return zOffset; } }
|
|
public bool IsDecoration { get { return true; } }
|
|
|
|
public IRenderable WithPalette(PaletteReference newPalette) { return new BeamRenderable(pos, zOffset, length, width, color); }
|
|
public IRenderable WithZOffset(int newOffset) { return new BeamRenderable(pos, zOffset, length, width, color); }
|
|
public IRenderable OffsetBy(WVec vec) { return new BeamRenderable(pos + vec, zOffset, length, width, color); }
|
|
public IRenderable AsDecoration() { return this; }
|
|
|
|
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
|
|
public void Render(WorldRenderer wr)
|
|
{
|
|
var wlr = Game.Renderer.WorldLineRenderer;
|
|
var src = wr.ScreenPosition(pos);
|
|
var dest = wr.ScreenPosition(pos + length);
|
|
|
|
var oldWidth = wlr.LineWidth;
|
|
wlr.LineWidth = wr.Viewport.Zoom * width;
|
|
wlr.DrawLine(src, dest, color);
|
|
wlr.LineWidth = oldWidth;
|
|
}
|
|
|
|
public void RenderDebugGeometry(WorldRenderer wr) { }
|
|
public Rectangle ScreenBounds(WorldRenderer wr) { return Rectangle.Empty; }
|
|
}
|
|
}
|