update SDL3 to 3.4.10.

This commit is contained in:
Sasha Szpakowski
2026-06-02 00:18:17 -03:00
parent 43fe5f52f1
commit c4192fe9ba
1594 changed files with 100926 additions and 191270 deletions
+7 -7
View File
@@ -18,7 +18,8 @@
#define SNAKE_GAME_HEIGHT 18U
#define SNAKE_MATRIX_SIZE (SNAKE_GAME_WIDTH * SNAKE_GAME_HEIGHT)
#define THREE_BITS 0x7U /* ~CHAR_MAX >> (CHAR_BIT - SNAKE_CELL_MAX_BITS) */
#define SNAKE_CELL_MAX_BITS 3U /* floor(log2(SNAKE_CELL_FOOD)) + 1 */
#define SNAKE_CELL_SET_BITS (~(~0u << SNAKE_CELL_MAX_BITS))
#define SHIFT(x, y) (((x) + ((y) * SNAKE_GAME_WIDTH)) * SNAKE_CELL_MAX_BITS)
static SDL_Joystick *joystick = NULL;
@@ -33,8 +34,6 @@ typedef enum
SNAKE_CELL_FOOD = 5U
} SnakeCell;
#define SNAKE_CELL_MAX_BITS 3U /* floor(log2(SNAKE_CELL_FOOD)) + 1 */
typedef enum
{
SNAKE_DIR_RIGHT,
@@ -68,7 +67,7 @@ SnakeCell snake_cell_at(const SnakeContext *ctx, char x, char y)
const int shift = SHIFT(x, y);
unsigned short range;
SDL_memcpy(&range, ctx->cells + (shift / 8), sizeof(range));
return (SnakeCell)((range >> (shift % 8)) & THREE_BITS);
return (SnakeCell)((range >> (shift % 8)) & SNAKE_CELL_SET_BITS);
}
static void set_rect_xy_(SDL_FRect *r, short x, short y)
@@ -84,8 +83,8 @@ static void put_cell_at_(SnakeContext *ctx, char x, char y, SnakeCell ct)
unsigned char *const pos = ctx->cells + (shift / 8);
unsigned short range;
SDL_memcpy(&range, pos, sizeof(range));
range &= ~(THREE_BITS << adjust); /* clear bits */
range |= (ct & THREE_BITS) << adjust;
range &= ~(SNAKE_CELL_SET_BITS << adjust); /* clear bits */
range |= (ct & SNAKE_CELL_SET_BITS) << adjust;
SDL_memcpy(pos, &range, sizeof(range));
}
@@ -341,9 +340,10 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
*appstate = as;
if (!SDL_CreateWindowAndRenderer("examples/demo/snake", SDL_WINDOW_WIDTH, SDL_WINDOW_HEIGHT, 0, &as->window, &as->renderer)) {
if (!SDL_CreateWindowAndRenderer("examples/demo/snake", SDL_WINDOW_WIDTH, SDL_WINDOW_HEIGHT, SDL_WINDOW_RESIZABLE, &as->window, &as->renderer)) {
return SDL_APP_FAILURE;
}
SDL_SetRenderLogicalPresentation(as->renderer, SDL_WINDOW_WIDTH, SDL_WINDOW_HEIGHT, SDL_LOGICAL_PRESENTATION_LETTERBOX);
snake_initialize(&as->snake_ctx);
@@ -206,7 +206,7 @@ static void draw(SDL_Renderer *renderer, const float (*edges)[6], const Player p
for (i = 0; i < players_len; i++) {
const Player *player = &players[i];
float mod_x = (float)(i % part_hor);
float mod_y = (float)(i / part_hor);
float mod_y = (float)i / part_hor;
float hor_origin = (mod_x + 0.5f) * size_hor;
float ver_origin = (mod_y + 0.5f) * size_ver;
float cam_origin = (float)(0.5 * SDL_sqrt(size_hor * size_hor + size_ver * size_ver));
@@ -265,7 +265,7 @@ static void draw(SDL_Renderer *renderer, const float (*edges)[6], const Player p
SDL_RenderLine(renderer, hor_origin-10, ver_origin, hor_origin+10, ver_origin);
}
}
SDL_SetRenderClipRect(renderer, 0);
SDL_SetRenderClipRect(renderer, NULL);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderDebugText(renderer, 0, 0, debug_string);
SDL_RenderPresent(renderer);
@@ -347,7 +347,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
if (!SDL_Init(SDL_INIT_VIDEO)) {
return SDL_APP_FAILURE;
}
if (!SDL_CreateWindowAndRenderer("examples/demo/woodeneye-008", 640, 480, 0, &as->window, &as->renderer)) {
if (!SDL_CreateWindowAndRenderer("examples/demo/woodeneye-008", 640, 480, SDL_WINDOW_RESIZABLE, &as->window, &as->renderer)) {
return SDL_APP_FAILURE;
}
@@ -477,4 +477,4 @@ SDL_AppResult SDL_AppIterate(void *appstate)
void SDL_AppQuit(void *appstate, SDL_AppResult result)
{
SDL_free(appstate); // just free the memory, SDL will clean up the window/renderer for us.
}
}
@@ -31,9 +31,8 @@ typedef struct {
Uint64 tick_acc;
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Surface* screen;
SDL_Texture* screentex;
SDL_Texture* rendertarget; /* we need this render target for text to look good */
SDL_Palette* palette;
SDL_Texture* texture;
SDL_AudioStream* audiostream;
char status[SCREEN_W / 8];
int status_ticks;
@@ -75,6 +74,8 @@ static bool load(BytePusher* vm, SDL_IOStream* stream, bool closeio) {
size_t bytes_read = 0;
bool ok = true;
vm->display_help = true; // will set to false if load succeeds.
SDL_memset(vm->ram, 0, RAM_SIZE);
if (!stream) {
@@ -130,16 +131,12 @@ static void print(BytePusher* vm, int x, int y, const char* str) {
SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
BytePusher* vm;
SDL_Palette* palette;
SDL_Rect usable_bounds;
SDL_AudioSpec audiospec = { SDL_AUDIO_S8, 1, SAMPLES_PER_FRAME * FRAMES_PER_SECOND };
SDL_DisplayID primary_display;
SDL_PropertiesID texprops;
int zoom = 2;
int i;
Uint8 r, g, b;
(void)argc;
(void)argv;
if (!SDL_SetAppMetadata("SDL 3 BytePusher", "1.0", "com.example.SDL3BytePusher")) {
return SDL_APP_FAILURE;
@@ -185,13 +182,7 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
return SDL_APP_FAILURE;
}
if (!(vm->screen = SDL_CreateSurfaceFrom(
SCREEN_W, SCREEN_H, SDL_PIXELFORMAT_INDEX8, vm->ram, SCREEN_W
))) {
return SDL_APP_FAILURE;
}
if (!(palette = SDL_CreateSurfacePalette(vm->screen))) {
if (!(vm->palette = SDL_CreatePalette(256))) {
return SDL_APP_FAILURE;
}
i = 0;
@@ -199,28 +190,21 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
for (g = 0; g < 6; ++g) {
for (b = 0; b < 6; ++b, ++i) {
SDL_Color color = { (Uint8)(r * 0x33), (Uint8)(g * 0x33), (Uint8)(b * 0x33), SDL_ALPHA_OPAQUE };
palette->colors[i] = color;
vm->palette->colors[i] = color;
}
}
}
for (; i < 256; ++i) {
SDL_Color color = { 0, 0, 0, SDL_ALPHA_OPAQUE };
palette->colors[i] = color;
vm->palette->colors[i] = color;
}
texprops = SDL_CreateProperties();
SDL_SetNumberProperty(texprops, SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER, SDL_TEXTUREACCESS_STREAMING);
SDL_SetNumberProperty(texprops, SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER, SCREEN_W);
SDL_SetNumberProperty(texprops, SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER, SCREEN_H);
vm->screentex = SDL_CreateTextureWithProperties(vm->renderer, texprops);
SDL_SetNumberProperty(texprops, SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER, SDL_TEXTUREACCESS_TARGET);
vm->rendertarget = SDL_CreateTextureWithProperties(vm->renderer, texprops);
SDL_DestroyProperties(texprops);
if (!vm->screentex || !vm->rendertarget) {
vm->texture = SDL_CreateTexture(vm->renderer, SDL_PIXELFORMAT_INDEX8, SDL_TEXTUREACCESS_STREAMING, SCREEN_W, SCREEN_H);
if (!vm->texture) {
return SDL_APP_FAILURE;
}
SDL_SetTextureScaleMode(vm->screentex, SDL_SCALEMODE_NEAREST);
SDL_SetTextureScaleMode(vm->rendertarget, SDL_SCALEMODE_NEAREST);
SDL_SetTexturePalette(vm->texture, vm->palette);
SDL_SetTextureScaleMode(vm->texture, SDL_SCALEMODE_NEAREST);
if (!(vm->audiostream = SDL_OpenAudioDeviceStream(
SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audiospec, NULL, NULL
@@ -235,6 +219,10 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
vm->last_tick = SDL_GetTicksNS();
vm->tick_acc = NS_PER_SECOND;
if (argc > 1) {
load_file(vm, argv[1]);
}
return SDL_APP_CONTINUE;
}
@@ -283,35 +271,28 @@ SDL_AppResult SDL_AppIterate(void* appstate) {
}
if (updated) {
SDL_Surface *tex;
SDL_SetRenderTarget(vm->renderer, vm->rendertarget);
if (!SDL_LockTextureToSurface(vm->screentex, NULL, &tex)) {
return SDL_APP_FAILURE;
}
vm->screen->pixels = &vm->ram[(Uint32)vm->ram[IO_SCREEN_PAGE] << 16];
SDL_BlitSurface(vm->screen, NULL, tex, NULL);
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->status_ticks > 0) {
vm->status_ticks -= 1;
print(vm, 4, SCREEN_H - 12, vm->status);
}
const void *pixels = &vm->ram[(Uint32)vm->ram[IO_SCREEN_PAGE] << 16];
SDL_UpdateTexture(vm->texture, NULL, pixels, SCREEN_W);
}
SDL_SetRenderTarget(vm->renderer, NULL);
SDL_RenderClear(vm->renderer);
SDL_RenderTexture(vm->renderer, vm->rendertarget, 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.");
} else {
SDL_RenderTexture(vm->renderer, vm->texture, NULL, NULL);
}
if (vm->status_ticks > 0) {
if (updated) {
vm->status_ticks--;
}
print(vm, 4, SCREEN_H - 12, vm->status);
}
SDL_RenderPresent(vm->renderer);
return SDL_APP_CONTINUE;
@@ -405,9 +386,8 @@ void SDL_AppQuit(void* appstate, SDL_AppResult result) {
if (appstate) {
BytePusher* vm = (BytePusher*)appstate;
SDL_DestroyAudioStream(vm->audiostream);
SDL_DestroyTexture(vm->rendertarget);
SDL_DestroyTexture(vm->screentex);
SDL_DestroySurface(vm->screen);
SDL_DestroyTexture(vm->texture);
SDL_DestroyPalette(vm->palette);
SDL_DestroyRenderer(vm->renderer);
SDL_DestroyWindow(vm->window);
SDL_free(vm);