C# you idiot that struct is totally blittable

master
Ethan Lee 2018-03-30 11:15:48 -04:00
parent 0f768e1c18
commit 8e75771fca
1 changed files with 44 additions and 4 deletions

View File

@ -5301,6 +5301,16 @@ namespace SDL2
public INTERNAL_GameControllerButtonBind_union value;
}
/* This exists to deal with C# being stupid about blittable types. */
[StructLayout(LayoutKind.Sequential)]
private struct INTERNAL_SDL_GameControllerButtonBind
{
public int bindType;
/* Largest data type in the union is two ints in size */
public int unionVal0;
public int unionVal1;
}
[DllImport(nativeLibName, EntryPoint = "SDL_GameControllerAddMapping", CallingConvention = CallingConvention.Cdecl)]
private static extern int INTERNAL_SDL_GameControllerAddMapping(
byte[] mappingString
@ -5470,11 +5480,26 @@ namespace SDL2
}
/* gamecontroller refers to an SDL_GameController* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(
[DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetBindForAxis", CallingConvention = CallingConvention.Cdecl)]
private static extern INTERNAL_SDL_GameControllerButtonBind INTERNAL_SDL_GameControllerGetBindForAxis(
IntPtr gamecontroller,
SDL_GameControllerAxis axis
);
public static SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(
IntPtr gamecontroller,
SDL_GameControllerAxis axis
) {
// This is guaranteed to never be null
INTERNAL_SDL_GameControllerButtonBind dumb = INTERNAL_SDL_GameControllerGetBindForAxis(
gamecontroller,
axis
);
SDL_GameControllerButtonBind result = new SDL_GameControllerButtonBind();
result.bindType = (SDL_GameControllerBindType) dumb.bindType;
result.value.hat.hat = dumb.unionVal0;
result.value.hat.hat_mask = dumb.unionVal1;
return result;
}
/* gamecontroller refers to an SDL_GameController* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -5508,11 +5533,26 @@ namespace SDL2
}
/* gamecontroller refers to an SDL_GameController* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(
[DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetBindForButton", CallingConvention = CallingConvention.Cdecl)]
private static extern INTERNAL_SDL_GameControllerButtonBind INTERNAL_SDL_GameControllerGetBindForButton(
IntPtr gamecontroller,
SDL_GameControllerButton button
);
public static SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(
IntPtr gamecontroller,
SDL_GameControllerButton button
) {
// This is guaranteed to never be null
INTERNAL_SDL_GameControllerButtonBind dumb = INTERNAL_SDL_GameControllerGetBindForButton(
gamecontroller,
button
);
SDL_GameControllerButtonBind result = new SDL_GameControllerButtonBind();
result.bindType = (SDL_GameControllerBindType) dumb.bindType;
result.value.hat.hat = dumb.unionVal0;
result.value.hat.hat_mask = dumb.unionVal1;
return result;
}
/* gamecontroller refers to an SDL_GameController* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]