Replace TexAtlas.PackedAtlasResults with List of ValueTuple

This commit is contained in:
YoshiRulz 2021-03-25 19:10:55 +10:00
parent 98c7db0274
commit fc30b0bd26
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 9 additions and 26 deletions

View File

@ -83,16 +83,16 @@ namespace BizHawk.Bizware.BizwareGL
var results = TexAtlas.PackAtlas(atlasItems); var results = TexAtlas.PackAtlas(atlasItems);
// this isn't supported yet: // this isn't supported yet:
if (results.Atlases.Count > 1) if (results.Count > 1)
throw new InvalidOperationException("Art files too big for atlas"); throw new InvalidOperationException("Art files too big for atlas");
// prepare the output buffer // prepare the output buffer
BitmapBuffer bmpResult = new BitmapBuffer(results.Atlases[0].Size); BitmapBuffer bmpResult = new BitmapBuffer(results[0].Size);
//for each item, copy it into the output buffer and set the tex parameters on them //for each item, copy it into the output buffer and set the tex parameters on them
for (int i = 0; i < atlasItems.Count; i++) for (int i = 0; i < atlasItems.Count; i++)
{ {
var item = results.Atlases[0].Items[i]; var item = results[0].Items[i];
var artAndBitmap = (KeyValuePair<Art, BitmapBuffer>)item.Item; var artAndBitmap = (KeyValuePair<Art, BitmapBuffer>)item.Item;
var art = artAndBitmap.Key; var art = artAndBitmap.Key;
var bitmap = artAndBitmap.Value; var bitmap = artAndBitmap.Value;

View File

@ -31,25 +31,14 @@ namespace BizHawk.Bizware.BizwareGL
public readonly List<RectangleBinPack.Node> nodes = new List<RectangleBinPack.Node>(); public readonly List<RectangleBinPack.Node> nodes = new List<RectangleBinPack.Node>();
} }
public class PackedAtlasResults
{
public class SingleAtlas
{
public Size Size;
public List<RectItem> Items;
}
public List<SingleAtlas> Atlases = new List<SingleAtlas>();
}
public static int MaxSizeBits = 16; public static int MaxSizeBits = 16;
/// <summary> /// <summary>
/// packs the supplied RectItems into an atlas. Modifies the RectItems with x/y values of location in new atlas. /// packs the supplied RectItems into an atlas. Modifies the RectItems with x/y values of location in new atlas.
/// </summary> /// </summary>
public static PackedAtlasResults PackAtlas(IEnumerable<RectItem> items) public static IReadOnlyList<(Size Size, List<RectItem> Items)> PackAtlas(IReadOnlyCollection<RectItem> items)
{ {
var ret = new PackedAtlasResults(); List<(Size Size, List<RectItem> Items)> atlases = new();
ret.Atlases.Add(new PackedAtlasResults.SingleAtlas());
// initially, we'll try all the items; none remain // initially, we'll try all the items; none remain
var currentItems = new List<RectItem>(items); var currentItems = new List<RectItem>(items);
@ -132,17 +121,14 @@ namespace BizHawk.Bizware.BizwareGL
} }
//we found a fit. setup this atlas in the result and drop the items into it //we found a fit. setup this atlas in the result and drop the items into it
var atlas = ret.Atlases[ret.Atlases.Count - 1]; atlases.Add((new Size(tfpFinal.w, tfpFinal.h), new List<RectItem>(currentItems)));
atlas.Size.Width = tfpFinal.w;
atlas.Size.Height = tfpFinal.h;
atlas.Items = new List<RectItem>(currentItems);
foreach (var item in currentItems) foreach (var item in currentItems)
{ {
object o = item.Item; object o = item.Item;
var node = tfpFinal.nodes.Find((x) => x.ri == item); var node = tfpFinal.nodes.Find((x) => x.ri == item);
item.X = node.x; item.X = node.x;
item.Y = node.y; item.Y = node.y;
item.TexIndex = ret.Atlases.Count - 1; item.TexIndex = atlases.Count - 1;
} }
//if we have any items left, we've got to run this again //if we have any items left, we've got to run this again
@ -153,14 +139,11 @@ namespace BizHawk.Bizware.BizwareGL
currentItems.AddRange(remainItems); currentItems.AddRange(remainItems);
remainItems.Clear(); remainItems.Clear();
ret.Atlases.Add(new PackedAtlasResults.SingleAtlas());
goto RETRY; goto RETRY;
} }
if (ret.Atlases.Count > 1) if (atlases.Count > 1) Console.WriteLine($"Created animset with >1 texture ({atlases.Count} textures)");
Console.WriteLine("Created animset with >1 texture ({0} textures)", ret.Atlases.Count); return atlases;
return ret;
} }
// original file: RectangleBinPack.cpp // original file: RectangleBinPack.cpp