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
@@ -9,6 +9,8 @@ public sealed class SdlAudio : IDisposable
|
||||
private nint data;
|
||||
private int length;
|
||||
private readonly bool loop;
|
||||
private bool audioInitialized;
|
||||
public bool Paused { get; private set; }
|
||||
public int QueuedBytes
|
||||
{
|
||||
get
|
||||
@@ -17,10 +19,11 @@ public sealed class SdlAudio : IDisposable
|
||||
return bytes >= 0 ? bytes : throw new InvalidOperationException(Sdl.Error);
|
||||
}
|
||||
}
|
||||
public SdlAudio(string path,bool loop=false)
|
||||
public SdlAudio(string path,bool loop=false,bool paused=false)
|
||||
{
|
||||
this.loop=loop;
|
||||
if(!Sdl.SDL_InitSubSystem(Sdl.InitAudio))throw new InvalidOperationException(Sdl.Error);
|
||||
audioInitialized = true;
|
||||
try
|
||||
{
|
||||
if(!Sdl.SDL_LoadWAV(Path.GetFullPath(path),out var spec,out data,out var size))throw new InvalidOperationException(Sdl.Error);
|
||||
@@ -28,17 +31,28 @@ public sealed class SdlAudio : IDisposable
|
||||
stream=Sdl.SDL_OpenAudioDeviceStream(uint.MaxValue,ref spec,0,0);
|
||||
if(stream==0)throw new InvalidOperationException(Sdl.Error);
|
||||
Queue();
|
||||
if(!Sdl.SDL_ResumeAudioStreamDevice(stream))throw new InvalidOperationException(Sdl.Error);
|
||||
// SDL_OpenAudioDeviceStream starts paused. Keep it paused from its
|
||||
// first sample when created while a debug menu has stopped playback.
|
||||
Paused = true;
|
||||
SetPaused(paused);
|
||||
Console.WriteLine($"SDL3 WAV stream: {spec.Frequency} Hz, {spec.Channels} channel(s), {length} source bytes.");
|
||||
}
|
||||
catch{Dispose();throw;}
|
||||
}
|
||||
public void SetPaused(bool paused)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(stream == 0, this);
|
||||
if (Paused == paused) return;
|
||||
var changed = paused ? Sdl.SDL_PauseAudioStreamDevice(stream) : Sdl.SDL_ResumeAudioStreamDevice(stream);
|
||||
if (!changed) throw new InvalidOperationException(Sdl.Error);
|
||||
Paused = paused;
|
||||
}
|
||||
private void Queue(){if(!Sdl.SDL_PutAudioStreamData(stream,data,length))throw new InvalidOperationException(Sdl.Error);}
|
||||
public void Pump(){if(loop && QueuedBytes<length)Queue();}
|
||||
public void Pump(){if(!Paused && loop && QueuedBytes<length)Queue();}
|
||||
public void Dispose()
|
||||
{
|
||||
if(stream!=0){Sdl.SDL_DestroyAudioStream(stream);stream=0;}
|
||||
if(data!=0){Sdl.SDL_free(data);data=0;}
|
||||
Sdl.SDL_QuitSubSystem(Sdl.InitAudio);
|
||||
if(audioInitialized){Sdl.SDL_QuitSubSystem(Sdl.InitAudio);audioInitialized=false;}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user