Add F1 debug menu with paused diagnostics and scene controls
This commit is contained in:
1 parent
8d60a68511
commit
3078b8afd0
21 files changed
+809
-36
No files matched your search
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType><TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks><EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="../../src/GamePort/Platform/Sdl.cs" />
|
||||
<Compile Include="../../src/GamePort/Audio/SdlAudio.cs" />
|
||||
<Compile Include="../../src/GamePort/Audio/SceneAudio.cs" />
|
||||
<Compile Include="../../src/GamePort/Assets/PreparedEntityResources.cs" />
|
||||
<Compile Include="../../src/GamePort/Assets/PngImage.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,96 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using GamePort.Assets;
|
||||
using GamePort.Audio;
|
||||
|
||||
// Actual SDL dummy-device behavior. Generated four-second WAVs keep this test
|
||||
// independent of original resources and long enough to observe consumption.
|
||||
var directory = Path.GetFullPath("artifacts/audio-pause");
|
||||
Directory.CreateDirectory(directory);
|
||||
var wave = Path.Combine(directory, "silence.wav");
|
||||
const int frequency = 11025, sourceBytes = frequency * 4 * 2;
|
||||
using (var file = File.Create(wave))
|
||||
using (var writer = new BinaryWriter(file))
|
||||
{
|
||||
writer.Write(Encoding.ASCII.GetBytes("RIFF")); writer.Write(36 + sourceBytes);
|
||||
writer.Write(Encoding.ASCII.GetBytes("WAVEfmt ")); writer.Write(16);
|
||||
writer.Write((short)1); writer.Write((short)1); writer.Write(frequency);
|
||||
writer.Write(frequency * 2); writer.Write((short)2); writer.Write((short)16);
|
||||
writer.Write(Encoding.ASCII.GetBytes("data")); writer.Write(sourceBytes);
|
||||
writer.Write(new byte[sourceBytes]);
|
||||
}
|
||||
|
||||
using (var stream = new SdlAudio(wave, loop: true, paused: true))
|
||||
{
|
||||
Require(stream.Paused && stream.QueuedBytes == sourceBytes, "New paused stream must retain its complete first WAV");
|
||||
var first = stream.QueuedBytes;
|
||||
Thread.Sleep(200); stream.Pump();
|
||||
Require(stream.QueuedBytes == first, "Paused loop must neither consume nor refill");
|
||||
stream.SetPaused(false); stream.SetPaused(false);
|
||||
Require(!stream.Paused, "Resume state");
|
||||
Thread.Sleep(200);
|
||||
Require(stream.QueuedBytes < first, "Resumed SDL device must consume queued audio");
|
||||
stream.SetPaused(true); stream.SetPaused(true);
|
||||
var stopped = stream.QueuedBytes;
|
||||
Thread.Sleep(200); stream.Pump();
|
||||
Require(stream.Paused && stream.QueuedBytes == stopped, "Existing stream pause must stop consumption and loop refills");
|
||||
stream.SetPaused(false);
|
||||
Thread.Sleep(200);
|
||||
Require(stream.QueuedBytes < stopped, "Second resume must consume again");
|
||||
}
|
||||
Console.WriteLine("PASS actual SDL stream starts paused, pause/resume is idempotent and loop pumping freezes");
|
||||
|
||||
var manifest = Path.Combine(directory, "resources.json");
|
||||
File.WriteAllText(manifest, JsonSerializer.Serialize(new { resources = new[]
|
||||
{
|
||||
Resource("music.omt", 0), Resource("voice.omt", 1),
|
||||
Resource("SoundEffects.omt", 58), Resource("SoundEffects.omt", 59)
|
||||
}}));
|
||||
using (var scene = new SceneAudio(new PreparedEntityResources(manifest)))
|
||||
{
|
||||
scene.SetPaused(true);
|
||||
scene.Music("music.omt", 0); scene.Speech("voice.omt", 1);
|
||||
scene.Effect(58); scene.Effect(59, "door");
|
||||
Require(scene.EffectCount == 1 && scene.LoopCount == 1, "One-shot and loop fixture");
|
||||
var first = Queued(scene);
|
||||
Require(scene.Paused && first == (sourceBytes, sourceBytes, sourceBytes * 2),
|
||||
"Every stream created under paused mixer must start with all source data queued");
|
||||
Thread.Sleep(200); scene.Pump();
|
||||
Require(Queued(scene) == first, "Paused music/speech/effects must retain their queues");
|
||||
scene.SetPaused(false); scene.SetPaused(false);
|
||||
Thread.Sleep(200);
|
||||
var consumed = Queued(scene);
|
||||
Require(consumed.Music < first.Music && consumed.Speech < first.Speech && consumed.Effects < first.Effects,
|
||||
"Every mixer stream category must resume consumption");
|
||||
scene.SetPaused(true); scene.SetPaused(true);
|
||||
var stopped = Queued(scene);
|
||||
Thread.Sleep(200); scene.Pump();
|
||||
Require(Queued(scene) == stopped, "Pausing active mixer must freeze music, speech, one-shots and loops");
|
||||
scene.RestartMusic(); scene.Speech("voice.omt", 1); scene.Effect(59, "door");
|
||||
var replaced = Queued(scene);
|
||||
Thread.Sleep(200); scene.Pump();
|
||||
Require(Queued(scene) == replaced, "Replacement streams inherit paused state");
|
||||
scene.SetPaused(false);
|
||||
Thread.Sleep(200);
|
||||
var restarted = Queued(scene);
|
||||
Require(restarted.Music < replaced.Music && restarted.Speech < replaced.Speech && restarted.Effects < replaced.Effects,
|
||||
"Replaced streams must resume with the existing one-shot");
|
||||
}
|
||||
Console.WriteLine("PASS mixer pauses all stream categories and preserves pause across replacement streams");
|
||||
|
||||
var disposed = new SdlAudio(wave, paused: true);
|
||||
disposed.Dispose(); disposed.Dispose();
|
||||
try { disposed.SetPaused(false); throw new InvalidOperationException("Expected disposed-state rejection"); }
|
||||
catch (ObjectDisposedException) { }
|
||||
Console.WriteLine("PASS repeated disposal balances SDL audio initialization and rejects further pause changes");
|
||||
|
||||
static object Resource(string database, int id) => new
|
||||
{
|
||||
database, id, type = "Wave", path = "silence.wav", audio = new { seconds = 4 }
|
||||
};
|
||||
static (int Music, int Speech, int Effects) Queued(SceneAudio scene) =>
|
||||
(scene.QueuedMusicBytes, scene.QueuedSpeechBytes, scene.QueuedEffectBytes);
|
||||
static void Require(bool condition, string message)
|
||||
{
|
||||
if (!condition) throw new InvalidOperationException(message);
|
||||
}
|
||||
@@ -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/Assets/*.cs" />
|
||||
<Compile Include="../../src/GamePort/Application/DebugMenu.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Numerics;
|
||||
using GamePort.Application;
|
||||
|
||||
var menu = new DebugMenu([new("level1b.gam", "LV1B", ["STARTEXP", "riverlab"]),
|
||||
new("VR04.gam", "VR04", ["PHONEBOOTH"])], "LEVEL1B.GAM", "startexp");
|
||||
Require(!menu.Open && menu.Key(40) == DebugAction.None, "Closed menu cannot issue commands");
|
||||
menu.Toggle(30);
|
||||
Require(menu.Open && menu.SceneTask == 30 && menu.Start == "STARTEXP", "F1 opens current context");
|
||||
menu.Key(82);
|
||||
Require(menu.Selected == 9 && menu.Key(40) == DebugAction.Reset, "Navigation wraps to reset");
|
||||
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);
|
||||
menu.Key(79); menu.Key(75);
|
||||
Require(menu.SceneTask == 41 && menu.Key(40) == DebugAction.ApplySceneTask, "SCENE edit is staged until apply");
|
||||
menu.Key(78); menu.Key(80);
|
||||
Require(menu.SceneTask == 30, "SCENE coarse/fine editing is reversible");
|
||||
for (var i = 0; i < 110; i++) menu.Key(78);
|
||||
Require(menu.SceneTask == 0, "SCENE lower bound");
|
||||
for (var i = 0; i < 110; i++) menu.Key(75);
|
||||
Require(menu.SceneTask == 999, "SCENE upper bound");
|
||||
menu.Key(81); menu.Key(79);
|
||||
Require(menu.Scene?.Code == "VR04" && menu.Start == "PHONEBOOTH", "Scene selection updates starts");
|
||||
menu.Key(80); menu.Key(81); menu.Key(79);
|
||||
Require(menu.Scene?.Code == "LV1B" && menu.Start == "riverlab", "Original named starts can be selected");
|
||||
menu.Key(81);
|
||||
Require(menu.Key(40) == DebugAction.LoadScene, "Load action is explicit");
|
||||
var view = menu.View(new("LV1B", "STARTEXP", new(1, 2, 3), 155, 0, true, 20, 50, 30, "NONE", true, 0, 10000, false));
|
||||
Require(view.Lines.Length <= 32 && view.SelectedLine == 17 && view.Lines.Any(s => s.Contains("riverlab")), "Bounded menu view highlights its action");
|
||||
menu.Key(41);
|
||||
Require(!menu.Open && menu.View(new("", "", Vector3.Zero, 0, 0, false, 0, 0, 0, "", false, 0, 0, false)).Lines.Length == 0,
|
||||
"Escape closes and hides the menu");
|
||||
menu.Toggle(65);
|
||||
Require(menu.SceneTask == 65, "Reopening refreshes live task state");
|
||||
Console.WriteLine("PASS debug navigation, input repeat, staged tasks, scene/start selection and view");
|
||||
|
||||
var original = Path.GetFullPath(args.Length == 1 ? args[0] : "../Original");
|
||||
var catalog = DebugMenu.AvailableScenes(original, Path.GetFullPath("artifacts/extracted"));
|
||||
Require(catalog.Length == 33 && catalog.All(s => s.Starts.Length > 0), "Only33 supplied scenes with prepared geometry are offered");
|
||||
Require(catalog.All(s => s.Code is not ("LV3B" or "LV3E")), "Absent geometry is not substituted into the menu");
|
||||
Require(catalog.Single(s => s.Code == "LV1B").Starts.Contains("riverlab"), "Actual underground STRT is available");
|
||||
Console.WriteLine("PASS original33-scene debug catalog and source startpoint coverage");
|
||||
|
||||
static void Require(bool condition, string message)
|
||||
{
|
||||
if (!condition) throw new InvalidOperationException(message);
|
||||
}
|
||||
@@ -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/Mesh.cs"/>
|
||||
<Compile Include="../../src/GamePort/Assets/PngImage.cs"/>
|
||||
<Compile Include="../../src/GamePort/Application/DebugMenuOverlay.cs"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Numerics;
|
||||
using GamePort.Assets;
|
||||
using GamePort.Application;
|
||||
|
||||
var source = new Mesh([new(new(10, 20, 30), Vector2.Zero, Vector3.One)], [0, 0, 0])
|
||||
{ Textures = new() { [int.MinValue] = PngImage.White } };
|
||||
var overlay = new DebugMenuOverlay(source);
|
||||
Check(overlay.Mesh.Vertices.Length == 1 + (2 + 32 * 76) * 4, "Fixed bounded vertex capacity");
|
||||
Check(overlay.Mesh.Draws.Length == 35 && !overlay.Mesh.Draws[0].ScreenSpace, "Implicit source draw preserved");
|
||||
Check(overlay.Mesh.Textures.Count == 2 && overlay.Mesh.Textures[int.MinValue + 1].Width == 128,
|
||||
"Atlas has its own noncolliding texture identity");
|
||||
Check(overlay.Mesh.Textures[int.MinValue + 1].Rgba.Count(b => b == 0) > 1000, "Font atlas contains alpha-tested spacing");
|
||||
var final = overlay.Mesh with { Vertices = overlay.Mesh.Vertices.ToArray(), Draws = overlay.Mesh.Draws.Select(d => d with {}).ToArray() };
|
||||
overlay.Update(final, ["Debug menu", "X: -123.5 / Y: 40.0", "Resume"], 2);
|
||||
Check(final.Vertices[0].Position == source.Vertices[0].Position, "World vertex preserved");
|
||||
Check(final.Draws.Skip(1).Count(d => d.Visible) == 5, "Background, selected row and three text draws shown");
|
||||
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");
|
||||
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, []);
|
||||
Check(final.Draws.Skip(1).All(d => !d.Visible) && final.Draws[0].Visible, "Closing hides overlay without hiding world");
|
||||
Reject(() => overlay.Update(source, ["Debug"]));
|
||||
Reject(() => overlay.Update(final, Enumerable.Repeat("X", 33).ToArray()));
|
||||
Reject(() => overlay.Update(final, ["Debug"], 1));
|
||||
Console.WriteLine("PASS fixed debug overlay capacity, texture identity, final-buffer composition, visibility and bounds");
|
||||
|
||||
static void Check(bool condition, string message) { if (!condition) throw new InvalidOperationException(message); }
|
||||
static void Reject(Action action)
|
||||
{
|
||||
try { action(); } catch (ArgumentException) { return; }
|
||||
throw new InvalidOperationException("Expected bounded overlay rejection");
|
||||
}
|
||||
Reference in new issue
Block a user