Add passive F2 diagnostics overlay with persistent session visibility
This commit is contained in:
1 parent
20aa1bc2b9
commit
113e9a41cc
17 files changed
+414
-24
No files matched your search
@@ -0,0 +1,9 @@
|
||||
<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/Assets/*.cs" />
|
||||
<Compile Include="../../src/GamePort/Application/DebugMenu.cs" />
|
||||
<Compile Include="../../src/GamePort/Application/DebugDiagnostics.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,80 @@
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
using GamePort.Application;
|
||||
|
||||
var diagnostics = new DebugDiagnostics();
|
||||
var status = new DebugStatus("LV1B", "STARTEXP", new(1.25f, 76.5f, -3.5f), 155, 600,
|
||||
true, 20, 150, 60, "NONE", true, 2, 10000, false);
|
||||
var motion = new DebugMotion(new(100, -20, 30), -12.5f, "RUN", 120, 1, 2, 1, 7.5f, -1, false, 0, false);
|
||||
Require(!diagnostics.Enabled && diagnostics.Lines(status, motion).Length == 0, "Live overlay starts hidden");
|
||||
diagnostics.ObserveFrame(0);
|
||||
Require(diagnostics.Frames == 1 && diagnostics.FramesPerSecond == 0 && diagnostics.FrameMilliseconds == 0,
|
||||
"A zero-duration headless frame counts without inventing timing");
|
||||
diagnostics.ObserveFrame(.125);
|
||||
Near(diagnostics.FramesPerSecond, 8, "Initial timing is immediately usable");
|
||||
Near(diagnostics.FrameMilliseconds, 125, "Frame time uses elapsed wall time");
|
||||
diagnostics.ObserveFrame(.25);
|
||||
Near(diagnostics.FramesPerSecond, 2 / .375, "Initial window updates its running mean");
|
||||
diagnostics.ObserveFrame(.125);
|
||||
Near(diagnostics.FramesPerSecond, 6, "Half-second equality publishes a complete window");
|
||||
diagnostics.ObserveFrame(.25);
|
||||
Near(diagnostics.FramesPerSecond, 6, "Published timing stays stable until the next window completes");
|
||||
diagnostics.ObserveFrame(0);
|
||||
diagnostics.ObserveFrame(.25);
|
||||
Near(diagnostics.FramesPerSecond, 4, "Zero samples do not inflate the next window's FPS");
|
||||
Near(diagnostics.FrameMilliseconds, 250, "Next window measures only its own positive elapsed samples");
|
||||
Require(diagnostics.Frames == 7, "Frame count includes zero-duration frames across windows");
|
||||
Console.WriteLine("PASS live frame timing, initial mean, half-second boundaries and zero samples");
|
||||
|
||||
foreach (var invalid in new[] { -1, double.NaN, double.PositiveInfinity, double.NegativeInfinity })
|
||||
{
|
||||
var frames = diagnostics.Frames;
|
||||
Reject(() => diagnostics.ObserveFrame(invalid));
|
||||
Require(diagnostics.Frames == frames, "Rejected input cannot mutate timing counters");
|
||||
}
|
||||
var extreme = new DebugDiagnostics();
|
||||
extreme.ObserveFrame(double.Epsilon);
|
||||
Require(double.IsFinite(extreme.FramesPerSecond) && double.IsFinite(extreme.FrameMilliseconds), "Tiny finite elapsed cannot produce infinite FPS");
|
||||
extreme.ObserveFrame(double.MaxValue);
|
||||
Require(double.IsFinite(extreme.FramesPerSecond) && double.IsFinite(extreme.FrameMilliseconds), "Large finite elapsed cannot produce infinite frame milliseconds");
|
||||
Console.WriteLine("PASS invalid elapsed rejection and finite timing arithmetic");
|
||||
|
||||
diagnostics.Enabled = true;
|
||||
var originalCulture = CultureInfo.CurrentCulture;
|
||||
var unusual = (CultureInfo)CultureInfo.InvariantCulture.Clone();
|
||||
unusual.NumberFormat.NumberDecimalSeparator = ",";
|
||||
unusual.NumberFormat.NegativeSign = "NEG";
|
||||
CultureInfo.CurrentCulture = unusual;
|
||||
string[] lines;
|
||||
try { lines = diagnostics.Lines(status, motion); }
|
||||
finally { CultureInfo.CurrentCulture = originalCulture; }
|
||||
Require(lines.Length == 12 && lines.All(l => l.Length <= 58), "Live diagnostics fit the compact overlay bounds");
|
||||
Require(lines[2].Contains("76.5") && lines[2].Contains("-3.5") && !lines.Any(l => l.Contains("NEG")), "Numeric output is invariant under user culture");
|
||||
Require(lines[6] == "CTRL T FORCE F PAUSED F", "Control and pause diagnostics use live state");
|
||||
Require(lines[7].Contains("SCENE 60 SCORE 150 JETPACK 1 7.5S"), "Task, score, ownership and burst countdown are visible together");
|
||||
var changedStatus = status with { Root = new(40, 50, 60), ForcedControl = true, Inspecting = true, Cutscene = "neutron1a" };
|
||||
var changedMotion = motion with { Velocity = new(0, 500, 0), Pose = "FLY", Shot = 2, Blocked = true, Paused = true, VulkanErrors = 3 };
|
||||
var changed = diagnostics.Lines(changedStatus, changedMotion);
|
||||
Require(changed[2] != lines[2] && changed[3] != lines[3] && changed[5].Contains("FLY"), "Motion and position text changes with every live snapshot");
|
||||
Require(changed[6] == "CTRL T FORCE T PAUSED T" && changed[8].Contains("ORBIT") && changed[9].Contains("neutron1a SHOT 2 BLOCK T")
|
||||
&& changed[11].Contains("VK ERR 3"), "Force/camera/cutscene/block/Vulkan diagnostics stay independent");
|
||||
var authoredView = diagnostics.Lines(changedStatus with { CameraMode = "STRT", FarPlane = 5000 }, changedMotion);
|
||||
Require(authoredView[8] == "CAM STRT FAR 5000.0", "Actual rendered camera/projection can override inferred mode");
|
||||
var bounded = diagnostics.Lines(changedStatus with { Start = new string('X', 200), Cutscene = "line\nbreak" }, changedMotion);
|
||||
Require(bounded.All(l => l.Length <= 58 && !l.Contains('\n') && !l.Contains('\r')), "Long or multiline source tags cannot escape the compact panel");
|
||||
diagnostics.Enabled = false;
|
||||
Require(diagnostics.Lines(changedStatus, changedMotion).Length == 0 && status.Root == new Vector3(1.25f, 76.5f, -3.5f),
|
||||
"Hiding diagnostics does not mutate gameplay snapshots");
|
||||
Console.WriteLine("PASS compact live snapshots, invariant formatting, visibility and label bounds");
|
||||
|
||||
static void Require(bool condition, string message)
|
||||
{
|
||||
if (!condition) throw new InvalidOperationException(message);
|
||||
}
|
||||
static void Near(double actual, double expected, string message) => Require(Math.Abs(actual - expected) < .000001, message);
|
||||
static void Reject(Action action)
|
||||
{
|
||||
try { action(); }
|
||||
catch (ArgumentOutOfRangeException) { return; }
|
||||
throw new InvalidOperationException("Expected invalid elapsed rejection");
|
||||
}
|
||||
@@ -7,11 +7,14 @@ Require(!menu.Open && menu.Key(40) == DebugAction.None, "Closed menu cannot issu
|
||||
menu.Toggle(30);
|
||||
Require(menu.Open && menu.SceneTask == 30 && menu.Start == "STARTEXP", "F1 opens current context");
|
||||
menu.Key(82);
|
||||
Require(menu.Selected == 11 && menu.Key(40) == DebugAction.ToggleOverlay,
|
||||
"Live overlay has an independent menu toggle");
|
||||
menu.Key(82);
|
||||
Require(menu.Selected == 10 && menu.Key(40) == DebugAction.ForceControl && menu.Key(40, true) == DebugAction.None,
|
||||
"Force-control row emits one command per Enter press");
|
||||
menu.Key(82);
|
||||
Require(menu.Selected == 9 && menu.Key(40) == DebugAction.Reset, "Navigation wraps to reset");
|
||||
menu.Key(81); menu.Key(81);
|
||||
menu.Key(81); menu.Key(81); menu.Key(81);
|
||||
Require(menu.Selected == 0 && menu.Key(40, true) == DebugAction.None && menu.Key(40) == DebugAction.Resume,
|
||||
"Enter repeats cannot repeat commands");
|
||||
for (var i = 0; i < 5; i++) menu.Key(81);
|
||||
|
||||
@@ -17,6 +17,15 @@ Check(final.Draws.Skip(1).Count(d => d.Visible) == 5, "Background, selected row
|
||||
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");
|
||||
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, []);
|
||||
|
||||
Reference in new issue
Block a user