emscripten: detach/attach the voice during loading

Should prevent audio artifacts when the browser is busy...

...when Emscripten gets it fixed, that is :P
This commit is contained in:
Sebastian Krzyszkowiak 2019-01-11 02:33:17 +01:00
parent f5ce67e6cb
commit 0d32d00890
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 13 additions and 1 deletions

View file

@ -481,7 +481,7 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) {
al_destroy_mixer(game->audio.music); al_destroy_mixer(game->audio.music);
al_destroy_mixer(game->audio.voice); al_destroy_mixer(game->audio.voice);
al_destroy_mixer(game->audio.mixer); al_destroy_mixer(game->audio.mixer);
al_destroy_voice(game->audio.v); // FIXME: doesn't seem to work in Chromium under Emscripten al_destroy_voice(game->audio.v);
al_destroy_cond(game->_priv.texture_sync_cond); al_destroy_cond(game->_priv.texture_sync_cond);
al_destroy_mutex(game->_priv.texture_sync_mutex); al_destroy_mutex(game->_priv.texture_sync_mutex);
al_destroy_cond(game->_priv.bsod_cond); al_destroy_cond(game->_priv.bsod_cond);

View file

@ -267,14 +267,23 @@ static inline bool MainloopTick(struct Game* game) {
while (tmp) { while (tmp) {
if (tmp->pending_unload) { if (tmp->pending_unload) {
#ifdef __EMSCRIPTEN__
al_detach_voice(game->audio.v);
#endif
PrintConsole(game, "Unloading gamestate \"%s\"...", tmp->name); PrintConsole(game, "Unloading gamestate \"%s\"...", tmp->name);
tmp->loaded = false; tmp->loaded = false;
tmp->pending_unload = false; tmp->pending_unload = false;
game->_priv.current_gamestate = tmp; game->_priv.current_gamestate = tmp;
(*tmp->api->unload)(game, tmp->data); (*tmp->api->unload)(game, tmp->data);
PrintConsole(game, "Gamestate \"%s\" unloaded successfully.", tmp->name); PrintConsole(game, "Gamestate \"%s\" unloaded successfully.", tmp->name);
#ifdef __EMSCRIPTEN__
al_attach_mixer_to_voice(game->audio.mixer, game->audio.v);
#endif
} }
if (tmp->pending_load) { if (tmp->pending_load) {
#ifdef __EMSCRIPTEN__
al_detach_voice(game->audio.v);
#endif
if (tmp->show_loading) { if (tmp->show_loading) {
(*game->_priv.loading.gamestate->api->start)(game, game->_priv.loading.gamestate->data); (*game->_priv.loading.gamestate->api->start)(game, game->_priv.loading.gamestate->data);
} }
@ -371,6 +380,9 @@ static inline bool MainloopTick(struct Game* game) {
} }
tmp->show_loading = true; tmp->show_loading = true;
game->_priv.timestamp = al_get_time(); game->_priv.timestamp = al_get_time();
#ifdef __EMSCRIPTEN__
al_attach_mixer_to_voice(game->audio.mixer, game->audio.v);
#endif
} }
tmp = tmp->next; tmp = tmp->next;