mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-14 22:05:59 +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:
@@ -23,30 +23,29 @@
|
||||
|
||||
#ifdef SDL_JOYSTICK_EMSCRIPTEN
|
||||
|
||||
#include <stdio.h> /* For the definition of NULL */
|
||||
#include <stdio.h> /* For the definition of NULL */
|
||||
|
||||
#include "SDL_sysjoystick_c.h"
|
||||
#include "../SDL_joystick_c.h"
|
||||
|
||||
static SDL_joylist_item * JoystickByIndex(int index);
|
||||
static SDL_joylist_item *JoystickByIndex(int index);
|
||||
|
||||
static SDL_joylist_item *SDL_joylist = NULL;
|
||||
static SDL_joylist_item *SDL_joylist_tail = NULL;
|
||||
static int numjoysticks = 0;
|
||||
static int instance_counter = 0;
|
||||
|
||||
static EM_BOOL
|
||||
Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
|
||||
static EM_BOOL Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
|
||||
{
|
||||
int i;
|
||||
|
||||
SDL_joylist_item *item;
|
||||
|
||||
if (JoystickByIndex(gamepadEvent->index) != NULL) {
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item));
|
||||
item = (SDL_joylist_item *)SDL_malloc(sizeof(SDL_joylist_item));
|
||||
if (item == NULL) {
|
||||
return 1;
|
||||
}
|
||||
@@ -55,13 +54,13 @@ Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepa
|
||||
item->index = gamepadEvent->index;
|
||||
|
||||
item->name = SDL_CreateJoystickName(0, 0, NULL, gamepadEvent->id);
|
||||
if ( item->name == NULL ) {
|
||||
if (item->name == NULL) {
|
||||
SDL_free(item);
|
||||
return 1;
|
||||
}
|
||||
|
||||
item->mapping = SDL_strdup(gamepadEvent->mapping);
|
||||
if ( item->mapping == NULL ) {
|
||||
if (item->mapping == NULL) {
|
||||
SDL_free(item->name);
|
||||
SDL_free(item);
|
||||
return 1;
|
||||
@@ -73,11 +72,11 @@ Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepa
|
||||
|
||||
item->timestamp = gamepadEvent->timestamp;
|
||||
|
||||
for ( i = 0; i < item->naxes; i++) {
|
||||
for (i = 0; i < item->naxes; i++) {
|
||||
item->axis[i] = gamepadEvent->axis[i];
|
||||
}
|
||||
|
||||
for ( i = 0; i < item->nbuttons; i++) {
|
||||
for (i = 0; i < item->nbuttons; i++) {
|
||||
item->analogButton[i] = gamepadEvent->analogButton[i];
|
||||
item->digitalButton[i] = gamepadEvent->digitalButton[i];
|
||||
}
|
||||
@@ -104,8 +103,7 @@ Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepa
|
||||
return 1;
|
||||
}
|
||||
|
||||
static EM_BOOL
|
||||
Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
|
||||
static EM_BOOL Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
|
||||
{
|
||||
SDL_joylist_item *item = SDL_joylist;
|
||||
SDL_joylist_item *prev = NULL;
|
||||
@@ -151,8 +149,7 @@ Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGamepadEvent *gam
|
||||
}
|
||||
|
||||
/* Function to perform any system-specific joystick related cleanup */
|
||||
static void
|
||||
EMSCRIPTEN_JoystickQuit(void)
|
||||
static void EMSCRIPTEN_JoystickQuit(void)
|
||||
{
|
||||
SDL_joylist_item *item = NULL;
|
||||
SDL_joylist_item *next = NULL;
|
||||
@@ -176,8 +173,7 @@ EMSCRIPTEN_JoystickQuit(void)
|
||||
/* Function to scan the system for joysticks.
|
||||
* It should return 0, or -1 on an unrecoverable fatal error.
|
||||
*/
|
||||
static int
|
||||
EMSCRIPTEN_JoystickInit(void)
|
||||
static int EMSCRIPTEN_JoystickInit(void)
|
||||
{
|
||||
int retval, i, numjs;
|
||||
EmscriptenGamepadEvent gamepadState;
|
||||
@@ -226,8 +222,7 @@ EMSCRIPTEN_JoystickInit(void)
|
||||
}
|
||||
|
||||
/* Returns item matching given SDL device index. */
|
||||
static SDL_joylist_item *
|
||||
JoystickByDeviceIndex(int device_index)
|
||||
static SDL_joylist_item *JoystickByDeviceIndex(int device_index)
|
||||
{
|
||||
SDL_joylist_item *item = SDL_joylist;
|
||||
|
||||
@@ -240,8 +235,7 @@ JoystickByDeviceIndex(int device_index)
|
||||
}
|
||||
|
||||
/* Returns item matching given HTML gamepad index. */
|
||||
static SDL_joylist_item *
|
||||
JoystickByIndex(int index)
|
||||
static SDL_joylist_item *JoystickByIndex(int index)
|
||||
{
|
||||
SDL_joylist_item *item = SDL_joylist;
|
||||
|
||||
@@ -259,42 +253,35 @@ JoystickByIndex(int index)
|
||||
return item;
|
||||
}
|
||||
|
||||
static int
|
||||
EMSCRIPTEN_JoystickGetCount(void)
|
||||
static int EMSCRIPTEN_JoystickGetCount(void)
|
||||
{
|
||||
return numjoysticks;
|
||||
}
|
||||
|
||||
static void
|
||||
EMSCRIPTEN_JoystickDetect(void)
|
||||
static void EMSCRIPTEN_JoystickDetect(void)
|
||||
{
|
||||
}
|
||||
|
||||
static const char *
|
||||
EMSCRIPTEN_JoystickGetDeviceName(int device_index)
|
||||
static const char *EMSCRIPTEN_JoystickGetDeviceName(int device_index)
|
||||
{
|
||||
return JoystickByDeviceIndex(device_index)->name;
|
||||
}
|
||||
|
||||
static const char *
|
||||
EMSCRIPTEN_JoystickGetDevicePath(int device_index)
|
||||
static const char *EMSCRIPTEN_JoystickGetDevicePath(int device_index)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
EMSCRIPTEN_JoystickGetDevicePlayerIndex(int device_index)
|
||||
static int EMSCRIPTEN_JoystickGetDevicePlayerIndex(int device_index)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
EMSCRIPTEN_JoystickSetDevicePlayerIndex(int device_index, int player_index)
|
||||
static void EMSCRIPTEN_JoystickSetDevicePlayerIndex(int device_index, int player_index)
|
||||
{
|
||||
}
|
||||
|
||||
static SDL_JoystickID
|
||||
EMSCRIPTEN_JoystickGetDeviceInstanceID(int device_index)
|
||||
static SDL_JoystickID EMSCRIPTEN_JoystickGetDeviceInstanceID(int device_index)
|
||||
{
|
||||
return JoystickByDeviceIndex(device_index)->device_instance;
|
||||
}
|
||||
@@ -304,12 +291,11 @@ EMSCRIPTEN_JoystickGetDeviceInstanceID(int device_index)
|
||||
This should fill the nbuttons and naxes fields of the joystick structure.
|
||||
It returns 0, or -1 if there is an error.
|
||||
*/
|
||||
static int
|
||||
EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
static int EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
{
|
||||
SDL_joylist_item *item = JoystickByDeviceIndex(device_index);
|
||||
|
||||
if (item == NULL ) {
|
||||
if (item == NULL) {
|
||||
return SDL_SetError("No such device");
|
||||
}
|
||||
|
||||
@@ -318,7 +304,7 @@ EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
}
|
||||
|
||||
joystick->instance_id = item->device_instance;
|
||||
joystick->hwdata = (struct joystick_hwdata *) item;
|
||||
joystick->hwdata = (struct joystick_hwdata *)item;
|
||||
item->joystick = joystick;
|
||||
|
||||
/* HTML5 Gamepad API doesn't say anything about these */
|
||||
@@ -336,22 +322,21 @@ EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
* but instead should call SDL_PrivateJoystick*() to deliver events
|
||||
* and update joystick device state.
|
||||
*/
|
||||
static void
|
||||
EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick)
|
||||
static void EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick)
|
||||
{
|
||||
EmscriptenGamepadEvent gamepadState;
|
||||
SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
|
||||
SDL_joylist_item *item = (SDL_joylist_item *)joystick->hwdata;
|
||||
int i, result, buttonState;
|
||||
|
||||
emscripten_sample_gamepad_data();
|
||||
|
||||
if (item) {
|
||||
result = emscripten_get_gamepad_status(item->index, &gamepadState);
|
||||
if ( result == EMSCRIPTEN_RESULT_SUCCESS) {
|
||||
if (result == EMSCRIPTEN_RESULT_SUCCESS) {
|
||||
if (gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {
|
||||
for (i = 0; i < item->nbuttons; i++) {
|
||||
if (item->digitalButton[i] != gamepadState.digitalButton[i]) {
|
||||
buttonState = gamepadState.digitalButton[i]? SDL_PRESSED: SDL_RELEASED;
|
||||
buttonState = gamepadState.digitalButton[i] ? SDL_PRESSED : SDL_RELEASED;
|
||||
SDL_PrivateJoystickButton(item->joystick, i, buttonState);
|
||||
}
|
||||
|
||||
@@ -364,7 +349,7 @@ EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick)
|
||||
if (item->axis[i] != gamepadState.axis[i]) {
|
||||
/* do we need to do conversion? */
|
||||
SDL_PrivateJoystickAxis(item->joystick, i,
|
||||
(Sint16) (32767.*gamepadState.axis[i]));
|
||||
(Sint16)(32767. * gamepadState.axis[i]));
|
||||
}
|
||||
|
||||
/* store to compare in next update */
|
||||
@@ -378,67 +363,57 @@ EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick)
|
||||
}
|
||||
|
||||
/* Function to close a joystick after use */
|
||||
static void
|
||||
EMSCRIPTEN_JoystickClose(SDL_Joystick *joystick)
|
||||
static void EMSCRIPTEN_JoystickClose(SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
|
||||
SDL_joylist_item *item = (SDL_joylist_item *)joystick->hwdata;
|
||||
if (item) {
|
||||
item->joystick = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_JoystickGUID
|
||||
EMSCRIPTEN_JoystickGetDeviceGUID(int device_index)
|
||||
static SDL_JoystickGUID EMSCRIPTEN_JoystickGetDeviceGUID(int device_index)
|
||||
{
|
||||
/* the GUID is just the name for now */
|
||||
const char *name = EMSCRIPTEN_JoystickGetDeviceName(device_index);
|
||||
return SDL_CreateJoystickGUIDForName(name);
|
||||
}
|
||||
|
||||
static int
|
||||
EMSCRIPTEN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
static int EMSCRIPTEN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int
|
||||
EMSCRIPTEN_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
static int EMSCRIPTEN_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
EMSCRIPTEN_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
static SDL_bool EMSCRIPTEN_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static Uint32
|
||||
EMSCRIPTEN_JoystickGetCapabilities(SDL_Joystick *joystick)
|
||||
static Uint32 EMSCRIPTEN_JoystickGetCapabilities(SDL_Joystick *joystick)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
EMSCRIPTEN_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
static int EMSCRIPTEN_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int
|
||||
EMSCRIPTEN_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
|
||||
static int EMSCRIPTEN_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int
|
||||
EMSCRIPTEN_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
|
||||
static int EMSCRIPTEN_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver =
|
||||
{
|
||||
SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver = {
|
||||
EMSCRIPTEN_JoystickInit,
|
||||
EMSCRIPTEN_JoystickGetCount,
|
||||
EMSCRIPTEN_JoystickDetect,
|
||||
|
@@ -24,25 +24,24 @@
|
||||
#ifdef SDL_JOYSTICK_EMSCRIPTEN
|
||||
#include "../SDL_sysjoystick.h"
|
||||
|
||||
|
||||
#include <emscripten/html5.h>
|
||||
|
||||
/* A linked list of available joysticks */
|
||||
typedef struct SDL_joylist_item
|
||||
{
|
||||
int index;
|
||||
char *name;
|
||||
char *mapping;
|
||||
SDL_JoystickID device_instance;
|
||||
SDL_Joystick *joystick;
|
||||
int nbuttons;
|
||||
int naxes;
|
||||
double timestamp;
|
||||
double axis[64];
|
||||
double analogButton[64];
|
||||
EM_BOOL digitalButton[64];
|
||||
int index;
|
||||
char *name;
|
||||
char *mapping;
|
||||
SDL_JoystickID device_instance;
|
||||
SDL_Joystick *joystick;
|
||||
int nbuttons;
|
||||
int naxes;
|
||||
double timestamp;
|
||||
double axis[64];
|
||||
double analogButton[64];
|
||||
EM_BOOL digitalButton[64];
|
||||
|
||||
struct SDL_joylist_item *next;
|
||||
struct SDL_joylist_item *next;
|
||||
} SDL_joylist_item;
|
||||
|
||||
typedef SDL_joylist_item joystick_hwdata;
|
||||
|
Reference in New Issue
Block a user