From 89c1406f5a05e8bb2491132890df35d81c9e0e2d Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 25 Mar 2021 19:13:18 +1000 Subject: [PATCH] Minor refactorings in TexAtlas.PackAtlas --- src/BizHawk.Bizware.BizwareGL/TexAtlas.cs | 37 ++++++++--------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/BizHawk.Bizware.BizwareGL/TexAtlas.cs b/src/BizHawk.Bizware.BizwareGL/TexAtlas.cs index 52741a0ed2..668b9dc6e1 100644 --- a/src/BizHawk.Bizware.BizwareGL/TexAtlas.cs +++ b/src/BizHawk.Bizware.BizwareGL/TexAtlas.cs @@ -38,12 +38,13 @@ namespace BizHawk.Bizware.BizwareGL /// public static IReadOnlyList<(Size Size, List Items)> PackAtlas(IReadOnlyCollection items) { - List<(Size Size, List Items)> atlases = new(); + List<(Size, List)> atlases = new(); // initially, we'll try all the items; none remain var currentItems = new List(items); var remainItems = new List(); + RETRY1: RETRY: // this is where the texture size range is determined. @@ -84,31 +85,19 @@ namespace BizHawk.Bizware.BizwareGL }); //find the best fit among the potential sizes that worked - long best = long.MaxValue; - TryFitParam tfpFinal = null; - foreach (TryFitParam tfp in todoSizes) + var best = long.MaxValue; + var tfpFinal = todoSizes[0]; + foreach (var tfp in todoSizes) { - if (tfp.ok) + if (!tfp.ok) continue; + var area = tfp.w * (long) tfp.h; + if (area > best) continue; // larger than best, not interested + if (area == best) // same area, compare perimeter as tie-breaker (to create squares, which are nicer to look at) { - long area = (long)tfp.w * (long)tfp.h; - long perimeter = (long)tfp.w + (long)tfp.h; - if (area < best) - { - best = area; - tfpFinal = tfp; - } - else if (area == best) - { - //try to minimize perimeter (to create squares, which are nicer to look at) - if (tfpFinal == null) - { } - else if (perimeter < tfpFinal.w + tfpFinal.h) - { - best = area; - tfpFinal = tfp; - } - } + if (tfp.w + tfp.h >= tfpFinal.w + tfpFinal.h) continue; } + best = area; + tfpFinal = tfp; } //did we find any fit? @@ -139,7 +128,7 @@ namespace BizHawk.Bizware.BizwareGL currentItems.AddRange(remainItems); remainItems.Clear(); - goto RETRY; + goto RETRY1; } if (atlases.Count > 1) Console.WriteLine($"Created animset with >1 texture ({atlases.Count} textures)");