From 05c7ec057c1c05307c73dbb5bb73d0e3b02fae76 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Wed, 2 Oct 2024 02:13:12 +0100 Subject: [PATCH] Add some missing macros --- SDL3-CS.Tests/TestInterface.cs | 44 ++++++++++++++++++++++++++++++++++ SDL3-CS/SDL3/SDL_audio.cs | 4 ++++ SDL3-CS/SDL3/SDL_stdinc.cs | 14 +++++++++++ 3 files changed, 62 insertions(+) create mode 100644 SDL3-CS.Tests/TestInterface.cs diff --git a/SDL3-CS.Tests/TestInterface.cs b/SDL3-CS.Tests/TestInterface.cs new file mode 100644 index 0000000..2eeeff8 --- /dev/null +++ b/SDL3-CS.Tests/TestInterface.cs @@ -0,0 +1,44 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; + +namespace SDL.Tests +{ + [TestFixture] + public class TestInterface + { + [Test] + public unsafe void TestIOInterface() + { + SDL_IOStreamInterface iface; + + SDL3.SDL_INIT_INTERFACE(out iface); + + Assert.That(iface.version, Is.EqualTo(sizeof(SDL_IOStreamInterface))); + Assert.That(iface.size == null); + Assert.That(iface.seek == null); + Assert.That(iface.read == null); + Assert.That(iface.write == null); + Assert.That(iface.flush == null); + Assert.That(iface.close == null); + } + + [Test] + public unsafe void TestIOInterfaceManual() + { + SDL_IOStreamInterface iface = new SDL_IOStreamInterface + { + version = (uint)sizeof(SDL_IOStreamInterface), + }; + + Assert.That(iface.version, Is.EqualTo(sizeof(SDL_IOStreamInterface))); + Assert.That(iface.size == null); + Assert.That(iface.seek == null); + Assert.That(iface.read == null); + Assert.That(iface.write == null); + Assert.That(iface.flush == null); + Assert.That(iface.close == null); + } + } +} diff --git a/SDL3-CS/SDL3/SDL_audio.cs b/SDL3-CS/SDL3/SDL_audio.cs index 8f7e3ef..09829b9 100644 --- a/SDL3-CS/SDL3/SDL_audio.cs +++ b/SDL3-CS/SDL3/SDL_audio.cs @@ -11,6 +11,10 @@ namespace SDL public static partial class SDL3 { + [Macro] + public static SDL_AudioFormat SDL_DEFINE_AUDIO_FORMAT(UInt16 signed, UInt16 bigendian, UInt16 @float, UInt16 size) => + (SDL_AudioFormat)(((UInt16)(signed) << 15) | ((UInt16)(bigendian) << 12) | ((UInt16)(@float) << 8) | ((size) & (UInt16)SDL_AUDIO_MASK_BITSIZE)); + [Constant] public static readonly SDL_AudioFormat SDL_AUDIO_S16 = BitConverter.IsLittleEndian ? SDL_AudioFormat.SDL_AUDIO_S16LE : SDL_AudioFormat.SDL_AUDIO_S16BE; diff --git a/SDL3-CS/SDL3/SDL_stdinc.cs b/SDL3-CS/SDL3/SDL_stdinc.cs index b13d02f..8897df5 100644 --- a/SDL3-CS/SDL3/SDL_stdinc.cs +++ b/SDL3-CS/SDL3/SDL_stdinc.cs @@ -46,6 +46,20 @@ namespace SDL [Macro] public static uint SDL_FOURCC(byte A, byte B, byte C, byte D) => (uint)((A << 0) | (B << 8) | (C << 16) | (D << 24)); + [Macro] + public static unsafe void SDL_INIT_INTERFACE(out SDL_IOStreamInterface iface) + { + iface = default; + iface.version = (uint)sizeof(SDL_IOStreamInterface); + } + + [Macro] + public static unsafe void SDL_INIT_INTERFACE(out SDL_StorageInterface iface) + { + iface = default; + iface.version = (uint)sizeof(SDL_StorageInterface); + } + public static unsafe void SDL_free(void* mem) => SDL_free((IntPtr)mem); } }