Inventory grid: pipes get a round fillet, an edge ramp in canvas units and a refit (S16 worst rms .0855 to .0187, S32 .0431); look changes are compared without allocating
Thermal: a quarter-circle fillet between perpendicular bars replaces the polynomial smooth union that chamfered T and + junctions at S16. NoticeLook compares fourteen floats in place, no array and no enumerator per Flush. Harness: LateLook changes every look field on a live grid under a Mask with no Resize and compares it with a grid built with the change. The Overlay capture's bound is 16, it adds a half-alpha regime and the mutation driver runs it (control, concave-bracket-dropped, alpha-multiply-dropped). Thermal atlas bound .075 and hull cell bound .132 by the margin rule; driver mutants look-notice-deleted and look-trimmed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
69671be609
commit
52e52541f9
5 changed files with 186 additions and 42 deletions
|
|
@ -17,7 +17,8 @@ public static class InventoryGridOverlayCapture
|
|||
{
|
||||
private const string Pending = "InventoryGridOverlayCapture.pending";
|
||||
private const string PngKey = "InventoryGridOverlayCapture.png";
|
||||
private const int Bound = 22;
|
||||
// The parity harness's atlas bound (InventoryGridParityCapture.AtlasBound): sqrt(4 x 66).
|
||||
private const int Bound = 16;
|
||||
|
||||
public static void Run()
|
||||
{
|
||||
|
|
@ -66,6 +67,7 @@ public static class InventoryGridOverlayCapture
|
|||
private IEnumerator Capture()
|
||||
{
|
||||
var failed = false;
|
||||
var overallWorst = 0;
|
||||
var png = SessionState.GetString(PngKey, "");
|
||||
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Prefabs/UI/Inventory.prefab");
|
||||
var panel = prefab.GetComponentInChildren<InventoryPanel>(true);
|
||||
|
|
@ -83,7 +85,7 @@ public static class InventoryGridOverlayCapture
|
|||
yield return new WaitForEndOfFrame();
|
||||
watchdog.Disarm();
|
||||
}
|
||||
foreach (var (name, size, multiplier) in new[] { ("S32m1", 32f, 1f), ("S16m1.5", 16f, 1.5f) })
|
||||
foreach (var (name, size, multiplier, alpha) in new[] { ("S32m1", 32f, 1f, 1f), ("S16m1.5", 16f, 1.5f, 1f), ("S32m1-halfalpha", 32f, 1f, .5f) })
|
||||
{
|
||||
var canvasObject = new GameObject("Overlay canvas", typeof(RectTransform));
|
||||
canvasObject.layer = LayerMask.NameToLayer("UI");
|
||||
|
|
@ -126,10 +128,10 @@ public static class InventoryGridOverlayCapture
|
|||
rect.sizeDelta = new Vector2(size, size);
|
||||
var node = cell.GetComponent<InventoryCell>();
|
||||
node.Background.sprite = panel.NodeBackgroundTextures[masks[k] & 255];
|
||||
node.Background.color = bgColor;
|
||||
node.Background.color = new Color(bgColor.r, bgColor.g, bgColor.b, bgColor.a * alpha);
|
||||
node.Icon.sprite = panel.NodeTextures[masks[k]];
|
||||
node.Icon.pixelsPerUnitMultiplier = multiplier;
|
||||
node.Icon.color = iconColor;
|
||||
node.Icon.color = new Color(iconColor.r, iconColor.g, iconColor.b, iconColor.a * alpha);
|
||||
}
|
||||
yield return null;
|
||||
watchdog.Arm("end of frame, sprite cells");
|
||||
|
|
@ -149,6 +151,7 @@ public static class InventoryGridOverlayCapture
|
|||
rect.sizeDelta = new Vector2(size, size);
|
||||
var grid = go.AddComponent<InventoryGrid>();
|
||||
grid.Shader = shader;
|
||||
grid.color = new Color(1, 1, 1, alpha);
|
||||
grid.IconTexel = InventoryGrid.TexelOf(66f, multiplier);
|
||||
grid.BgTexel = InventoryGrid.TexelOf(100f, 1f);
|
||||
grid.Resize(1, 1, size, new RectOffset(), GridOrientation.LowerLeft);
|
||||
|
|
@ -178,6 +181,7 @@ public static class InventoryGridOverlayCapture
|
|||
if (a[i].r + a[i].g + a[i].b > 30) lit++;
|
||||
}
|
||||
}
|
||||
overallWorst = Mathf.Max(overallWorst, worst);
|
||||
Log($"overlay {name}: {masks.Count} masks, scale {scale:F3}, max8bitDiff={worst}, {lit} lit pixels in the sprite render");
|
||||
if (lit == 0 || worst > Bound)
|
||||
{
|
||||
|
|
@ -207,6 +211,7 @@ public static class InventoryGridOverlayCapture
|
|||
Destroy(canvasObject);
|
||||
yield return null;
|
||||
}
|
||||
Log($"SUMMARY overlayWorst={overallWorst} bound={Bound}");
|
||||
Log(failed ? "FAIL" : "PASS");
|
||||
EditorApplication.Exit(failed ? 1 : 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,12 +27,14 @@ public static class InventoryGridParityCapture
|
|||
// least claimed mutant's reading (66, alpha-multiply-dropped), sqrt(4 x 66) = 16.2, a separation of about 4 on each side. The other
|
||||
// mutants read 122 to 255.
|
||||
private static int AtlasBound = 16;
|
||||
// The bound on a thermal mask's rms difference, 0..1 channel units, in the atlas and in every cell of the real hull's thermal state: the
|
||||
// geometric mean of the shipped worst reading (0.0980, the hull's menu-size cells at 1920, which sit at half-pixel offsets the sprites blur
|
||||
// across) and the pipe-width-minus mutant's (0.1474), a separation of 1.22 on each side.
|
||||
private static double ThermalBound = 0.120;
|
||||
// The bound on a thermal mask's rms difference, 0..1 channel units, in the atlas (the sprites at 1:1 and 2:1): the geometric mean of the
|
||||
// shipped worst reading (0.0430, S32 mask 0) and the pipe-width-minus mutant's (0.1306), a separation of 1.74 on each side. The real hull's
|
||||
// thermal cells have their own bound, ThermalHullBound, because they sit at half-pixel offsets the sprites blur across: shipped 0.1007,
|
||||
// mutant 0.1731, geometric mean 0.132, a separation of 1.31.
|
||||
private static double ThermalBound = 0.075;
|
||||
private static double ThermalHullBound = 0.132;
|
||||
private static int _atlasWorst, _hullWorst, _maskedWorst, _alphaClipWorst;
|
||||
private static double _thermalWorst;
|
||||
private static double _thermalWorst, _thermalHullWorst;
|
||||
|
||||
private static string _mutant = "";
|
||||
private static string _pngOut;
|
||||
|
|
@ -54,7 +56,7 @@ public static class InventoryGridParityCapture
|
|||
_pngOut = Arg("-pngOut");
|
||||
_mutant = Arg("-mutant") ?? "";
|
||||
if (Arg("-atlasBound") != null) AtlasBound = int.Parse(Arg("-atlasBound"));
|
||||
if (Arg("-thermalBound") != null) ThermalBound = double.Parse(Arg("-thermalBound"), System.Globalization.CultureInfo.InvariantCulture);
|
||||
if (Arg("-thermalBound") != null) ThermalHullBound = ThermalBound = double.Parse(Arg("-thermalBound"), System.Globalization.CultureInfo.InvariantCulture);
|
||||
if (_mutant != "" && !Mutants.Contains(_mutant)) throw new InvalidOperationException("Unknown mutant " + _mutant);
|
||||
if (_pngOut != null) Directory.CreateDirectory(_pngOut);
|
||||
Log("mutant=" + (_mutant == "" ? "none" : _mutant));
|
||||
|
|
@ -64,10 +66,11 @@ public static class InventoryGridParityCapture
|
|||
if (!hullOnly) Thermal(Array.IndexOf(args, "-fitThermal") >= 0);
|
||||
if (!hullOnly) Variants();
|
||||
if (!hullOnly) Masked();
|
||||
if (!hullOnly) LateLook();
|
||||
if (!hullOnly) AlphaAndClip();
|
||||
if (Array.IndexOf(args, "-noHull") < 0) Hull();
|
||||
|
||||
Log($"SUMMARY atlasWorst={_atlasWorst} hullWorst={_hullWorst} thermalWorstRms={_thermalWorst:F4} maskedWorst={_maskedWorst} alphaClipWorst={_alphaClipWorst} bounds atlas={AtlasBound} thermal={ThermalBound}");
|
||||
Log($"SUMMARY atlasWorst={_atlasWorst} hullWorst={_hullWorst} thermalWorstRms={_thermalWorst:F4} thermalHullRms={_thermalHullWorst:F4} maskedWorst={_maskedWorst} alphaClipWorst={_alphaClipWorst} bounds atlas={AtlasBound} thermal={ThermalBound} thermalHull={ThermalHullBound}");
|
||||
if (Breaches.Count > 0)
|
||||
{
|
||||
foreach (var breach in Breaches) Log("BOUND BREACHED " + breach);
|
||||
|
|
@ -407,6 +410,76 @@ public static class InventoryGridParityCapture
|
|||
}
|
||||
}
|
||||
|
||||
// A look field changed on a live grid, with no Resize and no other write, reaches the pixels at the next Flush. Every look field is changed
|
||||
// in turn on a grid that has already been drawn through a stencil Mask; the result is compared in one render with a grid built with the
|
||||
// change, and the change is asserted visible by comparing that grid with one built without it.
|
||||
private static void LateLook()
|
||||
{
|
||||
using var rig = new Rig(1920);
|
||||
var fields = new (string name, Action<InventoryGrid> change, bool thermal)[]
|
||||
{
|
||||
("RuleInset", g => g.RuleInset = 2.4f, false), ("RuleWidth", g => g.RuleWidth = 2f, false),
|
||||
("ArmTexels", g => g.ArmTexels = 2f, false), ("FillInset", g => g.FillInset = 2f, false),
|
||||
("Softness", g => g.Softness = 1.8f, false), ("RuleAlpha", g => g.RuleAlpha = .7f, false),
|
||||
("BracketAlpha", g => g.BracketAlpha = .5f, false), ("FillAlpha", g => g.FillAlpha = .6f, false),
|
||||
("BlobRadius", g => g.BlobRadius = .22f, true), ("PipeHalfWidth", g => g.PipeHalfWidth = .2f, true),
|
||||
("Fillet", g => g.Fillet = .3f, true), ("PipeSoft", g => g.PipeSoft = 6f, true),
|
||||
("IconTexel", g => g.IconTexel = 3f, false), ("BgTexel", g => g.BgTexel = 3f, false),
|
||||
};
|
||||
void Configure(InventoryGrid grid, bool thermal)
|
||||
{
|
||||
grid.Thermal = thermal;
|
||||
grid.Resize(4, 4, 64, new RectOffset(), GridOrientation.LowerLeft);
|
||||
for (var y = 0; y < 4; y++)
|
||||
for (var x = 0; x < 4; x++)
|
||||
{
|
||||
var record = SampleRecord(x * 37 + y * 101 + 9 + 256 * ((x + y) % 2), new Color(.9f, .5f, .2f), new Color(.1f, .2f, .5f, .9f));
|
||||
record.Conductivity = (byte) (x * 5 + y * 3 + 7);
|
||||
grid.SetCell(new int2(x, y), record);
|
||||
}
|
||||
grid.Flush();
|
||||
}
|
||||
InventoryGrid Place(float x, bool masked)
|
||||
{
|
||||
var side = NewObject("Place", rig.Page, x, 100, 500);
|
||||
if (masked)
|
||||
{
|
||||
side.AddComponent<UnityEngine.UI.Image>();
|
||||
side.AddComponent<Mask>().showMaskGraphic = false;
|
||||
}
|
||||
var grid = MakeGrid((RectTransform) side.transform, 20, 20, 300, 1f);
|
||||
((RectTransform) grid.transform).sizeDelta = new Vector2(300, 300);
|
||||
return grid;
|
||||
}
|
||||
foreach (var (name, change, thermal) in fields)
|
||||
{
|
||||
ClearPage(rig);
|
||||
var live = Place(100, true);
|
||||
Configure(live, thermal);
|
||||
rig.Render();
|
||||
change(live);
|
||||
live.Flush();
|
||||
var changed = Place(800, false);
|
||||
change(changed);
|
||||
Configure(changed, thermal);
|
||||
var unchanged = Place(1300, false);
|
||||
Configure(unchanged, thermal);
|
||||
var drawn = rig.Render();
|
||||
var worst = 0;
|
||||
var visible = 0;
|
||||
for (var y = 100; y < 600; y++)
|
||||
for (var x = 100; x < 600; x++)
|
||||
{
|
||||
worst = Mathf.Max(worst, MaxDifference(drawn[y * rig.Width + x], drawn[y * rig.Width + x + 700]));
|
||||
visible = Mathf.Max(visible, MaxDifference(drawn[y * rig.Width + x + 700], drawn[y * rig.Width + x + 1200]));
|
||||
}
|
||||
Log($"late look {name}: live grid against a grid built with the change = {worst}; the change moves the picture by {visible}");
|
||||
_maskedWorst = Math.Max(_maskedWorst, worst);
|
||||
if (worst > 1) Breaches.Add($"late look {name}: {worst} > 1");
|
||||
if (visible < 8) Breaches.Add($"late look {name}: the change is not visible ({visible}), so the check proves nothing");
|
||||
}
|
||||
}
|
||||
|
||||
// The vertex alpha (a CanvasGroup fade, the drag ghost's half alpha) and a RectMask2D clip, against the same two on the sprite cells.
|
||||
private static void AlphaAndClip()
|
||||
{
|
||||
|
|
@ -1081,8 +1154,8 @@ public static class InventoryGridParityCapture
|
|||
Log($"hull thermal w={width} background layer max8bitDiff={worstBackground}");
|
||||
_hullWorst = Math.Max(_hullWorst, worstBackground);
|
||||
if (worstBackground > AtlasBound) Breaches.Add($"hull thermal background w={width}: {worstBackground} > {AtlasBound}");
|
||||
_thermalWorst = Math.Max(_thermalWorst, worstRms);
|
||||
if (worstRms > ThermalBound) Breaches.Add($"hull thermal w={width}: cell rms {worstRms:F4} > {ThermalBound}");
|
||||
_thermalHullWorst = Math.Max(_thermalHullWorst, worstRms);
|
||||
if (worstRms > ThermalHullBound) Breaches.Add($"hull thermal w={width}: cell rms {worstRms:F4} > {ThermalHullBound}");
|
||||
}
|
||||
|
||||
// Hit-testing: CellAt returns the cell at every cell centre and nothing over an absent cell; empty cells pass clicks through.
|
||||
|
|
|
|||
Loading…
Reference in a new issue