mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 02:56:43 +01:00
proper gamestate freezing on suspending android activity
This commit is contained in:
parent
fd7f68d616
commit
4b53b59e05
5 changed files with 28 additions and 2 deletions
|
@ -39,6 +39,7 @@ SYMBOL_INTERNAL struct Gamestate* AddNewGamestate(struct Game *game, const char*
|
|||
tmp->handle = NULL;
|
||||
tmp->loaded = false;
|
||||
tmp->paused = false;
|
||||
tmp->frozen = false;
|
||||
tmp->started = false;
|
||||
tmp->pending_load = false;
|
||||
tmp->pending_start = false;
|
||||
|
|
|
@ -47,6 +47,7 @@ struct Gamestate {
|
|||
void* handle;
|
||||
bool loaded, pending_load, pending_unload;
|
||||
bool started, pending_start, pending_stop;
|
||||
bool frozen;
|
||||
bool showLoading;
|
||||
bool paused;
|
||||
struct Gamestate *next;
|
||||
|
|
|
@ -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) {
|
||||
if (game->_priv.showconsole) {
|
||||
al_set_target_backbuffer(game->display);
|
||||
|
|
|
@ -46,6 +46,8 @@ struct libsuperderpy_list {
|
|||
void DrawGamestates(struct Game *game);
|
||||
void LogicGamestates(struct Game *game);
|
||||
void EventGamestates(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void FreezeGamestates(struct Game *game);
|
||||
void UnfreezeGamestates(struct Game *game);
|
||||
void DrawConsole(struct Game *game);
|
||||
void Console_Load(struct Game *game);
|
||||
void Console_Unload(struct Game *game);
|
||||
|
|
|
@ -419,7 +419,7 @@ SYMBOL_EXPORT int libsuperderpy_run(struct Game *game) {
|
|||
game->_priv.draw = false;
|
||||
al_stop_timer(game->_priv.timer);
|
||||
al_detach_voice(game->audio.v);
|
||||
PauseAllGamestates(game); // TODO: store not paused gamestates
|
||||
FreezeGamestates(game);
|
||||
al_acknowledge_drawing_halt(game->display);
|
||||
}
|
||||
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");
|
||||
game->_priv.draw = true;
|
||||
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_resume_timer(game->_priv.timer);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue