diff --git a/.github/workflows/build-sdl3.yml b/.github/workflows/build-sdl3.yml index 403141b51a..058ca74ab7 100644 --- a/.github/workflows/build-sdl3.yml +++ b/.github/workflows/build-sdl3.yml @@ -87,6 +87,11 @@ jobs: - name: Build with SDL3 run: python3 dev.py build --sdl3 + # eventually we need to run all tests, but for now test that importing pygame + # works + - name: Test import works + run: python3 -c 'import pygame' + # - name: Run tests # env: # SDL_VIDEODRIVER: "dummy" diff --git a/src_c/_pygame.h b/src_c/_pygame.h index 46fe2d966d..07f236149a 100644 --- a/src_c/_pygame.h +++ b/src_c/_pygame.h @@ -284,6 +284,10 @@ typedef enum { SDL_ACTIVEEVENT = SDL_USEREVENT, SDL_VIDEORESIZE, SDL_VIDEOEXPOSE, +#if SDL_VERSION_ATLEAST(3, 0, 0) + /* SDL_SYSWMEVENT removed in SDL3, define it here for compat */ + SDL_SYSWMEVENT, +#endif PGE_MIDIIN, PGE_MIDIOUT, diff --git a/src_c/meson.build b/src_c/meson.build index fb43a584eb..07189d6180 100644 --- a/src_c/meson.build +++ b/src_c/meson.build @@ -18,8 +18,6 @@ color = py.extension_module( subdir: pg, ) -# TODO: support SDL3 -if sdl_api != 3 constants = py.extension_module( 'constants', 'constants.c', @@ -28,7 +26,6 @@ constants = py.extension_module( install: true, subdir: pg, ) -endif # TODO: support SDL3 if sdl_api != 3 @@ -147,7 +144,6 @@ surface = py.extension_module( endif # TODO: support SDL3 -if sdl_api != 3 surflock = py.extension_module( 'surflock', 'surflock.c', @@ -156,10 +152,7 @@ surflock = py.extension_module( install: true, subdir: pg, ) -endif -# TODO: support SDL3 -if sdl_api != 3 time = py.extension_module( 'time', 'time.c', @@ -168,7 +161,6 @@ time = py.extension_module( install: true, subdir: pg, ) -endif # TODO: support SDL3 if sdl_api != 3 diff --git a/src_c/surflock.c b/src_c/surflock.c index 62cd3acdbd..0786d0fe66 100644 --- a/src_c/surflock.c +++ b/src_c/surflock.c @@ -99,7 +99,12 @@ pgSurface_LockBy(pgSurfaceObject *surfobj, PyObject *lockobj) if (surf->subsurface != NULL) { pgSurface_Prep(surfobj); } - if (SDL_LockSurface(surf->surf) == -1) { +#if SDL_VERSION_ATLEAST(3, 0, 0) + if (!SDL_LockSurface(surf->surf)) +#else + if (SDL_LockSurface(surf->surf) == -1) +#endif + { PyErr_SetString(PyExc_RuntimeError, "error locking surface"); return 0; } diff --git a/src_c/time.c b/src_c/time.c index 66dc4fc6f3..a44d859209 100644 --- a/src_c/time.c +++ b/src_c/time.c @@ -276,8 +276,13 @@ _pg_clear_event_timer_type(int ev_type) /* Timer callback function * TODO: This needs better error handling and a way to report to the user */ +#if SDL_VERSION_ATLEAST(3, 0, 0) +static Uint32 +timer_callback(void *param, SDL_TimerID timerID, Uint32 interval) +#else static Uint32 timer_callback(Uint32 interval, void *param) +#endif { pgEventTimer *evtimer; PG_LOCK_TIMER_MUTEX @@ -316,12 +321,14 @@ accurate_delay(Sint64 ticks) if (ticks <= 0) return 0; +#if !SDL_VERSION_ATLEAST(3, 0, 0) if (!SDL_WasInit(SDL_INIT_TIMER)) { if (SDL_InitSubSystem(SDL_INIT_TIMER)) { PyErr_SetString(pgExc_SDLError, SDL_GetError()); return -1; } } +#endif funcstart = PG_GetTicks(); if (ticks >= WORST_CLOCK_ACCURACY) { @@ -342,8 +349,10 @@ accurate_delay(Sint64 ticks) static PyObject * time_get_ticks(PyObject *self, PyObject *_null) { +#if !SDL_VERSION_ATLEAST(3, 0, 0) if (!SDL_WasInit(SDL_INIT_TIMER)) return PyLong_FromLong(0); +#endif return PyLong_FromUnsignedLongLong(PG_GetTicks()); } @@ -371,11 +380,13 @@ time_wait(PyObject *self, PyObject *arg) if (!PyLong_Check(arg)) return RAISE(PyExc_TypeError, "wait requires one integer argument"); +#if !SDL_VERSION_ATLEAST(3, 0, 0) if (!SDL_WasInit(SDL_INIT_TIMER)) { if (SDL_InitSubSystem(SDL_INIT_TIMER)) { return RAISE(pgExc_SDLError, SDL_GetError()); } } +#endif ticks = PyLong_AsLongLong(arg); if (ticks < 0) @@ -455,6 +466,7 @@ time_set_timer(PyObject *self, PyObject *args, PyObject *kwargs) goto end; } +#if !SDL_VERSION_ATLEAST(3, 0, 0) /* just doublecheck that timer is initialized */ if (!SDL_WasInit(SDL_INIT_TIMER)) { if (SDL_InitSubSystem(SDL_INIT_TIMER)) { @@ -462,6 +474,7 @@ time_set_timer(PyObject *self, PyObject *args, PyObject *kwargs) goto end; } } +#endif ecode = _pg_add_event_timer(ev_type, ev_dict, loops); if (ecode != PG_TIMER_NO_ERROR) { @@ -522,12 +535,14 @@ clock_tick_base(pgClockObject *self, PyObject *arg, int use_accurate_delay) self->rawpassed = PG_GetTicks() - self->last_tick; delay = endtime - self->rawpassed; +#if !SDL_VERSION_ATLEAST(3, 0, 0) /*just doublecheck that timer is initialized*/ if (!SDL_WasInit(SDL_INIT_TIMER)) { if (SDL_InitSubSystem(SDL_INIT_TIMER)) { return RAISE(pgExc_SDLError, SDL_GetError()); } } +#endif if (use_accurate_delay) delay = accurate_delay(delay); @@ -639,11 +654,13 @@ clock_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return NULL; } +#if !SDL_VERSION_ATLEAST(3, 0, 0) if (!SDL_WasInit(SDL_INIT_TIMER)) { if (SDL_InitSubSystem(SDL_INIT_TIMER)) { return RAISE(pgExc_SDLError, SDL_GetError()); } } +#endif pgClockObject *self = (pgClockObject *)(type->tp_alloc(type, 0)); self->fps_tick = 0;