Add depth buffer support to sprites and sequences.

This commit is contained in:
Paul Chote
2015-10-01 18:55:54 +01:00
parent 2634643d91
commit 2915db67c4
15 changed files with 44 additions and 39 deletions

View File

@@ -79,6 +79,7 @@ namespace OpenRA.Mods.Common.Graphics
public int Facings { get; private set; }
public int Tick { get; private set; }
public int ZOffset { get; private set; }
public float ZRamp { get; private set; }
public int ShadowStart { get; private set; }
public int ShadowZOffset { get; private set; }
public int[] Frames { get; private set; }
@@ -119,6 +120,7 @@ namespace OpenRA.Mods.Common.Graphics
ShadowStart = LoadField(d, "ShadowStart", -1);
ShadowZOffset = LoadField(d, "ShadowZOffset", DefaultShadowSpriteZOffset).Length;
ZOffset = LoadField(d, "ZOffset", WDist.Zero).Length;
ZRamp = LoadField(d, "ZRamp", 0);
Tick = LoadField(d, "Tick", 40);
transpose = LoadField(d, "Transpose", false);
Frames = LoadField<int[]>(d, "Frames", null);
@@ -139,7 +141,7 @@ namespace OpenRA.Mods.Common.Graphics
"{0}: Sequence {1}.{2}: UseClassicFacingFudge is only valid for 32 facings"
.F(info.Nodes[0].Location, sequence, animation));
var offset = LoadField(d, "Offset", float2.Zero);
var offset = LoadField(d, "Offset", float3.Zero);
var blendMode = LoadField(d, "BlendMode", BlendMode.Alpha);
MiniYaml combine;
@@ -159,7 +161,7 @@ namespace OpenRA.Mods.Common.Graphics
var subSrc = GetSpriteSrc(modData, tileSet, sequence, animation, sub.Key, sd);
var subSprites = cache[subSrc].Select(
s => new Sprite(s.Sheet,
FlipRectangle(s.Bounds, subFlipX, subFlipY),
FlipRectangle(s.Bounds, subFlipX, subFlipY), ZRamp,
new float2(subFlipX ? -s.Offset.X : s.Offset.X, subFlipY ? -s.Offset.Y : s.Offset.Y) + subOffset + offset,
s.Channel, blendMode));
@@ -182,7 +184,7 @@ namespace OpenRA.Mods.Common.Graphics
var src = GetSpriteSrc(modData, tileSet, sequence, animation, info.Value, d);
sprites = cache[src].Select(
s => new Sprite(s.Sheet,
FlipRectangle(s.Bounds, flipX, flipY),
FlipRectangle(s.Bounds, flipX, flipY), ZRamp,
new float2(flipX ? -s.Offset.X : s.Offset.X, flipY ? -s.Offset.Y : s.Offset.Y) + offset,
s.Channel, blendMode)).ToArray();
}

View File

@@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Graphics
// Draw sprite rect
var offset = pxOrigin + renderProxy.Sprite.Offset - 0.5f * renderProxy.Sprite.Size;
Game.Renderer.WorldRgbaColorRenderer.DrawRect(offset, offset + renderProxy.Sprite.Size, iz, Color.Red);
Game.Renderer.WorldRgbaColorRenderer.DrawRect(offset.XY, (offset + renderProxy.Sprite.Size).XY, iz, Color.Red);
// Draw transformed shadow sprite rect
var c = Color.Purple;

View File

@@ -228,7 +228,7 @@ namespace OpenRA.Mods.Common.Traits
{
return anims.Where(b => b.IsVisible
&& b.Animation.Animation.CurrentSequence != null)
.Select(a => (a.Animation.Animation.Image.Size * info.Scale).ToInt2())
.Select(a => (a.Animation.Animation.Image.Size.XY * info.Scale).ToInt2())
.FirstOrDefault();
}
}

View File

@@ -109,7 +109,7 @@ namespace OpenRA.Mods.Common.Traits
pipImages.PlayFetchIndex("groups", () => (int)group);
pipImages.Tick();
var pos = basePosition - (0.5f * pipImages.Image.Size).ToInt2() + new int2(9, 5);
var pos = basePosition - (0.5f * pipImages.Image.Size.XY).ToInt2() + new int2(9, 5);
yield return new UISpriteRenderable(pipImages.Image, self.CenterPosition, pos, 0, pal, 1f);
}
@@ -122,7 +122,7 @@ namespace OpenRA.Mods.Common.Traits
var pipImages = new Animation(self.World, "pips");
pipImages.PlayRepeating(PipStrings[0]);
var pipSize = pipImages.Image.Size.ToInt2();
var pipSize = pipImages.Image.Size.XY.ToInt2();
var pipxyBase = basePosition + new int2(1 - pipSize.X / 2, -(3 + pipSize.Y / 2));
var pipxyOffset = new int2(0, 0);
var pal = wr.Palette(Info.Palette);

View File

@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Traits
return Enumerable.Empty<IRenderable>();
var bounds = self.VisualBounds;
var halfSize = (0.5f * Anim.Image.Size).ToInt2();
var halfSize = (0.5f * Anim.Image.Size.XY).ToInt2();
var boundsOffset = new int2(bounds.Left + bounds.Right, bounds.Top + bounds.Bottom) / 2;
var sizeOffset = -halfSize;

View File

@@ -71,10 +71,10 @@ namespace OpenRA.Mods.Common.Traits
struct TileInfo
{
public readonly float2 ScreenPosition;
public readonly float3 ScreenPosition;
public readonly byte Variant;
public TileInfo(float2 screenPosition, byte variant)
public TileInfo(float3 screenPosition, byte variant)
{
ScreenPosition = screenPosition;
Variant = variant;

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Widgets
if (sprite != cachedSprite)
{
offset = 0.5f * (new float2(RenderBounds.Size) - sprite.Size);
offset = 0.5f * (new float2(RenderBounds.Size) - sprite.Size.XY);
cachedSprite = sprite;
}