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 NOCLIP F", "Control, pause and noclip 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", Systems = new() { Noclip = true } }; 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 NOCLIP 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"); }