mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-03-04 17:21:27 +01:00
gamestate reloading and fix for calling Gamestate_Pause/Gamestate_Resume
This commit is contained in:
parent
4b53b59e05
commit
fdd48433bc
5 changed files with 32 additions and 14 deletions
|
@ -159,6 +159,10 @@ SYMBOL_EXPORT void PauseGamestate(struct Game *game, const char* name) {
|
|||
return;
|
||||
}
|
||||
gs->paused = true;
|
||||
if (!gs->frozen) {
|
||||
game->_priv.current_gamestate = gs;
|
||||
(*gs->api->Gamestate_Pause)(game, gs->data);
|
||||
}
|
||||
PrintConsole(game, "Gamestate \"%s\" paused.", name);
|
||||
} else {
|
||||
PrintConsole(game, "Tried to pause nonexisitent gamestate \"%s\"", name);
|
||||
|
@ -177,6 +181,10 @@ SYMBOL_EXPORT void ResumeGamestate(struct Game *game, const char* name) {
|
|||
return;
|
||||
}
|
||||
gs->paused = false;
|
||||
if (!gs->frozen) {
|
||||
game->_priv.current_gamestate = gs;
|
||||
(*gs->api->Gamestate_Resume)(game, gs->data);
|
||||
}
|
||||
PrintConsole(game, "Gamestate \"%s\" resumed.", name);
|
||||
} else {
|
||||
PrintConsole(game, "Tried to resume nonexisitent gamestate \"%s\"", name);
|
||||
|
|
|
@ -47,6 +47,17 @@ SYMBOL_INTERNAL void LogicGamestates(struct Game *game) {
|
|||
}
|
||||
}
|
||||
|
||||
SYMBOL_INTERNAL void ReloadGamestates(struct Game *game) {
|
||||
struct Gamestate *tmp = game->_priv.gamestates;
|
||||
while (tmp) {
|
||||
if (tmp->loaded) {
|
||||
game->_priv.current_gamestate = tmp;
|
||||
(*tmp->api->Gamestate_Reload)(game, tmp->data);
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
}
|
||||
|
||||
SYMBOL_INTERNAL void EventGamestates(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||
struct Gamestate *tmp = game->_priv.gamestates;
|
||||
while (tmp) {
|
||||
|
@ -61,9 +72,9 @@ 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);
|
||||
if (tmp->started && !tmp->paused) {
|
||||
tmp->frozen = true;
|
||||
PauseGamestate(game, tmp->name);
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ struct libsuperderpy_list {
|
|||
void DrawGamestates(struct Game *game);
|
||||
void LogicGamestates(struct Game *game);
|
||||
void EventGamestates(struct Game *game, ALLEGRO_EVENT *ev);
|
||||
void ReloadGamestates(struct Game *game);
|
||||
void FreezeGamestates(struct Game *game);
|
||||
void UnfreezeGamestates(struct Game *game);
|
||||
void DrawConsole(struct Game *game);
|
||||
|
|
|
@ -411,11 +411,8 @@ SYMBOL_EXPORT int libsuperderpy_run(struct Game *game) {
|
|||
else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
|
||||
break;
|
||||
}
|
||||
else if(ev.type == ALLEGRO_EVENT_DISPLAY_FOUND) {
|
||||
SetupViewport(game, game->viewport_config);
|
||||
}
|
||||
else if(ev.type == ALLEGRO_EVENT_DISPLAY_HALT_DRAWING) {
|
||||
PrintConsole(game, "halt drawing");
|
||||
PrintConsole(game, "Engine halted.");
|
||||
game->_priv.draw = false;
|
||||
al_stop_timer(game->_priv.timer);
|
||||
al_detach_voice(game->audio.v);
|
||||
|
@ -423,19 +420,17 @@ SYMBOL_EXPORT int libsuperderpy_run(struct Game *game) {
|
|||
al_acknowledge_drawing_halt(game->display);
|
||||
}
|
||||
else if(ev.type == ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING) {
|
||||
al_acknowledge_drawing_resume(game->display);
|
||||
PrintConsole(game, "resume drawing");
|
||||
game->_priv.draw = true;
|
||||
SetupViewport(game, game->viewport_config);
|
||||
al_acknowledge_drawing_resume(game->display);
|
||||
PrintConsole(game, "Engine resumed.");
|
||||
ReloadGamestates(game);
|
||||
UnfreezeGamestates(game);
|
||||
al_attach_mixer_to_voice(game->audio.mixer, game->audio.v);
|
||||
al_resume_timer(game->_priv.timer);
|
||||
}
|
||||
else if(ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE) {
|
||||
al_acknowledge_resize(game->display);
|
||||
if (game->_priv.draw) {
|
||||
SetupViewport(game, game->viewport_config);
|
||||
}
|
||||
SetupViewport(game, game->viewport_config);
|
||||
}
|
||||
#ifdef ALLEGRO_MACOSX
|
||||
else if ((ev.type == ALLEGRO_EVENT_KEY_DOWN) && (ev.keyboard.keycode == 104)) { //TODO: report to upstream
|
||||
|
|
|
@ -164,11 +164,14 @@ SYMBOL_EXPORT ALLEGRO_BITMAP* LoadScaledBitmap(struct Game *game, char* filename
|
|||
al_clear_to_color(al_map_rgba(0,0,0,0));
|
||||
char* origfn = GetDataFilePath(game, filename);
|
||||
|
||||
if (memoryscale) al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
|
||||
int flags = al_get_new_bitmap_flags();
|
||||
if (memoryscale) {
|
||||
al_add_new_bitmap_flag(ALLEGRO_MEMORY_BITMAP);
|
||||
}
|
||||
|
||||
source = al_load_bitmap( origfn );
|
||||
if (memoryscale) {
|
||||
al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR);
|
||||
al_set_new_bitmap_flags(flags);
|
||||
ScaleBitmap(source, width, height);
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Reference in a new issue