Skip to content

Commit ebf3fd2

Browse files
committed
Upgrade to use SDL3 version of libtcod
Reconfigure CFFI porting scripts for SDL3, add _libtcod.pyi Many SDL functions were renamed and I'd have to port them blind without this new `_libtcod.py` file. Update type ignores for newest Numpy Enable more strict Mypy settings SDL_CommonEvent and others needed to be marked as packed/flexible Remove outdated Sphinx directives Check if audio devices work before testing them Update Linux wheel build workflows for SDL3
1 parent 8c25d37 commit ebf3fd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+12233
-1075
lines changed

.github/workflows/python-package.yml

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ jobs:
4444
sdist:
4545
runs-on: ubuntu-latest
4646
steps:
47-
- name: APT update
48-
run: sudo apt-get update
49-
- name: Install APT dependencies
50-
run: sudo apt-get install libsdl2-dev
47+
- uses: libsdl-org/setup-sdl@6574e20ac65ce362cd12f9c26b3a5e4d3cd31dee
48+
with:
49+
install-linux-dependencies: true
50+
build-type: "Debug"
51+
version: "3.2.14"
5152
- uses: actions/checkout@v4
5253
with:
5354
fetch-depth: ${{ env.git-depth }}
@@ -71,7 +72,7 @@ jobs:
7172
strategy:
7273
matrix:
7374
os: ["windows-latest", "macos-latest"]
74-
sdl-version: ["2.0.14", "2.0.16", "2.30.0"]
75+
sdl-version: ["3.2.10"]
7576
fail-fast: true
7677
steps:
7778
- uses: actions/checkout@v4
@@ -90,7 +91,7 @@ jobs:
9091
SDL_VERSION: ${{ matrix.sdl-version }}
9192

9293
build:
93-
needs: [ruff, mypy]
94+
needs: [ruff, mypy, sdist]
9495
runs-on: ${{ matrix.os }}
9596
strategy:
9697
matrix:
@@ -122,7 +123,13 @@ jobs:
122123
if: runner.os == 'Linux'
123124
run: |
124125
sudo apt-get update
125-
sudo apt-get install libsdl2-dev xvfb
126+
sudo apt-get install xvfb
127+
- uses: libsdl-org/setup-sdl@6574e20ac65ce362cd12f9c26b3a5e4d3cd31dee
128+
if: runner.os == 'Linux'
129+
with:
130+
install-linux-dependencies: true
131+
build-type: "Release"
132+
version: "3.2.14"
126133
- name: Install Python dependencies
127134
run: |
128135
python -m pip install --upgrade pip
@@ -157,13 +164,15 @@ jobs:
157164
compression-level: 0
158165

159166
test-docs:
160-
needs: [ruff, mypy]
167+
needs: [ruff, mypy, sdist]
161168
runs-on: ubuntu-latest
162169
steps:
163-
- name: Install APT dependencies
164-
run: |
165-
sudo apt-get update
166-
sudo apt-get install libsdl2-dev
170+
- uses: libsdl-org/setup-sdl@6574e20ac65ce362cd12f9c26b3a5e4d3cd31dee
171+
if: runner.os == 'Linux'
172+
with:
173+
install-linux-dependencies: true
174+
build-type: "Debug"
175+
version: "3.2.14"
167176
- uses: actions/checkout@v4
168177
with:
169178
fetch-depth: ${{ env.git-depth }}
@@ -182,11 +191,11 @@ jobs:
182191
run: python -m sphinx -T -E -W --keep-going . _build/html
183192

184193
tox:
185-
needs: [ruff]
194+
needs: [ruff, sdist]
186195
runs-on: ${{ matrix.os }}
187196
strategy:
188197
matrix:
189-
os: ["ubuntu-latest", "windows-latest"]
198+
os: ["ubuntu-latest"] # "windows-latest" disabled due to free-threaded build issues
190199
steps:
191200
- uses: actions/checkout@v4
192201
with:
@@ -200,17 +209,18 @@ jobs:
200209
- name: Install Python dependencies
201210
run: |
202211
python -m pip install --upgrade pip tox
203-
- name: Install APT dependencies
212+
- uses: libsdl-org/setup-sdl@6574e20ac65ce362cd12f9c26b3a5e4d3cd31dee
204213
if: runner.os == 'Linux'
205-
run: |
206-
sudo apt-get update
207-
sudo apt-get install libsdl2-dev
214+
with:
215+
install-linux-dependencies: true
216+
build-type: "Debug"
217+
version: "3.2.14"
208218
- name: Run tox
209219
run: |
210220
tox -vv
211221
212222
linux-wheels:
213-
needs: [ruff, mypy]
223+
needs: [ruff, mypy, sdist]
214224
runs-on: ${{ matrix.arch == 'aarch64' && 'ubuntu-24.04-arm' || 'ubuntu-latest'}}
215225
strategy:
216226
matrix:
@@ -248,7 +258,19 @@ jobs:
248258
CIBW_BEFORE_ALL_LINUX: >
249259
yum install -y epel-release &&
250260
yum-config-manager --enable epel &&
251-
yum install -y SDL2-devel
261+
yum install -y gcc git-core make cmake \
262+
alsa-lib-devel pulseaudio-libs-devel \
263+
libX11-devel libXext-devel libXrandr-devel libXcursor-devel libXfixes-devel \
264+
libXi-devel libXScrnSaver-devel dbus-devel ibus-devel \
265+
systemd-devel mesa-libGL-devel libxkbcommon-devel mesa-libGLES-devel \
266+
mesa-libEGL-devel vulkan-devel wayland-devel wayland-protocols-devel \
267+
libdrm-devel mesa-libgbm-devel libusb-devel
268+
git clone --depth 1 --branch release-3.2.10 https://github.com/libsdl-org/SDL.git sdl_repo &&
269+
cmake -S sdl_repo -B sdl_build &&
270+
cmake --build sdl_build --config Release &&
271+
cmake --install sdl_build --config Release --prefix /usr/local &&
272+
cp --verbose /usr/local/lib64/pkgconfig/sdl3.pc /lib64/pkgconfig/sdl3.pc
273+
PKG_CONFIG_PATH: "/usr/local/lib64/pkgconfig"
252274
CIBW_BEFORE_TEST: pip install numpy
253275
CIBW_TEST_COMMAND: python -c "import tcod.context"
254276
# Skip test on emulated architectures
@@ -267,7 +289,7 @@ jobs:
267289
compression-level: 0
268290

269291
build-macos:
270-
needs: [ruff, mypy]
292+
needs: [ruff, mypy, sdist]
271293
runs-on: "macos-14"
272294
strategy:
273295
fail-fast: true
@@ -287,7 +309,7 @@ jobs:
287309
- name: Install Python dependencies
288310
run: pip install -r requirements.txt
289311
- name: Prepare package
290-
# Downloads SDL2 for the later step.
312+
# Downloads SDL for the later step.
291313
run: python build_sdl.py
292314
- name: Build wheels
293315
uses: pypa/[email protected]
@@ -298,7 +320,7 @@ jobs:
298320
CIBW_BEFORE_TEST: pip install numpy
299321
CIBW_TEST_COMMAND: python -c "import tcod.context"
300322
CIBW_TEST_SKIP: "pp* *-macosx_arm64 *-macosx_universal2:arm64"
301-
MACOSX_DEPLOYMENT_TARGET: "10.11"
323+
MACOSX_DEPLOYMENT_TARGET: "10.13"
302324
- name: Remove asterisk from label
303325
run: |
304326
PYTHON_DESC=${{ matrix.python }}

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ Release/
6969
tcod/_*.c
7070
tcod/_*.pyd
7171
.benchmarks
72-
dependencies/SDL2*
72+
dependencies/SDL*
7373
tcod/x86
7474
tcod/x64
75-
tcod/SDL2.framework
75+
tcod/SDL?.framework
7676
deb_dist/
7777
*.tar.gz
7878
tcod/version.py

.readthedocs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
version: 2
66

77
build:
8-
os: ubuntu-22.04
8+
os: ubuntu-24.04
99
tools:
1010
python: "3.11"
1111
apt_packages:
12-
- libsdl2-dev
12+
- libsdl3-dev
1313

1414
submodules:
1515
include: all

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"condlist",
9797
"consolas",
9898
"contextdata",
99+
"contextlib",
99100
"CONTROLLERAXISMOTION",
100101
"CONTROLLERBUTTONDOWN",
101102
"CONTROLLERBUTTONUP",
@@ -112,6 +113,7 @@
112113
"dataclasses",
113114
"datas",
114115
"DBLAMPERSAND",
116+
"DBLAPOSTROPHE",
115117
"DBLVERTICALBAR",
116118
"dcost",
117119
"DCROSS",
@@ -139,6 +141,7 @@
139141
"dunder",
140142
"DVLINE",
141143
"elif",
144+
"ENDCALL",
142145
"endianness",
143146
"epel",
144147
"epub",
@@ -250,6 +253,7 @@
250253
"lerp",
251254
"letterpaper",
252255
"LGUI",
256+
"LHYPER",
253257
"libsdl",
254258
"libtcod",
255259
"libtcodpy",
@@ -305,6 +309,7 @@
305309
"neww",
306310
"noarchive",
307311
"NODISCARD",
312+
"NOMESSAGE",
308313
"Nonrepresentable",
309314
"NONUSBACKSLASH",
310315
"NONUSHASH",
@@ -315,10 +320,12 @@
315320
"numpy",
316321
"ogrid",
317322
"ogrids",
323+
"oldnames",
318324
"onefile",
319325
"OPENGL",
320326
"opensearch",
321327
"OPER",
328+
"OVERSCAN",
322329
"packbits",
323330
"PAGEDOWN",
324331
"pagerefs",
@@ -365,6 +372,7 @@
365372
"repr",
366373
"rgba",
367374
"RGUI",
375+
"RHYPER",
368376
"RIGHTBRACE",
369377
"RIGHTBRACKET",
370378
"RIGHTDOWN",
@@ -406,6 +414,8 @@
406414
"SIZEWE",
407415
"SMILIE",
408416
"snprintf",
417+
"SOFTLEFT",
418+
"SOFTRIGHT",
409419
"soundfile",
410420
"sourcelink",
411421
"sphinxstrong",
@@ -444,6 +454,7 @@
444454
"typestr",
445455
"undoc",
446456
"Unifont",
457+
"UNISTD",
447458
"unraisable",
448459
"unraisablehook",
449460
"unraiseable",

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,45 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- Switched to SDL3.
12+
This will cause several breaking changes such as the names of keyboard constants and other SDL enums.
13+
- `tcod.sdl.video.Window.grab` has been split into `.mouse_grab` and `.keyboard_grab` attributes.
14+
- `tcod.event.KeySym` single letter symbols are now all uppercase.
15+
- Relative mouse mode is set via `tcod.sdl.video.Window.relative_mouse_mode` instead of `tcod.sdl.mouse.set_relative_mode`.
16+
- `tcod.sdl.render.new_renderer`: Removed `software` and `target_textures` parameters, `vsync` takes `int`, `driver` takes `str` instead of `int`.
17+
- SDL renderer logical
18+
- `tcod.sdl.render.Renderer`: `integer_scaling` and `logical_size` are now set with `set_logical_presentation` method.
19+
- `tcod.sdl.render.Renderer.geometry` now takes float values for `color` instead of 8-bit integers.
20+
- `tcod.event.Point` and other mouse/tile coordinate types now use `float` instead of `int`.
21+
SDL3 has decided that mouse events have subpixel precision.
22+
If you see any usual `float` types in your code then this is why.
23+
- `tcod.sdl.audio` has been affected by major changes to SDL3.
24+
- `tcod.sdl.audio.open` has new behavior due to SDL3 and should be avoided.
25+
- Callbacks which were assigned to `AudioDevice`'s must now be applied to `AudioStream`'s instead.
26+
- `AudioDevice`'s are now opened using references to existing devices.
27+
- Sound queueing methods were moved from `AudioDevice` to a new `AudioStream` class.
28+
- `BasicMixer` may require manually specifying `frequency` and `channels` to replicate old behavior.
29+
- `get_devices` and `get_capture_devices` now return `dict[str, AudioDevice]`.
30+
31+
### Deprecated
32+
33+
- `tcod.sdl.audio.open` was replaced with a newer API, get a default device with `tcod.sdl.audio.get_default_playback().open()`.
34+
- `tcod.sdl.audio.BasicMixer` should be replaced with `AudioStream`'s.
35+
- Should no longer use `tcod.sdl.audio.AudioDevice` in a context, use `contextlib.closing` for the old behavior.
36+
937
### Removed
1038

1139
- Support dropped for Python 3.8 and 3.9.
40+
- Removed `Joystick.get_current_power` due to SDL3 changes.
41+
- `WindowFlags.FULLSCREEN_DESKTOP` is now just `WindowFlags.FULLSCREEN`
42+
- `tcod.sdl.render.Renderer.integer_scaling` removed.
43+
- Removed `callback`, `spec`, `queued_samples`, `queue_audio`, and `dequeue_audio` attributes from `tcod.sdl.audio.AudioDevice`.
44+
45+
### Fixed
46+
47+
- `Joystick.get_ball` was broken.
1248

1349
## [18.1.0] - 2025-05-05
1450

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ For the most part it's just::
4848
==============
4949
* Python 3.10+
5050
* Windows, Linux, or MacOS X 10.9+.
51-
* On Linux, requires libsdl2 (2.0.10+).
51+
* On Linux, requires libsdl3 (3.2.0+).
5252

5353
===========
5454
Changelog

0 commit comments

Comments
 (0)