Remove requirement for depth sprites to share color sheet.
This commit is contained in:
@@ -50,13 +50,15 @@ namespace OpenRA.Graphics
|
||||
|
||||
public class SpriteWithSecondaryData : Sprite
|
||||
{
|
||||
public readonly Sheet SecondarySheet;
|
||||
public readonly Rectangle SecondaryBounds;
|
||||
public readonly TextureChannel SecondaryChannel;
|
||||
public readonly float SecondaryTop, SecondaryLeft, SecondaryBottom, SecondaryRight;
|
||||
|
||||
public SpriteWithSecondaryData(Sprite s, Rectangle secondaryBounds, TextureChannel secondaryChannel)
|
||||
public SpriteWithSecondaryData(Sprite s, Sheet secondarySheet, Rectangle secondaryBounds, TextureChannel secondaryChannel)
|
||||
: base(s.Sheet, s.Bounds, s.ZRamp, s.Offset, s.Channel, s.BlendMode)
|
||||
{
|
||||
SecondarySheet = secondarySheet;
|
||||
SecondaryBounds = secondaryBounds;
|
||||
SecondaryChannel = secondaryChannel;
|
||||
SecondaryLeft = (float)Math.Min(secondaryBounds.Left, secondaryBounds.Right) / s.Sheet.Size.Width;
|
||||
|
||||
@@ -111,23 +111,6 @@ namespace OpenRA.Graphics
|
||||
return sprite;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Returns all instances of sets of sprites with the given filename</summary>
|
||||
public IEnumerable<Sprite[]> AllCached(string filename)
|
||||
{
|
||||
return sprites.GetOrAdd(filename);
|
||||
}
|
||||
|
||||
/// <summary>Loads and caches a new instance of sprites with the given filename</summary>
|
||||
public Sprite[] Reload(string filename)
|
||||
{
|
||||
var sprite = FrameLoader.GetFrames(fileSystem, filename, loaders)
|
||||
.Select(a => SheetBuilder.Add(a))
|
||||
.ToArray();
|
||||
|
||||
sprites.GetOrAdd(filename).Add(sprite);
|
||||
return sprite;
|
||||
}
|
||||
}
|
||||
|
||||
public class FrameCache
|
||||
|
||||
@@ -62,26 +62,46 @@ namespace OpenRA.Graphics
|
||||
|
||||
currentBlend = s.BlendMode;
|
||||
|
||||
// Check if the sheet (or secondary data sheet) have already been mapped
|
||||
var sheet = s.Sheet;
|
||||
var sheetIndex = 0;
|
||||
for (; sheetIndex < ns; sheetIndex++)
|
||||
if (sheets[sheetIndex] == sheet)
|
||||
break;
|
||||
|
||||
if (sheetIndex == ns)
|
||||
var secondarySheetIndex = 0;
|
||||
var ss = s as SpriteWithSecondaryData;
|
||||
if (ss != null)
|
||||
{
|
||||
if (sheetIndex == sheets.Length)
|
||||
{
|
||||
Flush();
|
||||
sheetIndex = 0;
|
||||
}
|
||||
var secondarySheet = ss.SecondarySheet;
|
||||
for (; secondarySheetIndex < ns; secondarySheetIndex++)
|
||||
if (sheets[secondarySheetIndex] == secondarySheet)
|
||||
break;
|
||||
}
|
||||
|
||||
// Make sure that we have enough free samplers to map both if needed, otherwise flush
|
||||
var needSamplers = (sheetIndex == ns ? 1 : 0) + (secondarySheetIndex == ns ? 1 : 0);
|
||||
if (ns + needSamplers >= sheets.Length)
|
||||
{
|
||||
Flush();
|
||||
sheetIndex = 0;
|
||||
if (ss != null)
|
||||
secondarySheetIndex = 1;
|
||||
}
|
||||
|
||||
if (sheetIndex >= ns)
|
||||
{
|
||||
sheets[sheetIndex] = sheet;
|
||||
ns += 1;
|
||||
}
|
||||
|
||||
// TODO: Add support for secondary channels on different sheets
|
||||
return new int2(sheetIndex, sheetIndex);
|
||||
if (secondarySheetIndex >= ns && ss != null)
|
||||
{
|
||||
sheets[secondarySheetIndex] = ss.SecondarySheet;
|
||||
ns += 1;
|
||||
}
|
||||
|
||||
return new int2(sheetIndex, secondarySheetIndex);
|
||||
}
|
||||
|
||||
internal void DrawSprite(Sprite s, float3 location, float paletteTextureIndex, float3 size)
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
// s and ss are guaranteed to use the same sheet
|
||||
// because of the custom terrain sheet allocation
|
||||
s = new SpriteWithSecondaryData(s, ss.Bounds, ss.Channel);
|
||||
s = new SpriteWithSecondaryData(s, s.Sheet, ss.Bounds, ss.Channel);
|
||||
}
|
||||
|
||||
return s;
|
||||
|
||||
Reference in New Issue
Block a user