From fbedd1c7e787841893913206f7f4a2577c555ed5 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Fri, 2 Nov 2018 06:10:34 +0100 Subject: [PATCH] some stuff blocked by allegro bugs --- src/internal.c | 25 ++++++++++++++++++++++++- src/libsuperderpy.c | 2 ++ src/libsuperderpy.h | 1 + src/mainloop.c | 25 ++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/internal.c b/src/internal.c index db4690b..5b7638f 100644 --- a/src/internal.c +++ b/src/internal.c @@ -555,7 +555,11 @@ SYMBOL_INTERNAL void PauseExecution(struct Game* game) { } game->_priv.paused = true; al_stop_timer(game->_priv.timer); + if (game->audio.v) { al_detach_voice(game->audio.v); + } + al_set_default_voice(NULL); + game->audio.v = NULL; FreezeGamestates(game); PrintConsole(game, "Engine halted."); } @@ -589,7 +593,26 @@ SYMBOL_INTERNAL void ResumeExecution(struct Game* game) { return; } UnfreezeGamestates(game); - al_attach_mixer_to_voice(game->audio.mixer, game->audio.v); + ALLEGRO_AUDIO_DEPTH depth = ALLEGRO_AUDIO_DEPTH_FLOAT32; +#ifdef ALLEGRO_ANDROID + depth = ALLEGRO_AUDIO_DEPTH_INT16; +#endif + game->audio.v = al_create_voice(44100, depth, ALLEGRO_CHANNEL_CONF_2); + if (!game->audio.v) { + // fallback + depth = (depth == ALLEGRO_AUDIO_DEPTH_FLOAT32) ? ALLEGRO_AUDIO_DEPTH_INT16 : ALLEGRO_AUDIO_DEPTH_FLOAT32; + game->audio.v = al_create_voice(44100, depth, ALLEGRO_CHANNEL_CONF_2); + } + al_set_default_voice(game->audio.v); + if (game->audio.v) { + al_attach_mixer_to_voice(game->audio.mixer, game->audio.v); + } else { + PrintConsole(game, "AUUUDIOOOOOOO DIDN'T WOOOORK"); + } + //al_set_mixer_playing(game->audio.mixer, true); + //al_set_mixer_playing(game->audio.music, true); + //al_set_mixer_playing(game->audio.fx, true); + //al_set_mixer_playing(game->audio.voice, true); al_resume_timer(game->_priv.timer); game->_priv.paused = false; game->_priv.timestamp = al_get_time(); diff --git a/src/libsuperderpy.c b/src/libsuperderpy.c index 6910fc5..c41eb5e 100644 --- a/src/libsuperderpy.c +++ b/src/libsuperderpy.c @@ -96,6 +96,7 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char* game->_priv.shaders = NULL; game->_priv.paused = false; + game->_priv.candraw = true; game->handlers.event = NULL; game->handlers.destroy = NULL; @@ -301,6 +302,7 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char* al_set_mixer_gain(game->audio.music, game->config.music / 10.0); al_set_mixer_gain(game->audio.voice, game->config.voice / 10.0); al_set_mixer_gain(game->audio.mixer, game->config.mute ? 0.0 : 1.0); + al_set_default_voice(game->audio.v); al_set_default_mixer(game->audio.mixer); setlocale(LC_NUMERIC, "C"); diff --git a/src/libsuperderpy.h b/src/libsuperderpy.h index 72ad492..db56d56 100644 --- a/src/libsuperderpy.h +++ b/src/libsuperderpy.h @@ -143,6 +143,7 @@ struct Game { } clip_rect; bool paused; + bool candraw; volatile bool texture_sync; ALLEGRO_MUTEX* texture_sync_mutex; diff --git a/src/mainloop.c b/src/mainloop.c index b30a31c..067b2c0 100644 --- a/src/mainloop.c +++ b/src/mainloop.c @@ -32,15 +32,35 @@ static inline void HandleEvent(struct Game* game, ALLEGRO_EVENT* ev) { break; case ALLEGRO_EVENT_DISPLAY_HALT_DRAWING: - PauseExecution(game); + PrintConsole(game, "ALLEGRO_EVENT_DISPLAY_HALT_DRAWING"); al_acknowledge_drawing_halt(game->display); + PauseExecution(game); + game->_priv.candraw = false; break; case ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING: + PrintConsole(game, "ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING"); al_acknowledge_drawing_resume(game->display); + game->_priv.candraw = true; ReloadGamestates(game); ResumeExecution(game); break; + +#ifdef ALLEGRO_ANDROID + /* + case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT: + PrintConsole(game, "ALLEGRO_EVENT_DISPLAY_SWITCH_OUT"); + PauseExecution(game); + break; + + case ALLEGRO_EVENT_DISPLAY_SWITCH_IN: + PrintConsole(game, "ALLEGRO_EVENT_DISPLAY_SWITCH_IN"); + if (game->_priv.candraw) { + ResumeExecution(game); + } + break; + */ +#endif case ALLEGRO_EVENT_DISPLAY_RESIZE: al_acknowledge_resize(game->display); @@ -353,10 +373,13 @@ static inline bool MainloopEvents(struct Game* game) { if (game->_priv.paused) { // there's no frame flipping when paused, so avoid pointless busylooping + PrintConsole(game, "waiting for events"); al_wait_for_event(game->_priv.event_queue, &ev); } else if (!al_get_next_event(game->_priv.event_queue, &ev)) { + PrintConsole(game, "breaking from events"); break; } + PrintConsole(game, "handling an event"); if (game->handlers.event) { if ((*game->handlers.event)(game, &ev)) {