Skip to content

Commit a921edb

Browse files
committed
Typing fixes and small Pyglet 3 updates
1 parent c7f1d17 commit a921edb

File tree

4 files changed

+15
-70
lines changed

4 files changed

+15
-70
lines changed

arcade/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def configure_logging(level: int | None = None):
5959

6060
# Enable HiDPI support using stretch mode
6161
if os.environ.get("ARCADE_TEST"):
62-
pyglet.options.dpi_scaling = "real"
62+
pyglet.options.dpi_scaling = "platform"
6363
else:
6464
pyglet.options.dpi_scaling = "stretch"
6565

@@ -68,13 +68,6 @@ def configure_logging(level: int | None = None):
6868
if headless:
6969
pyglet.options.headless = headless
7070

71-
72-
# from arcade import utils
73-
# Disable shadow window on macs and in headless mode.
74-
# if sys.platform == "darwin" or os.environ.get("ARCADE_HEADLESS") or utils.is_raspberry_pi():
75-
# NOTE: We always disable shadow window now to have consistent behavior across platforms.
76-
pyglet.options.shadow_window = False
77-
7871
# Imports from modules that don't do anything circular
7972

8073
# Complex imports with potential circularity

arcade/future/video/video_player.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class VideoPlayer:
2323
"""
2424

2525
def __init__(self, path: str | Path, loop: bool = False):
26-
self.player = pyglet.media.Player()
26+
self.player = pyglet.media.VideoPlayer()
2727
self.player.loop = loop
2828
self.player.queue(pyglet.media.load(str(arcade.resources.resolve(path))))
2929
self.player.play()
@@ -80,7 +80,7 @@ def get_video_size(self) -> tuple[int, int]:
8080
width *= video_format.sample_aspect
8181
elif video_format.sample_aspect < 1:
8282
height /= video_format.sample_aspect
83-
return width, height
83+
return int(width), int(height)
8484

8585

8686
class VideoPlayerView(arcade.View):

arcade/sprite_list/sprite_list.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,13 +1681,17 @@ def get_nearby_sprite_indices(self, pos: Point, size: Point, length: int) -> lis
16811681
A list of indices of nearby sprites.
16821682
"""
16831683
ctx = self.ctx
1684+
16841685
ctx.collision_detection_program["check_pos"] = pos
16851686
ctx.collision_detection_program["check_size"] = size
16861687
buffer = ctx.collision_buffer
16871688
with ctx.collision_query:
1688-
self._geometry.transform( # type: ignore
1689-
ctx.collision_detection_program,
1690-
buffer,
1689+
# These calls are typed as | None because of the arcade.gl backends, but at this
1690+
# point if we have SpriteListBufferData these are guaranteed to be on a backend
1691+
# where they will not be None.
1692+
self._geometry.transform(
1693+
ctx.collision_detection_program, # type: ignore
1694+
buffer, # type: ignore
16911695
vertices=length,
16921696
)
16931697

@@ -1882,6 +1886,8 @@ def get_nearby_sprite_indices(self, pos: Point, size: Point, length: int) -> lis
18821886
A list of indices of nearby sprites.
18831887
"""
18841888
ctx = self.ctx
1889+
if (ctx._gl_api == "webgl"):
1890+
raise RuntimeError("GPU Collision is not supported on WebGL Backends")
18851891
buffer = ctx.collision_buffer
18861892
program = ctx.collision_detection_program_simple
18871893
program["check_pos"] = pos
@@ -1892,9 +1898,11 @@ def get_nearby_sprite_indices(self, pos: Point, size: Point, length: int) -> lis
18921898
self._storage_index.use(2)
18931899

18941900
with ctx.collision_query:
1901+
# This is ignored because it is guaranteed to not be none by the above context GL api
1902+
# check. This is only able to be None when we are on WebGL.
18951903
ctx.geometry_empty.transform(
18961904
program,
1897-
buffer,
1905+
buffer, # type: ignore
18981906
vertices=length,
18991907
)
19001908
emit_count = ctx.collision_query.primitives_generated

arcade/text.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,62 +19,6 @@
1919
__all__ = ["load_font", "Text", "create_text_sprite", "draw_text"]
2020

2121

22-
class _ArcadeTextLayoutGroup(pyglet.text.layout.TextLayoutGroup):
23-
"""Create a text layout rendering group.
24-
25-
Overrides pyglet blending handling to allow for additive blending.
26-
Furthermore, it resets the blend function to the previous state.
27-
"""
28-
29-
_prev_blend: bool
30-
_prev_blend_func: tuple[int, int, int, int]
31-
32-
def set_state(self) -> None:
33-
self.program.use()
34-
self.program["scissor"] = False
35-
36-
pyglet.gl.glActiveTexture(pyglet.gl.GL_TEXTURE0)
37-
pyglet.gl.glBindTexture(self.texture.target, self.texture.id)
38-
39-
blend = c_ubyte()
40-
pyglet.gl.glGetBooleanv(pyglet.gl.GL_BLEND, blend)
41-
self._prev_blend = bool(blend.value)
42-
43-
src_rgb = c_int()
44-
dst_rgb = c_int()
45-
src_alpha = c_int()
46-
dst_alpha = c_int()
47-
pyglet.gl.glGetIntegerv(pyglet.gl.GL_BLEND_SRC_RGB, src_rgb)
48-
pyglet.gl.glGetIntegerv(pyglet.gl.GL_BLEND_DST_RGB, dst_rgb)
49-
pyglet.gl.glGetIntegerv(pyglet.gl.GL_BLEND_SRC_ALPHA, src_alpha)
50-
pyglet.gl.glGetIntegerv(pyglet.gl.GL_BLEND_DST_ALPHA, dst_alpha)
51-
52-
self._prev_blend_func = (src_rgb.value, dst_rgb.value, src_alpha.value, dst_alpha.value)
53-
54-
pyglet.gl.glEnable(pyglet.gl.GL_BLEND)
55-
pyglet.gl.glBlendFuncSeparate(
56-
pyglet.gl.GL_SRC_ALPHA,
57-
pyglet.gl.GL_ONE_MINUS_SRC_ALPHA,
58-
pyglet.gl.GL_ONE,
59-
pyglet.gl.GL_ONE,
60-
)
61-
62-
def unset_state(self) -> None:
63-
if not self._prev_blend:
64-
pyglet.gl.glDisable(pyglet.gl.GL_BLEND)
65-
66-
pyglet.gl.glBlendFuncSeparate(
67-
self._prev_blend_func[0],
68-
self._prev_blend_func[1],
69-
self._prev_blend_func[2],
70-
self._prev_blend_func[3],
71-
)
72-
self.program.stop()
73-
74-
75-
pyglet.text.layout.TextLayout.group_class = _ArcadeTextLayoutGroup
76-
77-
7822
def load_font(path: str | Path) -> None:
7923
"""
8024
Load fonts in a file (usually .ttf) adding them to a global font registry.

0 commit comments

Comments
 (0)