Update bindings to 35e42d0a254f230bb736cf993a9c3855ea1680a1

This commit is contained in:
hwsmm 2024-07-28 14:31:48 +09:00 committed by hwsmm
parent e96b0ebb39
commit 1b1c59046b
32 changed files with 118 additions and 93 deletions

View File

@ -68,11 +68,9 @@ namespace SDL
public static extern byte* Unsafe_SDL_GetCurrentAudioDriver();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_AudioDeviceID *")]
public static extern SDL_AudioDeviceID* SDL_GetAudioPlaybackDevices(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_AudioDeviceID *")]
public static extern SDL_AudioDeviceID* SDL_GetAudioRecordingDevices(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetAudioDeviceName", ExactSpelling = true)]
@ -83,7 +81,6 @@ namespace SDL
public static extern int SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec* spec, int* sample_frames);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const int *")]
public static extern int* SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
@ -147,11 +144,9 @@ namespace SDL
public static extern int SDL_SetAudioStreamGain(SDL_AudioStream* stream, float gain);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const int *")]
public static extern int* SDL_GetAudioStreamInputChannelMap(SDL_AudioStream* stream, int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const int *")]
public static extern int* SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream* stream, int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]

View File

@ -67,11 +67,9 @@ namespace SDL
public static extern byte* Unsafe_SDL_GetCurrentCameraDriver();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_CameraID *")]
public static extern SDL_CameraID* SDL_GetCameras(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_CameraSpec *const *")]
public static extern SDL_CameraSpec** SDL_GetCameraSupportedFormats(SDL_CameraID devid, int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetCameraName", ExactSpelling = true)]

View File

@ -34,7 +34,7 @@ namespace SDL
public static extern int SDL_SetClipboardText([NativeTypeName("const char *")] byte* text);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetClipboardText", ExactSpelling = true)]
[return: NativeTypeName("const char *")]
[return: NativeTypeName("char *")]
public static extern byte* Unsafe_SDL_GetClipboardText();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
@ -44,7 +44,7 @@ namespace SDL
public static extern int SDL_SetPrimarySelectionText([NativeTypeName("const char *")] byte* text);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetPrimarySelectionText", ExactSpelling = true)]
[return: NativeTypeName("const char *")]
[return: NativeTypeName("char *")]
public static extern byte* Unsafe_SDL_GetPrimarySelectionText();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
@ -57,7 +57,7 @@ namespace SDL
public static extern int SDL_ClearClipboardData();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const void *")]
[return: NativeTypeName("void*")]
public static extern IntPtr SDL_GetClipboardData([NativeTypeName("const char *")] byte* mime_type, [NativeTypeName("size_t *")] nuint* size);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]

View File

@ -1110,14 +1110,6 @@ namespace SDL
[return: NativeTypeName("Uint32")]
public static extern uint SDL_RegisterEvents(int numevents);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("void*")]
public static extern IntPtr SDL_AllocateTemporaryMemory([NativeTypeName("size_t")] nuint size);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("void*")]
public static extern IntPtr SDL_ClaimTemporaryMemory([NativeTypeName("const void *")] IntPtr mem);
[NativeTypeName("#define SDL_RELEASED 0")]
public const int SDL_RELEASED = 0;

View File

@ -73,7 +73,7 @@ namespace SDL
public static extern byte* Unsafe_SDL_GetBasePath();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetPrefPath", ExactSpelling = true)]
[return: NativeTypeName("const char *")]
[return: NativeTypeName("char *")]
public static extern byte* Unsafe_SDL_GetPrefPath([NativeTypeName("const char *")] byte* org, [NativeTypeName("const char *")] byte* app);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetUserFolder", ExactSpelling = true)]
@ -99,7 +99,7 @@ namespace SDL
public static extern int SDL_GetPathInfo([NativeTypeName("const char *")] byte* path, SDL_PathInfo* info);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const char *const *")]
[return: NativeTypeName("char **")]
public static extern byte** SDL_GlobDirectory([NativeTypeName("const char *")] byte* path, [NativeTypeName("const char *")] byte* pattern, SDL_GlobFlags flags, int* count);
[NativeTypeName("#define SDL_GLOB_CASEINSENSITIVE (1u << 0)")]

View File

@ -192,15 +192,15 @@ namespace SDL
public static extern int SDL_ReloadGamepadMappings();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const char *const *")]
[return: NativeTypeName("char **")]
public static extern byte** SDL_GetGamepadMappings(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetGamepadMappingForGUID", ExactSpelling = true)]
[return: NativeTypeName("const char *")]
[return: NativeTypeName("char *")]
public static extern byte* Unsafe_SDL_GetGamepadMappingForGUID(SDL_GUID guid);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetGamepadMapping", ExactSpelling = true)]
[return: NativeTypeName("const char *")]
[return: NativeTypeName("char *")]
public static extern byte* Unsafe_SDL_GetGamepadMapping(SDL_Gamepad* gamepad);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
@ -210,7 +210,6 @@ namespace SDL
public static extern SDL_bool SDL_HasGamepad();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_JoystickID *")]
public static extern SDL_JoystickID* SDL_GetGamepads(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
@ -249,7 +248,7 @@ namespace SDL
public static extern SDL_GamepadType SDL_GetRealGamepadTypeForID(SDL_JoystickID instance_id);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetGamepadMappingForID", ExactSpelling = true)]
[return: NativeTypeName("const char *")]
[return: NativeTypeName("char *")]
public static extern byte* Unsafe_SDL_GetGamepadMappingForID(SDL_JoystickID instance_id);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
@ -330,7 +329,6 @@ namespace SDL
public static extern SDL_bool SDL_GamepadEventsEnabled();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_GamepadBinding *const *")]
public static extern SDL_GamepadBinding** SDL_GetGamepadBindings(SDL_Gamepad* gamepad, int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]

View File

@ -42,9 +42,8 @@ namespace SDL
public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GUIDToString", ExactSpelling = true)]
[return: NativeTypeName("const char *")]
public static extern byte* Unsafe_SDL_GUIDToString(SDL_GUID guid);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_GUIDToString(SDL_GUID guid, [NativeTypeName("char *")] byte* pszGUID, int cbGUID);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern SDL_GUID SDL_StringToGUID([NativeTypeName("const char *")] byte* pchGUID);

View File

@ -326,7 +326,6 @@ namespace SDL
public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_HapticID *")]
public static extern SDL_HapticID* SDL_GetHaptics(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetHapticNameForID", ExactSpelling = true)]

View File

@ -407,6 +407,9 @@ namespace SDL
[NativeTypeName("#define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME \"SDL_MOUSE_DOUBLE_CLICK_TIME\"")]
public static ReadOnlySpan<byte> SDL_HINT_MOUSE_DOUBLE_CLICK_TIME => "SDL_MOUSE_DOUBLE_CLICK_TIME"u8;
[NativeTypeName("#define SDL_HINT_MOUSE_EMULATE_WARP_WITH_RELATIVE \"SDL_MOUSE_EMULATE_WARP_WITH_RELATIVE\"")]
public static ReadOnlySpan<byte> SDL_HINT_MOUSE_EMULATE_WARP_WITH_RELATIVE => "SDL_MOUSE_EMULATE_WARP_WITH_RELATIVE"u8;
[NativeTypeName("#define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH \"SDL_MOUSE_FOCUS_CLICKTHROUGH\"")]
public static ReadOnlySpan<byte> SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH => "SDL_MOUSE_FOCUS_CLICKTHROUGH"u8;
@ -551,9 +554,6 @@ namespace SDL
[NativeTypeName("#define SDL_HINT_VIDEO_WAYLAND_ALLOW_LIBDECOR \"SDL_VIDEO_WAYLAND_ALLOW_LIBDECOR\"")]
public static ReadOnlySpan<byte> SDL_HINT_VIDEO_WAYLAND_ALLOW_LIBDECOR => "SDL_VIDEO_WAYLAND_ALLOW_LIBDECOR"u8;
[NativeTypeName("#define SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP \"SDL_VIDEO_WAYLAND_EMULATE_MOUSE_WARP\"")]
public static ReadOnlySpan<byte> SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP => "SDL_VIDEO_WAYLAND_EMULATE_MOUSE_WARP"u8;
[NativeTypeName("#define SDL_HINT_VIDEO_WAYLAND_MODE_EMULATION \"SDL_VIDEO_WAYLAND_MODE_EMULATION\"")]
public static ReadOnlySpan<byte> SDL_HINT_VIDEO_WAYLAND_MODE_EMULATION => "SDL_VIDEO_WAYLAND_MODE_EMULATION"u8;

View File

@ -170,7 +170,6 @@ namespace SDL
public static extern SDL_bool SDL_HasJoystick();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_JoystickID *")]
public static extern SDL_JoystickID* SDL_GetJoysticks(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetJoystickNameForID", ExactSpelling = true)]

View File

@ -33,7 +33,6 @@ namespace SDL
public static extern SDL_bool SDL_HasKeyboard();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_KeyboardID *")]
public static extern SDL_KeyboardID* SDL_GetKeyboards(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetKeyboardNameForID", ExactSpelling = true)]

View File

@ -39,7 +39,6 @@ namespace SDL
public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_Locale *const *")]
public static extern SDL_Locale** SDL_GetPreferredLocales(int* count);
}
}

View File

@ -68,7 +68,6 @@ namespace SDL
public static extern SDL_bool SDL_HasMouse();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_MouseID *")]
public static extern SDL_MouseID* SDL_GetMice(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetMouseNameForID", ExactSpelling = true)]

View File

@ -46,7 +46,6 @@ namespace SDL
public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_SensorID *")]
public static extern SDL_SensorID* SDL_GetSensors(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetSensorNameForID", ExactSpelling = true)]

View File

@ -80,6 +80,9 @@ namespace SDL
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int SDL_setenv([NativeTypeName("const char *")] byte* name, [NativeTypeName("const char *")] byte* value, int overwrite);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int SDL_unsetenv([NativeTypeName("const char *")] byte* name);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_qsort([NativeTypeName("void*")] IntPtr @base, [NativeTypeName("size_t")] nuint nmemb, [NativeTypeName("size_t")] nuint size, [NativeTypeName("SDL_CompareCallback")] delegate* unmanaged[Cdecl]<IntPtr, IntPtr, int> compare);

View File

@ -120,7 +120,7 @@ namespace SDL
public static extern ulong SDL_GetStorageSpaceRemaining(SDL_Storage* storage);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const char *const *")]
[return: NativeTypeName("char **")]
public static extern byte** SDL_GlobStorageDirectory(SDL_Storage* storage, [NativeTypeName("const char *")] byte* path, [NativeTypeName("const char *")] byte* pattern, SDL_GlobFlags flags, int* count);
}
}

View File

@ -49,7 +49,6 @@ namespace SDL
public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_TouchID *")]
public static extern SDL_TouchID* SDL_GetTouchDevices(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetTouchDeviceName", ExactSpelling = true)]
@ -60,7 +59,6 @@ namespace SDL
public static extern SDL_TouchDeviceType SDL_GetTouchDeviceType(SDL_TouchID touchID);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_Finger *const *")]
public static extern SDL_Finger** SDL_GetTouchFingers(SDL_TouchID touchID, int* count);
}
}

View File

@ -174,7 +174,6 @@ namespace SDL
public static extern SDL_SystemTheme SDL_GetSystemTheme();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_DisplayID *")]
public static extern SDL_DisplayID* SDL_GetDisplays(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
@ -203,12 +202,10 @@ namespace SDL
public static extern float SDL_GetDisplayContentScale(SDL_DisplayID displayID);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_DisplayMode *const *")]
public static extern SDL_DisplayMode** SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_DisplayMode *")]
public static extern SDL_DisplayMode* SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, SDL_bool include_high_density_modes);
public static extern int SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, SDL_bool include_high_density_modes, SDL_DisplayMode* mode);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const SDL_DisplayMode *")]
@ -241,14 +238,13 @@ namespace SDL
public static extern SDL_DisplayMode* SDL_GetWindowFullscreenMode(SDL_Window* window);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const void *")]
[return: NativeTypeName("void*")]
public static extern IntPtr SDL_GetWindowICCProfile(SDL_Window* window, [NativeTypeName("size_t *")] nuint* size);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern SDL_PixelFormat SDL_GetWindowPixelFormat(SDL_Window* window);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("SDL_Window *const *")]
public static extern SDL_Window** SDL_GetWindows(int* count);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]

View File

@ -47,18 +47,36 @@ namespace SDL
[Macro]
public static int SDL_AUDIO_FRAMESIZE(SDL_AudioSpec x) => SDL_AUDIO_BYTESIZE((x).format) * (x).channels;
[MustDisposeResource]
public static unsafe SDLArray<SDL_AudioDeviceID>? SDL_GetAudioPlaybackDevices()
{
int count;
var array = SDL_GetAudioPlaybackDevices(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
[MustDisposeResource]
public static unsafe SDLArray<SDL_AudioDeviceID>? SDL_GetAudioRecordingDevices()
{
int count;
var array = SDL_GetAudioRecordingDevices(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
[MustDisposeResource]
public static unsafe SDLArray<int>? SDL_GetAudioStreamInputChannelMap(SDL_AudioStream* stream)
{
int count;
int* array = SDL_GetAudioStreamInputChannelMap(stream, &count);
return SDLArray.Create(array, count);
}
[MustDisposeResource]
public static unsafe SDLArray<int>? SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream* stream)
{
int count;
int* array = SDL_GetAudioStreamOutputChannelMap(stream, &count);
return SDLArray.Create(array, count);
}
}
}

View File

@ -11,18 +11,20 @@ namespace SDL
public static partial class SDL3
{
[MustDisposeResource]
public static unsafe SDLArray<SDL_CameraID>? SDL_GetCameras()
{
int count;
var array = SDL_GetCameras(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
[MustDisposeResource]
public static unsafe SDLPointerArray<SDL_CameraSpec>? SDL_GetCameraSupportedFormats(SDL_CameraID devid)
{
int count;
var array = SDL_GetCameraSupportedFormats(devid, &count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
}
}

View File

@ -12,25 +12,28 @@ namespace SDL
/// <returns>
/// An array of <see cref="nint"/> that can be passed to <see cref="Marshal.PtrToStringUTF8(System.IntPtr)"/>.
/// </returns>
[MustDisposeResource]
public static unsafe SDLArray<IntPtr>? SDL_GetGamepadMappings()
{
int count;
IntPtr* array = (IntPtr*)SDL_GetGamepadMappings(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
[MustDisposeResource]
public static unsafe SDLArray<SDL_JoystickID>? SDL_GetGamepads()
{
int count;
var array = SDL_GetGamepads(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
[MustDisposeResource]
public static unsafe SDLPointerArray<SDL_GamepadBinding>? SDL_GetGamepadBindings(SDL_Gamepad* gamepad)
{
int count;
var array = SDL_GetGamepadBindings(gamepad, &count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
}
}

View File

@ -11,11 +11,12 @@ namespace SDL
public static partial class SDL3
{
[MustDisposeResource]
public static unsafe SDLArray<SDL_HapticID>? SDL_GetHaptics()
{
int count;
var array = SDL_GetHaptics(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
}
}

View File

@ -11,11 +11,12 @@ namespace SDL
public static partial class SDL3
{
[MustDisposeResource]
public static unsafe SDLArray<SDL_JoystickID>? SDL_GetJoysticks()
{
int count;
var array = SDL_GetJoysticks(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
}
}

View File

@ -11,11 +11,12 @@ namespace SDL
public static partial class SDL3
{
[MustDisposeResource]
public static unsafe SDLArray<SDL_KeyboardID>? SDL_GetKeyboards()
{
int count;
var array = SDL_GetKeyboards(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
}
}

View File

@ -0,0 +1,18 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using JetBrains.Annotations;
namespace SDL
{
public static partial class SDL3
{
[MustDisposeResource]
public static unsafe SDLPointerArray<SDL_Locale>? SDL_GetPreferredLocales()
{
int count;
var array = SDL_GetPreferredLocales(&count);
return SDLArray.Create(array, count);
}
}
}

View File

@ -34,11 +34,12 @@ namespace SDL
[Macro]
public static SDL_MouseButtonFlags SDL_BUTTON(SDLButton button) => (SDL_MouseButtonFlags)(1 << ((int)button - 1));
[MustDisposeResource]
public static unsafe SDLArray<SDL_MouseID>? SDL_GetMice()
{
int count;
var array = SDL_GetMice(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
}
}

View File

@ -11,11 +11,12 @@ namespace SDL
public static partial class SDL3
{
[MustDisposeResource]
public static unsafe SDLArray<SDL_SensorID>? SDL_GetSensors()
{
int count;
var array = SDL_GetSensors(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
}
}

View File

@ -0,0 +1,23 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Runtime.InteropServices;
using JetBrains.Annotations;
namespace SDL
{
public static partial class SDL3
{
/// <returns>
/// An array of <see cref="nint"/> that can be passed to <see cref="Marshal.PtrToStringUTF8(System.IntPtr)"/>.
/// </returns>
[MustDisposeResource]
public static unsafe SDLArray<IntPtr>? SDL_GlobStorageDirectory(SDL_Storage* storage, byte* path, byte* pattern, SDL_GlobFlags flags)
{
int count;
IntPtr* array = (IntPtr*)SDL_GlobStorageDirectory(storage, path, pattern, flags, &count);
return SDLArray.Create(array, count);
}
}
}

View File

@ -20,18 +20,20 @@ namespace SDL
[Constant]
public const SDL_TouchID SDL_MOUSE_TOUCHID = unchecked((SDL_TouchID)(-1));
[MustDisposeResource]
public static unsafe SDLArray<SDL_TouchID>? SDL_GetTouchDevices()
{
int count;
var array = SDL_GetTouchDevices(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
[MustDisposeResource]
public static unsafe SDLPointerArray<SDL_Finger>? SDL_GetTouchFingers(SDL_TouchID touchID)
{
int count;
var array = SDL_GetTouchFingers(touchID, &count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
}
}

View File

@ -55,25 +55,28 @@ namespace SDL
[Macro]
public static bool SDL_WINDOWPOS_ISCENTERED(int X) => (((X) & 0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK);
[MustDisposeResource]
public static unsafe SDLArray<SDL_DisplayID>? SDL_GetDisplays()
{
int count;
var array = SDL_GetDisplays(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
[MustDisposeResource]
public static unsafe SDLPointerArray<SDL_DisplayMode>? SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID)
{
int count;
var array = SDL_GetFullscreenDisplayModes(displayID, &count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
[MustDisposeResource]
public static unsafe SDLPointerArray<SDL_Window>? SDL_GetWindows()
{
int count;
var array = SDL_GetWindows(&count);
return SDLArray.CreatePooled(array, count);
return SDLArray.Create(array, count);
}
}
}

View File

@ -6,18 +6,17 @@ using JetBrains.Annotations;
namespace SDL
{
[MustDisposeResource]
public sealed unsafe class SDLArray<T> : IDisposable
where T : unmanaged
{
private readonly T* array;
private readonly bool isPooled;
public readonly int Count;
private bool isDisposed;
internal SDLArray(T* array, int count, bool isPooled = false)
internal SDLArray(T* array, int count)
{
this.array = array;
this.isPooled = isPooled;
Count = count;
}
@ -39,8 +38,7 @@ namespace SDL
isDisposed = true;
if (!isPooled)
SDL3.SDL_free(array);
SDL3.SDL_free(array);
}
}
@ -65,23 +63,5 @@ namespace SDL
return new SDLPointerArray<T>(array, count);
}
internal static SDLArray<T>? CreatePooled<T>(T* array, int count)
where T : unmanaged
{
if (array == null)
return null;
return new SDLArray<T>(array, count, true);
}
internal static SDLPointerArray<T>? CreatePooled<T>(T** array, int count)
where T : unmanaged
{
if (array == null)
return null;
return new SDLPointerArray<T>(array, count, true);
}
}
}

View File

@ -8,18 +8,17 @@ using JetBrains.Annotations;
namespace SDL
{
// T* can't be used as a type parameter, so this has to be a separate class
[MustDisposeResource]
public sealed unsafe class SDLPointerArray<T> : IDisposable
where T : unmanaged
{
private readonly T** array;
private readonly bool isPooled;
public readonly int Count;
private bool isDisposed;
internal SDLPointerArray(T** array, int count, bool isPooled = false)
internal SDLPointerArray(T** array, int count)
{
this.array = array;
this.isPooled = isPooled;
Count = count;
}
@ -41,9 +40,8 @@ namespace SDL
return;
isDisposed = true;
if (!isPooled)
SDL3.SDL_free(array);
SDL3.SDL_free(array);
}
}
}