StyleCop clean OpenRA.Game
This commit is contained in:
@@ -70,7 +70,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
static void LoadCollection(string name, MiniYaml yaml)
|
||||
{
|
||||
Game.modData.LoadScreen.Display();
|
||||
Game.ModData.LoadScreen.Display();
|
||||
var collection = new Collection()
|
||||
{
|
||||
Src = yaml.Value,
|
||||
|
||||
@@ -87,19 +87,19 @@ namespace OpenRA.Graphics
|
||||
|
||||
float2 ScreenPosition(WorldRenderer wr)
|
||||
{
|
||||
return wr.ScreenPxPosition(pos) + wr.ScreenPxOffset(offset) - (0.5f * scale * sprite.size).ToInt2();
|
||||
return wr.ScreenPxPosition(pos) + wr.ScreenPxOffset(offset) - (0.5f * scale * sprite.Size).ToInt2();
|
||||
}
|
||||
|
||||
public void BeforeRender(WorldRenderer wr) { }
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
Game.Renderer.WorldSpriteRenderer.DrawSprite(sprite, ScreenPosition(wr), palette, sprite.size * scale);
|
||||
Game.Renderer.WorldSpriteRenderer.DrawSprite(sprite, ScreenPosition(wr), palette, sprite.Size * scale);
|
||||
}
|
||||
|
||||
public void RenderDebugGeometry(WorldRenderer wr)
|
||||
{
|
||||
var offset = ScreenPosition(wr) + sprite.offset;
|
||||
Game.Renderer.WorldLineRenderer.DrawRect(offset, offset + sprite.size, Color.Red);
|
||||
var offset = ScreenPosition(wr) + sprite.Offset;
|
||||
Game.Renderer.WorldLineRenderer.DrawRect(offset, offset + sprite.Size, Color.Red);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Graphics
|
||||
// Apply offset to each sprite in the sequence
|
||||
// Different sequences may apply different offsets to the same frame
|
||||
sprites = cache[srcOverride ?? unit].Select(
|
||||
s => new Sprite(s.sheet, s.bounds, s.offset + offset, s.channel, blendMode)).ToArray();
|
||||
s => new Sprite(s.Sheet, s.Bounds, s.Offset + offset, s.Channel, blendMode)).ToArray();
|
||||
|
||||
if (!d.ContainsKey("Length"))
|
||||
Length = 1;
|
||||
|
||||
@@ -79,11 +79,11 @@ namespace OpenRA.Graphics
|
||||
|
||||
var cursorSequence = cursorProvider.GetCursorSequence(cursorName);
|
||||
var cursorSprite = sprites[cursorName][((int)cursorFrame % cursorSequence.Length)];
|
||||
var cursorSize = CursorProvider.CursorViewportZoomed ? 2.0f * cursorSprite.size : cursorSprite.size;
|
||||
var cursorSize = CursorProvider.CursorViewportZoomed ? 2.0f * cursorSprite.Size : cursorSprite.Size;
|
||||
|
||||
var cursorOffset = CursorProvider.CursorViewportZoomed ?
|
||||
(2 * cursorSequence.Hotspot) + cursorSprite.size.ToInt2() :
|
||||
cursorSequence.Hotspot + (0.5f * cursorSprite.size).ToInt2();
|
||||
(2 * cursorSequence.Hotspot) + cursorSprite.Size.ToInt2() :
|
||||
cursorSequence.Hotspot + (0.5f * cursorSprite.Size).ToInt2();
|
||||
|
||||
renderer.SetPalette(palette);
|
||||
renderer.SpriteRenderer.DrawSprite(cursorSprite,
|
||||
|
||||
@@ -14,14 +14,14 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
public class Sprite
|
||||
{
|
||||
public readonly Rectangle bounds;
|
||||
public readonly Sheet sheet;
|
||||
public readonly BlendMode blendMode;
|
||||
public readonly TextureChannel channel;
|
||||
public readonly float2 size;
|
||||
public readonly float2 offset;
|
||||
public readonly float2 fractionalOffset;
|
||||
public readonly float top, left, bottom, right;
|
||||
public readonly Rectangle Bounds;
|
||||
public readonly Sheet Sheet;
|
||||
public readonly BlendMode BlendMode;
|
||||
public readonly TextureChannel Channel;
|
||||
public readonly float2 Size;
|
||||
public readonly float2 Offset;
|
||||
public readonly float2 FractionalOffset;
|
||||
public readonly float Top, Left, Bottom, Right;
|
||||
|
||||
public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel)
|
||||
: this(sheet, bounds, float2.Zero, channel, BlendMode.Alpha) { }
|
||||
@@ -31,19 +31,19 @@ namespace OpenRA.Graphics
|
||||
|
||||
public Sprite(Sheet sheet, Rectangle bounds, float2 offset, TextureChannel channel, BlendMode blendMode)
|
||||
{
|
||||
this.sheet = sheet;
|
||||
this.bounds = bounds;
|
||||
this.offset = offset;
|
||||
this.channel = channel;
|
||||
this.size = new float2(bounds.Size);
|
||||
this.blendMode = blendMode;
|
||||
Sheet = sheet;
|
||||
Bounds = bounds;
|
||||
Offset = offset;
|
||||
Channel = channel;
|
||||
Size = new float2(bounds.Size);
|
||||
BlendMode = blendMode;
|
||||
|
||||
this.fractionalOffset = offset / this.size;
|
||||
FractionalOffset = offset / Size;
|
||||
|
||||
left = (float)bounds.Left / sheet.Size.Width;
|
||||
top = (float)bounds.Top / sheet.Size.Height;
|
||||
right = (float)bounds.Right / sheet.Size.Width;
|
||||
bottom = (float)bounds.Bottom / sheet.Size.Height;
|
||||
Left = (float)bounds.Left / sheet.Size.Width;
|
||||
Top = (float)bounds.Top / sheet.Size.Height;
|
||||
Right = (float)bounds.Right / sheet.Size.Width;
|
||||
Bottom = (float)bounds.Bottom / sheet.Size.Height;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,15 +117,15 @@ namespace OpenRA.Graphics
|
||||
unsafe
|
||||
{
|
||||
var p = (byte*)bitmap.Buffer;
|
||||
var dest = s.sheet.GetData();
|
||||
var destStride = s.sheet.Size.Width * 4;
|
||||
var dest = s.Sheet.GetData();
|
||||
var destStride = s.Sheet.Size.Width * 4;
|
||||
|
||||
for (var j = 0; j < s.size.Y; j++)
|
||||
for (var j = 0; j < s.Size.Y; j++)
|
||||
{
|
||||
for (var i = 0; i < s.size.X; i++)
|
||||
for (var i = 0; i < s.Size.X; i++)
|
||||
if (p[i] != 0)
|
||||
{
|
||||
var q = destStride * (j + s.bounds.Top) + 4 * (i + s.bounds.Left);
|
||||
var q = destStride * (j + s.Bounds.Top) + 4 * (i + s.Bounds.Left);
|
||||
dest[q] = c.Second.B;
|
||||
dest[q + 1] = c.Second.G;
|
||||
dest[q + 2] = c.Second.R;
|
||||
@@ -136,7 +136,7 @@ namespace OpenRA.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
s.sheet.CommitData();
|
||||
s.Sheet.CommitData();
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
public void DrawSprite(Sprite s, float2 location, PaletteReference pal)
|
||||
{
|
||||
DrawSprite(s, location, pal.Index, s.size);
|
||||
DrawSprite(s, location, pal.Index, s.Size);
|
||||
}
|
||||
|
||||
public void DrawSprite(Sprite s, float2 location, PaletteReference pal, float2 size)
|
||||
@@ -63,25 +63,25 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
renderer.CurrentBatchRenderer = this;
|
||||
|
||||
if (s.sheet != currentSheet)
|
||||
if (s.Sheet != currentSheet)
|
||||
Flush();
|
||||
|
||||
if (s.blendMode != currentBlend)
|
||||
if (s.BlendMode != currentBlend)
|
||||
Flush();
|
||||
|
||||
if (nv + 4 > renderer.TempBufferSize)
|
||||
Flush();
|
||||
|
||||
currentBlend = s.blendMode;
|
||||
currentSheet = s.sheet;
|
||||
Util.FastCreateQuad(vertices, location + s.fractionalOffset * size, s, paletteIndex, nv, size);
|
||||
currentBlend = s.BlendMode;
|
||||
currentSheet = s.Sheet;
|
||||
Util.FastCreateQuad(vertices, location + s.FractionalOffset * size, s, paletteIndex, nv, size);
|
||||
nv += 4;
|
||||
}
|
||||
|
||||
// For RGBASpriteRenderer, which doesn't use palettes
|
||||
public void DrawSprite(Sprite s, float2 location)
|
||||
{
|
||||
DrawSprite(s, location, 0, s.size);
|
||||
DrawSprite(s, location, 0, s.Size);
|
||||
}
|
||||
|
||||
public void DrawSprite(Sprite s, float2 location, float2 size)
|
||||
@@ -93,17 +93,17 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
renderer.CurrentBatchRenderer = this;
|
||||
|
||||
if (s.sheet != currentSheet)
|
||||
if (s.Sheet != currentSheet)
|
||||
Flush();
|
||||
|
||||
if (s.blendMode != currentBlend)
|
||||
if (s.BlendMode != currentBlend)
|
||||
Flush();
|
||||
|
||||
if (nv + 4 > renderer.TempBufferSize)
|
||||
Flush();
|
||||
|
||||
currentSheet = s.sheet;
|
||||
currentBlend = s.blendMode;
|
||||
currentSheet = s.Sheet;
|
||||
currentBlend = s.BlendMode;
|
||||
Util.FastCreateQuad(vertices, a, b, c, d, s, 0, nv);
|
||||
nv += 4;
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace OpenRA.Graphics
|
||||
foreach (var cell in map.Cells)
|
||||
{
|
||||
var tile = wr.Theater.TileSprite(map.MapTiles.Value[cell]);
|
||||
var pos = wr.ScreenPosition(map.CenterOfCell(cell)) + tile.offset - 0.5f * tile.size;
|
||||
Util.FastCreateQuad(vertices, pos, tile, terrainPalette, nv, tile.size);
|
||||
var pos = wr.ScreenPosition(map.CenterOfCell(cell)) + tile.Offset - 0.5f * tile.Size;
|
||||
Util.FastCreateQuad(vertices, pos, tile, terrainPalette, nv, tile.Size);
|
||||
nv += 4;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
var verticesPerRow = 4 * map.Bounds.Width;
|
||||
var cells = viewport.VisibleCells;
|
||||
var shape = wr.world.Map.TileShape;
|
||||
var shape = wr.World.Map.TileShape;
|
||||
|
||||
// Only draw the rows that are visible.
|
||||
// VisibleCells is clamped to the map, so additional checks are unnecessary
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Graphics
|
||||
sheetBuilder = new SheetBuilder(SheetType.Indexed, allocate);
|
||||
templates = new Dictionary<ushort, Sprite[]>();
|
||||
|
||||
var frameCache = new FrameCache(Game.modData.SpriteLoaders, tileset.Extensions);
|
||||
var frameCache = new FrameCache(Game.ModData.SpriteLoaders, tileset.Extensions);
|
||||
foreach (var t in tileset.Templates)
|
||||
{
|
||||
var allFrames = frameCache[t.Value.Image];
|
||||
@@ -48,7 +48,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
// Ignore the offsets baked into R8 sprites
|
||||
if (tileset.IgnoreTileSpriteOffsets)
|
||||
sprites = sprites.Select(s => new Sprite(s.sheet, s.bounds, float2.Zero, s.channel, s.blendMode));
|
||||
sprites = sprites.Select(s => new Sprite(s.Sheet, s.Bounds, float2.Zero, s.Channel, s.BlendMode));
|
||||
|
||||
templates.Add(t.Value.Id, sprites.ToArray());
|
||||
}
|
||||
@@ -91,8 +91,8 @@ namespace OpenRA.Graphics
|
||||
var u = tileShape == TileShape.Rectangle ? x : (x - y) / 2f;
|
||||
var v = tileShape == TileShape.Rectangle ? y : (x + y) / 2f;
|
||||
|
||||
var tl = new float2(u * tileSize.Width, (v - 0.5f * tileInfo.Height) * tileSize.Height) - 0.5f * sprite.size;
|
||||
var rect = new Rectangle((int)(tl.X + sprite.offset.X), (int)(tl.Y + sprite.offset.Y), (int)sprite.size.X, (int)sprite.size.Y);
|
||||
var tl = new float2(u * tileSize.Width, (v - 0.5f * tileInfo.Height) * tileSize.Height) - 0.5f * sprite.Size;
|
||||
var rect = new Rectangle((int)(tl.X + sprite.Offset.X), (int)(tl.Y + sprite.Offset.Y), (int)sprite.Size.X, (int)sprite.Size.Y);
|
||||
templateRect = templateRect.HasValue ? Rectangle.Union(templateRect.Value, rect) : rect;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,13 +49,13 @@ namespace OpenRA.Graphics
|
||||
public void BeforeRender(WorldRenderer wr) { }
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
Game.Renderer.SpriteRenderer.DrawSprite(sprite, screenPos, palette, sprite.size * scale);
|
||||
Game.Renderer.SpriteRenderer.DrawSprite(sprite, screenPos, palette, sprite.Size * scale);
|
||||
}
|
||||
|
||||
public void RenderDebugGeometry(WorldRenderer wr)
|
||||
{
|
||||
var offset = screenPos + sprite.offset;
|
||||
Game.Renderer.LineRenderer.DrawRect(offset, offset + sprite.size, Color.Red);
|
||||
var offset = screenPos + sprite.Offset;
|
||||
Game.Renderer.LineRenderer.DrawRect(offset, offset + sprite.Size, Color.Red);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace OpenRA.Graphics
|
||||
public static class Util
|
||||
{
|
||||
// yes, our channel order is nuts.
|
||||
static readonly int[] channelMasks = { 2, 1, 0, 3 };
|
||||
static float[] channelSelect = { 0.75f, 0.25f, -0.25f, -0.75f };
|
||||
static readonly int[] ChannelMasks = { 2, 1, 0, 3 };
|
||||
static readonly float[] ChannelSelect = { 0.75f, 0.25f, -0.25f, -0.75f };
|
||||
|
||||
public static void FastCreateQuad(Vertex[] vertices, float2 o, Sprite r, int palette, int nv, float2 size)
|
||||
{
|
||||
@@ -32,23 +32,23 @@ namespace OpenRA.Graphics
|
||||
public static void FastCreateQuad(Vertex[] vertices, float2 a, float2 b, float2 c, float2 d, Sprite r, int palette, int nv)
|
||||
{
|
||||
var attribP = palette / (float)HardwarePalette.MaxPalettes;
|
||||
var attribC = channelSelect[(int)r.channel];
|
||||
var attribC = ChannelSelect[(int)r.Channel];
|
||||
|
||||
vertices[nv] = new Vertex(a, r.left, r.top, attribP, attribC);
|
||||
vertices[nv + 1] = new Vertex(b, r.right, r.top, attribP, attribC);
|
||||
vertices[nv + 2] = new Vertex(c, r.right, r.bottom, attribP, attribC);
|
||||
vertices[nv + 3] = new Vertex(d, r.left, r.bottom, attribP, attribC);
|
||||
vertices[nv] = new Vertex(a, r.Left, r.Top, attribP, attribC);
|
||||
vertices[nv + 1] = new Vertex(b, r.Right, r.Top, attribP, attribC);
|
||||
vertices[nv + 2] = new Vertex(c, r.Right, r.Bottom, attribP, attribC);
|
||||
vertices[nv + 3] = new Vertex(d, r.Left, r.Bottom, attribP, attribC);
|
||||
}
|
||||
|
||||
public static void FastCopyIntoChannel(Sprite dest, byte[] src) { FastCopyIntoChannel(dest, 0, src); }
|
||||
public static void FastCopyIntoChannel(Sprite dest, int channelOffset, byte[] src)
|
||||
{
|
||||
var data = dest.sheet.GetData();
|
||||
var srcStride = dest.bounds.Width;
|
||||
var destStride = dest.sheet.Size.Width * 4;
|
||||
var destOffset = destStride * dest.bounds.Top + dest.bounds.Left * 4 + channelMasks[(int)dest.channel + channelOffset];
|
||||
var data = dest.Sheet.GetData();
|
||||
var srcStride = dest.Bounds.Width;
|
||||
var destStride = dest.Sheet.Size.Width * 4;
|
||||
var destOffset = destStride * dest.Bounds.Top + dest.Bounds.Left * 4 + ChannelMasks[(int)dest.Channel + channelOffset];
|
||||
var destSkip = destStride - 4 * srcStride;
|
||||
var height = dest.bounds.Height;
|
||||
var height = dest.Bounds.Height;
|
||||
|
||||
var srcOffset = 0;
|
||||
for (var j = 0; j < height; j++)
|
||||
@@ -65,12 +65,12 @@ namespace OpenRA.Graphics
|
||||
|
||||
public static void FastCopyIntoSprite(Sprite dest, Bitmap src)
|
||||
{
|
||||
var data = dest.sheet.GetData();
|
||||
var dataStride = dest.sheet.Size.Width * 4;
|
||||
var x = dest.bounds.Left * 4;
|
||||
var width = dest.bounds.Width * 4;
|
||||
var y = dest.bounds.Top;
|
||||
var height = dest.bounds.Height;
|
||||
var data = dest.Sheet.GetData();
|
||||
var dataStride = dest.Sheet.Size.Width * 4;
|
||||
var x = dest.Bounds.Left * 4;
|
||||
var width = dest.Bounds.Width * 4;
|
||||
var y = dest.Bounds.Top;
|
||||
var height = dest.Bounds.Height;
|
||||
|
||||
var bd = src.LockBits(src.Bounds(),
|
||||
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||
|
||||
@@ -98,14 +98,14 @@ namespace OpenRA.Graphics
|
||||
var br = wr.ScreenPxPosition(map.CenterOfCell(Map.MapToCell(map.TileShape, new CPos(b.Right, b.Bottom))) + new WVec(511, 511, 0));
|
||||
mapBounds = Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y);
|
||||
|
||||
maxGroundHeight = wr.world.TileSet.MaxGroundHeight;
|
||||
maxGroundHeight = wr.World.TileSet.MaxGroundHeight;
|
||||
CenterLocation = (tl + br) / 2;
|
||||
Zoom = Game.Settings.Graphics.PixelDouble ? 2 : 1;
|
||||
}
|
||||
|
||||
public CPos ViewToWorld(int2 view)
|
||||
{
|
||||
return worldRenderer.world.Map.CellContaining(worldRenderer.Position(ViewToWorldPx(view)));
|
||||
return worldRenderer.World.Map.CellContaining(worldRenderer.Position(ViewToWorldPx(view)));
|
||||
}
|
||||
|
||||
public int2 ViewToWorldPx(int2 view) { return (1f / Zoom * view.ToFloat2()).ToInt2() + TopLeft; }
|
||||
@@ -142,7 +142,7 @@ namespace OpenRA.Graphics
|
||||
get
|
||||
{
|
||||
// Visible rectangle in world coordinates (expanded to the corners of the cells)
|
||||
var map = worldRenderer.world.Map;
|
||||
var map = worldRenderer.World.Map;
|
||||
var ctl = map.CenterOfCell(VisibleCells.TopLeft) - new WVec(512, 512, 0);
|
||||
var cbr = map.CenterOfCell(VisibleCells.BottomRight) + new WVec(512, 512, 0);
|
||||
|
||||
@@ -159,7 +159,7 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
if (cellsDirty)
|
||||
{
|
||||
var map = worldRenderer.world.Map;
|
||||
var map = worldRenderer.World.Map;
|
||||
var wtl = worldRenderer.Position(TopLeft);
|
||||
var wbr = worldRenderer.Position(BottomRight);
|
||||
|
||||
|
||||
@@ -86,16 +86,16 @@ namespace OpenRA.Graphics
|
||||
var s = sheetBuilder.Allocate(new Size(su, sv));
|
||||
Util.FastCopyIntoChannel(s, 0, colors);
|
||||
Util.FastCopyIntoChannel(s, 1, normals);
|
||||
s.sheet.CommitData();
|
||||
s.Sheet.CommitData();
|
||||
|
||||
var channelP = ChannelSelect[(int)s.channel];
|
||||
var channelC = ChannelSelect[(int)s.channel + 1];
|
||||
var channelP = ChannelSelect[(int)s.Channel];
|
||||
var channelC = ChannelSelect[(int)s.Channel + 1];
|
||||
return new Vertex[4]
|
||||
{
|
||||
new Vertex(coord(0, 0), s.left, s.top, channelP, channelC),
|
||||
new Vertex(coord(su, 0), s.right, s.top, channelP, channelC),
|
||||
new Vertex(coord(su, sv), s.right, s.bottom, channelP, channelC),
|
||||
new Vertex(coord(0, sv), s.left, s.bottom, channelP, channelC)
|
||||
new Vertex(coord(0, 0), s.Left, s.Top, channelP, channelC),
|
||||
new Vertex(coord(su, 0), s.Right, s.Top, channelP, channelC),
|
||||
new Vertex(coord(su, sv), s.Right, s.Bottom, channelP, channelC),
|
||||
new Vertex(coord(0, sv), s.Left, s.Bottom, channelP, channelC)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Graphics
|
||||
foreach (var s in sequences)
|
||||
LoadVoxelsForUnit(s.Key, s.Value);
|
||||
|
||||
Game.modData.VoxelLoader.RefreshBuffer();
|
||||
Game.ModData.VoxelLoader.RefreshBuffer();
|
||||
}
|
||||
|
||||
static Voxel LoadVoxel(string unit, MiniYaml info)
|
||||
@@ -47,12 +47,12 @@ namespace OpenRA.Graphics
|
||||
hva = fields[1].Trim();
|
||||
}
|
||||
|
||||
return Game.modData.VoxelLoader.Load(vxl, hva);
|
||||
return Game.ModData.VoxelLoader.Load(vxl, hva);
|
||||
}
|
||||
|
||||
static void LoadVoxelsForUnit(string unit, MiniYaml sequences)
|
||||
{
|
||||
Game.modData.LoadScreen.Display();
|
||||
Game.ModData.LoadScreen.Display();
|
||||
try
|
||||
{
|
||||
var seq = sequences.ToDictionary(my => LoadVoxel(unit, my));
|
||||
|
||||
@@ -161,8 +161,8 @@ namespace OpenRA.Graphics
|
||||
|
||||
var sprite = sheetBuilder.Allocate(spriteSize, spriteOffset);
|
||||
var shadowSprite = sheetBuilder.Allocate(shadowSpriteSize, shadowSpriteOffset);
|
||||
var sb = sprite.bounds;
|
||||
var ssb = shadowSprite.bounds;
|
||||
var sb = sprite.Bounds;
|
||||
var ssb = shadowSprite.Bounds;
|
||||
var spriteCenter = new float2(sb.Left + sb.Width / 2, sb.Top + sb.Height / 2);
|
||||
var shadowCenter = new float2(ssb.Left + ssb.Width / 2, ssb.Top + ssb.Height / 2);
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace OpenRA.Graphics
|
||||
var correctionTransform = Util.MatrixMultiply(translateMtx, FlipMtx);
|
||||
var shadowCorrectionTransform = Util.MatrixMultiply(shadowTranslateMtx, ShadowScaleFlipMtx);
|
||||
|
||||
doRender.Add(Pair.New<Sheet, Action>(sprite.sheet, () =>
|
||||
doRender.Add(Pair.New<Sheet, Action>(sprite.Sheet, () =>
|
||||
{
|
||||
foreach (var v in voxels)
|
||||
{
|
||||
@@ -262,7 +262,7 @@ namespace OpenRA.Graphics
|
||||
shader.SetVec("AmbientLight", ambientLight, 3);
|
||||
shader.SetVec("DiffuseLight", diffuseLight, 3);
|
||||
|
||||
shader.Render(() => renderer.DrawBatch(Game.modData.VoxelLoader.VertexBuffer, renderData.Start, renderData.Count, PrimitiveType.QuadList));
|
||||
shader.Render(() => renderer.DrawBatch(Game.ModData.VoxelLoader.VertexBuffer, renderData.Start, renderData.Count, PrimitiveType.QuadList));
|
||||
}
|
||||
|
||||
public void BeginFrame()
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
public sealed class WorldRenderer : IDisposable
|
||||
{
|
||||
public readonly World world;
|
||||
public readonly World World;
|
||||
public readonly Theater Theater;
|
||||
public Viewport Viewport { get; private set; }
|
||||
|
||||
@@ -42,10 +42,10 @@ namespace OpenRA.Graphics
|
||||
|
||||
internal WorldRenderer(World world)
|
||||
{
|
||||
this.world = world;
|
||||
World = world;
|
||||
Viewport = new Viewport(this, world.Map);
|
||||
|
||||
foreach (var pal in world.traitDict.ActorsWithTrait<ILoadsPalettes>())
|
||||
foreach (var pal in world.TraitDict.ActorsWithTrait<ILoadsPalettes>())
|
||||
pal.Trait.LoadPalettes(this);
|
||||
|
||||
palette.Initialize();
|
||||
@@ -70,27 +70,27 @@ namespace OpenRA.Graphics
|
||||
List<IRenderable> GenerateRenderables()
|
||||
{
|
||||
var comparer = new RenderableComparer(this);
|
||||
var actors = world.ScreenMap.ActorsInBox(Viewport.TopLeft, Viewport.BottomRight)
|
||||
.Append(world.WorldActor)
|
||||
var actors = World.ScreenMap.ActorsInBox(Viewport.TopLeft, Viewport.BottomRight)
|
||||
.Append(World.WorldActor)
|
||||
.ToList();
|
||||
|
||||
// Include player actor for the rendered player
|
||||
if (world.RenderPlayer != null)
|
||||
actors.Add(world.RenderPlayer.PlayerActor);
|
||||
if (World.RenderPlayer != null)
|
||||
actors.Add(World.RenderPlayer.PlayerActor);
|
||||
|
||||
var worldRenderables = actors.SelectMany(a => a.Render(this));
|
||||
if (world.OrderGenerator != null)
|
||||
worldRenderables = worldRenderables.Concat(world.OrderGenerator.Render(this, world));
|
||||
if (World.OrderGenerator != null)
|
||||
worldRenderables = worldRenderables.Concat(World.OrderGenerator.Render(this, World));
|
||||
|
||||
worldRenderables = worldRenderables.OrderBy(r => r, comparer);
|
||||
|
||||
// Effects are drawn on top of all actors
|
||||
// HACK: Effects aren't interleaved with actors.
|
||||
var effectRenderables = world.Effects
|
||||
var effectRenderables = World.Effects
|
||||
.SelectMany(e => e.Render(this));
|
||||
|
||||
if (world.OrderGenerator != null)
|
||||
effectRenderables = effectRenderables.Concat(world.OrderGenerator.RenderAfterWorld(this, world));
|
||||
if (World.OrderGenerator != null)
|
||||
effectRenderables = effectRenderables.Concat(World.OrderGenerator.RenderAfterWorld(this, World));
|
||||
|
||||
// Iterating via foreach copies the structs, so enumerate by index
|
||||
var renderables = worldRenderables.Concat(effectRenderables).ToList();
|
||||
@@ -107,7 +107,7 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
RefreshPalette();
|
||||
|
||||
if (world.IsShellmap && !Game.Settings.Game.ShowShellmap)
|
||||
if (World.IsShellmap && !Game.Settings.Game.ShowShellmap)
|
||||
return;
|
||||
|
||||
var renderables = GenerateRenderables();
|
||||
@@ -121,13 +121,13 @@ namespace OpenRA.Graphics
|
||||
renderables[i].Render(this);
|
||||
|
||||
// added for contrails
|
||||
foreach (var a in world.ActorsWithTrait<IPostRender>())
|
||||
foreach (var a in World.ActorsWithTrait<IPostRender>())
|
||||
if (a.Actor.IsInWorld && !a.Actor.Destroyed)
|
||||
a.Trait.RenderAfterWorld(this, a.Actor);
|
||||
|
||||
var renderShroud = world.RenderPlayer != null ? world.RenderPlayer.Shroud : null;
|
||||
var renderShroud = World.RenderPlayer != null ? World.RenderPlayer.Shroud : null;
|
||||
|
||||
foreach (var a in world.ActorsWithTrait<IRenderShroud>())
|
||||
foreach (var a in World.ActorsWithTrait<IRenderShroud>())
|
||||
a.Trait.RenderShroud(this, renderShroud);
|
||||
|
||||
if (devTrait.Value != null && devTrait.Value.ShowDebugGeometry)
|
||||
@@ -136,7 +136,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
Game.Renderer.DisableScissor();
|
||||
|
||||
var overlayRenderables = world.Selection.Actors.Where(a => !a.Destroyed)
|
||||
var overlayRenderables = World.Selection.Actors.Where(a => !a.Destroyed)
|
||||
.SelectMany(a => a.TraitsImplementing<IPostRenderSelection>())
|
||||
.SelectMany(t => t.RenderAfterWorld(this))
|
||||
.ToList();
|
||||
@@ -156,12 +156,12 @@ namespace OpenRA.Graphics
|
||||
foreach (var r in g)
|
||||
r.RenderDebugGeometry(this);
|
||||
|
||||
if (!world.IsShellmap && Game.Settings.Game.AlwaysShowStatusBars)
|
||||
if (!World.IsShellmap && Game.Settings.Game.AlwaysShowStatusBars)
|
||||
{
|
||||
foreach (var g in world.Actors.Where(a => !a.Destroyed
|
||||
foreach (var g in World.Actors.Where(a => !a.Destroyed
|
||||
&& a.HasTrait<Selectable>()
|
||||
&& !world.FogObscures(a)
|
||||
&& !world.Selection.Actors.Contains(a)))
|
||||
&& !World.FogObscures(a)
|
||||
&& !World.Selection.Actors.Contains(a)))
|
||||
|
||||
DrawRollover(g);
|
||||
}
|
||||
@@ -206,14 +206,14 @@ namespace OpenRA.Graphics
|
||||
|
||||
public void RefreshPalette()
|
||||
{
|
||||
palette.ApplyModifiers(world.WorldActor.TraitsImplementing<IPaletteModifier>());
|
||||
palette.ApplyModifiers(World.WorldActor.TraitsImplementing<IPaletteModifier>());
|
||||
Game.Renderer.SetPalette(palette);
|
||||
}
|
||||
|
||||
// Conversion between world and screen coordinates
|
||||
public float2 ScreenPosition(WPos pos)
|
||||
{
|
||||
var ts = Game.modData.Manifest.TileSize;
|
||||
var ts = Game.ModData.Manifest.TileSize;
|
||||
return new float2(ts.Width * pos.X / 1024f, ts.Height * (pos.Y - pos.Z) / 1024f);
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ namespace OpenRA.Graphics
|
||||
// For scaling vectors to pixel sizes in the voxel renderer
|
||||
public float[] ScreenVector(WVec vec)
|
||||
{
|
||||
var ts = Game.modData.Manifest.TileSize;
|
||||
var ts = Game.ModData.Manifest.TileSize;
|
||||
return new float[] { ts.Width * vec.X / 1024f, ts.Height * vec.Y / 1024f, ts.Height * vec.Z / 1024f, 1 };
|
||||
}
|
||||
|
||||
@@ -240,13 +240,13 @@ namespace OpenRA.Graphics
|
||||
|
||||
public float ScreenZPosition(WPos pos, int offset)
|
||||
{
|
||||
var ts = Game.modData.Manifest.TileSize;
|
||||
var ts = Game.ModData.Manifest.TileSize;
|
||||
return (pos.Y + pos.Z + offset) * ts.Height / 1024f;
|
||||
}
|
||||
|
||||
public WPos Position(int2 screenPx)
|
||||
{
|
||||
var ts = Game.modData.Manifest.TileSize;
|
||||
var ts = Game.ModData.Manifest.TileSize;
|
||||
return new WPos(1024 * screenPx.X / ts.Width, 1024 * screenPx.Y / ts.Height, 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user