mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-15 22:35: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:
@@ -22,10 +22,11 @@
|
||||
/* Define this for verbose output while mapping controllers */
|
||||
#define DEBUG_CONTROLLERMAP
|
||||
|
||||
#define SCREEN_WIDTH 512
|
||||
#define SCREEN_HEIGHT 320
|
||||
#define SCREEN_WIDTH 512
|
||||
#define SCREEN_HEIGHT 320
|
||||
|
||||
enum marker_type {
|
||||
enum marker_type
|
||||
{
|
||||
MARKER_BUTTON,
|
||||
MARKER_AXIS,
|
||||
};
|
||||
@@ -61,10 +62,10 @@ static struct
|
||||
{ 174, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_BACK */
|
||||
{ 232, 128, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_GUIDE */
|
||||
{ 289, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_START */
|
||||
{ 75, 154, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
|
||||
{ 75, 154, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
|
||||
{ 305, 230, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
|
||||
{ 77, 40, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
|
||||
{ 396, 36, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
|
||||
{ 77, 40, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
|
||||
{ 396, 36, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
|
||||
{ 154, 188, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_UP */
|
||||
{ 154, 249, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
|
||||
{ 116, 217, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
|
||||
@@ -74,16 +75,16 @@ static struct
|
||||
{ 330, 135, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE2 */
|
||||
{ 132, 175, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE3 */
|
||||
{ 330, 175, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE4 */
|
||||
{ 0, 0, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
|
||||
{ 74, 153, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE */
|
||||
{ 74, 153, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE */
|
||||
{ 74, 153, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE */
|
||||
{ 74, 153, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE */
|
||||
{ 0, 0, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
|
||||
{ 74, 153, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE */
|
||||
{ 74, 153, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE */
|
||||
{ 74, 153, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE */
|
||||
{ 74, 153, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE */
|
||||
{ 306, 231, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_NEGATIVE */
|
||||
{ 306, 231, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE */
|
||||
{ 306, 231, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE */
|
||||
{ 306, 231, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE */
|
||||
{ 306, 231, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE */
|
||||
{ 306, 231, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_POSITIVE */
|
||||
{ 91, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT */
|
||||
{ 91, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT */
|
||||
{ 375, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERRIGHT */
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(s_arrBindingDisplay, SDL_arraysize(s_arrBindingDisplay) == BINDING_COUNT);
|
||||
@@ -130,13 +131,15 @@ typedef struct
|
||||
{
|
||||
int button;
|
||||
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
int axis;
|
||||
int axis_min;
|
||||
int axis_max;
|
||||
} axis;
|
||||
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
int hat;
|
||||
int hat_mask;
|
||||
} hat;
|
||||
@@ -159,7 +162,7 @@ typedef struct
|
||||
|
||||
static int s_nNumAxes;
|
||||
static AxisState *s_arrAxisState;
|
||||
|
||||
|
||||
static int s_iCurrentBinding;
|
||||
static Uint32 s_unPendingAdvanceTime;
|
||||
static SDL_bool s_bBindingComplete;
|
||||
@@ -172,9 +175,9 @@ static SDL_bool bind_touchpad = SDL_FALSE;
|
||||
static int
|
||||
StandardizeAxisValue(int nValue)
|
||||
{
|
||||
if (nValue > SDL_JOYSTICK_AXIS_MAX/2) {
|
||||
if (nValue > SDL_JOYSTICK_AXIS_MAX / 2) {
|
||||
return SDL_JOYSTICK_AXIS_MAX;
|
||||
} else if (nValue < SDL_JOYSTICK_AXIS_MIN/2) {
|
||||
} else if (nValue < SDL_JOYSTICK_AXIS_MIN / 2) {
|
||||
return SDL_JOYSTICK_AXIS_MIN;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -202,8 +205,7 @@ SetCurrentBinding(int iBinding)
|
||||
}
|
||||
|
||||
if (s_arrBindingOrder[iBinding] == SDL_CONTROLLER_BUTTON_TOUCHPAD &&
|
||||
!bind_touchpad)
|
||||
{
|
||||
!bind_touchpad) {
|
||||
SetCurrentBinding(iBinding + 1);
|
||||
return;
|
||||
}
|
||||
@@ -226,8 +228,7 @@ BBindingContainsBinding(const SDL_GameControllerExtendedBind *pBindingA, const S
|
||||
if (pBindingA->bindType != pBindingB->bindType) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
switch (pBindingA->bindType)
|
||||
{
|
||||
switch (pBindingA->bindType) {
|
||||
case SDL_CONTROLLER_BINDTYPE_AXIS:
|
||||
if (pBindingA->value.axis.axis != pBindingB->value.axis.axis) {
|
||||
return SDL_FALSE;
|
||||
@@ -277,19 +278,18 @@ ConfigureBinding(const SDL_GameControllerExtendedBind *pBinding)
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CONTROLLERMAP
|
||||
switch ( pBinding->bindType )
|
||||
{
|
||||
switch (pBinding->bindType) {
|
||||
case SDL_CONTROLLER_BINDTYPE_NONE:
|
||||
break;
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_BUTTON:
|
||||
SDL_Log("Configuring button binding for button %d\n", pBinding->value.button);
|
||||
break;
|
||||
SDL_Log("Configuring button binding for button %d\n", pBinding->value.button);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_AXIS:
|
||||
SDL_Log("Configuring axis binding for axis %d %d/%d committed = %s\n", pBinding->value.axis.axis, pBinding->value.axis.axis_min, pBinding->value.axis.axis_max, pBinding->committed ? "true" : "false");
|
||||
break;
|
||||
SDL_Log("Configuring axis binding for axis %d %d/%d committed = %s\n", pBinding->value.axis.axis, pBinding->value.axis.axis_min, pBinding->value.axis.axis_max, pBinding->committed ? "true" : "false");
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_HAT:
|
||||
SDL_Log("Configuring hat binding for hat %d %d\n", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
|
||||
break;
|
||||
SDL_Log("Configuring hat binding for hat %d %d\n", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
|
||||
break;
|
||||
}
|
||||
#endif /* DEBUG_CONTROLLERMAP */
|
||||
|
||||
@@ -298,7 +298,7 @@ ConfigureBinding(const SDL_GameControllerExtendedBind *pBinding)
|
||||
if (pCurrent->bindType != SDL_CONTROLLER_BINDTYPE_NONE) {
|
||||
SDL_bool bNativeDPad, bCurrentDPad;
|
||||
SDL_bool bNativeAxis, bCurrentAxis;
|
||||
|
||||
|
||||
bNativeDPad = (iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_UP ||
|
||||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_DOWN ||
|
||||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_LEFT ||
|
||||
@@ -332,7 +332,7 @@ static SDL_bool
|
||||
BMergeAxisBindings(int iIndex)
|
||||
{
|
||||
SDL_GameControllerExtendedBind *pBindingA = &s_arrBindings[iIndex];
|
||||
SDL_GameControllerExtendedBind *pBindingB = &s_arrBindings[iIndex+1];
|
||||
SDL_GameControllerExtendedBind *pBindingB = &s_arrBindings[iIndex + 1];
|
||||
if (pBindingA->bindType == SDL_CONTROLLER_BINDTYPE_AXIS &&
|
||||
pBindingB->bindType == SDL_CONTROLLER_BINDTYPE_AXIS &&
|
||||
pBindingA->value.axis.axis == pBindingB->value.axis.axis) {
|
||||
@@ -347,13 +347,13 @@ BMergeAxisBindings(int iIndex)
|
||||
}
|
||||
|
||||
static void
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
WatchJoystick(SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_Texture *background_front, *background_back, *button, *axis, *marker=NULL;
|
||||
SDL_Texture *background_front, *background_back, *button, *axis, *marker = NULL;
|
||||
const char *name = NULL;
|
||||
SDL_Event event;
|
||||
SDL_Rect dst;
|
||||
Uint8 alpha=200, alpha_step = -1;
|
||||
Uint8 alpha = 200, alpha_step = -1;
|
||||
Uint32 alpha_ticks = 0;
|
||||
SDL_JoystickID nJoystickID;
|
||||
|
||||
@@ -371,9 +371,9 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
SDL_Log("Watching joystick %" SDL_PRIs32 ": (%s)\n", SDL_JoystickInstanceID(joystick),
|
||||
name ? name : "Unknown Joystick");
|
||||
SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
|
||||
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
|
||||
SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
|
||||
|
||||
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
|
||||
SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
|
||||
|
||||
SDL_Log("\n\n\
|
||||
====================================================================================\n\
|
||||
Press the buttons on your controller when indicated\n\
|
||||
@@ -398,14 +398,14 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
int iElement = s_arrBindingOrder[s_iCurrentBinding];
|
||||
|
||||
switch (s_arrBindingDisplay[iElement].marker) {
|
||||
case MARKER_AXIS:
|
||||
marker = axis;
|
||||
break;
|
||||
case MARKER_BUTTON:
|
||||
marker = button;
|
||||
break;
|
||||
case MARKER_AXIS:
|
||||
marker = axis;
|
||||
break;
|
||||
case MARKER_BUTTON:
|
||||
marker = button;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
dst.x = s_arrBindingDisplay[iElement].x;
|
||||
dst.y = s_arrBindingDisplay[iElement].y;
|
||||
SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
|
||||
@@ -433,7 +433,7 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
SDL_SetTextureColorMod(marker, 10, 255, 21);
|
||||
SDL_RenderCopyEx(screen, marker, NULL, &dst, s_arrBindingDisplay[iElement].angle, NULL, SDL_FLIP_NONE);
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
switch (event.type) {
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
@@ -443,7 +443,7 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
break;
|
||||
case SDL_JOYAXISMOTION:
|
||||
if (event.jaxis.which == nJoystickID) {
|
||||
const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; /* ShanWan PS3 controller needed 96 */
|
||||
const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; /* ShanWan PS3 controller needed 96 */
|
||||
AxisState *pAxisState = &s_arrAxisState[event.jaxis.axis];
|
||||
int nValue = event.jaxis.value;
|
||||
int nCurrentDistance, nFarthestDistance;
|
||||
@@ -699,12 +699,11 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
|
||||
SDL_free(s_arrAxisState);
|
||||
s_arrAxisState = NULL;
|
||||
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *name;
|
||||
int i;
|
||||
@@ -769,11 +768,11 @@ main(int argc, char *argv[])
|
||||
joystick = SDL_JoystickOpen(i);
|
||||
if (joystick == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i,
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
} else {
|
||||
char guid[64];
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick),
|
||||
guid, sizeof (guid));
|
||||
guid, sizeof(guid));
|
||||
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick));
|
||||
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick));
|
||||
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick));
|
||||
|
Reference in New Issue
Block a user