Keep presentation alive across levels and scale UI for widescreen
This commit is contained in:
1 parent
113e9a41cc
commit
69d0187a21
26 files changed
+889
-70
No files matched your search
@@ -0,0 +1,84 @@
|
||||
using System.Numerics;
|
||||
using GamePort.Application;
|
||||
using GamePort.Game;
|
||||
|
||||
var sizes = new (uint Width, uint Height)[] { (640, 480), (960, 720), (1920, 1080),
|
||||
(2560, 1080), (3440, 1440), (3840, 1080), (1080, 1920), (1920, 1920), (3840, 2160) };
|
||||
foreach (var (width, height) in sizes)
|
||||
{
|
||||
var viewport = new UiViewport(width, height);
|
||||
var a = Pixels(viewport.ToNdc(new(100, 100)), width, height);
|
||||
var b = Pixels(viewport.ToNdc(new(200, 140)), width, height);
|
||||
Near((b.X - a.X) / 100, viewport.Scale, "Horizontal art scale");
|
||||
Near((b.Y - a.Y) / 40, viewport.Scale, "Vertical art scale");
|
||||
NearVector(Pixels(viewport.ToNdc(new Vector2(320, 240) + viewport.CenterOffset), width, height),
|
||||
new(width / 2f, height / 2f), "Centered authored canvas");
|
||||
NearVector(Pixels(viewport.ToNdc(new Vector2(640, 480) + viewport.BottomRightOffset), width, height),
|
||||
new(width, height), "Bottom-right authored canvas");
|
||||
Near(Pixels(viewport.ToNdc(new Vector2(704, 480) + viewport.BottomRightOffset), width, height).X,
|
||||
width + 64 * viewport.Scale, "Original HUD overscan remains clipped rather than squeezed");
|
||||
NearVector(Pixels(viewport.ToNdc(new(8, 8)), width, height), new(8 * viewport.Scale), "Corner safe inset scales uniformly");
|
||||
|
||||
var pointer = new Vector2(265, 270);
|
||||
NearVector(viewport.InverseModal((pointer + viewport.CenterOffset) * viewport.Scale), pointer,
|
||||
"Render/input mappings are inverses");
|
||||
foreach (var (point, choice) in new[] { (new Vector2(265, 270), true), (new Vector2(355, 270), false) })
|
||||
{
|
||||
var prompt = new PracticePrompt();
|
||||
bool? selected = null;
|
||||
prompt.Chosen += (_, yes) => selected = yes;
|
||||
prompt.Show(0);
|
||||
prompt.Click(viewport.InverseModal(Pixels(viewport.ToNdc(point + viewport.CenterOffset), width, height)));
|
||||
Check(!prompt.Active && selected == choice, "Centered practice hit regions match visible art");
|
||||
}
|
||||
foreach (var boundary in new[] { new Vector2(225, 270), new Vector2(305, 270),
|
||||
new Vector2(265, 240), new Vector2(265, 300), new Vector2(315, 270), new Vector2(395, 270) })
|
||||
{
|
||||
var prompt = new PracticePrompt();
|
||||
prompt.Show(0);
|
||||
prompt.Click(viewport.InverseModal(Pixels(viewport.ToNdc(boundary + viewport.CenterOffset), width, height)));
|
||||
Check(prompt.Active, $"Strict source boundary must remain unselected: {width}x{height} {boundary}");
|
||||
}
|
||||
}
|
||||
Console.WriteLine("PASS uniform4:3/widescreen/ultrawide/portrait scale, anchors and strict modal input regions");
|
||||
|
||||
foreach (var (width, height) in new[] { (800u, 600u), (1280u, 720u), (1720u, 720u) })
|
||||
{
|
||||
var logical = new UiViewport(width, height);
|
||||
var authored = new Vector2(265, 270);
|
||||
var pointer = (authored + logical.CenterOffset) * logical.Scale;
|
||||
foreach (var (numerator, denominator) in new[] { (2u, 1u), (3u, 2u) })
|
||||
{
|
||||
var pixelWidth = width * numerator / denominator;
|
||||
var pixelHeight = height * numerator / denominator;
|
||||
var drawable = new UiViewport(pixelWidth, pixelHeight);
|
||||
var drawn = Pixels(drawable.ToNdc(authored + drawable.CenterOffset), pixelWidth, pixelHeight);
|
||||
NearVector(pointer * numerator / denominator, drawn, "High-DPI drawable art corresponds to logical pointer pixels");
|
||||
NearVector(logical.InverseModal(pointer), authored, "High-DPI pointer returns original modal coordinates");
|
||||
}
|
||||
}
|
||||
var classic = new UiViewport(640, 480);
|
||||
var fractional = new UiViewport(1922, 1082);
|
||||
var authoredPoint = new Vector2(265, 270);
|
||||
var drawnPoint = Pixels(fractional.ToNdc(authoredPoint + fractional.CenterOffset), 1922, 1082);
|
||||
var logicalPoint = new Vector2(drawnPoint.X * 1281 / 1922, drawnPoint.Y * 721 / 1082);
|
||||
NearVector(fractional.InverseModal(logicalPoint, 1281, 721), authoredPoint,
|
||||
"Fractional DPI with independently rounded drawable dimensions maps to actual art");
|
||||
Reject(() => fractional.InverseModal(Vector2.Zero, 0, 721));
|
||||
var old = classic.ToNdc(new(384, 311));
|
||||
Check(Vector3.Distance(old, new(.2f, 2 * 311f / 480 - 1, 0)) < .00001f, "Original4:3 NDC is unchanged");
|
||||
Reject(() => new UiViewport(0, 480));
|
||||
Reject(() => new UiViewport(640, 0));
|
||||
Reject(() => classic.ToNdc(new(float.NaN, 0)));
|
||||
Reject(() => classic.InverseModal(new(0, float.PositiveInfinity)));
|
||||
Console.WriteLine("PASS high-DPI mapping, original4:3 compatibility and invalid viewport/input rejection");
|
||||
|
||||
static Vector2 Pixels(Vector3 ndc, uint width, uint height) => new((ndc.X + 1) * width / 2, (ndc.Y + 1) * height / 2);
|
||||
static void Near(float actual, float expected, string message) => Check(MathF.Abs(actual - expected) < .002f, $"{message}: {actual} != {expected}");
|
||||
static void NearVector(Vector2 actual, Vector2 expected, string message) => Check(Vector2.Distance(actual, expected) < .003f, $"{message}: {actual} != {expected}");
|
||||
static void Check(bool value, string message) { if (!value) throw new InvalidOperationException(message); }
|
||||
static void Reject(Action action)
|
||||
{
|
||||
try { action(); } catch (ArgumentOutOfRangeException) { return; }
|
||||
throw new InvalidOperationException("Expected invalid UI viewport/input rejection");
|
||||
}
|
||||
Reference in new issue
Block a user