ppb / pursuedpybear

A python game engine.
https://ppb.dev/
Artistic License 2.0
258 stars 98 forks source link

Changing Sound asset volume before setup causes hang at startup #419

Open ironfroggy opened 4 years ago

ironfroggy commented 4 years ago

This works:

SOUND_CHIME = ppb.Sound("resources/sound/chimes.wav")
def setup(scene):
    SOUND_SWAP.volume = 0.5
    ...
ppb.run(setup=setup)

But this causes a permanent hang at startup:

SOUND_CHIME = ppb.Sound("resources/sound/chimes.wav")
SOUND_CHIME.volume = 0.5
def setup(scene):
    ...
ppb.run(setup=setup)

The only output I get is this message about the asset:

Waited on <Sound name='resources/sound/chimes.wav'> before the engine began
pathunstrom commented 4 years ago

I know where that error comes from, but I don't know enough about the implementation to know if we can unhook the volume attribute from the asset load.

@astronouth7303 knows this bit of code.

AstraLuma commented 4 years ago

OH yes. That was a dumb implementation.

Asset loads don't begin until the engine initializes, and the volume implementation depends on it.

This can be fixed without API changes.

Although upon review I wonder if this is a bad API because it'll change the volume for all usages and there's no way to create new copies.

pathunstrom commented 4 years ago

Maybe make the volume be a parameter to the event and the sound system can duplicate at the place of use?