Remove requirement for depth sprites to share color sheet.

This commit is contained in:
Paul Chote
2018-05-31 23:36:14 +00:00
committed by reaperrr
parent 2f2a7724d5
commit 8461a82577
5 changed files with 35 additions and 47 deletions

View File

@@ -268,38 +268,21 @@ namespace OpenRA.Mods.Common.Graphics
{
var depthSpriteFrame = LoadField(d, "DepthSpriteFrame", 0);
var depthOffset = LoadField(d, "DepthSpriteOffset", float2.Zero);
var depthSprites = cache.AllCached(depthSprite)
.Select(s => s[depthSpriteFrame]);
Func<int, IEnumerable<int>> getDepthFrame = _ => new int[] { depthSpriteFrame };
var ds = cache[depthSprite, getDepthFrame][depthSpriteFrame];
sprites = sprites.Select(s =>
{
if (s == null)
return null;
// The depth sprite must live on the same sheet as the main sprite
var ds = depthSprites.FirstOrDefault(dss => dss.Sheet == s.Sheet);
if (ds == null)
{
// The sequence has probably overflowed onto a new sheet.
// Allocating a new depth sprite on this sheet will almost certainly work
ds = cache.Reload(depthSprite)[depthSpriteFrame];
depthSprites = cache.AllCached(depthSprite)
.Select(ss => ss[depthSpriteFrame]);
// If that doesn't work then we may be referencing a cached sprite from an earlier sheet
// TODO: We could try and reallocate the main sprite, but that requires more complicated code and a perf hit
// We'll only cross that bridge if this becomes a problem in reality
if (ds.Sheet != s.Sheet)
throw new SheetOverflowException("Cross-sheet depth sprite reference: {0}.{1}: {2}");
}
var cw = (ds.Bounds.Left + ds.Bounds.Right) / 2 + (int)(s.Offset.X + depthOffset.X);
var ch = (ds.Bounds.Top + ds.Bounds.Bottom) / 2 + (int)(s.Offset.Y + depthOffset.Y);
var w = s.Bounds.Width / 2;
var h = s.Bounds.Height / 2;
var r = Rectangle.FromLTRB(cw - w, ch - h, cw + w, ch + h);
return new SpriteWithSecondaryData(s, r, ds.Channel);
return new SpriteWithSecondaryData(s, ds.Sheet, r, ds.Channel);
}).ToArray();
}