mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-07 21:56:44 +01:00
emscripten: Destroy and recreate audio voice when in loading routines
This prevents awful audio stuttering in Blink based browsers.
This commit is contained in:
parent
e4925f2ecb
commit
6c56bb36b9
3 changed files with 13 additions and 4 deletions
|
@ -213,6 +213,14 @@ SYMBOL_INTERNAL int SetupAudio(struct Game* game) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
SYMBOL_INTERNAL void StopAudio(struct Game* game) {
|
||||
if (game->audio.v) {
|
||||
al_detach_voice(game->audio.v);
|
||||
}
|
||||
al_set_default_voice(NULL);
|
||||
game->audio.v = NULL;
|
||||
}
|
||||
|
||||
SYMBOL_INTERNAL void DrawConsole(struct Game* game) {
|
||||
double game_time = al_get_time();
|
||||
if (game->show_console) {
|
||||
|
|
|
@ -107,6 +107,7 @@ void FreezeGamestates(struct Game* game);
|
|||
void UnfreezeGamestates(struct Game* game);
|
||||
void ResizeGamestates(struct Game* game);
|
||||
int SetupAudio(struct Game* game);
|
||||
void StopAudio(struct Game* game);
|
||||
void DrawConsole(struct Game* game);
|
||||
void Console_Load(struct Game* game);
|
||||
void Console_Unload(struct Game* game);
|
||||
|
|
|
@ -311,7 +311,7 @@ static inline bool MainloopTick(struct Game* game) {
|
|||
while (tmp) {
|
||||
if (tmp->pending_unload) {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
al_detach_voice(game->audio.v);
|
||||
StopAudio(game);
|
||||
#endif
|
||||
PrintConsole(game, "Unloading gamestate \"%s\"...", tmp->name);
|
||||
tmp->loaded = false;
|
||||
|
@ -320,12 +320,12 @@ static inline bool MainloopTick(struct Game* game) {
|
|||
(*tmp->api->unload)(game, tmp->data);
|
||||
PrintConsole(game, "Gamestate \"%s\" unloaded successfully.", tmp->name);
|
||||
#ifdef __EMSCRIPTEN__
|
||||
al_attach_mixer_to_voice(game->audio.mixer, game->audio.v);
|
||||
SetupAudio(game);
|
||||
#endif
|
||||
}
|
||||
if (tmp->pending_load) {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
al_detach_voice(game->audio.v);
|
||||
StopAudio(game);
|
||||
#endif
|
||||
if (tmp->show_loading && game->_priv.loading.gamestate->open) {
|
||||
(*game->_priv.loading.gamestate->api->start)(game, game->_priv.loading.gamestate->data);
|
||||
|
@ -434,7 +434,7 @@ static inline bool MainloopTick(struct Game* game) {
|
|||
game->loading.shown = false;
|
||||
game->_priv.timestamp = al_get_time();
|
||||
#ifdef __EMSCRIPTEN__
|
||||
al_attach_mixer_to_voice(game->audio.mixer, game->audio.v);
|
||||
SetupAudio(game);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue