Skip to content

Commit

Permalink
Merge #622 #625
Browse files Browse the repository at this point in the history
622: Nix the last of the posers r=pathunstrom a=AstraLuma

There was some remaining usages of `pos` in various corners of the codebase. Fix that.

625: Fix sound r=pathunstrom a=AstraLuma

This will band-aid over #619.

However, it does not fix the underlying issue: Assets should only begin loading after all systems have been entered.

Co-authored-by: Jamie Bliss <[email protected]>
  • Loading branch information
bors[bot] and AstraLuma authored May 19, 2021
3 parents 273d450 + a9969e8 + 7eca130 commit 3e0d7a5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
6 changes: 3 additions & 3 deletions examples/keyboard_and_mouse_controls/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
)

Expand Down Expand Up @@ -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__":
Expand Down
30 changes: 29 additions & 1 deletion ppb/systems/sound.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import ctypes
import io
import time

from sdl2 import (
AUDIO_S16SYS, rw_from_object,
)

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
Expand All @@ -24,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(
Expand Down Expand Up @@ -97,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
Expand Down
2 changes: 1 addition & 1 deletion viztests/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 3e0d7a5

Please sign in to comment.