Skip to content

Commit 7cacbc9

Browse files
committed
Merge branch 'main' of https://github.com/pygame-community/pygame-ce into free-threading
2 parents 0c7e3d5 + 100d804 commit 7cacbc9

File tree

8 files changed

+82
-33
lines changed

8 files changed

+82
-33
lines changed

docs/reST/c_api/slots.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ base.c has this exposing the pg_RGBAFromObj function to the `c_api` structure:
1616

1717
Then in src_c/include/_pygame.h there is an
1818

19-
#define pg_RGBAFromObj.
19+
#define pg_RGBAFromObj.
2020

2121
Also in _pygame.h, it needs to define the number of slots the base module uses. This is PYGAMEAPI_BASE_NUMSLOTS. So if you were adding another function, you need to increment this PYGAMEAPI_BASE_NUMSLOTS number.
2222

@@ -25,6 +25,6 @@ Then to use the pg_RGBAFromObj in other files,
2525
1) include the "pygame.h" file,
2626
2) they have to make sure base is imported with:
2727

28-
import_pygame_base();
28+
import_pygame_base();
2929

3030
Examples that use pg_RGBAFromObj are: _freetype.c, color.c, gfxdraw.c, and surface.c.

docs/reST/ref/bufferproxy.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747

4848
``"strides"`` : tuple : (optional)
4949
Array stride information as a tuple of integers. It is required
50-
only of non C-contiguous arrays. The tuple length must match
51-
that of ``"shape"``.
50+
only of non C-contiguous arrays. The tuple length must match
51+
that of ``"shape"``.
5252

5353
``"parent"`` : object : (optional)
5454
The exporting object. It can be used to keep the parent object
@@ -57,7 +57,7 @@
5757
``"before"`` : callable : (optional)
5858
Callback invoked when the :class:`BufferProxy` instance
5959
exports the buffer. The callback is given one argument, the
60-
``"parent"`` object if given, otherwise ``None``.
60+
``"parent"`` object if given, otherwise ``None``.
6161
The callback is useful for setting a lock on the parent.
6262

6363
``"after"`` : callable : (optional)

docs/reST/ref/mask.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ to store which parts collide.
535535
component.
536536

537537
:param int minimum: (optional) indicates the minimum number of bits (to
538-
filter out noise) per connected component (default is 0, which equates
539-
to no minimum and is equivalent to setting it to 1, as a connected
538+
filter out noise) per connected component (default is 0, which equates
539+
to no minimum and is equivalent to setting it to 1, as a connected
540540
component must have at least 1 bit set)
541541

542542
:returns: a list containing a :class:`Mask` object for each connected

docs/reST/ref/mouse.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ scroll, such as ``which`` (it will tell you what exact mouse device trigger the
275275

276276
.. note:: Code that unpacked a get_cursor() call into
277277
``size, hotspot, xormasks, andmasks`` will still work,
278-
assuming the call returns an old school type cursor.
278+
assuming the call returns an old school type cursor.
279279

280280
.. versionchangedold:: 2.0.1
281281

docs/reST/ref/sdl2_video.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
:synopsis: Experimental pygame module for porting new SDL video systems
88

99
.. warning::
10-
This module isn't ready for prime time yet, it's still in development.
11-
These docs are primarily meant to help the pygame developers and
12-
super-early adopters who are in communication with the developers.
13-
This API will change.
10+
This module isn't ready for prime time yet, it's still in development.
11+
These docs are primarily meant to help the pygame developers and
12+
super-early adopters who are in communication with the developers.
13+
This API will change.
1414

1515
| :sl:`Experimental pygame module for porting new SDL video systems`
1616

docs/reST/tutorials/en/tom-games6.rst

+13-13
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ after we've worked out the new position of the ball.
2828

2929
::
3030

31-
if not self.area.contains(newpos):
32-
tl = not self.area.collidepoint(newpos.topleft)
33-
tr = not self.area.collidepoint(newpos.topright)
34-
bl = not self.area.collidepoint(newpos.bottomleft)
35-
br = not self.area.collidepoint(newpos.bottomright)
36-
if tr and tl or (br and bl):
37-
angle = -angle
38-
if tl and bl:
39-
self.offcourt(player=2)
40-
if tr and br:
41-
self.offcourt(player=1)
42-
43-
self.vector = (angle,z)
31+
if not self.area.contains(newpos):
32+
tl = not self.area.collidepoint(newpos.topleft)
33+
tr = not self.area.collidepoint(newpos.topright)
34+
bl = not self.area.collidepoint(newpos.bottomleft)
35+
br = not self.area.collidepoint(newpos.bottomright)
36+
if tr and tl or (br and bl):
37+
angle = -angle
38+
if tl and bl:
39+
self.offcourt(player=2)
40+
if tr and br:
41+
self.offcourt(player=1)
42+
43+
self.vector = (angle,z)
4444

4545
Here we check to see if the ``area``
4646
contains the new position of the ball (it always should, so we needn't have an ``else`` clause,

src_c/joystick.c

+57-5
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,17 @@ static PyObject *
112112
get_count(PyObject *self, PyObject *_null)
113113
{
114114
JOYSTICK_INIT_CHECK();
115+
#if SDL_VERSION_ATLEAST(3, 0, 0)
116+
int ret;
117+
SDL_JoystickID *joysticks = SDL_GetJoysticks(&ret);
118+
if (!joysticks) {
119+
return RAISE(pgExc_SDLError, SDL_GetError());
120+
}
121+
SDL_free(joysticks);
122+
return PyLong_FromLong(ret);
123+
#else
115124
return PyLong_FromLong(SDL_NumJoysticks());
125+
#endif
116126
}
117127

118128
static PyObject *
@@ -200,18 +210,53 @@ joy_get_guid(PyObject *self, PyObject *_null)
200210
guid = SDL_JoystickGetGUID(joy);
201211
}
202212
else {
213+
#if SDL_VERSION_ATLEAST(3, 0, 0)
214+
return RAISE(pgExc_SDLError, "Invalid/closed joystick object");
215+
#else
203216
guid = SDL_JoystickGetDeviceGUID(pgJoystick_AsID(self));
217+
#endif
204218
}
205219

220+
#if SDL_VERSION_ATLEAST(3, 0, 0)
221+
SDL_GUIDToString(guid, strguid, 33);
222+
#else
206223
SDL_JoystickGetGUIDString(guid, strguid, 33);
224+
#endif
207225

208226
return PyUnicode_FromString(strguid);
209227
}
210228

211229
const char *
212-
_pg_powerlevel_string(SDL_JoystickPowerLevel level)
230+
_pg_powerlevel_string(SDL_Joystick *joy)
213231
{
214-
switch (level) {
232+
#if SDL_VERSION_ATLEAST(3, 0, 0)
233+
int percent = -1;
234+
SDL_PowerState state = SDL_GetJoystickPowerInfo(joy, &percent);
235+
if (state == SDL_POWERSTATE_ON_BATTERY) {
236+
/* These percentages are based on SDL_JoystickCurrentPowerLevel defined
237+
* in sdl2-compat */
238+
if (percent > 70) {
239+
return "full";
240+
}
241+
else if (percent > 20) {
242+
return "medium";
243+
}
244+
else if (percent > 5) {
245+
return "low";
246+
}
247+
else {
248+
return "empty";
249+
}
250+
}
251+
else if (state == SDL_POWERSTATE_UNKNOWN ||
252+
state == SDL_POWERSTATE_ERROR) {
253+
return "unknown";
254+
}
255+
else {
256+
return "wired";
257+
}
258+
#else
259+
switch (SDL_JoystickCurrentPowerLevel(joy)) {
215260
case SDL_JOYSTICK_POWER_EMPTY:
216261
return "empty";
217262
case SDL_JOYSTICK_POWER_LOW:
@@ -227,12 +272,12 @@ _pg_powerlevel_string(SDL_JoystickPowerLevel level)
227272
default:
228273
return "unknown";
229274
}
275+
#endif
230276
}
231277

232278
static PyObject *
233279
joy_get_power_level(PyObject *self, PyObject *_null)
234280
{
235-
SDL_JoystickPowerLevel level;
236281
const char *leveltext;
237282
SDL_Joystick *joy = pgJoystick_AsSDL(self);
238283

@@ -241,8 +286,7 @@ joy_get_power_level(PyObject *self, PyObject *_null)
241286
return RAISE(pgExc_SDLError, "Joystick not initialized");
242287
}
243288

244-
level = SDL_JoystickCurrentPowerLevel(joy);
245-
leveltext = _pg_powerlevel_string(level);
289+
leveltext = _pg_powerlevel_string(joy);
246290

247291
return PyUnicode_FromString(leveltext);
248292
}
@@ -287,7 +331,11 @@ joy_rumble(pgJoystickObject *self, PyObject *args, PyObject *kwargs)
287331
low = (Uint32)(lowf * 0xFFFF);
288332
high = (Uint32)(highf * 0xFFFF);
289333

334+
#if SDL_VERSION_ATLEAST(3, 0, 0)
335+
if (!SDL_JoystickRumble(joy, low, high, duration)) {
336+
#else
290337
if (SDL_JoystickRumble(joy, low, high, duration) == -1) {
338+
#endif
291339
Py_RETURN_FALSE;
292340
}
293341
Py_RETURN_TRUE;
@@ -545,9 +593,13 @@ pgJoystick_New(int id)
545593
JOYSTICK_INIT_CHECK();
546594

547595
/* Open the SDL device */
596+
#if !SDL_VERSION_ATLEAST(3, 0, 0)
597+
/* This check should be redundant because SDL_JoystickOpen already checks
598+
* and errors if id is out of bounds on SDL3 */
548599
if (id >= SDL_NumJoysticks()) {
549600
return RAISE(pgExc_SDLError, "Invalid joystick device number");
550601
}
602+
#endif
551603
joy = SDL_JoystickOpen(id);
552604
if (!joy) {
553605
return RAISE(pgExc_SDLError, SDL_GetError());

src_c/meson.build

-3
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ time = py.extension_module(
152152
subdir: pg,
153153
)
154154

155-
# TODO: support SDL3
156-
if sdl_api != 3
157155
joystick = py.extension_module(
158156
'joystick',
159157
'joystick.c',
@@ -162,7 +160,6 @@ joystick = py.extension_module(
162160
install: true,
163161
subdir: pg,
164162
)
165-
endif
166163

167164
draw = py.extension_module(
168165
'draw',

0 commit comments

Comments
 (0)