Commit Graph

633 Commits

Author SHA1 Message Date
Susko3 91cef07624 Add friendly `string?` overloads to C `(const) char *` functions
This is done by adding a `Unsafe_` prefix to `(const) char *` (C# `byte*`) functions.
I am using `string?` instead of `ReadOnlyMemory<byte>?` because the returned pointer can
get invalidated and cause memory-safety issues.

The returned pointer is automatically freed if the return type is `char *`.
I've checked that the documentation for all functions (except in SDL_stdinc.h)
requires calling `SDL_free()` on the pointer.
2024-04-06 14:36:36 +02:00
Susko3 c5e3181962 Add source generator for `ReadOnlySpan<byte>` overloads of C `const char *` functions 2024-04-06 14:24:33 +02:00
Susko3 75db9b16c1 Add memory safe IDisposable overloads to array-returning functions
This could be done with a source generator, but this is simpler.
2024-04-06 14:20:08 +02:00
Susko3 9a5d2e4dbc Add C# type-friendly properties/getters to some structs 2024-04-06 14:12:44 +02:00
Susko3 711e004ecd Add `PtrToStringUTF8()` for `byte *` 2024-04-06 14:08:42 +02:00
Susko3 702dc06a03 Add `void *` overload for `SDL_free()`
Useful as any pointer type can implicitly covert to void *.
2024-04-06 14:07:38 +02:00
Susko3 42b196611d Manually implement macro functions
All of these get "Function like macro definition records are not supported: [...] Generated bindings may be incomplete."
warnings when running ClangSharp.
2024-04-06 14:05:52 +02:00
Susko3 4b1a1e2102 Move `SDL_Keycode` typdef to global python script to avoid duplicate definition 2024-04-06 13:47:08 +02:00
Susko3 b97a553ed4 Remap `SDL_KeyCode` enum to `SDL_Keycode` typedef
This doesn't compile because of duplicate `SDL_Keycode` definition
2024-04-06 13:45:49 +02:00
Susko3 5747f163ac Manually implement endianness-specific audio formats 2024-04-06 13:42:10 +02:00
Susko3 37da786af0 Define `SDL_FUNCTION_POINTER_IS_VOID_POINTER` 2024-04-06 13:38:13 +02:00
Susko3 caa48201d3 Manually define broken constants 2024-04-06 13:33:00 +02:00
Susko3 9e44316535 Fix invalid `int` -> `SDL_bool` conversion by manually changing SDL headers 2024-04-06 13:33:00 +02:00
Susko3 409ecf7536 Add C# enum "typedefs" for C typedefs
This doesn't compile as ClangSharp fails to emit `unchecked`
in `SDL_pen.g.cs` and `SDL_touch.g.cs`.
And `(SDL_bool)` casts in `SDL_rect.g.cs`.
2024-04-06 13:32:55 +02:00
Susko3 dfe0d2533c Add `[Flags]` attribute to mask/flags enums 2024-04-06 12:58:35 +02:00
Susko3 a25b4be3b2 Add [UnsupportedOSPlatform("windows")] to `SDL_CreateThread()` functions
See commit: 72353a8ab9
2024-04-06 12:54:12 +02:00
Susko3 75a9cde3f8 Don't log potential typedef remappings
Produces a lot of noise about unused remappings (as we're processing a header at a time).
All remappings (except `SDL_JoystickGUID`) have been added.

`SDL_JoystickGUID` is a remapping of a struct, so it's harded to do programatically.
2024-04-06 12:37:14 +02:00
Susko3 dfe2b5b251 Remap C `void *` to C# `IntPtr` 2024-04-06 12:34:11 +02:00
Susko3 53f98fece1 Map C `char` to C# `byte` instead of `sbyte`
This matches .NET's UTF-8 `ReadOnlySpan<byte>` (see `SDL_hints.g.cs`).
2024-04-06 12:31:32 +02:00
Susko3 13b34fe88b Remap `wchar_t *` to `IntPtr`
These map to 16-bit `ushort` on windows, but are 32-bit on Unix.
2024-04-06 12:28:16 +02:00
Susko3 a2178e0022 Add recommended remapping for `SDL_hidapi.h` 2024-04-06 12:22:50 +02:00
Susko3 4ed850c6f3 Exclude `SDL_main()` from DllImport as it isn't exported by SDL3.dll 2024-04-06 01:59:38 +02:00
Susko3 52d13f2972 Add custom definition for win32 MSG struct
The win32 types are kinda cursed, but it makes it easy to copy&paste and check.
2024-04-06 01:42:45 +02:00
Susko3 ba561098e7 Fix missing <endian.h> when cross-compiling on windows
This works because SDL checks <endian.h> iff SDL_BYTEORDER isn't defined.
6ad390fc50/include/SDL3/SDL_endian.h (L58-L60)
2024-04-06 01:37:05 +02:00
Susko3 cef2e24326 Fix duplicate `XEvent` struct definitions 2024-04-06 01:34:10 +02:00
Susko3 2ccdcb04b3 Add platform specific generation for `SDL_main.h` and `SDL_system.h`
Doesn't compile because of duplicate `_XEvent` definitions.
Linux fails crossgen on Windows due to missing `endian.h`
2024-04-06 01:31:16 +02:00
Susko3 0fc701a1d9 Add simple check for generated functions
There are warnings for platform-specific functions.
2024-04-06 01:17:00 +02:00
Susko3 4fbe435cbe Fix errors in `SDL_stdinc.g.cs` with define magic 2024-04-06 01:00:29 +02:00
Susko3 efc9422f7c Fix errors in `SDL_pixels.g.cs` by specifying enum types 2024-04-06 01:00:29 +02:00
Susko3 72353a8ab9 Undefine _WIN32 to generate only platform-agnostic APIs
Probably needs similar undefines on Linux and macOS.

Notice that the signatures of `SDL_CreateThread` and `SDL_CreateThreadWithStackSize`
have changed.
2024-04-06 01:00:29 +02:00
Susko3 1512bef026 Initial SDL3-CS binding project with ClangSharp
The bindings don't yet compile. There are errors in SDL_pixels.g.cs, SDL_stdinc.g.cs and SDL_thread.g.cs,
a bunch of warnings about "Function like macro definition records are not supported",
and a few "Info: Potential missing remapping".

Built on SDL commit:
6ad390fc50
2024-04-06 00:57:07 +02:00
Susko3 7012887e6f Add global/base files 2024-04-05 23:59:34 +02:00
Dan Balasescu a4270da3c0
Add README 2024-04-04 03:12:48 +09:00