Inventory grid parity: masked and late-configured use, vertex alpha and RectMask2D, Overlay canvas, thermal gated, fair frame time
Masked: a grid reconfigured under a Mask (resize, orientation, late Thermal, late look) equals a fresh unmasked grid. AlphaAndClip: quarter and half alpha and a RectMask2D against the same on the sprite cells. InventoryGridOverlayCapture enters play mode and compares a ScreenSpaceOverlay canvas. The thermal hull state is gated by cell rms (0.120 from the margin rule). The frame-time new side includes RefreshCells. Mutation driver gains alpha-multiply-dropped, clip-multiply-dropped and modified-material-unpushed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7060803ed9
commit
38f12838e2
4 changed files with 387 additions and 20 deletions
209
Assets/Scripts/Editor/InventoryGridOverlayCapture.cs
Normal file
209
Assets/Scripts/Editor/InventoryGridOverlayCapture.cs
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using int2 = CultMath.int2;
|
||||
|
||||
// Parity of the inventory grid on a ScreenSpaceOverlay canvas, the kind the game's canvases are, which the camera rig of
|
||||
// InventoryGridParityCapture cannot draw. An overlay canvas draws to the Game view's back buffer, so this enters play mode and
|
||||
// reads the screen at the end of a frame: once with the sprite cells, once with the grid over the same canvas rects.
|
||||
//
|
||||
// Unity -batchmode -projectPath <project> -executeMethod InventoryGridOverlayCapture.Run [-pngOut <dir>] -logFile <log>
|
||||
//
|
||||
// Needs a GPU device; do not pass -nographics or -quit. Logs "[InventoryGridOverlay]" lines and exits 0 or 1.
|
||||
public static class InventoryGridOverlayCapture
|
||||
{
|
||||
private const string Pending = "InventoryGridOverlayCapture.pending";
|
||||
private const string PngKey = "InventoryGridOverlayCapture.png";
|
||||
private const int Bound = 22;
|
||||
|
||||
public static void Run()
|
||||
{
|
||||
var args = Environment.GetCommandLineArgs();
|
||||
var i = Array.IndexOf(args, "-pngOut");
|
||||
SessionState.SetString(PngKey, i >= 0 && i + 1 < args.Length ? args[i + 1] : "");
|
||||
SessionState.SetBool(Pending, true);
|
||||
EditorApplication.EnterPlaymode();
|
||||
}
|
||||
|
||||
[InitializeOnLoadMethod]
|
||||
private static void Hook()
|
||||
{
|
||||
EditorApplication.playModeStateChanged += state =>
|
||||
{
|
||||
if (state != PlayModeStateChange.EnteredPlayMode || !SessionState.GetBool(Pending, false)) return;
|
||||
SessionState.SetBool(Pending, false);
|
||||
new GameObject("Overlay parity").AddComponent<Runner>();
|
||||
};
|
||||
}
|
||||
|
||||
private static void Log(string line) => Debug.Log("[InventoryGridOverlay] " + line);
|
||||
|
||||
private sealed class Runner : MonoBehaviour
|
||||
{
|
||||
private IEnumerator Start()
|
||||
{
|
||||
var failed = false;
|
||||
var png = SessionState.GetString(PngKey, "");
|
||||
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Prefabs/UI/Inventory.prefab");
|
||||
var panel = prefab.GetComponentInChildren<InventoryPanel>(true);
|
||||
var shader = AssetDatabase.LoadAssetAtPath<Shader>("Assets/Shaders/InventoryGrid.shader");
|
||||
// An overlay canvas draws to the Game view's back buffer, which batch mode does not create on its own.
|
||||
Log("Game view menu item: " + EditorApplication.ExecuteMenuItem("Window/General/Game"));
|
||||
yield return null;
|
||||
yield return null;
|
||||
Log($"screen {Screen.width}x{Screen.height}");
|
||||
var watchdog = gameObject.AddComponent<Watchdog>();
|
||||
// The first frames of a freshly opened Game view are not drawn yet (solid cyan).
|
||||
for (var warm = 0; warm < 5; warm++)
|
||||
{
|
||||
watchdog.Arm("warm-up end of frame");
|
||||
yield return new WaitForEndOfFrame();
|
||||
watchdog.Disarm();
|
||||
}
|
||||
foreach (var (name, size, multiplier) in new[] { ("S32m1", 32f, 1f), ("S16m1.5", 16f, 1.5f) })
|
||||
{
|
||||
var canvasObject = new GameObject("Overlay canvas", typeof(RectTransform));
|
||||
canvasObject.layer = LayerMask.NameToLayer("UI");
|
||||
var canvas = canvasObject.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
canvas.vertexColorAlwaysGammaSpace = false;
|
||||
canvas.sortingOrder = 5000;
|
||||
// The Main Menu scene behind it moves, so the canvas lays an opaque black page under the cells.
|
||||
var page = new GameObject("Page", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image)) { layer = canvasObject.layer };
|
||||
var pageRect = (RectTransform) page.transform;
|
||||
pageRect.SetParent(canvasObject.transform, false);
|
||||
pageRect.anchorMin = Vector2.zero;
|
||||
pageRect.anchorMax = Vector2.one;
|
||||
pageRect.offsetMin = pageRect.offsetMax = Vector2.zero;
|
||||
page.GetComponent<Image>().color = Color.black;
|
||||
var scaler = canvasObject.AddComponent<CanvasScaler>();
|
||||
// The Game view of a batch session is small (321x531), so the canvas runs at the 1920 reference's own scale, one pixel
|
||||
// to a canvas unit, which is where the camera rig's 1920 captures sit.
|
||||
scaler.uiScaleMode = CanvasScaler.ScaleMode.ConstantPixelSize;
|
||||
scaler.scaleFactor = 1;
|
||||
scaler.referencePixelsPerUnit = 100;
|
||||
var stride = size + 8;
|
||||
var masks = new System.Collections.Generic.List<int>();
|
||||
for (var m = 0; m < 512 && masks.Count < 96; m += 4)
|
||||
if (m != 33 && m != 289 && m != 136 && m != 392) masks.Add(m);
|
||||
var iconColor = new Color(.9f, .45f, .15f) * .7071f;
|
||||
var bgColor = new Color(.6f, .2f, .1f, .8f);
|
||||
Vector2 At(int k) => new Vector2(8 + k % 8 * stride, 8 + k / 8 * stride);
|
||||
|
||||
for (var k = 0; k < masks.Count; k++)
|
||||
{
|
||||
var cell = Instantiate(panel.NodePrototype.gameObject, canvasObject.transform, false);
|
||||
// The prototype deactivates itself in Start unless it is an instance it handed out; a plain clone is not one.
|
||||
Destroy(cell.GetComponent<Prototype>());
|
||||
cell.SetActive(true);
|
||||
var rect = (RectTransform) cell.transform;
|
||||
rect.anchorMin = rect.anchorMax = Vector2.zero;
|
||||
rect.pivot = Vector2.zero;
|
||||
rect.anchoredPosition = At(k);
|
||||
rect.sizeDelta = new Vector2(size, size);
|
||||
var node = cell.GetComponent<InventoryCell>();
|
||||
node.Background.sprite = panel.NodeBackgroundTextures[masks[k] & 255];
|
||||
node.Background.color = bgColor;
|
||||
node.Icon.sprite = panel.NodeTextures[masks[k]];
|
||||
node.Icon.pixelsPerUnitMultiplier = multiplier;
|
||||
node.Icon.color = iconColor;
|
||||
}
|
||||
yield return null;
|
||||
watchdog.Arm("end of frame, sprite cells");
|
||||
yield return new WaitForEndOfFrame();
|
||||
watchdog.Disarm();
|
||||
var old = ScreenCapture.CaptureScreenshotAsTexture();
|
||||
for (var c = canvasObject.transform.childCount - 1; c >= 1; c--) Destroy(canvasObject.transform.GetChild(c).gameObject);
|
||||
yield return null;
|
||||
for (var k = 0; k < masks.Count; k++)
|
||||
{
|
||||
var go = new GameObject("Grid", typeof(RectTransform), typeof(CanvasRenderer)) { layer = canvasObject.layer };
|
||||
var rect = (RectTransform) go.transform;
|
||||
rect.SetParent(canvasObject.transform, false);
|
||||
rect.anchorMin = rect.anchorMax = Vector2.zero;
|
||||
rect.pivot = Vector2.zero;
|
||||
rect.anchoredPosition = At(k);
|
||||
rect.sizeDelta = new Vector2(size, size);
|
||||
var grid = go.AddComponent<InventoryGrid>();
|
||||
grid.Shader = shader;
|
||||
grid.IconTexel = InventoryGrid.TexelOf(66f, multiplier);
|
||||
grid.BgTexel = InventoryGrid.TexelOf(100f, 1f);
|
||||
grid.Resize(1, 1, size, new RectOffset(), GridOrientation.LowerLeft);
|
||||
grid.SetCell(new int2(0, 0), new CellRecord
|
||||
{
|
||||
Mask = (byte) (masks[k] & 255), Present = true, Item = masks[k] >= 256, Icon = iconColor, Background = bgColor
|
||||
});
|
||||
}
|
||||
watchdog.Arm("end of frame, grid");
|
||||
yield return new WaitForEndOfFrame();
|
||||
watchdog.Disarm();
|
||||
var fresh = ScreenCapture.CaptureScreenshotAsTexture();
|
||||
|
||||
var scale = 1f;
|
||||
var worst = 0;
|
||||
var lit = 0;
|
||||
var a = old.GetPixels32();
|
||||
var b = fresh.GetPixels32();
|
||||
for (var k = 0; k < masks.Count; k++)
|
||||
{
|
||||
var origin = At(k) * scale;
|
||||
for (var y = Mathf.Max(0, Mathf.FloorToInt(origin.y) - 1); y < Mathf.Min(old.height, Mathf.CeilToInt(origin.y + size * scale) + 1); y++)
|
||||
for (var x = Mathf.Max(0, Mathf.FloorToInt(origin.x) - 1); x < Mathf.Min(old.width, Mathf.CeilToInt(origin.x + size * scale) + 1); x++)
|
||||
{
|
||||
var i = y * old.width + x;
|
||||
worst = Mathf.Max(worst, Mathf.Abs(a[i].r - b[i].r), Mathf.Abs(a[i].g - b[i].g), Mathf.Abs(a[i].b - b[i].b));
|
||||
if (a[i].r + a[i].g + a[i].b > 30) lit++;
|
||||
}
|
||||
}
|
||||
Log($"overlay {name}: {masks.Count} masks, scale {scale:F3}, max8bitDiff={worst}, {lit} lit pixels in the sprite render");
|
||||
if (lit == 0 || worst > Bound)
|
||||
{
|
||||
failed = true;
|
||||
Log($"BOUND BREACHED overlay {name}: worst {worst} (bound {Bound}), lit {lit}");
|
||||
}
|
||||
if (png != "")
|
||||
{
|
||||
Directory.CreateDirectory(png);
|
||||
var cropW = Mathf.Min(old.width, Mathf.CeilToInt((8 + 8 * stride) * scale));
|
||||
var cropH = Mathf.Min(old.height, Mathf.CeilToInt((8 + 12 * stride) * scale));
|
||||
var sheet = new Texture2D(cropW * 3, cropH, TextureFormat.RGBA32, false);
|
||||
var pixels = new Color32[cropW * 3 * cropH];
|
||||
for (var y = 0; y < cropH; y++)
|
||||
for (var x = 0; x < cropW; x++)
|
||||
{
|
||||
var i = y * old.width + x;
|
||||
pixels[y * cropW * 3 + x] = new Color32(a[i].r, a[i].g, a[i].b, 255);
|
||||
pixels[y * cropW * 3 + cropW + x] = new Color32(b[i].r, b[i].g, b[i].b, 255);
|
||||
pixels[y * cropW * 3 + 2 * cropW + x] = new Color32(
|
||||
(byte) Mathf.Min(255, 8 * Mathf.Abs(a[i].r - b[i].r)), (byte) Mathf.Min(255, 8 * Mathf.Abs(a[i].g - b[i].g)),
|
||||
(byte) Mathf.Min(255, 8 * Mathf.Abs(a[i].b - b[i].b)), 255);
|
||||
}
|
||||
sheet.SetPixels32(pixels);
|
||||
File.WriteAllBytes(Path.Combine(png, $"overlay-{name}.png"), sheet.EncodeToPNG());
|
||||
}
|
||||
Destroy(canvasObject);
|
||||
yield return null;
|
||||
}
|
||||
Log(failed ? "FAIL" : "PASS");
|
||||
EditorApplication.Exit(failed ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Exits when an end of frame never comes: no Game view renders in this batch session, so an overlay canvas cannot be drawn.
|
||||
private sealed class Watchdog : MonoBehaviour
|
||||
{
|
||||
private string _waiting;
|
||||
private float _since;
|
||||
public void Arm(string what) { _waiting = what; _since = Time.realtimeSinceStartup; }
|
||||
public void Disarm() => _waiting = null;
|
||||
private void Update()
|
||||
{
|
||||
if (_waiting == null || Time.realtimeSinceStartup - _since < 20f) return;
|
||||
Log($"BLOCKED: no {_waiting} within 20 s; the Game view does not render in this session");
|
||||
EditorApplication.Exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 88f470014ea5fdd43a80ec1eba54b42a
|
||||
|
|
@ -26,10 +26,11 @@ public static class InventoryGridParityCapture
|
|||
// oracle's own slips. lodur:ruling:deterministic-bound-margin: the geometric mean of the shipped worst reading (4) and the least
|
||||
// claimed mutant's reading (122, fill-inset-2.5), sqrt(4 x 122) = 22.1, a separation of 5.5 on each side. The other mutants read 170 to 255.
|
||||
private static int AtlasBound = 22;
|
||||
// The bound on a thermal mask's rms difference in the atlas, 0..1 channel units, after the fit: the geometric mean of the shipped
|
||||
// worst reading (0.0577, S32 mask 15) and the pipe-width-minus mutant's (0.1363, S16 mask 15), a separation of 1.53 on each side.
|
||||
private static double ThermalBound = 0.089;
|
||||
private static int _atlasWorst, _hullWorst;
|
||||
// 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;
|
||||
private static int _atlasWorst, _hullWorst, _maskedWorst, _alphaClipWorst;
|
||||
private static double _thermalWorst;
|
||||
|
||||
private static string _mutant = "";
|
||||
|
|
@ -61,9 +62,11 @@ public static class InventoryGridParityCapture
|
|||
if (!hullOnly) Atlas();
|
||||
if (!hullOnly) Thermal(Array.IndexOf(args, "-fitThermal") >= 0);
|
||||
if (!hullOnly) Variants();
|
||||
if (!hullOnly) Masked();
|
||||
if (!hullOnly) AlphaAndClip();
|
||||
if (Array.IndexOf(args, "-noHull") < 0) Hull();
|
||||
|
||||
Log($"SUMMARY atlasWorst={_atlasWorst} hullWorst={_hullWorst} thermalWorstRms={_thermalWorst:F4} bounds atlas={AtlasBound} thermal={ThermalBound}");
|
||||
Log($"SUMMARY atlasWorst={_atlasWorst} hullWorst={_hullWorst} thermalWorstRms={_thermalWorst:F4} maskedWorst={_maskedWorst} alphaClipWorst={_alphaClipWorst} bounds atlas={AtlasBound} thermal={ThermalBound}");
|
||||
if (Breaches.Count > 0)
|
||||
{
|
||||
foreach (var breach in Breaches) Log("BOUND BREACHED " + breach);
|
||||
|
|
@ -329,6 +332,146 @@ public static class InventoryGridParityCapture
|
|||
for (var i = rig.Page.childCount - 1; i >= 0; i--) UnityEngine.Object.DestroyImmediate(rig.Page.GetChild(i).gameObject);
|
||||
}
|
||||
|
||||
// ---- Masked, late-configured and faded use ---------------------------------------------------------------------------
|
||||
|
||||
private static InventoryGrid MakeGrid(RectTransform parent, float x, float y, float size, float iconMultiplier)
|
||||
{
|
||||
var grid = NewObject("Grid", parent, x, y, size).AddComponent<InventoryGrid>();
|
||||
Look(grid, iconMultiplier);
|
||||
return grid;
|
||||
}
|
||||
|
||||
private static CellRecord SampleRecord(int m, Color icon, Color background) => new CellRecord
|
||||
{
|
||||
Mask = (byte) (m & 255), Present = true, Item = m >= 256, Conductivity = (byte) (m & 15), Icon = icon, Background = background
|
||||
};
|
||||
|
||||
// Under a stencil Mask Unity draws a clone of the material, so a grid reconfigured after its first draw (Resize, orientation, Thermal,
|
||||
// look) must still draw as a grid configured that way from the start. Each step is compared with a fresh grid outside any mask.
|
||||
private static void Masked()
|
||||
{
|
||||
using var rig = new Rig(1920);
|
||||
var holder = NewObject("Mask", rig.Page, 100, 100, 500);
|
||||
holder.AddComponent<UnityEngine.UI.Image>();
|
||||
holder.AddComponent<Mask>().showMaskGraphic = false;
|
||||
var masked = MakeGrid((RectTransform) holder.transform, 20, 20, 300, 1f);
|
||||
((RectTransform) masked.transform).sizeDelta = new Vector2(300, 300);
|
||||
|
||||
Color32[] Reference(Action<InventoryGrid> configure)
|
||||
{
|
||||
var side = NewObject("Reference", rig.Page, 100, 100, 500);
|
||||
var grid = MakeGrid((RectTransform) side.transform, 20, 20, 300, 1f);
|
||||
((RectTransform) grid.transform).sizeDelta = new Vector2(300, 300);
|
||||
configure(grid);
|
||||
grid.Flush();
|
||||
var drawn = rig.Render();
|
||||
UnityEngine.Object.DestroyImmediate(side);
|
||||
return drawn;
|
||||
}
|
||||
void Fill(InventoryGrid grid, int w, int h)
|
||||
{
|
||||
for (var y = 0; y < h; y++)
|
||||
for (var x = 0; x < w; x++)
|
||||
grid.SetCell(new int2(x, y), SampleRecord(x * 37 + y * 101 + 9, new Color(.9f, .5f, .2f), new Color(.1f, .2f, .5f, .9f)));
|
||||
}
|
||||
void Step(string name, Action<InventoryGrid> configure)
|
||||
{
|
||||
configure(masked);
|
||||
masked.Flush();
|
||||
var drawn = rig.Render();
|
||||
// The reference page holds the masked grid too, so hide it for the reference render.
|
||||
masked.gameObject.SetActive(false);
|
||||
var expected = Reference(configure);
|
||||
masked.gameObject.SetActive(true);
|
||||
var worst = 0;
|
||||
for (var i = 0; i < drawn.Length; i++) worst = Mathf.Max(worst, MaxDifference(drawn[i], expected[i]));
|
||||
Log($"masked {name}: max8bitDiff against a fresh unmasked grid = {worst}");
|
||||
_maskedWorst = Math.Max(_maskedWorst, worst);
|
||||
if (worst > 1) Breaches.Add($"masked {name}: {worst} > 1");
|
||||
}
|
||||
// The reference helper configures a fresh grid with the same calls, so each step is a full configuration, not a delta.
|
||||
var steps = new List<Action<InventoryGrid>>();
|
||||
steps.Add(grid => { grid.Resize(1, 1, 32, new RectOffset(), GridOrientation.LowerLeft); Fill(grid, 1, 1); });
|
||||
steps.Add(grid => { grid.Resize(3, 3, 48, new RectOffset(), GridOrientation.UpperRight); Fill(grid, 3, 3); });
|
||||
steps.Add(grid => { grid.Thermal = true; });
|
||||
steps.Add(grid => { grid.RuleInset = 2f; });
|
||||
var applied = new List<Action<InventoryGrid>>();
|
||||
var names = new[] { "first draw", "resize 3x3 at 48, UpperRight", "late Thermal", "late RuleInset" };
|
||||
for (var i = 0; i < steps.Count; i++)
|
||||
{
|
||||
applied.Add(steps[i]);
|
||||
var upto = applied.ToArray();
|
||||
Step(names[i], grid => { foreach (var apply in upto) apply(grid); });
|
||||
}
|
||||
}
|
||||
|
||||
// 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()
|
||||
{
|
||||
using var oracle = new Oracle();
|
||||
var panel = oracle.Panel;
|
||||
using var rig = new Rig(1920);
|
||||
const float stride = 40;
|
||||
foreach (var (name, alpha, clip) in new[] { ("opaque", 1f, false), ("quarter alpha", .25f, false), ("half alpha", .5f, false), ("RectMask2D", 1f, true), ("RectMask2D and half alpha", .5f, true) })
|
||||
{
|
||||
// Old: the cells under the clip rect (children of a RectMask2D object).
|
||||
Transform OldRoot()
|
||||
{
|
||||
ClearPage(rig);
|
||||
if (!clip) return rig.Page;
|
||||
var mask = NewObject("Clip", rig.Page, 8 + 3 * stride - 9f, 8 + 1 * stride + 5f, 0);
|
||||
mask.AddComponent<RectMask2D>();
|
||||
var rect = (RectTransform) mask.transform;
|
||||
rect.sizeDelta = new Vector2(6 * stride + 3.5f, 4 * stride + 7f);
|
||||
return rect;
|
||||
}
|
||||
var origin = clip ? new Vector2(8 + 3 * stride - 9f, 8 + 1 * stride + 5f) : Vector2.zero;
|
||||
var (iconColor, bgColor) = Passes[1];
|
||||
var oldParent = OldRoot();
|
||||
for (var m = 0; m < 64; m++)
|
||||
{
|
||||
if (m + 128 == 136) continue; // Nodes8BG_136 carries a wrong pad (see the atlas)
|
||||
var cell = UnityEngine.Object.Instantiate(panel.NodePrototype.gameObject, oldParent, false);
|
||||
cell.SetActive(true);
|
||||
var rect = (RectTransform) cell.transform;
|
||||
rect.anchorMin = rect.anchorMax = Vector2.zero;
|
||||
rect.pivot = Vector2.zero;
|
||||
rect.anchoredPosition = new Vector2(8 + m % 16 * stride, 8 + m / 16 * stride) - origin;
|
||||
rect.sizeDelta = new Vector2(32, 32);
|
||||
var node = cell.GetComponent<InventoryCell>();
|
||||
node.Background.color = new Color(bgColor.r, bgColor.g, bgColor.b, bgColor.a * alpha);
|
||||
node.Icon.sprite = panel.NodeTextures[m + 128];
|
||||
node.Background.sprite = panel.NodeBackgroundTextures[(m + 128) & 255];
|
||||
node.Icon.color = new Color(iconColor.r, iconColor.g, iconColor.b, iconColor.a * alpha);
|
||||
}
|
||||
var old = rig.Render();
|
||||
var newParent = OldRoot();
|
||||
for (var m = 0; m < 64; m++)
|
||||
{
|
||||
if (m + 128 == 136) continue;
|
||||
var grid = MakeGrid((RectTransform) newParent, 0, 0, 32, 1f);
|
||||
var rect = (RectTransform) grid.transform;
|
||||
rect.anchoredPosition = new Vector2(8 + m % 16 * stride, 8 + m / 16 * stride) - origin;
|
||||
grid.color = new Color(1, 1, 1, alpha);
|
||||
grid.Resize(1, 1, 32, new RectOffset(), GridOrientation.LowerLeft);
|
||||
grid.SetCell(new int2(0, 0), SampleRecord(m + 128, iconColor, bgColor));
|
||||
}
|
||||
var fresh = rig.Render();
|
||||
var worst = 0;
|
||||
var lit = 0;
|
||||
for (var i = 0; i < old.Length; i++)
|
||||
{
|
||||
worst = Mathf.Max(worst, MaxDifference(old[i], fresh[i]));
|
||||
if (fresh[i].r + fresh[i].g + fresh[i].b > 30) lit++;
|
||||
}
|
||||
Log($"{name}: max8bitDiff against the sprite cells = {worst}, {lit} lit pixels");
|
||||
_alphaClipWorst = Math.Max(_alphaClipWorst, worst);
|
||||
if (lit == 0) Breaches.Add($"{name}: nothing drawn");
|
||||
if (worst > AtlasBound) Breaches.Add($"{name}: {worst} > {AtlasBound}");
|
||||
SaveSideBySide($"alpha-clip-{name.Replace(' ', '-')}.png", rig, old, fresh, new RectInt(0, 0, Mathf.CeilToInt(8 + 16 * stride), Mathf.CeilToInt(8 + 4 * stride)));
|
||||
}
|
||||
}
|
||||
|
||||
// The shader's keyword variants: with and without UNITY_UI_CLIP_RECT and UNITY_UI_ALPHACLIP it reports no shader error and draws what the
|
||||
// plain variant draws (the clip rect is opened wide, so clipping changes nothing).
|
||||
private static void Variants()
|
||||
|
|
@ -648,8 +791,9 @@ public static class InventoryGridParityCapture
|
|||
}
|
||||
|
||||
// A reading, not a gate: 101 paired, interleaved iterations of the menu real-hull state. Each times a full refresh with changed content
|
||||
// (RefreshCells for the sprite cells; SetCell for every cell plus the texture Apply for the grid) plus Canvas.ForceUpdateCanvases plus
|
||||
// camera.Render plus a 1-pixel ReadPixels sync.
|
||||
// plus Canvas.ForceUpdateCanvases plus camera.Render plus a 1-pixel ReadPixels sync. The writer stays in both: the sprite cells time
|
||||
// RefreshCells; the grid times RefreshCells (its match predicates, GetColor and sprite sets still run until the switch cut) plus SetCell
|
||||
// for every cell plus the texture Apply. The writer alone is timed too.
|
||||
private static void FrameTime(Rig rig, InventoryPanel panel, InventoryGrid grid, Dictionary<int2, CellRecord> recordsA)
|
||||
{
|
||||
var fixtureShip = (Entity) panel.GameManager.CurrentEntity;
|
||||
|
|
@ -688,7 +832,9 @@ public static class InventoryGridParityCapture
|
|||
foreach (var cell in panel.CellInstances.Values) cell.gameObject.SetActive(false);
|
||||
grid.gameObject.SetActive(true);
|
||||
Sync();
|
||||
panel.IgnoreOccupancy = i % 2 == 0 ? shape : null;
|
||||
var watch = System.Diagnostics.Stopwatch.StartNew();
|
||||
panel.RefreshCells();
|
||||
foreach (var (v, record) in i % 2 == 0 ? recordsB : recordsA) grid.SetCell(v, record);
|
||||
grid.Flush();
|
||||
Sync();
|
||||
|
|
@ -824,8 +970,12 @@ public static class InventoryGridParityCapture
|
|||
minY = Mathf.Min(minY, Mathf.FloorToInt(pixels.yMin));
|
||||
maxX = Mathf.Max(maxX, Mathf.CeilToInt(pixels.xMax));
|
||||
maxY = Mathf.Max(maxY, Mathf.CeilToInt(pixels.yMax));
|
||||
// A pixel centre exactly on a cell boundary is drawn by both neighbouring cells of the oracle, so its additive icon
|
||||
// layer counts twice: a tie of the rasteriser, not of the look. Such a pixel is not judged.
|
||||
// A pixel centre exactly on a cell boundary (panels at half-pixel offsets at 1920) is not judged. The sprite cells are separate
|
||||
// quads whose edges the rasteriser resolves by float noise: the pixel comes out as one neighbour or the other, or as both
|
||||
// (the additive icon doubled), and the choice moves with the panel's offset. The grid draws it from one cell by the
|
||||
// floor of its coordinate, so a boundary pixel can differ from the sprite cells by one seam's worth of rule or bracket
|
||||
// tip. Trying the fill rule with float slack in the shader matched no better (the menu stayed at 122, the enemy state
|
||||
// went from 1 to 131), so the shader keeps the plain floor.
|
||||
for (var y = Mathf.Max(0, Mathf.FloorToInt(pixels.yMin) - 1); y < Mathf.Min(rig.Height, Mathf.CeilToInt(pixels.yMax) + 1); y++)
|
||||
for (var x = Mathf.Max(0, Mathf.FloorToInt(pixels.xMin) - 1); x < Mathf.Min(rig.Width, Mathf.CeilToInt(pixels.xMax) + 1); x++)
|
||||
if (Mathf.Abs(x + .5f - pixels.xMin) < .01f || Mathf.Abs(x + .5f - pixels.xMax) < .01f ||
|
||||
|
|
@ -881,7 +1031,7 @@ public static class InventoryGridParityCapture
|
|||
Log($" worst cell {v.x},{v.y} {where}: diff {diff} mask {r.Mask} ({Convert.ToString(r.Mask, 2).PadLeft(8, '0')}) item {r.Item} icon {r.Icon} bg {r.Background} sprite {panel.CellInstances[v].Icon.sprite.name}/{panel.CellInstances[v].Background.sprite.name}");
|
||||
}
|
||||
}
|
||||
Log($"hull {state.Name} w={width} cells={records.Count} max8bitDiff={worst} at {worstAt} tiePixelsNotJudged={ties}" + (state.Thermal ? " (thermal: the pipes are a fit, judged by cell rms)" : ""));
|
||||
Log($"hull {state.Name} w={width} cells={records.Count} max8bitDiff={worst} at {worstAt} boundaryPixelsNotJudged={ties}" + (state.Thermal ? " (thermal: the pipes are a fit, judged by cell rms)" : ""));
|
||||
if (!state.Thermal) _hullWorst = Math.Max(_hullWorst, worst);
|
||||
if (!state.Thermal && worst > AtlasBound) Breaches.Add($"hull {state.Name} w={width}: {worst} > {AtlasBound}");
|
||||
if (state.Thermal)
|
||||
|
|
@ -901,7 +1051,7 @@ public static class InventoryGridParityCapture
|
|||
}
|
||||
if (n > 0) worstRms = Math.Max(worstRms, Math.Sqrt(sum / n));
|
||||
}
|
||||
Log($"hull thermal w={width} worst cell rms={worstRms:F4} (a reading; the pipe fit is gated by the atlas thermal section)");
|
||||
Log($"hull thermal w={width} worst cell rms={worstRms:F4}");
|
||||
|
||||
// The background layer of every thermal cell, icons hidden in both paths, judged by the atlas bound.
|
||||
foreach (var cell in panel.CellInstances.Values)
|
||||
|
|
@ -929,7 +1079,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}");
|
||||
// A reading: the pipes are a fit, gated by the atlas section. The cells' background layer is judged below.
|
||||
_thermalWorst = Math.Max(_thermalWorst, worstRms);
|
||||
if (worstRms > ThermalBound) Breaches.Add($"hull thermal w={width}: cell rms {worstRms:F4} > {ThermalBound}");
|
||||
}
|
||||
|
||||
// Hit-testing: CellAt returns the cell at every cell centre and nothing over an absent cell; empty cells pass clicks through.
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ UNITY_EXE = r"C:\Program Files\Unity\Hub\Editor\6000.3.24f1\Editor\Unity.exe"
|
|||
LOCK = Path("F:/aeth-wt/unity.lock.d")
|
||||
HARNESS = REPO_ROOT / "Assets" / "Scripts" / "Editor" / "InventoryGridParityCapture.cs"
|
||||
SHADER = REPO_ROOT / "Assets" / "Shaders" / "InventoryGrid.shader"
|
||||
GRID = REPO_ROOT / "Assets" / "Scripts" / "UI" / "Menu" / "InventoryGrid.cs"
|
||||
SCRATCH = REPO_ROOT / "tests" / "_scratch_inventory_grid"
|
||||
|
||||
# name -> (harness argument or None, (file, anchor, mutated) or None, which bound kills it)
|
||||
|
|
@ -43,6 +44,9 @@ MUTANTS = {
|
|||
"no-border-clamp": (None, (SHADER, "float t = min(texel, S / 8.0);", "float t = texel;"), "atlas"),
|
||||
"concave-bracket-dropped": (None, (SHADER, "else if (concave)", "else if (false)"), "atlas"),
|
||||
"pipe-width-minus": ("pipe-width-minus", None, "thermal"),
|
||||
"alpha-multiply-dropped": (None, (SHADER, "color *= IN.color.a;", "color *= 1.0;"), "atlas"),
|
||||
"clip-multiply-dropped": (None, (SHADER, "color *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);", "color *= 1.0;"), "atlas"),
|
||||
"modified-material-unpushed": (None, (GRID, "PushUniforms(drawn);", "// PushUniforms(drawn);"), "masked"),
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -91,11 +95,11 @@ def run_harness(log: Path, extra: list[str]) -> tuple[int, str]:
|
|||
return code, log.read_text(encoding="utf-8", errors="replace")
|
||||
|
||||
|
||||
def summary(text: str) -> tuple[int, int, float]:
|
||||
m = re.search(r"SUMMARY atlasWorst=(\d+) hullWorst=(\d+) thermalWorstRms=([0-9.]+)", text)
|
||||
def summary(text: str) -> tuple[int, int, float, int, int]:
|
||||
m = re.search(r"SUMMARY atlasWorst=(\d+) hullWorst=(\d+) thermalWorstRms=([0-9.]+) maskedWorst=(\d+) alphaClipWorst=(\d+)", text)
|
||||
if not m:
|
||||
raise SystemExit("no SUMMARY line in the harness log")
|
||||
return int(m.group(1)), int(m.group(2)), float(m.group(3))
|
||||
return int(m.group(1)), int(m.group(2)), float(m.group(3)), int(m.group(4)), int(m.group(5))
|
||||
|
||||
|
||||
def replace_unique(path: Path, anchor: str, mutated: str) -> str:
|
||||
|
|
@ -119,8 +123,8 @@ def main() -> int:
|
|||
print("control FAILED")
|
||||
else:
|
||||
print("control OK: exit 0, PASS")
|
||||
atlas_c, hull_c, thermal_c = summary(text)
|
||||
shipped = max(atlas_c, hull_c)
|
||||
atlas_c, hull_c, thermal_c, masked_c, alphaclip_c = summary(text)
|
||||
shipped = max(atlas_c, hull_c, alphaclip_c)
|
||||
bound_atlas = int(re.search(r"private static int AtlasBound = (\d+);", HARNESS.read_text(encoding="utf-8")).group(1))
|
||||
bound_thermal = float(re.search(r"private static double ThermalBound = ([0-9.]+);", HARNESS.read_text(encoding="utf-8")).group(1))
|
||||
print(f"shipped worst: {shipped} (atlas {atlas_c}, hull {hull_c}), thermal rms {thermal_c}; bounds {bound_atlas}, {bound_thermal}")
|
||||
|
|
@ -133,17 +137,18 @@ def main() -> int:
|
|||
finally:
|
||||
if edit:
|
||||
edit[0].write_bytes(original.encode("utf-8"))
|
||||
atlas_m, hull_m, thermal_m = summary(text)
|
||||
reading = max(atlas_m, hull_m) if kind == "atlas" else thermal_m
|
||||
atlas_m, hull_m, thermal_m, masked_m, alphaclip_m = summary(text)
|
||||
reading = {"atlas": max(atlas_m, hull_m, alphaclip_m), "thermal": thermal_m, "masked": masked_m}[kind]
|
||||
readings[name] = (kind, reading)
|
||||
killed = code == 1 and "BOUND BREACHED" in text
|
||||
claimed = kind == "thermal" or reading >= 1.2 * bound_atlas
|
||||
claimed = kind in ("thermal", "masked") or reading >= 1.2 * bound_atlas
|
||||
print(f"{name}: exit {code}, reading {reading} ({kind}), killed={killed}, claimed={claimed}")
|
||||
if claimed and not killed:
|
||||
failures.append(f"{name}: claimed but not killed by the bound (exit {code}, reading {reading})")
|
||||
|
||||
# The margin rule: separation at least 1.2 on each side of each bound; an unseparated mutant is unclaimed.
|
||||
atlas_least = min((r for k, r in readings.values() if k == "atlas" and r >= 1.2 * bound_atlas), default=None)
|
||||
# The masked check is exact: a grid reconfigured under a Mask must draw what a fresh grid does, to one level (bound 1, shipped 0).
|
||||
thermal_least = min((r for k, r in readings.values() if k == "thermal"), default=None)
|
||||
print(f"\natlas: shipped {shipped}, bound {bound_atlas}, least claimed mutant {atlas_least}, "
|
||||
f"geometric mean {math.sqrt(shipped * atlas_least):.2f}" if atlas_least else "\natlas: no claimed mutant")
|
||||
|
|
|
|||
Loading…
Reference in a new issue