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
@@ -5,5 +5,6 @@
|
||||
<Compile Include="../../src/GamePort/Assets/Mesh.cs"/>
|
||||
<Compile Include="../../src/GamePort/Assets/PngImage.cs"/>
|
||||
<Compile Include="../../src/GamePort/Application/DebugMenuOverlay.cs"/>
|
||||
<Compile Include="../../src/GamePort/Application/UiViewport.cs"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -26,6 +26,28 @@ Check(final.Draws.Skip(1).Count(d => d.Visible) == 3, "Live panel has no selecte
|
||||
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, []);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<Compile Include="../../src/GamePort/Assets/Mesh.cs"/>
|
||||
<Compile Include="../../src/GamePort/Assets/PngImage.cs"/>
|
||||
<Compile Include="../../src/GamePort/Application/SceneHud.cs"/>
|
||||
<Compile Include="../../src/GamePort/Application/UiViewport.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/ObjectivePanel.cs"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -50,6 +50,27 @@ try
|
||||
Check(final.Draws.Skip(1).All(d => !d.Visible), "Timed-out objective has no remaining overlay draw");
|
||||
panel.Key(true); panel.Step(1); PresentPanel();
|
||||
Check(final.Draws.Skip(1).Count(d => d.Visible) == 3, "O reopens timed-out panel through the timer");
|
||||
foreach (var (width, height) in new[] { (1920u, 1080u), (3440u, 1440u), (3840u, 1080u), (1080u, 1920u) })
|
||||
{
|
||||
hud.Update(final, 1, true, true, viewportWidth: width, viewportHeight: height);
|
||||
var viewport = new UiViewport(width, height);
|
||||
Vector2 Pixel(int index)
|
||||
{
|
||||
var p = final.Vertices[index].Position;
|
||||
return new((p.X + 1) * width / 2, (p.Y + 1) * height / 2);
|
||||
}
|
||||
var pad = Pixel(1); var modal = Pixel(29);
|
||||
Check(Vector2.Distance(pad, new(width - 256 * viewport.Scale, height - 169 * viewport.Scale)) < .003f,
|
||||
"Objective pad remains bottom/right anchored");
|
||||
var modalExpected = (new Vector2(210, 210) + viewport.CenterOffset) * viewport.Scale;
|
||||
Check(Vector2.Distance(modal, modalExpected) < .003f, "Modal shifts with centered authored canvas");
|
||||
Check(MathF.Abs((Pixel(30).X - modal.X) / 207 - (Pixel(32).Y - modal.Y) / 100) < .0001f,
|
||||
"Original modal art has equal physical X/Y scale");
|
||||
Check(MathF.Abs((Pixel(2).X - pad.X) / 320 - (Pixel(4).Y - pad.Y) / 173) < .0001f,
|
||||
"Objective pad is never stretched in widescreen");
|
||||
}
|
||||
hud.Update(final, 2, true, true);
|
||||
Near(final.Vertices[1].Position, new(.2f, 2*311f/480-1, 0), "Returning to4:3 restores source positions");
|
||||
Reject(() => hud.Update(source, 1, true, false), "Missing final ranges");
|
||||
Reject(() => hud.Update(final, 1, true, false, float.NaN), "Nonfinite HUD offset");
|
||||
File.WriteAllText(path, Manifest(entries.Select(e => new { e.id, width=e.id==120 ? 0 : e.width, e.height, e.path })));
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net10.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><EnableDefaultCompileItems>false</EnableDefaultCompileItems></PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="../../src/GamePort/Application/UiViewport.cs" />
|
||||
<Compile Include="../../src/GamePort/Game/PracticePrompt.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -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