66 lines
4.2 KiB
C#
66 lines
4.2 KiB
C#
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");
|
|
var menuRight = final.Vertices[2].Position.X;
|
|
var menuBottom = final.Vertices[3].Position.Y;
|
|
overlay.Update(final, ["F2 LIVE DEBUG", "POSITION X 1.0 Y 2.0 Z 3.0"], compact: true);
|
|
Check(final.Vertices[2].Position.X < menuRight && final.Vertices[3].Position.Y < menuBottom,
|
|
"Live panel occupies a smaller corner while preserving world geometry");
|
|
Check(final.Draws.Skip(1).Count(d => d.Visible) == 3, "Live panel has no selected menu row");
|
|
overlay.Update(final, ["Menu", "Resume", "Camera"], 1);
|
|
Check(final.Vertices[2].Position.X == menuRight && final.Vertices[3].Position.Y == menuBottom,
|
|
"Returning to menu restores its full layout using the same buffers");
|
|
foreach (var (width, height) in new[] { (1920u, 1080u), (3440u, 1440u), (3840u, 1080u), (1080u, 1920u) })
|
|
{
|
|
Vector2 Pixel(int index)
|
|
{
|
|
var p = final.Vertices[index].Position;
|
|
return new((p.X + 1) * width / 2, (p.Y + 1) * height / 2);
|
|
}
|
|
var viewport = new UiViewport(width, height);
|
|
overlay.Update(final, ["Menu", "Resume", "Camera"], 1, viewportWidth: width, viewportHeight: height);
|
|
var backgroundLeft = Pixel(1).X; var backgroundRight = Pixel(2).X;
|
|
Check(MathF.Abs((backgroundLeft + backgroundRight) / 2 - width / 2f) < .003f,
|
|
"F1 panel centers in the wide physical viewport");
|
|
var character = Pixel(9);
|
|
Check(MathF.Abs((Pixel(10).X - character.X) / 7 - (Pixel(12).Y - character.Y) / 9.8f) < .0001f,
|
|
"F1 glyphs retain equal X/Y scale");
|
|
overlay.Update(final, ["F2 LIVE DEBUG", "ROOT X 10 Y 20 Z 30"], compact: true, viewportWidth: width, viewportHeight: height);
|
|
Check(Vector2.Distance(Pixel(1), new Vector2(8 * viewport.Scale)) < .003f,
|
|
"F2 remains at the uniform top-left safe inset");
|
|
character = Pixel(9);
|
|
Check(MathF.Abs((Pixel(10).X - character.X) / 5.6f - (Pixel(12).Y - character.Y) / 7.84f) < .0001f,
|
|
"F2 glyphs are never stretched across widescreen");
|
|
}
|
|
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");
|
|
}
|