mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-30 23:18:29 +00:00
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. The script I ran for the src directory is added as build-scripts/clang-format-src.sh This fixes: #6592 #6593 #6594
This commit is contained in:
@@ -33,12 +33,11 @@
|
||||
#include <objidlbase.h>
|
||||
#include <roapi.h>
|
||||
|
||||
|
||||
#ifdef ____FIReference_1_INT32_INTERFACE_DEFINED__
|
||||
/* MinGW-64 uses __FIReference_1_INT32 instead of Microsoft's __FIReference_1_int */
|
||||
#define __FIReference_1_int __FIReference_1_INT32
|
||||
#define __FIReference_1_int __FIReference_1_INT32
|
||||
#define __FIReference_1_int_get_Value __FIReference_1_INT32_get_Value
|
||||
#define __FIReference_1_int_Release __FIReference_1_INT32_Release
|
||||
#define __FIReference_1_int_Release __FIReference_1_INT32_Release
|
||||
#endif
|
||||
|
||||
struct joystick_hwdata
|
||||
@@ -51,7 +50,8 @@ struct joystick_hwdata
|
||||
UINT64 timestamp;
|
||||
};
|
||||
|
||||
typedef struct WindowsGamingInputControllerState {
|
||||
typedef struct WindowsGamingInputControllerState
|
||||
{
|
||||
SDL_JoystickID instance_id;
|
||||
__x_ABI_CWindows_CGaming_CInput_CIRawGameController *controller;
|
||||
char *name;
|
||||
@@ -62,7 +62,8 @@ typedef struct WindowsGamingInputControllerState {
|
||||
int nbuttons;
|
||||
} WindowsGamingInputControllerState;
|
||||
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
__x_ABI_CWindows_CGaming_CInput_CIRawGameControllerStatics *statics;
|
||||
__x_ABI_CWindows_CGaming_CInput_CIArcadeStickStatics *arcade_stick_statics;
|
||||
__x_ABI_CWindows_CGaming_CInput_CIArcadeStickStatics2 *arcade_stick_statics2;
|
||||
@@ -99,8 +100,7 @@ static const IID IID_IRacingWheelStatics2 = { 0xE666BCAA, 0xEDFD, 0x4323, { 0xA9
|
||||
extern SDL_bool SDL_XINPUT_Enabled(void);
|
||||
extern SDL_bool SDL_DINPUT_JoystickPresent(Uint16 vendor, Uint16 product, Uint16 version);
|
||||
|
||||
static SDL_bool
|
||||
SDL_IsXInputDevice(Uint16 vendor, Uint16 product)
|
||||
static SDL_bool SDL_IsXInputDevice(Uint16 vendor, Uint16 product)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_XINPUT
|
||||
PRAWINPUTDEVICELIST raw_devices = NULL;
|
||||
@@ -112,13 +112,13 @@ SDL_IsXInputDevice(Uint16 vendor, Uint16 product)
|
||||
#ifdef SDL_JOYSTICK_RAWINPUT
|
||||
&& !RAWINPUT_IsEnabled()
|
||||
#endif
|
||||
) {
|
||||
) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
/* Go through RAWINPUT (WinXP and later) to find HID devices. */
|
||||
if ((GetRawInputDeviceList(NULL, &raw_device_count, sizeof(RAWINPUTDEVICELIST)) == -1) || (!raw_device_count)) {
|
||||
return SDL_FALSE; /* oh well. */
|
||||
return SDL_FALSE; /* oh well. */
|
||||
}
|
||||
|
||||
raw_devices = (PRAWINPUTDEVICELIST)SDL_malloc(sizeof(RAWINPUTDEVICELIST) * raw_device_count);
|
||||
@@ -130,7 +130,7 @@ SDL_IsXInputDevice(Uint16 vendor, Uint16 product)
|
||||
if (GetRawInputDeviceList(raw_devices, &raw_device_count, sizeof(RAWINPUTDEVICELIST)) == -1) {
|
||||
SDL_free(raw_devices);
|
||||
raw_devices = NULL;
|
||||
return SDL_FALSE; /* oh well. */
|
||||
return SDL_FALSE; /* oh well. */
|
||||
}
|
||||
|
||||
for (i = 0; i < raw_device_count; i++) {
|
||||
@@ -205,12 +205,13 @@ SDL_IsXInputDevice(Uint16 vendor, Uint16 product)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
typedef struct RawGameControllerDelegate {
|
||||
typedef struct RawGameControllerDelegate
|
||||
{
|
||||
__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController iface;
|
||||
SDL_atomic_t refcount;
|
||||
} RawGameControllerDelegate;
|
||||
|
||||
static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_QueryInterface(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController * This, REFIID riid, void **ppvObject)
|
||||
static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_QueryInterface(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController *This, REFIID riid, void **ppvObject)
|
||||
{
|
||||
if (ppvObject == NULL) {
|
||||
return E_INVALIDARG;
|
||||
@@ -229,13 +230,13 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_QueryInter
|
||||
}
|
||||
}
|
||||
|
||||
static ULONG STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_AddRef(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController * This)
|
||||
static ULONG STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_AddRef(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController *This)
|
||||
{
|
||||
RawGameControllerDelegate *self = (RawGameControllerDelegate *)This;
|
||||
return SDL_AtomicAdd(&self->refcount, 1) + 1;
|
||||
}
|
||||
|
||||
static ULONG STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_Release(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController * This)
|
||||
static ULONG STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_Release(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController *This)
|
||||
{
|
||||
RawGameControllerDelegate *self = (RawGameControllerDelegate *)This;
|
||||
int rc = SDL_AtomicAdd(&self->refcount, -1) - 1;
|
||||
@@ -244,7 +245,7 @@ static ULONG STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_Release(__FI
|
||||
return rc;
|
||||
}
|
||||
|
||||
static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdded(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController * This, IInspectable *sender, __x_ABI_CWindows_CGaming_CInput_CIRawGameController *e)
|
||||
static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdded(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController *This, IInspectable *sender, __x_ABI_CWindows_CGaming_CInput_CIRawGameController *e)
|
||||
{
|
||||
HRESULT hr;
|
||||
__x_ABI_CWindows_CGaming_CInput_CIRawGameController *controller = NULL;
|
||||
@@ -275,8 +276,8 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
|
||||
|
||||
hr = __x_ABI_CWindows_CGaming_CInput_CIRawGameController_QueryInterface(controller, &IID_IRawGameController2, (void **)&controller2);
|
||||
if (SUCCEEDED(hr)) {
|
||||
typedef PCWSTR (WINAPI *WindowsGetStringRawBuffer_t)(HSTRING string, UINT32 *length);
|
||||
typedef HRESULT (WINAPI *WindowsDeleteString_t)(HSTRING string);
|
||||
typedef PCWSTR(WINAPI * WindowsGetStringRawBuffer_t)(HSTRING string, UINT32 * length);
|
||||
typedef HRESULT(WINAPI * WindowsDeleteString_t)(HSTRING string);
|
||||
|
||||
WindowsGetStringRawBuffer_t WindowsGetStringRawBufferFunc = NULL;
|
||||
WindowsDeleteString_t WindowsDeleteStringFunc = NULL;
|
||||
@@ -336,7 +337,7 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
|
||||
__x_ABI_CWindows_CGaming_CInput_CIGameController_Release(gamecontroller);
|
||||
}
|
||||
|
||||
guid = SDL_CreateJoystickGUID(bus, vendor, product, version, name, 'w', (Uint8) type);
|
||||
guid = SDL_CreateJoystickGUID(bus, vendor, product, version, name, 'w', (Uint8)type);
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI
|
||||
if (!ignore_joystick && HIDAPI_IsDevicePresent(vendor, product, version, name)) {
|
||||
@@ -399,7 +400,7 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeAdde
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeRemoved(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController * This, IInspectable *sender, __x_ABI_CWindows_CGaming_CInput_CIRawGameController *e)
|
||||
static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeRemoved(__FIEventHandler_1_Windows__CGaming__CInput__CRawGameController *This, IInspectable *sender, __x_ABI_CWindows_CGaming_CInput_CIRawGameController *e)
|
||||
{
|
||||
HRESULT hr;
|
||||
__x_ABI_CWindows_CGaming_CInput_CIRawGameController *controller = NULL;
|
||||
@@ -416,7 +417,7 @@ static HRESULT STDMETHODCALLTYPE IEventHandler_CRawGameControllerVtbl_InvokeRemo
|
||||
if (SUCCEEDED(hr)) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < wgi.controller_count ; i++) {
|
||||
for (i = 0; i < wgi.controller_count; i++) {
|
||||
if (wgi.controllers[i].controller == controller) {
|
||||
WindowsGamingInputControllerState *state = &wgi.controllers[i];
|
||||
SDL_JoystickID joystickID = state->instance_id;
|
||||
@@ -465,11 +466,10 @@ static RawGameControllerDelegate controller_removed = {
|
||||
{ 1 }
|
||||
};
|
||||
|
||||
static int
|
||||
WGI_JoystickInit(void)
|
||||
static int WGI_JoystickInit(void)
|
||||
{
|
||||
typedef HRESULT (WINAPI *WindowsCreateStringReference_t)(PCWSTR sourceString, UINT32 length, HSTRING_HEADER *hstringHeader, HSTRING* string);
|
||||
typedef HRESULT (WINAPI *RoGetActivationFactory_t)(HSTRING activatableClassId, REFIID iid, void** factory);
|
||||
typedef HRESULT(WINAPI * WindowsCreateStringReference_t)(PCWSTR sourceString, UINT32 length, HSTRING_HEADER * hstringHeader, HSTRING * string);
|
||||
typedef HRESULT(WINAPI * RoGetActivationFactory_t)(HSTRING activatableClassId, REFIID iid, void **factory);
|
||||
|
||||
WindowsCreateStringReference_t WindowsCreateStringReferenceFunc = NULL;
|
||||
RoGetActivationFactory_t RoGetActivationFactoryFunc = NULL;
|
||||
@@ -489,7 +489,7 @@ WGI_JoystickInit(void)
|
||||
*/
|
||||
static PVOID cookie = NULL;
|
||||
if (!cookie) {
|
||||
typedef HRESULT (WINAPI *CoIncrementMTAUsage_t)(PVOID* pCookie);
|
||||
typedef HRESULT(WINAPI * CoIncrementMTAUsage_t)(PVOID * pCookie);
|
||||
CoIncrementMTAUsage_t CoIncrementMTAUsageFunc = (CoIncrementMTAUsage_t)WIN_LoadComBaseFunction("CoIncrementMTAUsage");
|
||||
if (CoIncrementMTAUsageFunc) {
|
||||
if (FAILED(CoIncrementMTAUsageFunc(&cookie))) {
|
||||
@@ -606,54 +606,45 @@ WGI_JoystickInit(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
WGI_JoystickGetCount(void)
|
||||
static int WGI_JoystickGetCount(void)
|
||||
{
|
||||
return wgi.controller_count;
|
||||
}
|
||||
|
||||
static void
|
||||
WGI_JoystickDetect(void)
|
||||
static void WGI_JoystickDetect(void)
|
||||
{
|
||||
}
|
||||
|
||||
static const char *
|
||||
WGI_JoystickGetDeviceName(int device_index)
|
||||
static const char *WGI_JoystickGetDeviceName(int device_index)
|
||||
{
|
||||
return wgi.controllers[device_index].name;
|
||||
}
|
||||
|
||||
static const char *
|
||||
WGI_JoystickGetDevicePath(int device_index)
|
||||
static const char *WGI_JoystickGetDevicePath(int device_index)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
WGI_JoystickGetDevicePlayerIndex(int device_index)
|
||||
static int WGI_JoystickGetDevicePlayerIndex(int device_index)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
WGI_JoystickSetDevicePlayerIndex(int device_index, int player_index)
|
||||
static void WGI_JoystickSetDevicePlayerIndex(int device_index, int player_index)
|
||||
{
|
||||
}
|
||||
|
||||
static SDL_JoystickGUID
|
||||
WGI_JoystickGetDeviceGUID(int device_index)
|
||||
static SDL_JoystickGUID WGI_JoystickGetDeviceGUID(int device_index)
|
||||
{
|
||||
return wgi.controllers[device_index].guid;
|
||||
}
|
||||
|
||||
static SDL_JoystickID
|
||||
WGI_JoystickGetDeviceInstanceID(int device_index)
|
||||
static SDL_JoystickID WGI_JoystickGetDeviceInstanceID(int device_index)
|
||||
{
|
||||
return wgi.controllers[device_index].instance_id;
|
||||
}
|
||||
|
||||
static int
|
||||
WGI_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
static int WGI_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
{
|
||||
WindowsGamingInputControllerState *state = &wgi.controllers[device_index];
|
||||
struct joystick_hwdata *hwdata;
|
||||
@@ -724,8 +715,7 @@ WGI_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
WGI_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
static int WGI_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
{
|
||||
struct joystick_hwdata *hwdata = joystick->hwdata;
|
||||
|
||||
@@ -745,8 +735,7 @@ WGI_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 h
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
WGI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
static int WGI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
{
|
||||
struct joystick_hwdata *hwdata = joystick->hwdata;
|
||||
|
||||
@@ -766,8 +755,7 @@ WGI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 ri
|
||||
}
|
||||
}
|
||||
|
||||
static Uint32
|
||||
WGI_JoystickGetCapabilities(SDL_Joystick *joystick)
|
||||
static Uint32 WGI_JoystickGetCapabilities(SDL_Joystick *joystick)
|
||||
{
|
||||
struct joystick_hwdata *hwdata = joystick->hwdata;
|
||||
|
||||
@@ -779,26 +767,22 @@ WGI_JoystickGetCapabilities(SDL_Joystick *joystick)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
WGI_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
static int WGI_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int
|
||||
WGI_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
|
||||
static int WGI_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int
|
||||
WGI_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
|
||||
static int WGI_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static Uint8
|
||||
ConvertHatValue(__x_ABI_CWindows_CGaming_CInput_CGameControllerSwitchPosition value)
|
||||
static Uint8 ConvertHatValue(__x_ABI_CWindows_CGaming_CInput_CGameControllerSwitchPosition value)
|
||||
{
|
||||
switch (value) {
|
||||
case GameControllerSwitchPosition_Up:
|
||||
@@ -822,8 +806,7 @@ ConvertHatValue(__x_ABI_CWindows_CGaming_CInput_CGameControllerSwitchPosition va
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
WGI_JoystickUpdate(SDL_Joystick *joystick)
|
||||
static void WGI_JoystickUpdate(SDL_Joystick *joystick)
|
||||
{
|
||||
struct joystick_hwdata *hwdata = joystick->hwdata;
|
||||
HRESULT hr;
|
||||
@@ -861,13 +844,13 @@ WGI_JoystickUpdate(SDL_Joystick *joystick)
|
||||
SDL_PrivateJoystickForceRecentering(joystick);
|
||||
} else {
|
||||
for (i = 0; i < nbuttons; ++i) {
|
||||
SDL_PrivateJoystickButton(joystick, (Uint8) i, buttons[i]);
|
||||
SDL_PrivateJoystickButton(joystick, (Uint8)i, buttons[i]);
|
||||
}
|
||||
for (i = 0; i < nhats; ++i) {
|
||||
SDL_PrivateJoystickHat(joystick, (Uint8) i, ConvertHatValue(hats[i]));
|
||||
SDL_PrivateJoystickHat(joystick, (Uint8)i, ConvertHatValue(hats[i]));
|
||||
}
|
||||
for (i = 0; i < naxes; ++i) {
|
||||
SDL_PrivateJoystickAxis(joystick, (Uint8)i, (Sint16)((int) (axes[i] * 65535) - 32768));
|
||||
SDL_PrivateJoystickAxis(joystick, (Uint8)i, (Sint16)((int)(axes[i] * 65535) - 32768));
|
||||
}
|
||||
}
|
||||
hwdata->timestamp = timestamp;
|
||||
@@ -878,8 +861,7 @@ WGI_JoystickUpdate(SDL_Joystick *joystick)
|
||||
SDL_stack_free(axes);
|
||||
}
|
||||
|
||||
static void
|
||||
WGI_JoystickClose(SDL_Joystick *joystick)
|
||||
static void WGI_JoystickClose(SDL_Joystick *joystick)
|
||||
{
|
||||
struct joystick_hwdata *hwdata = joystick->hwdata;
|
||||
|
||||
@@ -901,8 +883,7 @@ WGI_JoystickClose(SDL_Joystick *joystick)
|
||||
joystick->hwdata = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
WGI_JoystickQuit(void)
|
||||
static void WGI_JoystickQuit(void)
|
||||
{
|
||||
if (wgi.statics) {
|
||||
while (wgi.controller_count > 0) {
|
||||
@@ -946,14 +927,12 @@ WGI_JoystickQuit(void)
|
||||
SDL_zero(wgi);
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
WGI_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
static SDL_bool WGI_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
SDL_JoystickDriver SDL_WGI_JoystickDriver =
|
||||
{
|
||||
SDL_JoystickDriver SDL_WGI_JoystickDriver = {
|
||||
WGI_JoystickInit,
|
||||
WGI_JoystickGetCount,
|
||||
WGI_JoystickDetect,
|
||||
|
Reference in New Issue
Block a user