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,82 @@
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
|
||||
namespace GamePort.Application;
|
||||
|
||||
public readonly record struct DebugMotion(Vector3 Velocity, float TurnRate, string Pose,
|
||||
int Steps, int Jumps, int WallHits, int JetpackState, float JetpackRemaining,
|
||||
int Shot, bool Blocked, int VulkanErrors, bool Paused);
|
||||
|
||||
/// <summary>Modern read-only gameplay diagnostics and measured wall-frame timing.</summary>
|
||||
public sealed class DebugDiagnostics
|
||||
{
|
||||
public const uint ToggleKey = 59; // SDL scancode F2.
|
||||
public const int MaxLines = 12, MaxColumns = 58;
|
||||
private const double SampleSeconds = .5;
|
||||
private double windowSeconds;
|
||||
private long windowFrames;
|
||||
private bool publishedWindow;
|
||||
public bool Enabled { get; set; }
|
||||
public double FramesPerSecond { get; private set; }
|
||||
public double FrameMilliseconds { get; private set; }
|
||||
public long Frames { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Count all rendered frames; timing uses only positive elapsed samples.
|
||||
/// Show the running mean initially, then publish each half-second window.
|
||||
/// Caller supplies wall time, independently of paused simulation time.
|
||||
/// </summary>
|
||||
public void ObserveFrame(double seconds)
|
||||
{
|
||||
if (!double.IsFinite(seconds) || seconds < 0) throw new ArgumentOutOfRangeException(nameof(seconds));
|
||||
Frames++;
|
||||
if (seconds == 0) return;
|
||||
windowSeconds = Finite(windowSeconds + seconds);
|
||||
windowFrames++;
|
||||
if (!publishedWindow || windowSeconds >= SampleSeconds)
|
||||
{
|
||||
var mean = windowSeconds / windowFrames;
|
||||
FramesPerSecond = Finite(1 / mean);
|
||||
FrameMilliseconds = Finite(mean * 1000);
|
||||
}
|
||||
if (windowSeconds >= SampleSeconds)
|
||||
{
|
||||
publishedWindow = true;
|
||||
windowSeconds = 0;
|
||||
windowFrames = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public string[] Lines(DebugStatus status, DebugMotion motion)
|
||||
{
|
||||
if (!Enabled) return [];
|
||||
ArgumentNullException.ThrowIfNull(status);
|
||||
static string F(float value) => value.ToString("0.0", CultureInfo.InvariantCulture);
|
||||
static string B(bool value) => value ? "T" : "F";
|
||||
static string I(FormattableString text) => FormattableString.Invariant(text);
|
||||
var camera = status.CameraMode ?? (status.Inspecting ? "ORBIT" :
|
||||
string.Equals(status.Cutscene, "NONE", StringComparison.OrdinalIgnoreCase) ? "GAMEPLAY" : "CUTSCENE");
|
||||
string[] lines = [
|
||||
I($"DEBUG F2 | FPS {FramesPerSecond:0.0} | {FrameMilliseconds:0.00} MS"),
|
||||
I($"LEVEL {status.Level} START {status.Start}"),
|
||||
I($"ROOT X {F(status.Root.X)} Y {F(status.Root.Y)} Z {F(status.Root.Z)}"),
|
||||
I($"VEL X {F(motion.Velocity.X)} Y {F(motion.Velocity.Y)} Z {F(motion.Velocity.Z)}"),
|
||||
I($"YAW {F(status.Yaw)} SPEED {F(status.Speed)} TURN {F(motion.TurnRate)}"),
|
||||
I($"GROUND {B(status.Grounded)} POSE {motion.Pose} ENERGY {F(status.Energy)}"),
|
||||
I($"CTRL {B(status.Controlled)} FORCE {B(status.ForcedControl)} PAUSED {B(motion.Paused)}"),
|
||||
I($"SCENE {status.SceneTask} SCORE {status.Score} JETPACK {motion.JetpackState} {F(motion.JetpackRemaining)}S"),
|
||||
I($"CAM {camera} FAR {F(status.FarPlane)}"),
|
||||
I($"CUT {status.Cutscene} SHOT {motion.Shot} BLOCK {B(motion.Blocked)}"),
|
||||
I($"STEPS {motion.Steps} JUMPS {motion.Jumps} WALL {motion.WallHits}"),
|
||||
I($"ISSUES {status.Issues} VK ERR {motion.VulkanErrors} FRAME {Frames}")
|
||||
];
|
||||
for (var i = 0; i < lines.Length; i++)
|
||||
{
|
||||
var line = lines[i].Replace('\r', ' ').Replace('\n', ' ');
|
||||
lines[i] = line.Length > MaxColumns ? line[..MaxColumns] : line;
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
private static double Finite(double value) => double.IsFinite(value) ? value : double.MaxValue;
|
||||
}
|
||||
@@ -5,17 +5,17 @@ using GamePort.Assets;
|
||||
namespace GamePort.Application;
|
||||
|
||||
public sealed record DebugScene(string LevelFile, string Code, string[] Starts);
|
||||
public enum DebugAction { None, Resume, Camera, SkipCutscene, RefillEnergy, GiveJetpack, ApplySceneTask, LoadScene, Reset, ForceControl }
|
||||
public enum DebugAction { None, Resume, Camera, SkipCutscene, RefillEnergy, GiveJetpack, ApplySceneTask, LoadScene, Reset, ForceControl, ToggleOverlay }
|
||||
public sealed record DebugMenuView(string[] Lines, int SelectedLine);
|
||||
public sealed record DebugStatus(string Level, string Start, Vector3 Root, float Yaw, float Speed,
|
||||
bool Grounded, float Energy, int Score, int SceneTask, string Cutscene, bool Controlled,
|
||||
int Issues, float FarPlane, bool Inspecting, bool ForcedControl = false);
|
||||
int Issues, float FarPlane, bool Inspecting, bool ForcedControl = false, bool DiagnosticsVisible = false, string? CameraMode = null);
|
||||
|
||||
/// <summary>Modern investigation tools, deliberately separate from recovered game UI.</summary>
|
||||
public sealed class DebugMenu
|
||||
{
|
||||
public const uint ToggleKey = 58; // SDL scancode F1; F11 remains fullscreen.
|
||||
public const int ItemCount = 11;
|
||||
public const int ItemCount = 12;
|
||||
public bool Open { get; private set; }
|
||||
public int Selected { get; private set; }
|
||||
public int SceneTask { get; private set; }
|
||||
@@ -66,6 +66,7 @@ public sealed class DebugMenu
|
||||
3 => DebugAction.RefillEnergy, 4 => DebugAction.GiveJetpack, 5 => DebugAction.ApplySceneTask,
|
||||
8 => Scene == null ? DebugAction.None : DebugAction.LoadScene, 9 => DebugAction.Reset,
|
||||
10 => DebugAction.ForceControl,
|
||||
11 => DebugAction.ToggleOverlay,
|
||||
_ => DebugAction.None
|
||||
};
|
||||
return DebugAction.None;
|
||||
@@ -84,7 +85,7 @@ public sealed class DebugMenu
|
||||
$"YAW {F(status.Yaw)} SPEED {F(status.Speed)} GROUNDED {status.Grounded}",
|
||||
$"ENERGY {F(status.Energy)} SCORE {status.Score} SCENE {status.SceneTask}",
|
||||
$"CONTROL {status.Controlled} CUTSCENE {status.Cutscene}",
|
||||
$"ISSUES {status.Issues} FAR {F(status.FarPlane)} CAMERA {(status.Inspecting ? "ORBIT" : "GAMEPLAY")}",
|
||||
$"ISSUES {status.Issues} FAR {F(status.FarPlane)} CAMERA {status.CameraMode ?? (status.Inspecting ? "ORBIT" : "GAMEPLAY")}",
|
||||
"",
|
||||
"RESUME",
|
||||
$"CAMERA: {(status.Inspecting ? "SWITCH TO GAMEPLAY" : "SWITCH TO ORBIT")}",
|
||||
@@ -97,6 +98,7 @@ public sealed class DebugMenu
|
||||
"LOAD SELECTED LEVEL / START",
|
||||
"RESET CURRENT START",
|
||||
$"FORCE CONTROL: {status.ForcedControl} (ENTER TOGGLE)",
|
||||
$"LIVE OVERLAY: {status.DiagnosticsVisible} (F2 / ENTER TOGGLE)",
|
||||
"",
|
||||
"UP/DOWN SELECT LEFT/RIGHT CHANGE ENTER APPLY",
|
||||
"SCENE TASK: PAGE UP/DOWN CHANGES BY 10",
|
||||
|
||||
@@ -63,8 +63,9 @@ public sealed class DebugMenuOverlay
|
||||
/// lines clip at76 characters. selectedLine is -1 or an index into lines.
|
||||
/// Lowercase renders as uppercase, unsupported characters as question marks.
|
||||
/// Layout uses the same640x480 reference viewport as the original HUD.
|
||||
/// Compact mode uses a corner panel with58 columns and smaller live text.
|
||||
/// </summary>
|
||||
public void Update(Mesh destination, IReadOnlyList<string> lines, int selectedLine = -1)
|
||||
public void Update(Mesh destination, IReadOnlyList<string> lines, int selectedLine = -1, bool compact = false)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(destination);
|
||||
ArgumentNullException.ThrowIfNull(lines);
|
||||
@@ -77,7 +78,14 @@ public sealed class DebugMenuOverlay
|
||||
background.Visible = lines.Count > 0;
|
||||
highlight.Visible = selectedLine >= 0;
|
||||
var solid = new Vector2(127.5f / AtlasWidth, 63.5f / AtlasHeight);
|
||||
Quad(firstVertex, 18, 18, 604, Math.Clamp(lines.Count * LineHeight + 24, 80, 444), solid, solid, new(.025f, .04f, .07f));
|
||||
var lineHeight = compact ? 10 : LineHeight;
|
||||
var advance = compact ? 6 : CharacterAdvance;
|
||||
var textX = compact ? 16 : 30;
|
||||
var textY = compact ? 16 : 30;
|
||||
var compactColumns = lines.Count == 0 ? 24 : Math.Clamp(lines.Max(line => line?.Length ?? 0), 24, 58);
|
||||
Quad(firstVertex, compact ? 8 : 18, compact ? 8 : 18, compact ? compactColumns * advance + 16 : 604,
|
||||
Math.Clamp(lines.Count * lineHeight + (compact ? 16 : 24), compact ? 30 : 80, 444),
|
||||
solid, solid, new(.025f, .04f, .07f));
|
||||
Quad(firstVertex + 4, 25, 27 + selectedLine * LineHeight, 590, LineHeight,
|
||||
solid, solid, new(.07f, .24f, .33f));
|
||||
for (var row = 0; row < MaxLines; row++)
|
||||
@@ -89,13 +97,13 @@ public sealed class DebugMenuOverlay
|
||||
var color = row == 0 ? new Vector3(1, .83f, .35f) : new(.85f, .93f, .98f);
|
||||
for (var column = 0; column < MaxColumns; column++)
|
||||
{
|
||||
var character = column < line.Length ? char.ToUpperInvariant(line[column]) : ' ';
|
||||
var character = column < line.Length && (!compact || column < 58) ? char.ToUpperInvariant(line[column]) : ' ';
|
||||
if (character is < ' ' or > '~') character = '?';
|
||||
var cell = character - ' ';
|
||||
var x = cell % 16 * 8 + 1;
|
||||
var y = cell / 16 * 8;
|
||||
Quad(firstVertex + 8 + (row * MaxColumns + column) * 4,
|
||||
30 + column * CharacterAdvance, 30 + row * LineHeight, 7, 9.8f,
|
||||
textX + column * advance, textY + row * lineHeight, compact ? 5.6f : 7, compact ? 7.84f : 9.8f,
|
||||
new((float)x / AtlasWidth, (float)y / AtlasHeight),
|
||||
new((x + 5f) / AtlasWidth, (y + 7f) / AtlasHeight), color);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user