add support for routing the loading gamestate through compositor

This commit is contained in:
Sebastian Krzyszkowiak 2018-11-22 04:53:51 +01:00
parent 7f7c522b3c
commit 6c59ef1049
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
5 changed files with 32 additions and 15 deletions

View file

@ -34,6 +34,9 @@ SYMBOL_INTERNAL void SimpleCompositor(struct Game* game, struct Gamestate* games
} }
tmp = tmp->next; tmp = tmp->next;
} }
if (game->_priv.loading.inProgress) {
al_draw_bitmap(game->loading_fb, 0, 0, 0);
}
} }
SYMBOL_INTERNAL void DrawGamestates(struct Game* game) { SYMBOL_INTERNAL void DrawGamestates(struct Game* game) {
@ -57,6 +60,16 @@ SYMBOL_INTERNAL void DrawGamestates(struct Game* game) {
tmp = tmp->next; tmp = tmp->next;
} }
if (game->_priv.loading.inProgress) {
// same as above, but for the loading gamestate
game->_priv.current_gamestate = NULL;
SetFramebufferAsTarget(game);
if (game->handlers.compositor) {
al_clear_to_color(al_map_rgb(0, 0, 0));
}
game->_priv.loading.gamestate->api->Gamestate_Draw(game, game->_priv.loading.gamestate->data);
}
if (game->handlers.compositor) { if (game->handlers.compositor) {
ALLEGRO_TRANSFORM t; ALLEGRO_TRANSFORM t;
al_set_target_backbuffer(game->display); al_set_target_backbuffer(game->display);
@ -163,6 +176,12 @@ SYMBOL_INTERNAL void ResizeGamestates(struct Game* game) {
} }
tmp = tmp->next; tmp = tmp->next;
} }
al_destroy_bitmap(game->loading_fb);
if (game->handlers.compositor) {
game->loading_fb = CreateNotPreservedBitmap(game->_priv.clip_rect.w, game->_priv.clip_rect.h);
} else {
game->loading_fb = al_create_sub_bitmap(al_get_backbuffer(game->display), game->_priv.clip_rect.x, game->_priv.clip_rect.y, game->_priv.clip_rect.w, game->_priv.clip_rect.h);
}
} }
SYMBOL_INTERNAL void DrawConsole(struct Game* game) { SYMBOL_INTERNAL void DrawConsole(struct Game* game) {
@ -278,13 +297,10 @@ SYMBOL_INTERNAL void GamestateProgress(struct Game* game) {
al_unlock_mutex(game->_priv.texture_sync_mutex); al_unlock_mutex(game->_priv.texture_sync_mutex);
#else #else
al_convert_memory_bitmaps(); al_convert_memory_bitmaps();
DrawGamestates(game);
SetFramebufferAsTarget(game);
al_clear_to_color(al_map_rgb(0, 0, 0));
double delta = al_get_time() - game->_priv.loading.time; double delta = al_get_time() - game->_priv.loading.time;
if (game->_priv.loading.current->showLoading) { if (game->_priv.loading.current->showLoading) {
game->_priv.loading.gamestate->api->Gamestate_Logic(game, game->_priv.loading.gamestate->data, delta); game->_priv.loading.gamestate->api->Gamestate_Logic(game, game->_priv.loading.gamestate->data, delta);
game->_priv.loading.gamestate->api->Gamestate_Draw(game, game->_priv.loading.gamestate->data); DrawGamestates(game);
} }
game->_priv.loading.time += delta; game->_priv.loading.time += delta;
DrawConsole(game); DrawConsole(game);

View file

@ -317,6 +317,12 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
game->loading_progress = 0; game->loading_progress = 0;
if (game->handlers.compositor) {
game->loading_fb = CreateNotPreservedBitmap(game->_priv.clip_rect.w, game->_priv.clip_rect.h);
} else {
game->loading_fb = al_create_sub_bitmap(al_get_backbuffer(game->display), game->_priv.clip_rect.x, game->_priv.clip_rect.y, game->_priv.clip_rect.w, game->_priv.clip_rect.h);
}
return game; return game;
} }

View file

@ -110,8 +110,6 @@ struct Game {
bool showconsole; /*!< If true, game console is rendered on screen. */ bool showconsole; /*!< If true, game console is rendered on screen. */
bool showtimeline; bool showtimeline;
ALLEGRO_BITMAP* fb; /*!< Default framebuffer. */
struct { struct {
double old_time, fps, time; double old_time, fps, time;
int frames_done; int frames_done;
@ -171,6 +169,7 @@ struct Game {
ALLEGRO_EVENT_SOURCE event_source; ALLEGRO_EVENT_SOURCE event_source;
float loading_progress; float loading_progress;
ALLEGRO_BITMAP* loading_fb;
struct { struct {
bool (*event)(struct Game* game, ALLEGRO_EVENT* ev); bool (*event)(struct Game* game, ALLEGRO_EVENT* ev);

View file

@ -250,16 +250,10 @@ static inline bool MainloopTick(struct Game* game) {
#ifndef LIBSUPERDERPY_SINGLE_THREAD #ifndef LIBSUPERDERPY_SINGLE_THREAD
al_run_detached_thread(GamestateLoadingThread, &data); al_run_detached_thread(GamestateLoadingThread, &data);
while (game->_priv.loading.inProgress) { while (game->_priv.loading.inProgress) {
DrawGamestates(game);
SetFramebufferAsTarget(game);
al_clear_to_color(al_map_rgb(0, 0, 0));
double delta = al_get_time() - game->_priv.loading.time; double delta = al_get_time() - game->_priv.loading.time;
if (tmp->showLoading) { if (tmp->showLoading) {
(*game->_priv.loading.gamestate->api->Gamestate_Logic)(game, game->_priv.loading.gamestate->data, delta); (*game->_priv.loading.gamestate->api->Gamestate_Logic)(game, game->_priv.loading.gamestate->data, delta);
(*game->_priv.loading.gamestate->api->Gamestate_Draw)(game, game->_priv.loading.gamestate->data); DrawGamestates(game);
if (game->handlers.postdraw) {
game->handlers.postdraw(game);
}
} }
game->_priv.loading.time += delta; game->_priv.loading.time += delta;
game->time += delta; // TODO: ability to disable passing time during loading game->time += delta; // TODO: ability to disable passing time during loading
@ -284,6 +278,8 @@ static inline bool MainloopTick(struct Game* game) {
tmp->api->Gamestate_PostLoad(game, tmp->data); tmp->api->Gamestate_PostLoad(game, tmp->data);
} }
tmp->showLoading = true;
game->_priv.loading.progress++; game->_priv.loading.progress++;
CalculateProgress(game); CalculateProgress(game);
PrintConsole(game, "Gamestate \"%s\" loaded successfully in %f seconds.", tmp->name, al_get_time() - time); PrintConsole(game, "Gamestate \"%s\" loaded successfully in %f seconds.", tmp->name, al_get_time() - time);

View file

@ -486,8 +486,8 @@ SYMBOL_EXPORT void WindowCoordsToViewport(struct Game* game, int* x, int* y) {
} }
SYMBOL_EXPORT ALLEGRO_BITMAP* GetFramebuffer(struct Game* game) { SYMBOL_EXPORT ALLEGRO_BITMAP* GetFramebuffer(struct Game* game) {
if (game->_priv.loading.inProgress) { if (!game->_priv.current_gamestate) {
return al_get_backbuffer(game->display); return game->loading_fb;
} }
return game->_priv.current_gamestate->fb; return game->_priv.current_gamestate->fb;
} }