Skip to content

Commit

Permalink
Remove enum mappings
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Slusny <[email protected]>
  • Loading branch information
deathbeam committed Oct 29, 2024
1 parent 72430e2 commit d12ca88
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 52 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Everything is 100% generated, Im not touching the generated stuff, only generato
The goal is to eventually PR some of this stuff to [Raylib-cs](https://github.com/chrisdill/raylib-cs). Natives PR requires 5.5 update there first and generator is a lot of effort
due to Raylib-cs project structure being quite difficult to work with. If I decide that its not worth it, I will just keep this as a separate project.

### Stuff not being done here

- Enum to argument mappings - this is raylib design decision, if raylib maintainers decide to provide type info in headers I can parse it, but without it too bad
- Array->Span mappings - C arrays are fake, ideally raylib should provide C99 [] notation for arrays in headers, but when it doesnt, too bad

### Included bindings

- Raylib
Expand Down Expand Up @@ -97,7 +102,3 @@ cd emsdk
./emsdk activate latest
export EMSDK=$PWD
```

### TODO/Maybe

- [ ] Generate Span wrappers for arrays?
32 changes: 0 additions & 32 deletions src/Raylib.NET.Bindgen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,6 @@
var libPath = "../../lib";
var includePath = args[0];

var transformEnum = (string parent, string name) =>
parent switch
{
"IsKeyPressed" or "IsKeyPressedRepeat" or "IsKeyDown" or "IsKeyReleased" or "IsKeyUp" or "GetKeyPressed" =>
name switch
{
"key" or "return" => "KeyboardKey",
_ => null,
},
"IsMouseButtonPressed" or "IsMouseButtonDown" or "IsMouseButtonReleased" or "IsMouseButtonUp" => name switch
{
"button" => "MouseButton",
_ => null,
},
"IsGampadButtonPressed"
or "IsGamepadButtonDown"
or "IsGamepadButtonReleased"
or "IsGamepadButtonUp"
or "GetGamepadButtonPressed" => name switch
{
"button" or "return" => "GamepadButton",
_ => null,
},
"GuiGetStyle" or "GuiSetStyle" => name switch
{
"control" => "GuiControl",
_ => null,
},
_ => null,
};

var options = new GeneratorOptions
{
DetectArray = (string parent, string name) =>
Expand All @@ -51,7 +20,6 @@
"Matrix" => "Matrix4x4",
"Rectangle" => "Vector4",
"va_list" => "IntPtr",
"int" => transformEnum(parent, name),
_ => Regex.Replace(type, @"\b(rres|rl|r)", ""),
},
TransformName = (string name) => Regex.Replace(name, @"\b(rres|rl)", ""),
Expand Down
4 changes: 2 additions & 2 deletions src/Raylib.NET/Raygui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ public static unsafe partial class Raygui
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void GuiSetStyle(GuiControl control, int @property, int value);
public static partial void GuiSetStyle(int control, int @property, int value);

/// <summary>
/// Get one style property
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int GuiGetStyle(GuiControl control, int @property);
public static partial int GuiGetStyle(int control, int @property);

/// <summary>
/// Load style file over global style variable (.rgs)
Expand Down
28 changes: 14 additions & 14 deletions src/Raylib.NET/Raylib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,42 +1142,42 @@ public static unsafe partial class Raylib
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial NativeBool IsKeyPressed(KeyboardKey key);
public static partial NativeBool IsKeyPressed(int key);

/// <summary>
/// Check if a key has been pressed again
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial NativeBool IsKeyPressedRepeat(KeyboardKey key);
public static partial NativeBool IsKeyPressedRepeat(int key);

/// <summary>
/// Check if a key is being pressed
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial NativeBool IsKeyDown(KeyboardKey key);
public static partial NativeBool IsKeyDown(int key);

/// <summary>
/// Check if a key has been released once
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial NativeBool IsKeyReleased(KeyboardKey key);
public static partial NativeBool IsKeyReleased(int key);

/// <summary>
/// Check if a key is NOT being pressed
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial NativeBool IsKeyUp(KeyboardKey key);
public static partial NativeBool IsKeyUp(int key);

/// <summary>
/// Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial KeyboardKey GetKeyPressed();
public static partial int GetKeyPressed();

/// <summary>
/// Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty
Expand Down Expand Up @@ -1219,28 +1219,28 @@ public static unsafe partial class Raylib
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial NativeBool IsGamepadButtonDown(int gamepad, GamepadButton button);
public static partial NativeBool IsGamepadButtonDown(int gamepad, int button);

/// <summary>
/// Check if a gamepad button has been released once
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial NativeBool IsGamepadButtonReleased(int gamepad, GamepadButton button);
public static partial NativeBool IsGamepadButtonReleased(int gamepad, int button);

/// <summary>
/// Check if a gamepad button is NOT being pressed
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial NativeBool IsGamepadButtonUp(int gamepad, GamepadButton button);
public static partial NativeBool IsGamepadButtonUp(int gamepad, int button);

/// <summary>
/// Get the last gamepad button pressed
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial GamepadButton GetGamepadButtonPressed();
public static partial int GetGamepadButtonPressed();

/// <summary>
/// Get gamepad axis count for a gamepad
Expand Down Expand Up @@ -1275,28 +1275,28 @@ public static unsafe partial class Raylib
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial NativeBool IsMouseButtonPressed(MouseButton button);
public static partial NativeBool IsMouseButtonPressed(int button);

/// <summary>
/// Check if a mouse button is being pressed
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial NativeBool IsMouseButtonDown(MouseButton button);
public static partial NativeBool IsMouseButtonDown(int button);

/// <summary>
/// Check if a mouse button has been released once
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial NativeBool IsMouseButtonReleased(MouseButton button);
public static partial NativeBool IsMouseButtonReleased(int button);

/// <summary>
/// Check if a mouse button is NOT being pressed
/// </summary>
[LibraryImport(LIBRARY, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial NativeBool IsMouseButtonUp(MouseButton button);
public static partial NativeBool IsMouseButtonUp(int button);

/// <summary>
/// Get mouse position X
Expand Down

0 comments on commit d12ca88

Please sign in to comment.