Fix invalid `int` -> `SDL_bool` conversion by manually changing SDL headers

This commit is contained in:
Susko3 2024-04-06 13:24:42 +02:00
parent 556c6cd1a3
commit a4ecfd1c75
4 changed files with 26 additions and 10 deletions

View File

@ -0,0 +1,15 @@
diff --git a/include/SDL3/SDL_stdinc.h b/include/SDL3/SDL_stdinc.h
index e6a387c31..46c225953 100644
--- a/include/SDL3/SDL_stdinc.h
+++ b/include/SDL3/SDL_stdinc.h
@@ -132,8 +132,8 @@ char *alloca();
/**
* A boolean type.
*/
-#define SDL_FALSE 0
-#define SDL_TRUE 1
+#define SDL_FALSE (SDL_bool)0
+#define SDL_TRUE (SDL_bool)1
typedef int SDL_bool;
/**

View File

@ -67,17 +67,17 @@ namespace SDL
{
public static SDL_bool SDL_PointInRect([NativeTypeName("const SDL_Point *")] SDL_Point* p, [NativeTypeName("const SDL_Rect *")] SDL_Rect* r)
{
return ((p->x >= r->x) && (p->x < (r->x + r->w)) && (p->y >= r->y) && (p->y < (r->y + r->h))) ? 1 : 0;
return ((p->x >= r->x) && (p->x < (r->x + r->w)) && (p->y >= r->y) && (p->y < (r->y + r->h))) ? (SDL_bool)(1) : (SDL_bool)(0);
}
public static SDL_bool SDL_RectEmpty([NativeTypeName("const SDL_Rect *")] SDL_Rect* r)
{
return ((r == null) || (r->w <= 0) || (r->h <= 0)) ? 1 : 0;
return ((r == null) || (r->w <= 0) || (r->h <= 0)) ? (SDL_bool)(1) : (SDL_bool)(0);
}
public static SDL_bool SDL_RectsEqual([NativeTypeName("const SDL_Rect *")] SDL_Rect* a, [NativeTypeName("const SDL_Rect *")] SDL_Rect* b)
{
return ((a) != null && (b) != null && (a->x == b->x) && (a->y == b->y) && (a->w == b->w) && (a->h == b->h)) ? 1 : 0;
return ((a) != null && (b) != null && (a->x == b->x) && (a->y == b->y) && (a->w == b->w) && (a->h == b->h)) ? (SDL_bool)(1) : (SDL_bool)(0);
}
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
@ -97,17 +97,17 @@ namespace SDL
public static SDL_bool SDL_PointInRectFloat([NativeTypeName("const SDL_FPoint *")] SDL_FPoint* p, [NativeTypeName("const SDL_FRect *")] SDL_FRect* r)
{
return ((p->x >= r->x) && (p->x < (r->x + r->w)) && (p->y >= r->y) && (p->y < (r->y + r->h))) ? 1 : 0;
return ((p->x >= r->x) && (p->x < (r->x + r->w)) && (p->y >= r->y) && (p->y < (r->y + r->h))) ? (SDL_bool)(1) : (SDL_bool)(0);
}
public static SDL_bool SDL_RectEmptyFloat([NativeTypeName("const SDL_FRect *")] SDL_FRect* r)
{
return ((r == null) || (r->w <= 0.0f) || (r->h <= 0.0f)) ? 1 : 0;
return ((r == null) || (r->w <= 0.0f) || (r->h <= 0.0f)) ? (SDL_bool)(1) : (SDL_bool)(0);
}
public static SDL_bool SDL_RectsEqualEpsilon([NativeTypeName("const SDL_FRect *")] SDL_FRect* a, [NativeTypeName("const SDL_FRect *")] SDL_FRect* b, [NativeTypeName("const float")] float epsilon)
{
return ((a) != null && (b) != null && ((a == b) || ((SDL_fabsf(a->x - b->x) <= epsilon) && (SDL_fabsf(a->y - b->y) <= epsilon) && (SDL_fabsf(a->w - b->w) <= epsilon) && (SDL_fabsf(a->h - b->h) <= epsilon)))) ? 1 : 0;
return ((a) != null && (b) != null && ((a == b) || ((SDL_fabsf(a->x - b->x) <= epsilon) && (SDL_fabsf(a->y - b->y) <= epsilon) && (SDL_fabsf(a->w - b->w) <= epsilon) && (SDL_fabsf(a->h - b->h) <= epsilon)))) ? (SDL_bool)(1) : (SDL_bool)(0);
}
public static SDL_bool SDL_RectsEqualFloat([NativeTypeName("const SDL_FRect *")] SDL_FRect* a, [NativeTypeName("const SDL_FRect *")] SDL_FRect* b)

View File

@ -541,11 +541,11 @@ namespace SDL
[NativeTypeName("#define SDL_SIZE_MAX SIZE_MAX")]
public const ulong SDL_SIZE_MAX = 0xffffffffffffffffUL;
[NativeTypeName("#define SDL_FALSE 0")]
public const int SDL_FALSE = 0;
[NativeTypeName("#define SDL_FALSE (SDL_bool)0")]
public const SDL_bool SDL_FALSE = (SDL_bool)(0);
[NativeTypeName("#define SDL_TRUE 1")]
public const int SDL_TRUE = 1;
[NativeTypeName("#define SDL_TRUE (SDL_bool)1")]
public const SDL_bool SDL_TRUE = (SDL_bool)(1);
[NativeTypeName("#define SDL_MAX_SINT8 ((Sint8)0x7F)")]
public const sbyte SDL_MAX_SINT8 = ((sbyte)(0x7F));

View File

@ -7,6 +7,7 @@ Generates C# bindings for SDL3 using ClangSharp.
Prerequisites:
- run `dotnet tool restore` (to install ClangSharpPInvokeGenerator)
- https://github.com/libsdl-org/SDL checked out alongside this repository
- git apply `SDL-use-proper-types.patch` to SDL repo
This script should be run manually.
"""