proper gamestate freezing on suspending android activity

This commit is contained in:
Sebastian Krzyszkowiak 2016-11-09 00:40:13 +01:00
parent fd7f68d616
commit 4b53b59e05
5 changed files with 28 additions and 2 deletions

View file

@ -39,6 +39,7 @@ SYMBOL_INTERNAL struct Gamestate* AddNewGamestate(struct Game *game, const char*
tmp->handle = NULL; tmp->handle = NULL;
tmp->loaded = false; tmp->loaded = false;
tmp->paused = false; tmp->paused = false;
tmp->frozen = false;
tmp->started = false; tmp->started = false;
tmp->pending_load = false; tmp->pending_load = false;
tmp->pending_start = false; tmp->pending_start = false;

View file

@ -47,6 +47,7 @@ struct Gamestate {
void* handle; void* handle;
bool loaded, pending_load, pending_unload; bool loaded, pending_load, pending_unload;
bool started, pending_start, pending_stop; bool started, pending_start, pending_stop;
bool frozen;
bool showLoading; bool showLoading;
bool paused; bool paused;
struct Gamestate *next; struct Gamestate *next;

View file

@ -58,6 +58,28 @@ SYMBOL_INTERNAL void EventGamestates(struct Game *game, ALLEGRO_EVENT *ev) {
} }
} }
SYMBOL_INTERNAL void FreezeGamestates(struct Game *game) {
struct Gamestate *tmp = game->_priv.gamestates;
while (tmp) {
if (tmp->started || !tmp->paused) {
PauseGamestate(game, tmp->name);
tmp->frozen = true;
}
tmp = tmp->next;
}
}
SYMBOL_INTERNAL void UnfreezeGamestates(struct Game *game) {
struct Gamestate *tmp = game->_priv.gamestates;
while (tmp) {
if (tmp->frozen) {
ResumeGamestate(game, tmp->name);
tmp->frozen = false;
}
tmp = tmp->next;
}
}
SYMBOL_INTERNAL void DrawConsole(struct Game *game) { SYMBOL_INTERNAL void DrawConsole(struct Game *game) {
if (game->_priv.showconsole) { if (game->_priv.showconsole) {
al_set_target_backbuffer(game->display); al_set_target_backbuffer(game->display);

View file

@ -46,6 +46,8 @@ struct libsuperderpy_list {
void DrawGamestates(struct Game *game); void DrawGamestates(struct Game *game);
void LogicGamestates(struct Game *game); void LogicGamestates(struct Game *game);
void EventGamestates(struct Game *game, ALLEGRO_EVENT *ev); void EventGamestates(struct Game *game, ALLEGRO_EVENT *ev);
void FreezeGamestates(struct Game *game);
void UnfreezeGamestates(struct Game *game);
void DrawConsole(struct Game *game); void DrawConsole(struct Game *game);
void Console_Load(struct Game *game); void Console_Load(struct Game *game);
void Console_Unload(struct Game *game); void Console_Unload(struct Game *game);

View file

@ -419,7 +419,7 @@ SYMBOL_EXPORT int libsuperderpy_run(struct Game *game) {
game->_priv.draw = false; game->_priv.draw = false;
al_stop_timer(game->_priv.timer); al_stop_timer(game->_priv.timer);
al_detach_voice(game->audio.v); al_detach_voice(game->audio.v);
PauseAllGamestates(game); // TODO: store not paused gamestates FreezeGamestates(game);
al_acknowledge_drawing_halt(game->display); al_acknowledge_drawing_halt(game->display);
} }
else if(ev.type == ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING) { else if(ev.type == ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING) {
@ -427,7 +427,7 @@ SYMBOL_EXPORT int libsuperderpy_run(struct Game *game) {
PrintConsole(game, "resume drawing"); PrintConsole(game, "resume drawing");
game->_priv.draw = true; game->_priv.draw = true;
SetupViewport(game, game->viewport_config); SetupViewport(game, game->viewport_config);
ResumeAllGamestates(game); // FIXME: resumes even those that were paused earlier! UnfreezeGamestates(game);
al_attach_mixer_to_voice(game->audio.mixer, game->audio.v); al_attach_mixer_to_voice(game->audio.mixer, game->audio.v);
al_resume_timer(game->_priv.timer); al_resume_timer(game->_priv.timer);
} }