using System.Numerics; using GamePort.Assets; using GamePort.Application; var source = new Mesh([new(new(10, 20, 30), Vector2.Zero, Vector3.One)], [0, 0, 0]) { Textures = new() { [int.MinValue] = PngImage.White } }; var overlay = new DebugMenuOverlay(source); Check(overlay.Mesh.Vertices.Length == 1 + (2 + 32 * 76) * 4, "Fixed bounded vertex capacity"); Check(overlay.Mesh.Draws.Length == 35 && !overlay.Mesh.Draws[0].ScreenSpace, "Implicit source draw preserved"); Check(overlay.Mesh.Textures.Count == 2 && overlay.Mesh.Textures[int.MinValue + 1].Width == 128, "Atlas has its own noncolliding texture identity"); Check(overlay.Mesh.Textures[int.MinValue + 1].Rgba.Count(b => b == 0) > 1000, "Font atlas contains alpha-tested spacing"); var final = overlay.Mesh with { Vertices = overlay.Mesh.Vertices.ToArray(), Draws = overlay.Mesh.Draws.Select(d => d with {}).ToArray() }; overlay.Update(final, ["Debug menu", "X: -123.5 / Y: 40.0", "Resume"], 2); Check(final.Vertices[0].Position == source.Vertices[0].Position, "World vertex preserved"); Check(final.Draws.Skip(1).Count(d => d.Visible) == 5, "Background, selected row and three text draws shown"); Check(final.Vertices[1].Position != Vector3.Zero && overlay.Mesh.Vertices[1].Position == Vector3.Zero, "Update targets final copied buffer"); Check(final.Vertices.All(v => float.IsFinite(v.Position.X + v.Position.Y + v.Uv.X + v.Uv.Y)), "All overlay coordinates finite"); overlay.Update(final, [new string('X', 100)], -1); Check(final.Draws.Skip(1).Count(d => d.Visible) == 2, "Long labels clip to bounded text range"); overlay.Update(final, []); Check(final.Draws.Skip(1).All(d => !d.Visible) && final.Draws[0].Visible, "Closing hides overlay without hiding world"); Reject(() => overlay.Update(source, ["Debug"])); Reject(() => overlay.Update(final, Enumerable.Repeat("X", 33).ToArray())); Reject(() => overlay.Update(final, ["Debug"], 1)); Console.WriteLine("PASS fixed debug overlay capacity, texture identity, final-buffer composition, visibility and bounds"); static void Check(bool condition, string message) { if (!condition) throw new InvalidOperationException(message); } static void Reject(Action action) { try { action(); } catch (ArgumentException) { return; } throw new InvalidOperationException("Expected bounded overlay rejection"); }