From a9969e8b1a7d68e2c9be658efb0f01648360f575 Mon Sep 17 00:00:00 2001 From: Jamie Bliss Date: Tue, 18 May 2021 11:57:04 -0400 Subject: [PATCH 1/3] Nix the last of the posers There was some remaining usages of pos in various corners of the codebase. Fix that. --- examples/keyboard_and_mouse_controls/targets.py | 6 +++--- viztests/loading.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/keyboard_and_mouse_controls/targets.py b/examples/keyboard_and_mouse_controls/targets.py index bc452a7a..039f8914 100644 --- a/examples/keyboard_and_mouse_controls/targets.py +++ b/examples/keyboard_and_mouse_controls/targets.py @@ -43,7 +43,7 @@ def on_button_pressed(self, event, signal): def _fire_bullet(self, scene, signal): signal(PlaySound(self.fire_sound)) scene.add( - Bullet(pos=self.position), + Bullet(position=self.position), tags=['bullet'] ) @@ -77,11 +77,11 @@ def __init__(self, *p, **kw): super().__init__(*p, **kw) # Set up sprites - self.add(Player(pos=Vector(0, 0)), tags=['player']) + self.add(Player(position=Vector(0, 0)), tags=['player']) # 5 targets in x = -3.75 -> 3.75, with margin for x in (-3, -1.5, 0, 1.5, 3): - self.add(Target(pos=Vector(x, 1.875)), tags=['target']) + self.add(Target(position=Vector(x, 1.875)), tags=['target']) if __name__ == "__main__": diff --git a/viztests/loading.py b/viztests/loading.py index e2c2040d..f0887505 100644 --- a/viztests/loading.py +++ b/viztests/loading.py @@ -54,7 +54,7 @@ def on_asset_loaded(self, event, signal): def get_progress_sprites(self): for x in range(-2, 3): - yield ppb.Sprite(pos=ppb.Vector(x, 0)) + yield ppb.Sprite(position=ppb.Vector(x, 0)) ppb.run(starting_scene=LoadingScene) From 55ebaab59f9be07fdd6219c2d60d8efad58f305f Mon Sep 17 00:00:00 2001 From: Jamie Bliss Date: Tue, 18 May 2021 13:24:52 -0400 Subject: [PATCH 2/3] add Mix_QuerySpec() wrapper --- ppb/systems/sound.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ppb/systems/sound.py b/ppb/systems/sound.py index 7c541cba..8b4abd36 100644 --- a/ppb/systems/sound.py +++ b/ppb/systems/sound.py @@ -1,3 +1,4 @@ +import ctypes import io from sdl2 import ( @@ -5,10 +6,12 @@ ) from sdl2.sdlmixer import ( + # Errors, https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_7.html#SEC7 + Mix_GetError, # Support library loading https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_7.html#SEC7 Mix_Init, Mix_Quit, MIX_INIT_FLAC, MIX_INIT_MOD, MIX_INIT_MP3, MIX_INIT_OGG, # Mixer init https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_7.html#SEC7 - Mix_OpenAudio, Mix_CloseAudio, + Mix_OpenAudio, Mix_CloseAudio, Mix_QuerySpec, # Samples https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_16.html#SEC16 Mix_LoadWAV_RW, Mix_FreeChunk, Mix_VolumeChunk, # Channels https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_25.html#SEC25 @@ -63,6 +66,20 @@ def _filler_channel_finished(channel): pass +def query_spec(): + frequency = ctypes.c_int() + format = ctypes.c_uint16() + channels = ctypes.c_int() + count = mix_call( + Mix_QuerySpec, + ctypes.byref(frequency), + ctypes.byref(format), + ctypes.byref(channels), + _check_error=lambda rv: rv == 0 and Mix_GetError(), + ) + return count, frequency, format, channels + + class SoundController(SdlSubSystem, LoggingMixin): _finished_callback = None From 7eca130ee0a3104b966ac2481e77f8ed4afbf237 Mon Sep 17 00:00:00 2001 From: Jamie Bliss Date: Tue, 18 May 2021 13:38:59 -0400 Subject: [PATCH 3/3] Band-aid over wrong-order running --- ppb/systems/sound.py | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/ppb/systems/sound.py b/ppb/systems/sound.py index 8b4abd36..0755e2a7 100644 --- a/ppb/systems/sound.py +++ b/ppb/systems/sound.py @@ -1,5 +1,6 @@ import ctypes import io +import time from sdl2 import ( AUDIO_S16SYS, rw_from_object, @@ -27,10 +28,31 @@ __all__ = ('SoundController', 'Sound') +def query_spec(): + """ + Helpful wrapper around Mix_QuerySpec() + """ + frequency = ctypes.c_int() + format = ctypes.c_uint16() + channels = ctypes.c_int() + count = mix_call( + Mix_QuerySpec, + ctypes.byref(frequency), + ctypes.byref(format), + ctypes.byref(channels), + _check_error=lambda rv: rv == 0 and Mix_GetError(), + ) + return count, frequency, format, channels + + class Sound(assetlib.Asset): # This is wrapping a ctypes.POINTER(Mix_Chunk) def background_parse(self, data): + # Band-aid over some synchronization issues + # https://github.com/ppb/pursuedpybear/issues/619 + while not any(query_spec()): + time.sleep(0) file = rw_from_object(io.BytesIO(data)) # ^^^^ is a pure-python emulation, does not need cleanup. return mix_call( @@ -66,20 +88,6 @@ def _filler_channel_finished(channel): pass -def query_spec(): - frequency = ctypes.c_int() - format = ctypes.c_uint16() - channels = ctypes.c_int() - count = mix_call( - Mix_QuerySpec, - ctypes.byref(frequency), - ctypes.byref(format), - ctypes.byref(channels), - _check_error=lambda rv: rv == 0 and Mix_GetError(), - ) - return count, frequency, format, channels - - class SoundController(SdlSubSystem, LoggingMixin): _finished_callback = None @@ -114,6 +122,9 @@ def __enter__(self): _check_error=lambda rv: rv == -1 ) mix_call(Mix_Init, MIX_INIT_FLAC | MIX_INIT_MOD | MIX_INIT_MP3 | MIX_INIT_OGG) + + print("SoundController", query_spec(), flush=True) + self.allocated_channels = 16 # Register callback, keeping reference for later cleanup