update SDL3 to libsdl-org/SDL@038a380 (3.3 development)

This commit is contained in:
Sasha Szpakowski
2025-06-22 16:51:22 -03:00
parent 8830ab01fe
commit ab332aa6ef
537 changed files with 50325 additions and 23727 deletions
+47 -1
View File
@@ -21,6 +21,8 @@
#define THREE_BITS 0x7U /* ~CHAR_MAX >> (CHAR_BIT - SNAKE_CELL_MAX_BITS) */
#define SHIFT(x, y) (((x) + ((y) * SNAKE_GAME_WIDTH)) * SNAKE_CELL_MAX_BITS)
static SDL_Joystick *joystick = NULL;
typedef enum
{
SNAKE_CELL_NOTHING = 0U,
@@ -186,6 +188,8 @@ void snake_step(SnakeContext *ctx)
case SNAKE_DIR_DOWN:
++ctx->head_ypos;
break;
default:
break;
}
wrap_around_(&ctx->head_xpos, SNAKE_GAME_WIDTH);
wrap_around_(&ctx->head_ypos, SNAKE_GAME_HEIGHT);
@@ -238,6 +242,26 @@ static SDL_AppResult handle_key_event_(SnakeContext *ctx, SDL_Scancode key_code)
return SDL_APP_CONTINUE;
}
static SDL_AppResult handle_hat_event_(SnakeContext *ctx, Uint8 hat) {
switch (hat) {
case SDL_HAT_RIGHT:
snake_redir(ctx, SNAKE_DIR_RIGHT);
break;
case SDL_HAT_UP:
snake_redir(ctx, SNAKE_DIR_UP);
break;
case SDL_HAT_LEFT:
snake_redir(ctx, SNAKE_DIR_LEFT);
break;
case SDL_HAT_DOWN:
snake_redir(ctx, SNAKE_DIR_DOWN);
break;
default:
break;
}
return SDL_APP_CONTINUE;
}
SDL_AppResult SDL_AppIterate(void *appstate)
{
AppState *as = (AppState *)appstate;
@@ -305,7 +329,8 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
}
}
if (!SDL_Init(SDL_INIT_VIDEO)) {
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK)) {
SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
return SDL_APP_FAILURE;
}
@@ -333,14 +358,35 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
switch (event->type) {
case SDL_EVENT_QUIT:
return SDL_APP_SUCCESS;
case SDL_EVENT_JOYSTICK_ADDED:
if (joystick == NULL) {
joystick = SDL_OpenJoystick(event->jdevice.which);
if (!joystick) {
SDL_Log("Failed to open joystick ID %u: %s", (unsigned int) event->jdevice.which, SDL_GetError());
}
}
break;
case SDL_EVENT_JOYSTICK_REMOVED:
if (joystick && (SDL_GetJoystickID(joystick) == event->jdevice.which)) {
SDL_CloseJoystick(joystick);
joystick = NULL;
}
break;
case SDL_EVENT_JOYSTICK_HAT_MOTION:
return handle_hat_event_(ctx, event->jhat.value);
case SDL_EVENT_KEY_DOWN:
return handle_key_event_(ctx, event->key.scancode);
default:
break;
}
return SDL_APP_CONTINUE;
}
void SDL_AppQuit(void *appstate, SDL_AppResult result)
{
if (joystick) {
SDL_CloseJoystick(joystick);
}
if (appstate != NULL) {
AppState *as = (AppState *)appstate;
SDL_DestroyRenderer(as->renderer);
@@ -27,7 +27,6 @@
typedef struct {
Uint8 ram[RAM_SIZE + 8];
Uint8 screenbuf[SCREEN_W * SCREEN_H];
Uint64 last_tick;
Uint64 tick_acc;
SDL_Window* window;
@@ -187,7 +186,7 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
}
if (!(vm->screen = SDL_CreateSurfaceFrom(
SCREEN_W, SCREEN_H, SDL_PIXELFORMAT_INDEX8, vm->screenbuf, SCREEN_W
SCREEN_W, SCREEN_H, SDL_PIXELFORMAT_INDEX8, vm->ram, SCREEN_W
))) {
return SDL_APP_FAILURE;
}
@@ -296,18 +295,18 @@ SDL_AppResult SDL_AppIterate(void* appstate) {
SDL_UnlockTexture(vm->screentex);
SDL_RenderTexture(vm->renderer, vm->screentex, NULL, NULL);
}
if (vm->display_help) {
print(vm, 4, 4, "Drop a BytePusher file in this");
print(vm, 8, 12, "window to load and run it!");
print(vm, 4, 28, "Press ENTER to switch between");
print(vm, 8, 36, "positional and symbolic input.");
}
if (vm->display_help) {
print(vm, 4, 4, "Drop a BytePusher file in this");
print(vm, 8, 12, "window to load and run it!");
print(vm, 4, 28, "Press ENTER to switch between");
print(vm, 8, 36, "positional and symbolic input.");
}
if (vm->status_ticks > 0) {
vm->status_ticks -= 1;
print(vm, 4, SCREEN_H - 12, vm->status);
if (vm->status_ticks > 0) {
vm->status_ticks -= 1;
print(vm, 4, SCREEN_H - 12, vm->status);
}
}
SDL_SetRenderTarget(vm->renderer, NULL);