Update SDL2 to version 2.28.1.

This commit is contained in:
Sasha Szpakowski
2023-08-31 22:21:03 -03:00
parent 99b2757fc5
commit a82fcdd079
1394 changed files with 313046 additions and 190617 deletions
+47 -37
View File
@@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@@ -28,8 +28,8 @@
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 480
#else
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#endif
static SDL_Window *window = NULL;
@@ -44,7 +44,7 @@ PrintJoystick(SDL_Joystick *joy)
char guid[64];
SDL_assert(SDL_JoystickFromInstanceID(SDL_JoystickInstanceID(joy)) == joy);
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), guid, sizeof (guid));
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), guid, sizeof(guid));
switch (SDL_JoystickGetType(joy)) {
case SDL_JOYSTICK_TYPE_GAMECONTROLLER:
type = "Game Controller";
@@ -87,7 +87,7 @@ PrintJoystick(SDL_Joystick *joy)
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joy));
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joy));
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joy));
SDL_Log(" instance id: %d\n", SDL_JoystickInstanceID(joy));
SDL_Log(" instance id: %" SDL_PRIs32 "\n", SDL_JoystickInstanceID(joy));
SDL_Log(" guid: %s\n", guid);
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joy), SDL_JoystickGetProduct(joy));
}
@@ -103,8 +103,7 @@ DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
SDL_RenderFillRect(r, &area);
}
void
loop(void *arg)
void loop(void *arg)
{
SDL_Event event;
int i;
@@ -117,8 +116,8 @@ loop(void *arg)
switch (event.type) {
case SDL_JOYDEVICEADDED:
SDL_Log("Joystick device %d added.\n", (int) event.jdevice.which);
if (!joystick) {
SDL_Log("Joystick device %d added.\n", (int)event.jdevice.which);
if (joystick == NULL) {
joystick = SDL_JoystickOpen(event.jdevice.which);
if (joystick) {
PrintJoystick(joystick);
@@ -129,7 +128,7 @@ loop(void *arg)
break;
case SDL_JOYDEVICEREMOVED:
SDL_Log("Joystick device %d removed.\n", (int) event.jdevice.which);
SDL_Log("Joystick device %d removed.\n", (int)event.jdevice.which);
if (event.jdevice.which == SDL_JoystickInstanceID(joystick)) {
SDL_JoystickClose(joystick);
joystick = SDL_JoystickOpen(0);
@@ -137,41 +136,46 @@ loop(void *arg)
break;
case SDL_JOYAXISMOTION:
SDL_Log("Joystick %d axis %d value: %d\n",
event.jaxis.which,
event.jaxis.axis, event.jaxis.value);
SDL_Log("Joystick %" SDL_PRIs32 " axis %d value: %d\n",
event.jaxis.which,
event.jaxis.axis, event.jaxis.value);
break;
case SDL_JOYHATMOTION:
SDL_Log("Joystick %d hat %d value:",
event.jhat.which, event.jhat.hat);
if (event.jhat.value == SDL_HAT_CENTERED)
SDL_Log("Joystick %" SDL_PRIs32 " hat %d value:",
event.jhat.which, event.jhat.hat);
if (event.jhat.value == SDL_HAT_CENTERED) {
SDL_Log(" centered");
if (event.jhat.value & SDL_HAT_UP)
}
if (event.jhat.value & SDL_HAT_UP) {
SDL_Log(" up");
if (event.jhat.value & SDL_HAT_RIGHT)
}
if (event.jhat.value & SDL_HAT_RIGHT) {
SDL_Log(" right");
if (event.jhat.value & SDL_HAT_DOWN)
}
if (event.jhat.value & SDL_HAT_DOWN) {
SDL_Log(" down");
if (event.jhat.value & SDL_HAT_LEFT)
}
if (event.jhat.value & SDL_HAT_LEFT) {
SDL_Log(" left");
}
SDL_Log("\n");
break;
case SDL_JOYBALLMOTION:
SDL_Log("Joystick %d ball %d delta: (%d,%d)\n",
event.jball.which,
event.jball.ball, event.jball.xrel, event.jball.yrel);
SDL_Log("Joystick %" SDL_PRIs32 " ball %d delta: (%d,%d)\n",
event.jball.which,
event.jball.ball, event.jball.xrel, event.jball.yrel);
break;
case SDL_JOYBUTTONDOWN:
SDL_Log("Joystick %d button %d down\n",
event.jbutton.which, event.jbutton.button);
SDL_Log("Joystick %" SDL_PRIs32 " button %d down\n",
event.jbutton.which, event.jbutton.button);
/* First button triggers a 0.5 second full strength rumble */
if (event.jbutton.button == 0) {
SDL_JoystickRumble(joystick, 0xFFFF, 0xFFFF, 500);
}
break;
case SDL_JOYBUTTONUP:
SDL_Log("Joystick %d button %d up\n",
event.jbutton.which, event.jbutton.button);
SDL_Log("Joystick %" SDL_PRIs32 " button %d up\n",
event.jbutton.which, event.jbutton.button);
break;
case SDL_KEYDOWN:
/* Press the L key to lag for 3 seconds, to see what happens
@@ -198,20 +202,26 @@ loop(void *arg)
}
if (joystick) {
const int BUTTONS_PER_LINE = ((SCREEN_WIDTH - 4) / 34);
int x, y;
/* Update visual joystick state */
SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE);
y = SCREEN_HEIGHT - ((((SDL_JoystickNumButtons(joystick) + (BUTTONS_PER_LINE - 1)) / BUTTONS_PER_LINE) + 1) * 34);
for (i = 0; i < SDL_JoystickNumButtons(joystick); ++i) {
if ((i % BUTTONS_PER_LINE) == 0) {
y += 34;
}
if (SDL_JoystickGetButton(joystick, i) == SDL_PRESSED) {
DrawRect(screen, (i%20) * 34, SCREEN_HEIGHT - 68 + (i/20) * 34, 32, 32);
x = 2 + (i % BUTTONS_PER_LINE) * 34;
DrawRect(screen, x, y, 32, 32);
}
}
SDL_SetRenderDrawColor(screen, 0xFF, 0x00, 0x00, SDL_ALPHA_OPAQUE);
for (i = 0; i < SDL_JoystickNumAxes(joystick); ++i) {
/* Draw the X/Y axis */
int x, y;
x = (((int) SDL_JoystickGetAxis(joystick, i)) + 32768);
x = (((int)SDL_JoystickGetAxis(joystick, i)) + 32768);
x *= SCREEN_WIDTH;
x /= 65535;
if (x < 0) {
@@ -221,7 +231,7 @@ loop(void *arg)
}
++i;
if (i < SDL_JoystickNumAxes(joystick)) {
y = (((int) SDL_JoystickGetAxis(joystick, i)) + 32768);
y = (((int)SDL_JoystickGetAxis(joystick, i)) + 32768);
} else {
y = 32768;
}
@@ -239,26 +249,27 @@ loop(void *arg)
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0xFF, SDL_ALPHA_OPAQUE);
for (i = 0; i < SDL_JoystickNumHats(joystick); ++i) {
/* Derive the new position */
int x = SCREEN_WIDTH/2;
int y = SCREEN_HEIGHT/2;
const Uint8 hat_pos = SDL_JoystickGetHat(joystick, i);
x = SCREEN_WIDTH / 2;
y = SCREEN_HEIGHT / 2;
if (hat_pos & SDL_HAT_UP) {
y = 0;
} else if (hat_pos & SDL_HAT_DOWN) {
y = SCREEN_HEIGHT-8;
y = SCREEN_HEIGHT - 8;
}
if (hat_pos & SDL_HAT_LEFT) {
x = 0;
} else if (hat_pos & SDL_HAT_RIGHT) {
x = SCREEN_WIDTH-8;
x = SCREEN_WIDTH - 8;
}
DrawRect(screen, x, y, 8, 8);
}
}
SDL_Delay(16);
SDL_RenderPresent(screen);
#ifdef __EMSCRIPTEN__
@@ -268,8 +279,7 @@ loop(void *arg)
#endif
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");