SDL3 or SDL2 behind one set of calls: SDL3 first on Linux #328

Merged
gab9281 merged 1 commit from linux/sdl3 into main 2026-11-08 19:22:25 +00:00
gab9281 commented 2026-11-07 20:59:48 +00:00 (Migrated from github.com)

Part of splitting #83 into small PRs. This is the first step toward SDL3. The next ones (shipping SDL3 in the AppImage and beside the Windows game, then removing SDL2) are separate PRs that build on this one.

host/hos_sdl.c holds stubs for the few SDL calls the host makes: the window and its events, the sound, and the controllers. Each stub has an SDL3 body and an SDL2 body: the same work under the other version's names and struct layouts (SDL3's SDL_Event is 128 bytes with other offsets, its window events are event types of their own, and it returns bool).

One SDL is loaded for the whole process: SDL3 beside the executable, else the system's, else SDL2 the same way. HOS_SDL_VERSION=2 takes SDL2 even when SDL3 is there.

  • host/posix/display_sdl.c (the window), win32_posix.c's waveOut and host/pad_sdl.c (controllers, on both systems) call only the stubs.
  • Linux runs on SDL3 where it is installed: Wayland natively, the sound on an SDL3 audio stream. A folder or AppImage that only carries SDL2 keeps working as before.
  • Windows loads SDL3.dll for the controllers when one is beside the game, SDL2.dll otherwise, as now.
  • On SDL3 the desktop size stays in pixels for GetSystemMetrics (its display mode is in screen units, so it is scaled by the pixel density).

Tested

  • Linux, the game built from this branch, on the system's SDL3 and with HOS_SDL_VERSION=2 (SDL2): the window and the title screen render, a sound stream plays, the DualSense is found (hid: controller "DualSense Wireless Controller" connected (SDL)), and closing the window ends the game (display: window closed, exiting).
  • Windows, under Proton (GE-Proton 11-7), a test program built on host/hos_sdl.c: with only SDL2.dll beside it, SDL2 loaded and the DualSense opened; with SDL 3.4.18's SDL3.dll, SDL3 did the same.
  • tests/test_sdl_audio_library.py was rewritten for the stubs (3 tests, they pass). The rest of tests/ gives the same result as on main (the 4 test_cpp_preflight checks need Visual Studio).

🤖 Generated with Claude Code

Part of splitting #83 into small PRs. This is the first step toward SDL3. The next ones (shipping SDL3 in the AppImage and beside the Windows game, then removing SDL2) are separate PRs that build on this one. `host/hos_sdl.c` holds stubs for the few SDL calls the host makes: the window and its events, the sound, and the controllers. Each stub has an SDL3 body and an SDL2 body: the same work under the other version's names and struct layouts (SDL3's `SDL_Event` is 128 bytes with other offsets, its window events are event types of their own, and it returns `bool`). One SDL is loaded for the whole process: SDL3 beside the executable, else the system's, else SDL2 the same way. `HOS_SDL_VERSION=2` takes SDL2 even when SDL3 is there. - `host/posix/display_sdl.c` (the window), `win32_posix.c`'s waveOut and `host/pad_sdl.c` (controllers, on both systems) call only the stubs. - Linux runs on SDL3 where it is installed: Wayland natively, the sound on an SDL3 audio stream. A folder or AppImage that only carries SDL2 keeps working as before. - Windows loads `SDL3.dll` for the controllers when one is beside the game, `SDL2.dll` otherwise, as now. - On SDL3 the desktop size stays in pixels for `GetSystemMetrics` (its display mode is in screen units, so it is scaled by the pixel density). **Tested** - Linux, the game built from this branch, on the system's SDL3 and with `HOS_SDL_VERSION=2` (SDL2): the window and the title screen render, a sound stream plays, the DualSense is found (`hid: controller "DualSense Wireless Controller" connected (SDL)`), and closing the window ends the game (`display: window closed, exiting`). - Windows, under Proton (GE-Proton 11-7), a test program built on `host/hos_sdl.c`: with only `SDL2.dll` beside it, SDL2 loaded and the DualSense opened; with SDL 3.4.18's `SDL3.dll`, SDL3 did the same. - `tests/test_sdl_audio_library.py` was rewritten for the stubs (3 tests, they pass). The rest of `tests/` gives the same result as on main (the 4 `test_cpp_preflight` checks need Visual Studio). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
NotRexed commented 2026-11-07 23:07:54 +00:00 (Migrated from github.com)

Thanks! This one conflicts with main now (main moved a lot today: the controller chain 335/343/350 and the input-in-background PR are merged, and the Windows package now ships SDL2 as sdl2-compat on SDL3 3.4.20). Could you rebase it on main? I'll merge it once it applies cleanly.

Thanks! This one conflicts with main now (main moved a lot today: the controller chain 335/343/350 and the input-in-background PR are merged, and the Windows package now ships SDL2 as sdl2-compat on SDL3 3.4.20). Could you rebase it on main? I'll merge it once it applies cleanly.
gab9281 commented 2026-11-07 23:26:35 +00:00 (Migrated from github.com)

@NotRexed rebased on current main (9e8fb5b). One conflict in host/pad_sdl.c with the per-controller rumble refresh from 40c3f85: that logic is kept as is, now through the hos_sdl_* calls. Built and run again on Linux: SDL3 loaded, sound on, a DualSense and an Xbox 360 pad connected, and the window closes cleanly.

@NotRexed rebased on current main (9e8fb5b). One conflict in `host/pad_sdl.c` with the per-controller rumble refresh from 40c3f85: that logic is kept as is, now through the `hos_sdl_*` calls. Built and run again on Linux: SDL3 loaded, sound on, a DualSense and an Xbox 360 pad connected, and the window closes cleanly.
Commenting is not possible because the repository is archived.
No description provided.